From 569c4ac21864d9576717650814c6d84fb0c8166a Mon Sep 17 00:00:00 2001 From: Alexander Stein Date: Wed, 19 Dec 2012 17:56:00 +0000 Subject: iio: Fix some comments Signed-off-by: Alexander Stein Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c index a865adf..aee76c7 100644 --- a/drivers/staging/iio/iio_simple_dummy.c +++ b/drivers/staging/iio/iio_simple_dummy.c @@ -54,7 +54,7 @@ struct iio_dummy_accel_calibscale { static const struct iio_dummy_accel_calibscale dummy_scales[] = { { 0, 100, 0x8 }, /* 0.000100 */ { 0, 133, 0x7 }, /* 0.000133 */ - { 733, 13, 0x9 }, /* 733.00013 */ + { 733, 13, 0x9 }, /* 733.000013 */ }; /* @@ -284,7 +284,7 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev, /** * iio_dummy_write_raw() - data write function. * @indio_dev: the struct iio_dev associated with this device instance - * @chan: the channel whose data is to be read + * @chan: the channel whose data is to be written * @val: first element of value to set (typically INT) * @val2: second element of value to set (typically MICRO) * @mask: what we actually want to write. 0 is the channel, everything else diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c index dee16f0..72f400c 100644 --- a/drivers/staging/iio/iio_simple_dummy_buffer.c +++ b/drivers/staging/iio/iio_simple_dummy_buffer.c @@ -155,7 +155,7 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev, * occurs, this function is run. Typically this grabs data * from the device. * - * NULL for the top half. This is normally implemented only if we + * NULL for the bottom half. This is normally implemented only if we * either want to ping a capture now pin (no sleeping) or grab * a timestamp as close as possible to a data ready trigger firing. * -- cgit v0.10.2 From 99e02018df52e9bf723ea3f0c18cf412c7e75108 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 14 Dec 2012 01:46:00 +0000 Subject: iio: mxs: Remove unused struct mxs_lradc_chan This structure definition seems to be some kind of remnant from previous development that accidentally made it mainline. Remove it as it's unused. Remove unused "enable" field from struct mxs_lradc as well. This seems to be remnant of early development too. Signed-off-by: Marek Vasut Cc: Fabio Estevam Cc: Jonathan Cameron Cc: Shawn Guo Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index fb31b45..3a4d5f0 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -75,11 +75,6 @@ static const char * const mxs_lradc_irq_name[] = { "mxs-lradc-button1", }; -struct mxs_lradc_chan { - uint8_t slot; - uint8_t flags; -}; - struct mxs_lradc { struct device *dev; void __iomem *base; @@ -90,8 +85,6 @@ struct mxs_lradc { struct mutex lock; - uint8_t enable; - struct completion completion; }; -- cgit v0.10.2 From 4389fbec5b8fd0577c1e854ff5d7139329558c20 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Sun, 30 Dec 2012 23:26:00 +0000 Subject: iio: cleanup buffer setup code in max1363 driver use iio_triggered_buffer_setup(), iio_triggered_buffer_cleanup() Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 1e84b5b..46d8365 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -39,6 +39,7 @@ #include #include #include +#include #define MAX1363_SETUP_BYTE(a) ((a) | 0x80) @@ -1483,48 +1484,6 @@ static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = { .predisable = &iio_triggered_buffer_predisable, }; -static int max1363_register_buffered_funcs_and_init(struct iio_dev *indio_dev) -{ - struct max1363_state *st = iio_priv(indio_dev); - int ret = 0; - - indio_dev->buffer = iio_kfifo_allocate(indio_dev); - if (!indio_dev->buffer) { - ret = -ENOMEM; - goto error_ret; - } - indio_dev->pollfunc = iio_alloc_pollfunc(NULL, - &max1363_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - st->client->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_deallocate_sw_rb; - } - /* Buffer functions - here trigger setup related */ - indio_dev->setup_ops = &max1363_buffered_setup_ops; - - /* Flag that polled buffering is possible */ - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - - return 0; - -error_deallocate_sw_rb: - iio_kfifo_free(indio_dev->buffer); -error_ret: - return ret; -} - -static void max1363_buffer_cleanup(struct iio_dev *indio_dev) -{ - /* ensure that the trigger has been detached */ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_kfifo_free(indio_dev->buffer); -} - static int __devinit max1363_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1577,16 +1536,11 @@ static int __devinit max1363_probe(struct i2c_client *client, if (ret < 0) goto error_free_available_scan_masks; - ret = max1363_register_buffered_funcs_and_init(indio_dev); + ret = iio_triggered_buffer_setup(indio_dev, NULL, + &max1363_trigger_handler, &max1363_buffered_setup_ops); if (ret) goto error_free_available_scan_masks; - ret = iio_buffer_register(indio_dev, - st->chip_info->channels, - st->chip_info->num_channels); - if (ret) - goto error_cleanup_buffer; - if (client->irq) { ret = request_threaded_irq(st->client->irq, NULL, @@ -1607,9 +1561,7 @@ static int __devinit max1363_probe(struct i2c_client *client, error_free_irq: free_irq(st->client->irq, indio_dev); error_uninit_buffer: - iio_buffer_unregister(indio_dev); -error_cleanup_buffer: - max1363_buffer_cleanup(indio_dev); + iio_triggered_buffer_cleanup(indio_dev); error_free_available_scan_masks: kfree(indio_dev->available_scan_masks); error_unregister_map: @@ -1632,8 +1584,7 @@ static int __devexit max1363_remove(struct i2c_client *client) iio_device_unregister(indio_dev); if (client->irq) free_irq(st->client->irq, indio_dev); - iio_buffer_unregister(indio_dev); - max1363_buffer_cleanup(indio_dev); + iio_triggered_buffer_cleanup(indio_dev); kfree(indio_dev->available_scan_masks); if (!IS_ERR(st->reg)) { regulator_disable(st->reg); -- cgit v0.10.2 From 71d2c120fda094d14339bdbe6ff0a9328154940d Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Sun, 30 Dec 2012 23:26:00 +0000 Subject: iio: max1363 comment and whitespace fixes Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 46d8365..0ba4fea 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -56,7 +56,7 @@ #define MAX1363_SETUP_POWER_UP_INT_REF 0x10 #define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00 -/* think about includeing max11600 etc - more settings */ +/* think about including max11600 etc - more settings */ #define MAX1363_SETUP_EXT_CLOCK 0x08 #define MAX1363_SETUP_INT_CLOCK 0x00 #define MAX1363_SETUP_UNIPOLAR 0x00 @@ -87,7 +87,7 @@ /* max123{6-9} only */ #define MAX1236_SCAN_MID_TO_CHANNEL 0x40 -/* max1363 only - merely part of channel selects or don't care for others*/ +/* max1363 only - merely part of channel selects or don't care for others */ #define MAX1363_CONFIG_EN_MON_MODE_READ 0x18 #define MAX1363_CHANNEL_SEL(a) ((a) << 1) @@ -134,7 +134,7 @@ enum max1363_modes { * @mode_list: array of available scan modes * @default_mode: the scan mode in which the chip starts up * @int_vref_mv: the internal reference voltage - * @num_channels: number of channels + * @num_modes: number of modes * @bits: accuracy of the adc in bits */ struct max1363_chip_info { @@ -153,7 +153,7 @@ struct max1363_chip_info { * @client: i2c_client * @setupbyte: cache of current device setup byte * @configbyte: cache of current device config byte - * @chip_info: chip model specific constants, available modes etc + * @chip_info: chip model specific constants, available modes, etc. * @current_mode: the scan mode of this chip * @requestedmask: a valid requested set of channels * @reg: supply regulator @@ -294,7 +294,7 @@ static const struct max1363_mode max1363_mode_table[] = { static const struct max1363_mode *max1363_match_mode(const unsigned long *mask, -const struct max1363_chip_info *ci) + const struct max1363_chip_info *ci) { int i; if (mask) @@ -1395,7 +1395,7 @@ static int max1363_initial_setup(struct max1363_state *st) | MAX1363_SETUP_UNIPOLAR | MAX1363_SETUP_NORESET; - /* Set scan mode writes the config anyway so wait until then*/ + /* Set scan mode writes the config anyway so wait until then */ st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); @@ -1424,7 +1424,6 @@ static int __devinit max1363_alloc_scan_masks(struct iio_dev *indio_dev) return 0; } - static irqreturn_t max1363_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -1523,7 +1522,7 @@ static int __devinit max1363_probe(struct i2c_client *client, if (ret) goto error_disable_reg; - /* Estabilish that the iio_dev is a child of the i2c device */ + /* Establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; indio_dev->name = id->name; indio_dev->channels = st->chip_info->channels; -- cgit v0.10.2 From dc11699908b270940b1245986236864decb6f8cc Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 3 Jan 2013 06:28:00 +0000 Subject: iio: lp8788_adc: fix a parent device in _probe() The lp8788-adc is a platform driver of lp8788-mfd. The platform device is allocated when mfd_add_devices() is called in lp8788-mfd. On the other hand, 'lp->dev' is the i2c client device. Therefore, this 'platform_device' is a proper parent device of iio device and device kernel message. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c index a93aaf0..9b9c26d 100644 --- a/drivers/iio/adc/lp8788_adc.c +++ b/drivers/iio/adc/lp8788_adc.c @@ -214,7 +214,7 @@ static int __devinit lp8788_adc_probe(struct platform_device *pdev) mutex_init(&adc->lock); - indio_dev->dev.parent = lp->dev; + indio_dev->dev.parent = &pdev->dev; indio_dev->name = pdev->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &lp8788_adc_info; @@ -223,7 +223,7 @@ static int __devinit lp8788_adc_probe(struct platform_device *pdev) ret = iio_device_register(indio_dev); if (ret) { - dev_err(lp->dev, "iio dev register err: %d\n", ret); + dev_err(&pdev->dev, "iio dev register err: %d\n", ret); goto err_iio_device; } -- cgit v0.10.2 From 5306f416ad9e7d6134fc1e357e895e69823975d8 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 3 Jan 2013 06:28:00 +0000 Subject: iio: lp8788_adc: fix parent device in kernel message Use 'dev' of iio device in a kernel message rather than i2c client device node. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c index 9b9c26d..f8ae81c 100644 --- a/drivers/iio/adc/lp8788_adc.c +++ b/drivers/iio/adc/lp8788_adc.c @@ -179,7 +179,7 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev, ret = iio_map_array_register(indio_dev, map); if (ret) { - dev_err(adc->lp->dev, "iio map err: %d\n", ret); + dev_err(&indio_dev->dev, "iio map err: %d\n", ret); return ret; } -- cgit v0.10.2 From 8e3cdca26c9d9f0936c555bc67e2a5d71e61bb0d Mon Sep 17 00:00:00 2001 From: Alexander Holler Date: Sat, 15 Dec 2012 12:45:00 +0000 Subject: iio: Add Usage IDs for HID time sensors. These are Usage IDs for the attributes year, month, day, hour, minute and second, needed to read HID time sensors. Signed-off-by: Alexander Holler Signed-off-by: Jiri Kosina Signed-off-by: Jonathan Cameron diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index 55f2773..6f24446 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -66,6 +66,15 @@ #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS 0x200486 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS 0x200487 +/* Time (2000a0) */ +#define HID_USAGE_SENSOR_TIME 0x2000a0 +#define HID_USAGE_SENSOR_TIME_YEAR 0x200521 +#define HID_USAGE_SENSOR_TIME_MONTH 0x200522 +#define HID_USAGE_SENSOR_TIME_DAY 0x200523 +#define HID_USAGE_SENSOR_TIME_HOUR 0x200525 +#define HID_USAGE_SENSOR_TIME_MINUTE 0x200526 +#define HID_USAGE_SENSOR_TIME_SECOND 0x200527 + /* Units */ #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED 0x00 #define HID_USAGE_SENSOR_UNITS_LUX 0x01 -- cgit v0.10.2 From 2974cdf293e1cb00860522624252aeaba502c8bf Mon Sep 17 00:00:00 2001 From: Alexander Holler Date: Sat, 15 Dec 2012 12:45:00 +0000 Subject: iio: merge hid-sensor-attributes.h into hid-sensor-hub.h The stuff in hid-sensor-attributes.h is needed by every piece which uses hid-sensor-hub and merging it into hid-sensor-hub.h makes it accessible from outside the iio subdirectory. Signed-off-by: Alexander Holler Acked-by: Jiri Kosina Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index e67bb91..268ca3a 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -28,7 +28,6 @@ #include #include #include -#include "../common/hid-sensors/hid-sensor-attributes.h" #include "../common/hid-sensors/hid-sensor-trigger.h" /*Format: HID-SENSOR-usage_id_in_hex*/ diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index 7537495..5873f16 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -25,7 +25,6 @@ #include #include #include -#include "hid-sensor-attributes.h" static int pow_10(unsigned power) { diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h deleted file mode 100644 index a4676a0..0000000 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * HID Sensors Driver - * Copyright (c) 2012, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -#ifndef _HID_SENSORS_ATTRIBUTES_H -#define _HID_SENSORS_ATTRIBUTES_H - -/* Common hid sensor iio structure */ -struct hid_sensor_iio_common { - struct hid_sensor_hub_device *hsdev; - struct platform_device *pdev; - unsigned usage_id; - bool data_ready; - struct hid_sensor_hub_attribute_info poll; - struct hid_sensor_hub_attribute_info report_state; - struct hid_sensor_hub_attribute_info power_state; - struct hid_sensor_hub_attribute_info sensitivity; -}; - -/*Convert from hid unit expo to regular exponent*/ -static inline int hid_sensor_convert_exponent(int unit_expo) -{ - if (unit_expo < 0x08) - return unit_expo; - else if (unit_expo <= 0x0f) - return -(0x0f-unit_expo+1); - else - return 0; -} - -int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, - u32 usage_id, - struct hid_sensor_iio_common *st); -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st, - int val1, int val2); -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st, - int *val1, int *val2); -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st, - int val1, int val2); -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st, - int *val1, int *val2); - -#endif diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index d60198a..7da7380 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -26,7 +26,6 @@ #include #include #include -#include "hid-sensor-attributes.h" #include "hid-sensor-trigger.h" static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index 4c8b158..8d34ee4 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c @@ -28,7 +28,6 @@ #include #include #include -#include "../common/hid-sensors/hid-sensor-attributes.h" #include "../common/hid-sensors/hid-sensor-trigger.h" /*Format: HID-SENSOR-usage_id_in_hex*/ diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 23eeeef..723f203 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -28,7 +28,6 @@ #include #include #include -#include "../common/hid-sensors/hid-sensor-attributes.h" #include "../common/hid-sensors/hid-sensor-trigger.h" /*Format: HID-SENSOR-usage_id_in_hex*/ diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index 8e75eb7..7811c0b 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -28,7 +28,6 @@ #include #include #include -#include "../common/hid-sensors/hid-sensor-attributes.h" #include "../common/hid-sensors/hid-sensor-trigger.h" /*Format: HID-SENSOR-usage_id_in_hex*/ diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index 0aa5f4c..e6265f9 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, */ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, u32 field_index, s32 *value); + +/* hid-sensor-attributes */ + +/* Common hid sensor iio structure */ +struct hid_sensor_iio_common { + struct hid_sensor_hub_device *hsdev; + struct platform_device *pdev; + unsigned usage_id; + bool data_ready; + struct hid_sensor_hub_attribute_info poll; + struct hid_sensor_hub_attribute_info report_state; + struct hid_sensor_hub_attribute_info power_state; + struct hid_sensor_hub_attribute_info sensitivity; +}; + +/*Convert from hid unit expo to regular exponent*/ +static inline int hid_sensor_convert_exponent(int unit_expo) +{ + if (unit_expo < 0x08) + return unit_expo; + else if (unit_expo <= 0x0f) + return -(0x0f-unit_expo+1); + else + return 0; +} + +int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, + u32 usage_id, + struct hid_sensor_iio_common *st); +int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st, + int val1, int val2); +int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st, + int *val1, int *val2); +int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st, + int val1, int val2); +int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st, + int *val1, int *val2); + #endif -- cgit v0.10.2 From 62e00cb9a39a889c39a4241645e860284a975e6d Mon Sep 17 00:00:00 2001 From: Alexander Holler Date: Sat, 15 Dec 2012 12:45:00 +0000 Subject: rtc: add rtc-driver for HID sensors of type time This driver makes the time from HID sensors (hubs) which are offering such available like any other RTC does. It is necessary that all values like year, month etc, are send as 8bit values (1 byte each) and all of them in 1 report. Also the spec HUTRR39b doesn't define the range of the year field, we tread it as 0 - 99 because that's what most RTCs I know about are offering. Currently the time can only be read. Setting the time must be done through sending a report (or a feature). The spec currently doesn't define how and I'm not sure if I just should define something by myself. Signed-off-by: Alexander Holler Signed-off-by: Jonathan Cameron diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index d0cea02..eed335c 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1165,4 +1165,20 @@ config RTC_DRV_SNVS This driver can also be built as a module, if so, the module will be called "rtc-snvs". +comment "HID Sensor RTC drivers" + +config RTC_DRV_HID_SENSOR_TIME + tristate "HID Sensor Time" + depends on USB_HID + select IIO + select HID_SENSOR_HUB + select HID_SENSOR_IIO_COMMON + help + Say yes here to build support for the HID Sensors of type Time. + This drivers makes such sensors available as RTCs. + + If this driver is compiled as a module, it will be named + rtc-hid-sensor-time. + + endif # RTC_CLASS diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index c3f62c8..63be277 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -52,6 +52,7 @@ obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o +obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c new file mode 100644 index 0000000..25cac6e --- /dev/null +++ b/drivers/rtc/rtc-hid-sensor-time.c @@ -0,0 +1,291 @@ +/* + * HID Sensor Time Driver + * Copyright (c) 2012, Alexander Holler. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ +#include +#include +#include +#include +#include +#include + +/* Format: HID-SENSOR-usage_id_in_hex */ +/* Usage ID from spec for Time: 0x2000A0 */ +#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */ + +enum hid_time_channel { + CHANNEL_SCAN_INDEX_YEAR, + CHANNEL_SCAN_INDEX_MONTH, + CHANNEL_SCAN_INDEX_DAY, + CHANNEL_SCAN_INDEX_HOUR, + CHANNEL_SCAN_INDEX_MINUTE, + CHANNEL_SCAN_INDEX_SECOND, + TIME_RTC_CHANNEL_MAX, +}; + +struct hid_time_state { + struct hid_sensor_hub_callbacks callbacks; + struct hid_sensor_iio_common common_attributes; + struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX]; + struct rtc_time last_time; + spinlock_t lock_last_time; + struct completion comp_last_time; + struct rtc_time time_buf; + struct rtc_device *rtc; +}; + +static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = { + HID_USAGE_SENSOR_TIME_YEAR, + HID_USAGE_SENSOR_TIME_MONTH, + HID_USAGE_SENSOR_TIME_DAY, + HID_USAGE_SENSOR_TIME_HOUR, + HID_USAGE_SENSOR_TIME_MINUTE, + HID_USAGE_SENSOR_TIME_SECOND, +}; + +/* Channel names for verbose error messages */ +static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = { + "year", "month", "day", "hour", "minute", "second", +}; + +/* Callback handler to send event after all samples are received and captured */ +static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev, + unsigned usage_id, void *priv) +{ + unsigned long flags; + struct hid_time_state *time_state = platform_get_drvdata(priv); + + spin_lock_irqsave(&time_state->lock_last_time, flags); + time_state->last_time = time_state->time_buf; + spin_unlock_irqrestore(&time_state->lock_last_time, flags); + complete(&time_state->comp_last_time); + return 0; +} + +static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev, + unsigned usage_id, size_t raw_len, + char *raw_data, void *priv) +{ + struct hid_time_state *time_state = platform_get_drvdata(priv); + struct rtc_time *time_buf = &time_state->time_buf; + + switch (usage_id) { + case HID_USAGE_SENSOR_TIME_YEAR: + time_buf->tm_year = *(u8 *)raw_data; + if (time_buf->tm_year < 70) + /* assume we are in 1970...2069 */ + time_buf->tm_year += 100; + break; + case HID_USAGE_SENSOR_TIME_MONTH: + /* sensor sending the month as 1-12, we need 0-11 */ + time_buf->tm_mon = *(u8 *)raw_data-1; + break; + case HID_USAGE_SENSOR_TIME_DAY: + time_buf->tm_mday = *(u8 *)raw_data; + break; + case HID_USAGE_SENSOR_TIME_HOUR: + time_buf->tm_hour = *(u8 *)raw_data; + break; + case HID_USAGE_SENSOR_TIME_MINUTE: + time_buf->tm_min = *(u8 *)raw_data; + break; + case HID_USAGE_SENSOR_TIME_SECOND: + time_buf->tm_sec = *(u8 *)raw_data; + break; + default: + return -EINVAL; + } + return 0; +} + +/* small helper, haven't found any other way */ +static const char *hid_time_attrib_name(u32 attrib_id) +{ + static const char unknown[] = "unknown"; + unsigned i; + + for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) { + if (hid_time_addresses[i] == attrib_id) + return hid_time_channel_names[i]; + } + return unknown; /* should never happen */ +} + +static int hid_time_parse_report(struct platform_device *pdev, + struct hid_sensor_hub_device *hsdev, + unsigned usage_id, + struct hid_time_state *time_state) +{ + int report_id, i; + + for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) + if (sensor_hub_input_get_attribute_info(hsdev, + HID_INPUT_REPORT, usage_id, + hid_time_addresses[i], + &time_state->info[i]) < 0) + return -EINVAL; + /* Check the (needed) attributes for sanity */ + report_id = time_state->info[0].report_id; + if (report_id < 0) { + dev_err(&pdev->dev, "bad report ID!\n"); + return -EINVAL; + } + for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) { + if (time_state->info[i].report_id != report_id) { + dev_err(&pdev->dev, + "not all needed attributes inside the same report!\n"); + return -EINVAL; + } + if (time_state->info[i].size != 1) { + dev_err(&pdev->dev, + "attribute '%s' not 8 bits wide!\n", + hid_time_attrib_name( + time_state->info[i].attrib_id)); + return -EINVAL; + } + if (time_state->info[i].units != + HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED && + /* allow attribute seconds with unit seconds */ + !(time_state->info[i].attrib_id == + HID_USAGE_SENSOR_TIME_SECOND && + time_state->info[i].units == + HID_USAGE_SENSOR_UNITS_SECOND)) { + dev_err(&pdev->dev, + "attribute '%s' hasn't a unit of type 'none'!\n", + hid_time_attrib_name( + time_state->info[i].attrib_id)); + return -EINVAL; + } + if (time_state->info[i].unit_expo) { + dev_err(&pdev->dev, + "attribute '%s' hasn't a unit exponent of 1!\n", + hid_time_attrib_name( + time_state->info[i].attrib_id)); + return -EINVAL; + } + } + + return 0; +} + +static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + unsigned long flags; + struct hid_time_state *time_state = + platform_get_drvdata(to_platform_device(dev)); + int ret; + + INIT_COMPLETION(time_state->comp_last_time); + /* get a report with all values through requesting one value */ + sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev, + HID_USAGE_SENSOR_TIME, hid_time_addresses[0], + time_state->info[0].report_id); + /* wait for all values (event) */ + ret = wait_for_completion_killable_timeout( + &time_state->comp_last_time, HZ*6); + if (ret > 0) { + /* no error */ + spin_lock_irqsave(&time_state->lock_last_time, flags); + *tm = time_state->last_time; + spin_unlock_irqrestore(&time_state->lock_last_time, flags); + return 0; + } + if (!ret) + return -EIO; /* timeouted */ + return ret; /* killed (-ERESTARTSYS) */ +} + +static const struct rtc_class_ops hid_time_rtc_ops = { + .read_time = hid_rtc_read_time, +}; + +static int hid_time_probe(struct platform_device *pdev) +{ + int ret = 0; + struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; + struct hid_time_state *time_state = devm_kzalloc(&pdev->dev, + sizeof(struct hid_time_state), GFP_KERNEL); + + if (time_state == NULL) + return -ENOMEM; + + platform_set_drvdata(pdev, time_state); + + init_completion(&time_state->comp_last_time); + time_state->common_attributes.hsdev = hsdev; + time_state->common_attributes.pdev = pdev; + + ret = hid_sensor_parse_common_attributes(hsdev, + HID_USAGE_SENSOR_TIME, + &time_state->common_attributes); + if (ret) { + dev_err(&pdev->dev, "failed to setup common attributes!\n"); + return ret; + } + + ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME, + time_state); + if (ret) { + dev_err(&pdev->dev, "failed to setup attributes!\n"); + return ret; + } + + time_state->callbacks.send_event = hid_time_proc_event; + time_state->callbacks.capture_sample = hid_time_capture_sample; + time_state->callbacks.pdev = pdev; + ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME, + &time_state->callbacks); + if (ret < 0) { + dev_err(&pdev->dev, "register callback failed!\n"); + return ret; + } + + time_state->rtc = rtc_device_register("hid-sensor-time", + &pdev->dev, &hid_time_rtc_ops, THIS_MODULE); + + if (IS_ERR(time_state->rtc)) { + dev_err(&pdev->dev, "rtc device register failed!\n"); + return PTR_ERR(time_state->rtc); + } + + return ret; +} + +static int hid_time_remove(struct platform_device *pdev) +{ + struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; + struct hid_time_state *time_state = platform_get_drvdata(pdev); + + rtc_device_unregister(time_state->rtc); + sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); + + return 0; +} + +static struct platform_driver hid_time_platform_driver = { + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + }, + .probe = hid_time_probe, + .remove = hid_time_remove, +}; +module_platform_driver(hid_time_platform_driver); + +MODULE_DESCRIPTION("HID Sensor Time"); +MODULE_AUTHOR("Alexander Holler "); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From e07c6d170ccec9e7377a43a2999b87b860c642e9 Mon Sep 17 00:00:00 2001 From: Alexander Holler Date: Sat, 15 Dec 2012 12:45:00 +0000 Subject: hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common The structure with common attributes for hid-sensors isn't specific to the iio-subsystem, so rename it to hid_sensor_common. Signed-off-by: Alexander Holler Acked-by: Jiri Kosina Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index 268ca3a..253684e 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -43,7 +43,7 @@ enum accel_3d_channel { struct accel_3d_state { struct hid_sensor_hub_callbacks callbacks; - struct hid_sensor_iio_common common_attributes; + struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX]; u32 accel_val[ACCEL_3D_CHANNEL_MAX]; }; diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index 5873f16..75b5473 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -113,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2) return value; } -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st, +int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, int *val1, int *val2) { s32 value; @@ -140,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st, } EXPORT_SYMBOL(hid_sensor_read_samp_freq_value); -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st, +int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st, int val1, int val2) { s32 value; @@ -168,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st, } EXPORT_SYMBOL(hid_sensor_write_samp_freq_value); -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st, +int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, int *val1, int *val2) { s32 value; @@ -190,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st, } EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value); -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st, +int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st, int val1, int val2) { s32 value; @@ -211,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value); int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, u32 usage_id, - struct hid_sensor_iio_common *st) + struct hid_sensor_common *st) { sensor_hub_input_get_attribute_info(hsdev, diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 7da7380..7a525a9 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -31,7 +31,7 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - struct hid_sensor_iio_common *st = trig->private_data; + struct hid_sensor_common *st = trig->private_data; int state_val; state_val = state ? 1 : 0; @@ -63,7 +63,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = { }; int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, - struct hid_sensor_iio_common *attrb) + struct hid_sensor_common *attrb) { int ret; struct iio_trigger *trig; diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h index fd98297..9a87314 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h @@ -20,7 +20,7 @@ #define _HID_SENSOR_TRIGGER_H int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, - struct hid_sensor_iio_common *attrb); + struct hid_sensor_common *attrb); void hid_sensor_remove_trigger(struct iio_dev *indio_dev); #endif diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index 8d34ee4..1a64f88 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c @@ -43,7 +43,7 @@ enum gyro_3d_channel { struct gyro_3d_state { struct hid_sensor_hub_callbacks callbacks; - struct hid_sensor_iio_common common_attributes; + struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX]; u32 gyro_val[GYRO_3D_CHANNEL_MAX]; }; diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 723f203..6ab987a 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -38,7 +38,7 @@ struct als_state { struct hid_sensor_hub_callbacks callbacks; - struct hid_sensor_iio_common common_attributes; + struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info als_illum; u32 illum; }; diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index 7811c0b..28026e2 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -43,7 +43,7 @@ enum magn_3d_channel { struct magn_3d_state { struct hid_sensor_hub_callbacks callbacks; - struct hid_sensor_iio_common common_attributes; + struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX]; u32 magn_val[MAGN_3D_CHANNEL_MAX]; }; diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index 25cac6e..0438c9e 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c @@ -39,7 +39,7 @@ enum hid_time_channel { struct hid_time_state { struct hid_sensor_hub_callbacks callbacks; - struct hid_sensor_iio_common common_attributes; + struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX]; struct rtc_time last_time; spinlock_t lock_last_time; diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index e6265f9..ecefb73 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -161,7 +161,7 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, /* hid-sensor-attributes */ /* Common hid sensor iio structure */ -struct hid_sensor_iio_common { +struct hid_sensor_common { struct hid_sensor_hub_device *hsdev; struct platform_device *pdev; unsigned usage_id; @@ -185,14 +185,14 @@ static inline int hid_sensor_convert_exponent(int unit_expo) int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, u32 usage_id, - struct hid_sensor_iio_common *st); -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st, + struct hid_sensor_common *st); +int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st, int val1, int val2); -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st, +int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, int *val1, int *val2); -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st, +int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st, int val1, int val2); -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st, +int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, int *val1, int *val2); #endif -- cgit v0.10.2 From 0a42577ddfa455bde219aa615de06fd8d2e6988c Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:44 -0500 Subject: Staging: bcm: Fix all white space issues in nvm.h This patch fixes all white space issues in nvm.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 651b5a4..fd03582 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -10,15 +10,14 @@ // // // Revision History: -// Who When What -// -------- -------- ---------------------------------------------- -// Name Date Created/reviewed/modified +// Who When What +// -------- -------- ---------------------------------------------- +// Name Date Created/reviewed/modified // // Notes: // ****************************************************************************************/ - #ifndef _NVM_H_ #define _NVM_H_ @@ -26,169 +25,121 @@ typedef struct _FLASH_SECTOR_INFO { UINT uiSectorSig; UINT uiSectorSize; - -}FLASH_SECTOR_INFO,*PFLASH_SECTOR_INFO; +} FLASH_SECTOR_INFO, *PFLASH_SECTOR_INFO; typedef struct _FLASH_CS_INFO { B_UINT32 MagicNumber; -// let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" - - B_UINT32 FlashLayoutVersion ; - - // ISO Image/Format/BuildTool versioning - B_UINT32 ISOImageVersion; - - // SCSI/Flash BootLoader versioning - B_UINT32 SCSIFirmwareVersion; - - + // let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" + B_UINT32 FlashLayoutVersion; + // ISO Image/Format/BuildTool versioning + B_UINT32 ISOImageVersion; + // SCSI/Flash BootLoader versioning + B_UINT32 SCSIFirmwareVersion; B_UINT32 OffsetFromZeroForPart1ISOImage; -// typically 0 - + // typically 0 B_UINT32 OffsetFromZeroForScsiFirmware; -//typically at 12MB - - B_UINT32 SizeOfScsiFirmware ; -//size of the firmware - depends on binary size - + //typically at 12MB + B_UINT32 SizeOfScsiFirmware; + //size of the firmware - depends on binary size B_UINT32 OffsetFromZeroForPart2ISOImage; -// typically at first Word Aligned offset 12MB + sizeOfScsiFirmware. - + // typically at first Word Aligned offset 12MB + sizeOfScsiFirmware. B_UINT32 OffsetFromZeroForCalibrationStart; -// typically at 15MB - + // typically at 15MB B_UINT32 OffsetFromZeroForCalibrationEnd; - -// VSA0 offsets + // VSA0 offsets B_UINT32 OffsetFromZeroForVSAStart; B_UINT32 OffsetFromZeroForVSAEnd; - -// Control Section offsets + // Control Section offsets B_UINT32 OffsetFromZeroForControlSectionStart; B_UINT32 OffsetFromZeroForControlSectionData; - -// NO Data Activity timeout to switch from MSC to NW Mode + // NO Data Activity timeout to switch from MSC to NW Mode B_UINT32 CDLessInactivityTimeout; - -// New ISO Image Signature + // New ISO Image Signature B_UINT32 NewImageSignature; - -// Signature to validate the sector size. + // Signature to validate the sector size. B_UINT32 FlashSectorSizeSig; - -// Sector Size + // Sector Size B_UINT32 FlashSectorSize; - -// Write Size Support + // Write Size Support B_UINT32 FlashWriteSupportSize; - -// Total Flash Size + // Total Flash Size B_UINT32 TotalFlashSize; - -// Flash Base Address for offset specified + // Flash Base Address for offset specified B_UINT32 FlashBaseAddr; - -// Flash Part Max Size + // Flash Part Max Size B_UINT32 FlashPartMaxSize; - -// Is CDLess or Flash Bootloader + // Is CDLess or Flash Bootloader B_UINT32 IsCDLessDeviceBootSig; - -// MSC Timeout after reset to switch from MSC to NW Mode + // MSC Timeout after reset to switch from MSC to NW Mode B_UINT32 MassStorageTimeout; +} FLASH_CS_INFO, *PFLASH_CS_INFO; - -}FLASH_CS_INFO,*PFLASH_CS_INFO; - -#define FLASH2X_TOTAL_SIZE (64*1024*1024) -#define DEFAULT_SECTOR_SIZE (64*1024) +#define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024) +#define DEFAULT_SECTOR_SIZE (64 * 1024) typedef struct _FLASH_2X_CS_INFO { - // magic number as 0xBECE-F1A5 - F1A5 for "flas-h" B_UINT32 MagicNumber; - - B_UINT32 FlashLayoutVersion ; - - // ISO Image/Format/BuildTool versioning - B_UINT32 ISOImageVersion; - - // SCSI/Flash BootLoader versioning - B_UINT32 SCSIFirmwareVersion; - + B_UINT32 FlashLayoutVersion; + // ISO Image/Format/BuildTool versioning + B_UINT32 ISOImageVersion; + // SCSI/Flash BootLoader versioning + B_UINT32 SCSIFirmwareVersion; // ISO Image1 Part1/SCSI Firmware/Flash Bootloader Start offset, size B_UINT32 OffsetFromZeroForPart1ISOImage; B_UINT32 OffsetFromZeroForScsiFirmware; - B_UINT32 SizeOfScsiFirmware ; - + B_UINT32 SizeOfScsiFirmware; // ISO Image1 Part2 start offset B_UINT32 OffsetFromZeroForPart2ISOImage; - - // DSD0 offset B_UINT32 OffsetFromZeroForDSDStart; B_UINT32 OffsetFromZeroForDSDEnd; - // VSA0 offset B_UINT32 OffsetFromZeroForVSAStart; B_UINT32 OffsetFromZeroForVSAEnd; - // Control Section offset B_UINT32 OffsetFromZeroForControlSectionStart; B_UINT32 OffsetFromZeroForControlSectionData; - // NO Data Activity timeout to switch from MSC to NW Mode B_UINT32 CDLessInactivityTimeout; - // New ISO Image Signature B_UINT32 NewImageSignature; - B_UINT32 FlashSectorSizeSig; // Sector Size Signature B_UINT32 FlashSectorSize; // Sector Size - B_UINT32 FlashWriteSupportSize; // Write Size Support - + B_UINT32 FlashWriteSupportSize; // Write Size Support B_UINT32 TotalFlashSize; // Total Flash Size - // Flash Base Address for offset specified B_UINT32 FlashBaseAddr; B_UINT32 FlashPartMaxSize; // Flash Part Max Size - // Is CDLess or Flash Bootloader B_UINT32 IsCDLessDeviceBootSig; - // MSC Timeout after reset to switch from MSC to NW Mode B_UINT32 MassStorageTimeout; - /* Flash Map 2.0 Field */ - B_UINT32 OffsetISOImage1Part1Start; // ISO Image1 Part1 offset + B_UINT32 OffsetISOImage1Part1Start; // ISO Image1 Part1 offset B_UINT32 OffsetISOImage1Part1End; - B_UINT32 OffsetISOImage1Part2Start; // ISO Image1 Part2 offset + B_UINT32 OffsetISOImage1Part2Start; // ISO Image1 Part2 offset B_UINT32 OffsetISOImage1Part2End; - B_UINT32 OffsetISOImage1Part3Start; // ISO Image1 Part3 offset + B_UINT32 OffsetISOImage1Part3Start; // ISO Image1 Part3 offset B_UINT32 OffsetISOImage1Part3End; - - B_UINT32 OffsetISOImage2Part1Start; // ISO Image2 Part1 offset + B_UINT32 OffsetISOImage2Part1Start; // ISO Image2 Part1 offset B_UINT32 OffsetISOImage2Part1End; - B_UINT32 OffsetISOImage2Part2Start; // ISO Image2 Part2 offset + B_UINT32 OffsetISOImage2Part2Start; // ISO Image2 Part2 offset B_UINT32 OffsetISOImage2Part2End; - B_UINT32 OffsetISOImage2Part3Start; // ISO Image2 Part3 offset + B_UINT32 OffsetISOImage2Part3Start; // ISO Image2 Part3 offset B_UINT32 OffsetISOImage2Part3End; - - // DSD Header offset from start of DSD B_UINT32 OffsetFromDSDStartForDSDHeader; B_UINT32 OffsetFromZeroForDSD1Start; // DSD 1 offset B_UINT32 OffsetFromZeroForDSD1End; B_UINT32 OffsetFromZeroForDSD2Start; // DSD 2 offset B_UINT32 OffsetFromZeroForDSD2End; - B_UINT32 OffsetFromZeroForVSA1Start; // VSA 1 offset B_UINT32 OffsetFromZeroForVSA1End; B_UINT32 OffsetFromZeroForVSA2Start; // VSA 2 offset B_UINT32 OffsetFromZeroForVSA2End; - /* * ACCESS_BITS_PER_SECTOR 2 * ACCESS_RW 0 @@ -196,11 +147,9 @@ typedef struct _FLASH_2X_CS_INFO * ACCESS_RESVD 2 * ACCESS_RESVD 3 * */ - B_UINT32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE/(DEFAULT_SECTOR_SIZE *16)]; - + B_UINT32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)]; // All expansions to the control data structure should add here - -}FLASH2X_CS_INFO,*PFLASH2X_CS_INFO; +} FLASH2X_CS_INFO, *PFLASH2X_CS_INFO; typedef struct _VENDOR_SECTION_INFO { @@ -208,14 +157,12 @@ typedef struct _VENDOR_SECTION_INFO B_UINT32 OffsetFromZeroForSectionEnd; B_UINT32 AccessFlags; B_UINT32 Reserved[16]; - } VENDOR_SECTION_INFO, *PVENDOR_SECTION_INFO; typedef struct _FLASH2X_VENDORSPECIFIC_INFO { VENDOR_SECTION_INFO VendorSection[TOTAL_SECTIONS]; B_UINT32 Reserved[16]; - } FLASH2X_VENDORSPECIFIC_INFO, *PFLASH2X_VENDORSPECIFIC_INFO; typedef struct _DSD_HEADER @@ -226,8 +173,7 @@ typedef struct _DSD_HEADER //We should not consider right now. Reading reserve is worthless. B_UINT32 Reserved[252]; // Resvd for DSD Header B_UINT32 DSDImageMagicNumber; - -}DSD_HEADER, *PDSD_HEADER; +} DSD_HEADER, *PDSD_HEADER; typedef struct _ISO_HEADER { @@ -237,173 +183,141 @@ typedef struct _ISO_HEADER B_UINT32 ISOImagePriority; //We should not consider right now. Reading reserve is worthless. B_UINT32 Reserved[60]; //Resvd for ISO Header extension - -}ISO_HEADER, *PISO_HEADER; - -#define EEPROM_BEGIN_CIS (0) -#define EEPROM_BEGIN_NON_CIS (0x200) -#define EEPROM_END (0x2000) - -#define INIT_PARAMS_SIGNATURE (0x95a7a597) - -#define MAX_INIT_PARAMS_LENGTH (2048) - - -#define MAC_ADDRESS_OFFSET 0x200 - - -#define INIT_PARAMS_1_SIGNATURE_ADDRESS EEPROM_BEGIN_NON_CIS -#define INIT_PARAMS_1_DATA_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+16) -#define INIT_PARAMS_1_MACADDRESS_ADDRESS (MAC_ADDRESS_OFFSET) -#define INIT_PARAMS_1_LENGTH_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+4) - -#define INIT_PARAMS_2_SIGNATURE_ADDRESS (EEPROM_BEGIN_NON_CIS+2048+16) -#define INIT_PARAMS_2_DATA_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS+16) -#define INIT_PARAMS_2_MACADDRESS_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS+8) -#define INIT_PARAMS_2_LENGTH_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS+4) - -#define EEPROM_SPI_DEV_CONFIG_REG 0x0F003000 -#define EEPROM_SPI_Q_STATUS1_REG 0x0F003004 -#define EEPROM_SPI_Q_STATUS1_MASK_REG 0x0F00300C - -#define EEPROM_SPI_Q_STATUS_REG 0x0F003008 -#define EEPROM_CMDQ_SPI_REG 0x0F003018 -#define EEPROM_WRITE_DATAQ_REG 0x0F00301C -#define EEPROM_READ_DATAQ_REG 0x0F003020 -#define SPI_FLUSH_REG 0x0F00304C - -#define EEPROM_WRITE_ENABLE 0x06000000 -#define EEPROM_READ_STATUS_REGISTER 0x05000000 -#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000 -#define EEPROM_WRITE_QUEUE_EMPTY 0x00001000 -#define EEPROM_WRITE_QUEUE_AVAIL 0x00002000 -#define EEPROM_WRITE_QUEUE_FULL 0x00004000 -#define EEPROM_16_BYTE_PAGE_READ 0xFB000000 -#define EEPROM_4_BYTE_PAGE_READ 0x3B000000 - -#define EEPROM_CMD_QUEUE_FLUSH 0x00000001 -#define EEPROM_WRITE_QUEUE_FLUSH 0x00000002 -#define EEPROM_READ_QUEUE_FLUSH 0x00000004 -#define EEPROM_ETH_QUEUE_FLUSH 0x00000008 -#define EEPROM_ALL_QUEUE_FLUSH 0x0000000f -#define EEPROM_READ_ENABLE 0x06000000 -#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000 -#define EEPROM_READ_DATA_FULL 0x00000010 -#define EEPROM_READ_DATA_AVAIL 0x00000020 -#define EEPROM_READ_QUEUE_EMPTY 0x00000002 -#define EEPROM_CMD_QUEUE_EMPTY 0x00000100 -#define EEPROM_CMD_QUEUE_AVAIL 0x00000200 -#define EEPROM_CMD_QUEUE_FULL 0x00000400 +} ISO_HEADER, *PISO_HEADER; + +#define EEPROM_BEGIN_CIS (0) +#define EEPROM_BEGIN_NON_CIS (0x200) +#define EEPROM_END (0x2000) +#define INIT_PARAMS_SIGNATURE (0x95a7a597) +#define MAX_INIT_PARAMS_LENGTH (2048) +#define MAC_ADDRESS_OFFSET 0x200 + +#define INIT_PARAMS_1_SIGNATURE_ADDRESS EEPROM_BEGIN_NON_CIS +#define INIT_PARAMS_1_DATA_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+16) +#define INIT_PARAMS_1_MACADDRESS_ADDRESS (MAC_ADDRESS_OFFSET) +#define INIT_PARAMS_1_LENGTH_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+4) + +#define INIT_PARAMS_2_SIGNATURE_ADDRESS (EEPROM_BEGIN_NON_CIS + 2048 + 16) +#define INIT_PARAMS_2_DATA_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 16) +#define INIT_PARAMS_2_MACADDRESS_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 8) +#define INIT_PARAMS_2_LENGTH_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 4) + +#define EEPROM_SPI_DEV_CONFIG_REG 0x0F003000 +#define EEPROM_SPI_Q_STATUS1_REG 0x0F003004 +#define EEPROM_SPI_Q_STATUS1_MASK_REG 0x0F00300C + +#define EEPROM_SPI_Q_STATUS_REG 0x0F003008 +#define EEPROM_CMDQ_SPI_REG 0x0F003018 +#define EEPROM_WRITE_DATAQ_REG 0x0F00301C +#define EEPROM_READ_DATAQ_REG 0x0F003020 +#define SPI_FLUSH_REG 0x0F00304C + +#define EEPROM_WRITE_ENABLE 0x06000000 +#define EEPROM_READ_STATUS_REGISTER 0x05000000 +#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000 +#define EEPROM_WRITE_QUEUE_EMPTY 0x00001000 +#define EEPROM_WRITE_QUEUE_AVAIL 0x00002000 +#define EEPROM_WRITE_QUEUE_FULL 0x00004000 +#define EEPROM_16_BYTE_PAGE_READ 0xFB000000 +#define EEPROM_4_BYTE_PAGE_READ 0x3B000000 + +#define EEPROM_CMD_QUEUE_FLUSH 0x00000001 +#define EEPROM_WRITE_QUEUE_FLUSH 0x00000002 +#define EEPROM_READ_QUEUE_FLUSH 0x00000004 +#define EEPROM_ETH_QUEUE_FLUSH 0x00000008 +#define EEPROM_ALL_QUEUE_FLUSH 0x0000000f +#define EEPROM_READ_ENABLE 0x06000000 +#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000 +#define EEPROM_READ_DATA_FULL 0x00000010 +#define EEPROM_READ_DATA_AVAIL 0x00000020 +#define EEPROM_READ_QUEUE_EMPTY 0x00000002 +#define EEPROM_CMD_QUEUE_EMPTY 0x00000100 +#define EEPROM_CMD_QUEUE_AVAIL 0x00000200 +#define EEPROM_CMD_QUEUE_FULL 0x00000400 /* Most EEPROM status register bit 0 indicates if the EEPROM is busy * with a write if set 1. See the details of the EEPROM Status Register * in the EEPROM data sheet. */ -#define EEPROM_STATUS_REG_WRITE_BUSY 0x00000001 +#define EEPROM_STATUS_REG_WRITE_BUSY 0x00000001 // We will have 1 mSec for every RETRIES_PER_DELAY count and have a max attempts of MAX_EEPROM_RETRIES // This will give us 80 mSec minimum of delay = 80mSecs -#define MAX_EEPROM_RETRIES 80 -#define RETRIES_PER_DELAY 64 - - -#define MAX_RW_SIZE 0x10 -#define MAX_READ_SIZE 0x10 -#define MAX_SECTOR_SIZE (512*1024) -#define MIN_SECTOR_SIZE (1024) -#define FLASH_SECTOR_SIZE_OFFSET 0xEFFFC -#define FLASH_SECTOR_SIZE_SIG_OFFSET 0xEFFF8 -#define FLASH_SECTOR_SIZE_SIG 0xCAFEBABE -#define FLASH_CS_INFO_START_ADDR 0xFF0000 -#define FLASH_CONTROL_STRUCT_SIGNATURE 0xBECEF1A5 -#define SCSI_FIRMWARE_MAJOR_VERSION 0x1 -#define SCSI_FIRMWARE_MINOR_VERSION 0x5 -#define BYTE_WRITE_SUPPORT 0x1 - -#define FLASH_AUTO_INIT_BASE_ADDR 0xF00000 - - - - -#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000 -#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000 - -#define FLASH_CONTIGIOUS_START_ADDR_BCS350 0x08000000 -#define FLASH_CONTIGIOUS_END_ADDR_BCS350 0x08FFFFFF - - - -#define FLASH_SIZE_ADDR 0xFFFFEC - -#define FLASH_SPI_CMDQ_REG 0xAF003040 -#define FLASH_SPI_WRITEQ_REG 0xAF003044 -#define FLASH_SPI_READQ_REG 0xAF003048 -#define FLASH_CONFIG_REG 0xAF003050 -#define FLASH_GPIO_CONFIG_REG 0xAF000030 - -#define FLASH_CMD_WRITE_ENABLE 0x06 -#define FLASH_CMD_READ_ENABLE 0x03 -#define FLASH_CMD_RESET_WRITE_ENABLE 0x04 -#define FLASH_CMD_STATUS_REG_READ 0x05 -#define FLASH_CMD_STATUS_REG_WRITE 0x01 -#define FLASH_CMD_READ_ID 0x9F - -#define PAD_SELECT_REGISTER 0xAF000410 - -#define FLASH_PART_SST25VF080B 0xBF258E - -#define EEPROM_CAL_DATA_INTERNAL_LOC 0xbFB00008 - -#define EEPROM_CALPARAM_START 0x200 -#define EEPROM_SIZE_OFFSET 524 +#define MAX_EEPROM_RETRIES 80 +#define RETRIES_PER_DELAY 64 +#define MAX_RW_SIZE 0x10 +#define MAX_READ_SIZE 0x10 +#define MAX_SECTOR_SIZE (512 * 1024) +#define MIN_SECTOR_SIZE (1024) +#define FLASH_SECTOR_SIZE_OFFSET 0xEFFFC +#define FLASH_SECTOR_SIZE_SIG_OFFSET 0xEFFF8 +#define FLASH_SECTOR_SIZE_SIG 0xCAFEBABE +#define FLASH_CS_INFO_START_ADDR 0xFF0000 +#define FLASH_CONTROL_STRUCT_SIGNATURE 0xBECEF1A5 +#define SCSI_FIRMWARE_MAJOR_VERSION 0x1 +#define SCSI_FIRMWARE_MINOR_VERSION 0x5 +#define BYTE_WRITE_SUPPORT 0x1 +#define FLASH_AUTO_INIT_BASE_ADDR 0xF00000 +#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000 +#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000 +#define FLASH_CONTIGIOUS_START_ADDR_BCS350 0x08000000 +#define FLASH_CONTIGIOUS_END_ADDR_BCS350 0x08FFFFFF +#define FLASH_SIZE_ADDR 0xFFFFEC +#define FLASH_SPI_CMDQ_REG 0xAF003040 +#define FLASH_SPI_WRITEQ_REG 0xAF003044 +#define FLASH_SPI_READQ_REG 0xAF003048 +#define FLASH_CONFIG_REG 0xAF003050 +#define FLASH_GPIO_CONFIG_REG 0xAF000030 +#define FLASH_CMD_WRITE_ENABLE 0x06 +#define FLASH_CMD_READ_ENABLE 0x03 +#define FLASH_CMD_RESET_WRITE_ENABLE 0x04 +#define FLASH_CMD_STATUS_REG_READ 0x05 +#define FLASH_CMD_STATUS_REG_WRITE 0x01 +#define FLASH_CMD_READ_ID 0x9F +#define PAD_SELECT_REGISTER 0xAF000410 +#define FLASH_PART_SST25VF080B 0xBF258E +#define EEPROM_CAL_DATA_INTERNAL_LOC 0xbFB00008 +#define EEPROM_CALPARAM_START 0x200 +#define EEPROM_SIZE_OFFSET 524 //As Read/Write time vaires from 1.5 to 3.0 ms. //so After Ignoring the rdm/wrm time(that is dependent on many factor like interface etc.), //here time calculated meets the worst case delay, 3.0 ms -#define MAX_FLASH_RETRIES 4 -#define FLASH_PER_RETRIES_DELAY 16 - - -#define EEPROM_MAX_CAL_AREA_SIZE 0xF0000 - - - -#define BECM ntohl(0x4245434d) - -#define FLASH_2X_MAJOR_NUMBER 0x2 -#define DSD_IMAGE_MAGIC_NUMBER 0xBECE0D5D -#define ISO_IMAGE_MAGIC_NUMBER 0xBECE0150 -#define NON_CDLESS_DEVICE_BOOT_SIG 0xBECEB007 -#define MINOR_VERSION(x) ((x >>16) & 0xFFFF) +#define MAX_FLASH_RETRIES 4 +#define FLASH_PER_RETRIES_DELAY 16 +#define EEPROM_MAX_CAL_AREA_SIZE 0xF0000 +#define BECM ntohl(0x4245434d) +#define FLASH_2X_MAJOR_NUMBER 0x2 +#define DSD_IMAGE_MAGIC_NUMBER 0xBECE0D5D +#define ISO_IMAGE_MAGIC_NUMBER 0xBECE0150 +#define NON_CDLESS_DEVICE_BOOT_SIG 0xBECEB007 + +#define MINOR_VERSION(x) ((x >> 16) & 0xFFFF) #define MAJOR_VERSION(x) (x & 0xFFFF) -#define CORRUPTED_PATTERN 0x0 -#define UNINIT_PTR_IN_CS 0xBBBBDDDD - -#define VENDOR_PTR_IN_CS 0xAAAACCCC - - -#define FLASH2X_SECTION_PRESENT 1<<0 -#define FLASH2X_SECTION_VALID 1<<1 -#define FLASH2X_SECTION_RO 1<<2 -#define FLASH2X_SECTION_ACT 1<<3 -#define SECTOR_IS_NOT_WRITABLE STATUS_FAILURE -#define INVALID_OFFSET STATUS_FAILURE -#define INVALID_SECTION STATUS_FAILURE -#define SECTOR_1K 1024 -#define SECTOR_64K (64 *SECTOR_1K) -#define SECTOR_128K (2 * SECTOR_64K) -#define SECTOR_256k (2 * SECTOR_128K) -#define SECTOR_512K (2 * SECTOR_256k) -#define FLASH_PART_SIZE (16 * 1024 * 1024) -#define RESET_CHIP_SELECT -1 -#define CHIP_SELECT_BIT12 12 - -#define SECTOR_READWRITE_PERMISSION 0 -#define SECTOR_READONLY 1 -#define SIGNATURE_SIZE 4 -#define DEFAULT_BUFF_SIZE 0x10000 - -#define FIELD_OFFSET_IN_HEADER(HeaderPointer,Field) ((PUCHAR)&((HeaderPointer)(NULL))->Field - (PUCHAR)(NULL)) +#define CORRUPTED_PATTERN 0x0 +#define UNINIT_PTR_IN_CS 0xBBBBDDDD +#define VENDOR_PTR_IN_CS 0xAAAACCCC +#define FLASH2X_SECTION_PRESENT 1 << 0 +#define FLASH2X_SECTION_VALID 1 << 1 +#define FLASH2X_SECTION_RO 1 << 2 +#define FLASH2X_SECTION_ACT 1 << 3 +#define SECTOR_IS_NOT_WRITABLE STATUS_FAILURE +#define INVALID_OFFSET STATUS_FAILURE +#define INVALID_SECTION STATUS_FAILURE +#define SECTOR_1K 1024 +#define SECTOR_64K (64 * SECTOR_1K) +#define SECTOR_128K (2 * SECTOR_64K) +#define SECTOR_256k (2 * SECTOR_128K) +#define SECTOR_512K (2 * SECTOR_256k) +#define FLASH_PART_SIZE (16 * 1024 * 1024) +#define RESET_CHIP_SELECT -1 +#define CHIP_SELECT_BIT12 12 +#define SECTOR_READWRITE_PERMISSION 0 +#define SECTOR_READONLY 1 +#define SIGNATURE_SIZE 4 +#define DEFAULT_BUFF_SIZE 0x10000 + +#define FIELD_OFFSET_IN_HEADER(HeaderPointer, Field) ((PUCHAR)&((HeaderPointer)(NULL))->Field - (PUCHAR)(NULL)) #endif -- cgit v0.10.2 From 04ac0434c10e4b57db3f8b6d49010b8fd5213b3c Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:45 -0500 Subject: Staging: bcm: Properly format and remove comments as needed in nvm.h This patch formats all comments and removes them as needed. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index fd03582..5544975 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -1,22 +1,22 @@ /*************************************************************************************** -// -// Copyright (c) Beceem Communications Inc. -// -// Module Name: -// NVM.h -// -// Abstract: -// This file has the prototypes,preprocessors and definitions various NVM libraries. -// -// -// Revision History: -// Who When What -// -------- -------- ---------------------------------------------- -// Name Date Created/reviewed/modified -// -// Notes: -// -****************************************************************************************/ + * + * Copyright (c) Beceem Communications Inc. + * + * Module Name: + * NVM.h + * + * Abstract: + * This file has the prototypes,preprocessors and definitions various NVM libraries. + * + * + * Revision History: + * Who When What + * -------- -------- ---------------------------------------------- + * Name Date Created/reviewed/modified + * + * Notes: + * + ****************************************************************************************/ #ifndef _NVM_H_ #define _NVM_H_ @@ -30,48 +30,30 @@ typedef struct _FLASH_SECTOR_INFO typedef struct _FLASH_CS_INFO { B_UINT32 MagicNumber; - // let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" + /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */ B_UINT32 FlashLayoutVersion; - // ISO Image/Format/BuildTool versioning B_UINT32 ISOImageVersion; - // SCSI/Flash BootLoader versioning B_UINT32 SCSIFirmwareVersion; B_UINT32 OffsetFromZeroForPart1ISOImage; - // typically 0 B_UINT32 OffsetFromZeroForScsiFirmware; - //typically at 12MB B_UINT32 SizeOfScsiFirmware; - //size of the firmware - depends on binary size B_UINT32 OffsetFromZeroForPart2ISOImage; - // typically at first Word Aligned offset 12MB + sizeOfScsiFirmware. B_UINT32 OffsetFromZeroForCalibrationStart; - // typically at 15MB B_UINT32 OffsetFromZeroForCalibrationEnd; - // VSA0 offsets B_UINT32 OffsetFromZeroForVSAStart; B_UINT32 OffsetFromZeroForVSAEnd; - // Control Section offsets B_UINT32 OffsetFromZeroForControlSectionStart; B_UINT32 OffsetFromZeroForControlSectionData; - // NO Data Activity timeout to switch from MSC to NW Mode B_UINT32 CDLessInactivityTimeout; - // New ISO Image Signature B_UINT32 NewImageSignature; - // Signature to validate the sector size. B_UINT32 FlashSectorSizeSig; - // Sector Size B_UINT32 FlashSectorSize; - // Write Size Support B_UINT32 FlashWriteSupportSize; - // Total Flash Size B_UINT32 TotalFlashSize; - // Flash Base Address for offset specified B_UINT32 FlashBaseAddr; - // Flash Part Max Size B_UINT32 FlashPartMaxSize; - // Is CDLess or Flash Bootloader B_UINT32 IsCDLessDeviceBootSig; - // MSC Timeout after reset to switch from MSC to NW Mode + /* MSC Timeout after reset to switch from MSC to NW Mode */ B_UINT32 MassStorageTimeout; } FLASH_CS_INFO, *PFLASH_CS_INFO; @@ -80,75 +62,65 @@ typedef struct _FLASH_CS_INFO typedef struct _FLASH_2X_CS_INFO { - // magic number as 0xBECE-F1A5 - F1A5 for "flas-h" + /* magic number as 0xBECE-F1A5 - F1A5 for "flas-h" */ B_UINT32 MagicNumber; B_UINT32 FlashLayoutVersion; - // ISO Image/Format/BuildTool versioning B_UINT32 ISOImageVersion; - // SCSI/Flash BootLoader versioning B_UINT32 SCSIFirmwareVersion; - // ISO Image1 Part1/SCSI Firmware/Flash Bootloader Start offset, size B_UINT32 OffsetFromZeroForPart1ISOImage; B_UINT32 OffsetFromZeroForScsiFirmware; B_UINT32 SizeOfScsiFirmware; - // ISO Image1 Part2 start offset B_UINT32 OffsetFromZeroForPart2ISOImage; - // DSD0 offset B_UINT32 OffsetFromZeroForDSDStart; B_UINT32 OffsetFromZeroForDSDEnd; - // VSA0 offset B_UINT32 OffsetFromZeroForVSAStart; B_UINT32 OffsetFromZeroForVSAEnd; - // Control Section offset B_UINT32 OffsetFromZeroForControlSectionStart; B_UINT32 OffsetFromZeroForControlSectionData; - // NO Data Activity timeout to switch from MSC to NW Mode + /* NO Data Activity timeout to switch from MSC to NW Mode */ B_UINT32 CDLessInactivityTimeout; - // New ISO Image Signature B_UINT32 NewImageSignature; - B_UINT32 FlashSectorSizeSig; // Sector Size Signature - B_UINT32 FlashSectorSize; // Sector Size - B_UINT32 FlashWriteSupportSize; // Write Size Support - B_UINT32 TotalFlashSize; // Total Flash Size - // Flash Base Address for offset specified + B_UINT32 FlashSectorSizeSig; + B_UINT32 FlashSectorSize; + B_UINT32 FlashWriteSupportSize; + B_UINT32 TotalFlashSize; B_UINT32 FlashBaseAddr; - B_UINT32 FlashPartMaxSize; // Flash Part Max Size - // Is CDLess or Flash Bootloader + B_UINT32 FlashPartMaxSize; B_UINT32 IsCDLessDeviceBootSig; - // MSC Timeout after reset to switch from MSC to NW Mode + /* MSC Timeout after reset to switch from MSC to NW Mode */ B_UINT32 MassStorageTimeout; /* Flash Map 2.0 Field */ - B_UINT32 OffsetISOImage1Part1Start; // ISO Image1 Part1 offset + B_UINT32 OffsetISOImage1Part1Start; B_UINT32 OffsetISOImage1Part1End; - B_UINT32 OffsetISOImage1Part2Start; // ISO Image1 Part2 offset + B_UINT32 OffsetISOImage1Part2Start; B_UINT32 OffsetISOImage1Part2End; - B_UINT32 OffsetISOImage1Part3Start; // ISO Image1 Part3 offset + B_UINT32 OffsetISOImage1Part3Start; B_UINT32 OffsetISOImage1Part3End; - B_UINT32 OffsetISOImage2Part1Start; // ISO Image2 Part1 offset + B_UINT32 OffsetISOImage2Part1Start; B_UINT32 OffsetISOImage2Part1End; - B_UINT32 OffsetISOImage2Part2Start; // ISO Image2 Part2 offset + B_UINT32 OffsetISOImage2Part2Start; B_UINT32 OffsetISOImage2Part2End; - B_UINT32 OffsetISOImage2Part3Start; // ISO Image2 Part3 offset + B_UINT32 OffsetISOImage2Part3Start; B_UINT32 OffsetISOImage2Part3End; - // DSD Header offset from start of DSD + /* DSD Header offset from start of DSD */ B_UINT32 OffsetFromDSDStartForDSDHeader; - B_UINT32 OffsetFromZeroForDSD1Start; // DSD 1 offset + B_UINT32 OffsetFromZeroForDSD1Start; B_UINT32 OffsetFromZeroForDSD1End; - B_UINT32 OffsetFromZeroForDSD2Start; // DSD 2 offset + B_UINT32 OffsetFromZeroForDSD2Start; B_UINT32 OffsetFromZeroForDSD2End; - B_UINT32 OffsetFromZeroForVSA1Start; // VSA 1 offset + B_UINT32 OffsetFromZeroForVSA1Start; B_UINT32 OffsetFromZeroForVSA1End; - B_UINT32 OffsetFromZeroForVSA2Start; // VSA 2 offset + B_UINT32 OffsetFromZeroForVSA2Start; B_UINT32 OffsetFromZeroForVSA2End; /* -* ACCESS_BITS_PER_SECTOR 2 -* ACCESS_RW 0 -* ACCESS_RO 1 -* ACCESS_RESVD 2 -* ACCESS_RESVD 3 -* */ + * ACCESS_BITS_PER_SECTOR 2 + * ACCESS_RW 0 + * ACCESS_RO 1 + * ACCESS_RESVD 2 + * ACCESS_RESVD 3 + */ B_UINT32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)]; -// All expansions to the control data structure should add here + /* All expansions to the control data structure should add here */ } FLASH2X_CS_INFO, *PFLASH2X_CS_INFO; typedef struct _VENDOR_SECTION_INFO @@ -170,8 +142,8 @@ typedef struct _DSD_HEADER B_UINT32 DSDImageSize; B_UINT32 DSDImageCRC; B_UINT32 DSDImagePriority; - //We should not consider right now. Reading reserve is worthless. - B_UINT32 Reserved[252]; // Resvd for DSD Header + /* We should not consider right now. Reading reserve is worthless. */ + B_UINT32 Reserved[252]; /* Resvd for DSD Header */ B_UINT32 DSDImageMagicNumber; } DSD_HEADER, *PDSD_HEADER; @@ -181,8 +153,8 @@ typedef struct _ISO_HEADER B_UINT32 ISOImageSize; B_UINT32 ISOImageCRC; B_UINT32 ISOImagePriority; - //We should not consider right now. Reading reserve is worthless. - B_UINT32 Reserved[60]; //Resvd for ISO Header extension + /* We should not consider right now. Reading reserve is worthless. */ + B_UINT32 Reserved[60]; /* Resvd for ISO Header extension */ } ISO_HEADER, *PISO_HEADER; #define EEPROM_BEGIN_CIS (0) @@ -237,11 +209,13 @@ typedef struct _ISO_HEADER /* Most EEPROM status register bit 0 indicates if the EEPROM is busy * with a write if set 1. See the details of the EEPROM Status Register - * in the EEPROM data sheet. */ + * in the EEPROM data sheet. + */ #define EEPROM_STATUS_REG_WRITE_BUSY 0x00000001 -// We will have 1 mSec for every RETRIES_PER_DELAY count and have a max attempts of MAX_EEPROM_RETRIES -// This will give us 80 mSec minimum of delay = 80mSecs +/* We will have 1 mSec for every RETRIES_PER_DELAY count and have a max attempts of MAX_EEPROM_RETRIES + * This will give us 80 mSec minimum of delay = 80mSecs + */ #define MAX_EEPROM_RETRIES 80 #define RETRIES_PER_DELAY 64 #define MAX_RW_SIZE 0x10 @@ -279,9 +253,10 @@ typedef struct _ISO_HEADER #define EEPROM_CALPARAM_START 0x200 #define EEPROM_SIZE_OFFSET 524 -//As Read/Write time vaires from 1.5 to 3.0 ms. -//so After Ignoring the rdm/wrm time(that is dependent on many factor like interface etc.), -//here time calculated meets the worst case delay, 3.0 ms +/* As Read/Write time vaires from 1.5 to 3.0 ms. + * so After Ignoring the rdm/wrm time(that is dependent on many factor like interface etc.), + * here time calculated meets the worst case delay, 3.0 ms + */ #define MAX_FLASH_RETRIES 4 #define FLASH_PER_RETRIES_DELAY 16 #define EEPROM_MAX_CAL_AREA_SIZE 0xF0000 -- cgit v0.10.2 From 72a57c08b5eaddd64174940ff5f9edf269ca7f9d Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:46 -0500 Subject: Staging: bcm: Properly format braces in nvm.h This patch properly formats braces in nvm.h as reported by checkpath.pl Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 5544975..36a9707 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -21,14 +21,12 @@ #ifndef _NVM_H_ #define _NVM_H_ -typedef struct _FLASH_SECTOR_INFO -{ +typedef struct _FLASH_SECTOR_INFO { UINT uiSectorSig; UINT uiSectorSize; } FLASH_SECTOR_INFO, *PFLASH_SECTOR_INFO; -typedef struct _FLASH_CS_INFO -{ +typedef struct _FLASH_CS_INFO { B_UINT32 MagicNumber; /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */ B_UINT32 FlashLayoutVersion; @@ -60,8 +58,7 @@ typedef struct _FLASH_CS_INFO #define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024) #define DEFAULT_SECTOR_SIZE (64 * 1024) -typedef struct _FLASH_2X_CS_INFO -{ +typedef struct _FLASH_2X_CS_INFO { /* magic number as 0xBECE-F1A5 - F1A5 for "flas-h" */ B_UINT32 MagicNumber; B_UINT32 FlashLayoutVersion; @@ -123,22 +120,19 @@ typedef struct _FLASH_2X_CS_INFO /* All expansions to the control data structure should add here */ } FLASH2X_CS_INFO, *PFLASH2X_CS_INFO; -typedef struct _VENDOR_SECTION_INFO -{ +typedef struct _VENDOR_SECTION_INFO { B_UINT32 OffsetFromZeroForSectionStart; B_UINT32 OffsetFromZeroForSectionEnd; B_UINT32 AccessFlags; B_UINT32 Reserved[16]; } VENDOR_SECTION_INFO, *PVENDOR_SECTION_INFO; -typedef struct _FLASH2X_VENDORSPECIFIC_INFO -{ +typedef struct _FLASH2X_VENDORSPECIFIC_INFO { VENDOR_SECTION_INFO VendorSection[TOTAL_SECTIONS]; B_UINT32 Reserved[16]; } FLASH2X_VENDORSPECIFIC_INFO, *PFLASH2X_VENDORSPECIFIC_INFO; -typedef struct _DSD_HEADER -{ +typedef struct _DSD_HEADER { B_UINT32 DSDImageSize; B_UINT32 DSDImageCRC; B_UINT32 DSDImagePriority; @@ -147,8 +141,7 @@ typedef struct _DSD_HEADER B_UINT32 DSDImageMagicNumber; } DSD_HEADER, *PDSD_HEADER; -typedef struct _ISO_HEADER -{ +typedef struct _ISO_HEADER { B_UINT32 ISOImageMagicNumber; B_UINT32 ISOImageSize; B_UINT32 ISOImageCRC; -- cgit v0.10.2 From e5b2445e4608219fe5b9dfea0485200a34360814 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:47 -0500 Subject: Staging: bcm: Enclose complex values in parenthesis in nvm.h This patch fixes the warning: "Macros with complex values should be enclosed in parenthesis" as reported by checkpatch.pl Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 36a9707..a7b2d3f 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -265,10 +265,10 @@ typedef struct _ISO_HEADER { #define CORRUPTED_PATTERN 0x0 #define UNINIT_PTR_IN_CS 0xBBBBDDDD #define VENDOR_PTR_IN_CS 0xAAAACCCC -#define FLASH2X_SECTION_PRESENT 1 << 0 -#define FLASH2X_SECTION_VALID 1 << 1 -#define FLASH2X_SECTION_RO 1 << 2 -#define FLASH2X_SECTION_ACT 1 << 3 +#define FLASH2X_SECTION_PRESENT (1 << 0) +#define FLASH2X_SECTION_VALID (1 << 1) +#define FLASH2X_SECTION_RO (1 << 2) +#define FLASH2X_SECTION_ACT (1 << 3) #define SECTOR_IS_NOT_WRITABLE STATUS_FAILURE #define INVALID_OFFSET STATUS_FAILURE #define INVALID_SECTION STATUS_FAILURE -- cgit v0.10.2 From 6f98775fe99a1c0c3e14f08c7a82f772982807da Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:48 -0500 Subject: Staging: bcm: Replace B_UINT32 with u32 in nvm.h This patch replace "B_UINT32" with "u32" in nvm.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index a7b2d3f..a4f329c 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -27,32 +27,32 @@ typedef struct _FLASH_SECTOR_INFO { } FLASH_SECTOR_INFO, *PFLASH_SECTOR_INFO; typedef struct _FLASH_CS_INFO { - B_UINT32 MagicNumber; + u32 MagicNumber; /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */ - B_UINT32 FlashLayoutVersion; - B_UINT32 ISOImageVersion; - B_UINT32 SCSIFirmwareVersion; - B_UINT32 OffsetFromZeroForPart1ISOImage; - B_UINT32 OffsetFromZeroForScsiFirmware; - B_UINT32 SizeOfScsiFirmware; - B_UINT32 OffsetFromZeroForPart2ISOImage; - B_UINT32 OffsetFromZeroForCalibrationStart; - B_UINT32 OffsetFromZeroForCalibrationEnd; - B_UINT32 OffsetFromZeroForVSAStart; - B_UINT32 OffsetFromZeroForVSAEnd; - B_UINT32 OffsetFromZeroForControlSectionStart; - B_UINT32 OffsetFromZeroForControlSectionData; - B_UINT32 CDLessInactivityTimeout; - B_UINT32 NewImageSignature; - B_UINT32 FlashSectorSizeSig; - B_UINT32 FlashSectorSize; - B_UINT32 FlashWriteSupportSize; - B_UINT32 TotalFlashSize; - B_UINT32 FlashBaseAddr; - B_UINT32 FlashPartMaxSize; - B_UINT32 IsCDLessDeviceBootSig; + u32 FlashLayoutVersion; + u32 ISOImageVersion; + u32 SCSIFirmwareVersion; + u32 OffsetFromZeroForPart1ISOImage; + u32 OffsetFromZeroForScsiFirmware; + u32 SizeOfScsiFirmware; + u32 OffsetFromZeroForPart2ISOImage; + u32 OffsetFromZeroForCalibrationStart; + u32 OffsetFromZeroForCalibrationEnd; + u32 OffsetFromZeroForVSAStart; + u32 OffsetFromZeroForVSAEnd; + u32 OffsetFromZeroForControlSectionStart; + u32 OffsetFromZeroForControlSectionData; + u32 CDLessInactivityTimeout; + u32 NewImageSignature; + u32 FlashSectorSizeSig; + u32 FlashSectorSize; + u32 FlashWriteSupportSize; + u32 TotalFlashSize; + u32 FlashBaseAddr; + u32 FlashPartMaxSize; + u32 IsCDLessDeviceBootSig; /* MSC Timeout after reset to switch from MSC to NW Mode */ - B_UINT32 MassStorageTimeout; + u32 MassStorageTimeout; } FLASH_CS_INFO, *PFLASH_CS_INFO; #define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024) @@ -60,55 +60,55 @@ typedef struct _FLASH_CS_INFO { typedef struct _FLASH_2X_CS_INFO { /* magic number as 0xBECE-F1A5 - F1A5 for "flas-h" */ - B_UINT32 MagicNumber; - B_UINT32 FlashLayoutVersion; - B_UINT32 ISOImageVersion; - B_UINT32 SCSIFirmwareVersion; - B_UINT32 OffsetFromZeroForPart1ISOImage; - B_UINT32 OffsetFromZeroForScsiFirmware; - B_UINT32 SizeOfScsiFirmware; - B_UINT32 OffsetFromZeroForPart2ISOImage; - B_UINT32 OffsetFromZeroForDSDStart; - B_UINT32 OffsetFromZeroForDSDEnd; - B_UINT32 OffsetFromZeroForVSAStart; - B_UINT32 OffsetFromZeroForVSAEnd; - B_UINT32 OffsetFromZeroForControlSectionStart; - B_UINT32 OffsetFromZeroForControlSectionData; + u32 MagicNumber; + u32 FlashLayoutVersion; + u32 ISOImageVersion; + u32 SCSIFirmwareVersion; + u32 OffsetFromZeroForPart1ISOImage; + u32 OffsetFromZeroForScsiFirmware; + u32 SizeOfScsiFirmware; + u32 OffsetFromZeroForPart2ISOImage; + u32 OffsetFromZeroForDSDStart; + u32 OffsetFromZeroForDSDEnd; + u32 OffsetFromZeroForVSAStart; + u32 OffsetFromZeroForVSAEnd; + u32 OffsetFromZeroForControlSectionStart; + u32 OffsetFromZeroForControlSectionData; /* NO Data Activity timeout to switch from MSC to NW Mode */ - B_UINT32 CDLessInactivityTimeout; - B_UINT32 NewImageSignature; - B_UINT32 FlashSectorSizeSig; - B_UINT32 FlashSectorSize; - B_UINT32 FlashWriteSupportSize; - B_UINT32 TotalFlashSize; - B_UINT32 FlashBaseAddr; - B_UINT32 FlashPartMaxSize; - B_UINT32 IsCDLessDeviceBootSig; + u32 CDLessInactivityTimeout; + u32 NewImageSignature; + u32 FlashSectorSizeSig; + u32 FlashSectorSize; + u32 FlashWriteSupportSize; + u32 TotalFlashSize; + u32 FlashBaseAddr; + u32 FlashPartMaxSize; + u32 IsCDLessDeviceBootSig; /* MSC Timeout after reset to switch from MSC to NW Mode */ - B_UINT32 MassStorageTimeout; + u32 MassStorageTimeout; /* Flash Map 2.0 Field */ - B_UINT32 OffsetISOImage1Part1Start; - B_UINT32 OffsetISOImage1Part1End; - B_UINT32 OffsetISOImage1Part2Start; - B_UINT32 OffsetISOImage1Part2End; - B_UINT32 OffsetISOImage1Part3Start; - B_UINT32 OffsetISOImage1Part3End; - B_UINT32 OffsetISOImage2Part1Start; - B_UINT32 OffsetISOImage2Part1End; - B_UINT32 OffsetISOImage2Part2Start; - B_UINT32 OffsetISOImage2Part2End; - B_UINT32 OffsetISOImage2Part3Start; - B_UINT32 OffsetISOImage2Part3End; + u32 OffsetISOImage1Part1Start; + u32 OffsetISOImage1Part1End; + u32 OffsetISOImage1Part2Start; + u32 OffsetISOImage1Part2End; + u32 OffsetISOImage1Part3Start; + u32 OffsetISOImage1Part3End; + u32 OffsetISOImage2Part1Start; + u32 OffsetISOImage2Part1End; + u32 OffsetISOImage2Part2Start; + u32 OffsetISOImage2Part2End; + u32 OffsetISOImage2Part3Start; + u32 OffsetISOImage2Part3End; /* DSD Header offset from start of DSD */ - B_UINT32 OffsetFromDSDStartForDSDHeader; - B_UINT32 OffsetFromZeroForDSD1Start; - B_UINT32 OffsetFromZeroForDSD1End; - B_UINT32 OffsetFromZeroForDSD2Start; - B_UINT32 OffsetFromZeroForDSD2End; - B_UINT32 OffsetFromZeroForVSA1Start; - B_UINT32 OffsetFromZeroForVSA1End; - B_UINT32 OffsetFromZeroForVSA2Start; - B_UINT32 OffsetFromZeroForVSA2End; + u32 OffsetFromDSDStartForDSDHeader; + u32 OffsetFromZeroForDSD1Start; + u32 OffsetFromZeroForDSD1End; + u32 OffsetFromZeroForDSD2Start; + u32 OffsetFromZeroForDSD2End; + u32 OffsetFromZeroForVSA1Start; + u32 OffsetFromZeroForVSA1End; + u32 OffsetFromZeroForVSA2Start; + u32 OffsetFromZeroForVSA2End; /* * ACCESS_BITS_PER_SECTOR 2 * ACCESS_RW 0 @@ -116,38 +116,38 @@ typedef struct _FLASH_2X_CS_INFO { * ACCESS_RESVD 2 * ACCESS_RESVD 3 */ - B_UINT32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)]; + u32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)]; /* All expansions to the control data structure should add here */ } FLASH2X_CS_INFO, *PFLASH2X_CS_INFO; typedef struct _VENDOR_SECTION_INFO { - B_UINT32 OffsetFromZeroForSectionStart; - B_UINT32 OffsetFromZeroForSectionEnd; - B_UINT32 AccessFlags; - B_UINT32 Reserved[16]; + u32 OffsetFromZeroForSectionStart; + u32 OffsetFromZeroForSectionEnd; + u32 AccessFlags; + u32 Reserved[16]; } VENDOR_SECTION_INFO, *PVENDOR_SECTION_INFO; typedef struct _FLASH2X_VENDORSPECIFIC_INFO { VENDOR_SECTION_INFO VendorSection[TOTAL_SECTIONS]; - B_UINT32 Reserved[16]; + u32 Reserved[16]; } FLASH2X_VENDORSPECIFIC_INFO, *PFLASH2X_VENDORSPECIFIC_INFO; typedef struct _DSD_HEADER { - B_UINT32 DSDImageSize; - B_UINT32 DSDImageCRC; - B_UINT32 DSDImagePriority; + u32 DSDImageSize; + u32 DSDImageCRC; + u32 DSDImagePriority; /* We should not consider right now. Reading reserve is worthless. */ - B_UINT32 Reserved[252]; /* Resvd for DSD Header */ - B_UINT32 DSDImageMagicNumber; + u32 Reserved[252]; /* Resvd for DSD Header */ + u32 DSDImageMagicNumber; } DSD_HEADER, *PDSD_HEADER; typedef struct _ISO_HEADER { - B_UINT32 ISOImageMagicNumber; - B_UINT32 ISOImageSize; - B_UINT32 ISOImageCRC; - B_UINT32 ISOImagePriority; + u32 ISOImageMagicNumber; + u32 ISOImageSize; + u32 ISOImageCRC; + u32 ISOImagePriority; /* We should not consider right now. Reading reserve is worthless. */ - B_UINT32 Reserved[60]; /* Resvd for ISO Header extension */ + u32 Reserved[60]; /* Resvd for ISO Header extension */ } ISO_HEADER, *PISO_HEADER; #define EEPROM_BEGIN_CIS (0) -- cgit v0.10.2 From b5ec04ed75a5ffee36611aac58936f33db41ba92 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:49 -0500 Subject: Staging: bcm: Replace UINT with unsigned int in nvm.h This patch replaces "UINT" with "unsigned int" in nvm.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index a4f329c..9a45df1 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -22,8 +22,8 @@ #define _NVM_H_ typedef struct _FLASH_SECTOR_INFO { - UINT uiSectorSig; - UINT uiSectorSize; + unsigned int uiSectorSig; + unsigned int uiSectorSize; } FLASH_SECTOR_INFO, *PFLASH_SECTOR_INFO; typedef struct _FLASH_CS_INFO { -- cgit v0.10.2 From 20a2ae8019080d6641fb409016b55e48e6773dcc Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:50 -0500 Subject: Staging: bcm: Replace PUCHAR with u8 * in nmv.h This patch replaces "PUCHAR" with "u8 *" in nvm.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 9a45df1..7aed263 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -285,7 +285,7 @@ typedef struct _ISO_HEADER { #define SIGNATURE_SIZE 4 #define DEFAULT_BUFF_SIZE 0x10000 -#define FIELD_OFFSET_IN_HEADER(HeaderPointer, Field) ((PUCHAR)&((HeaderPointer)(NULL))->Field - (PUCHAR)(NULL)) +#define FIELD_OFFSET_IN_HEADER(HeaderPointer, Field) ((u8 *)&((HeaderPointer)(NULL))->Field - (u8 *)(NULL)) #endif -- cgit v0.10.2 From be5e219dcdc7af02cf7e9d1033ec6c45902fdcb0 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:51 -0500 Subject: Staging: bcm: Remove typedef for _ISO_HEADER and call directly. This patch removes typedef for _ISO_HEADER, and changes the name of the struct to bcm_iso_header. In addition, any calls to typedefs ISO_HEADER, or *PISO_HEADER are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index eab676f..3a77db3 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -3355,7 +3355,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti int Status = STATUS_SUCCESS; /* DSD_HEADER sDSD = {0}; - * ISO_HEADER sISO = {0}; + * struct bcm_iso_header sISO = {0}; */ int HighestPriDSD = 0 ; int HighestPriISO = 0; @@ -3391,7 +3391,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti Status = BcmFlash2xBulkWrite(Adapter, &SectImagePriority, HighestPriISO, - 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority), + 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority), SIGNATURE_SIZE, TRUE); if (Status) { @@ -3416,7 +3416,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti Status = BcmFlash2xBulkWrite(Adapter, &SectImagePriority, eFlash2xSectVal, - 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority), + 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority), SIGNATURE_SIZE, TRUE); if (Status) { @@ -3550,7 +3550,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section Status = BcmFlash2xBulkRead(Adapter, &ISOLength, sCopySectStrut.SrcSection, - 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageSize), + 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageSize), 4); if (Status) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO\n"); @@ -3561,7 +3561,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section if (ISOLength % Adapter->uiSectorSize) ISOLength = Adapter->uiSectorSize * (1 + ISOLength/Adapter->uiSectorSize); - sigOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber); + sigOffset = FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber); Buff = kzalloc(Adapter->uiSectorSize, GFP_KERNEL); @@ -3872,7 +3872,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio } else if ((eFlashSectionVal == ISO_IMAGE1) || (eFlashSectionVal == ISO_IMAGE2)) { uiSignature = htonl(ISO_IMAGE_MAGIC_NUMBER); /* uiOffset = 0; */ - uiOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber); + uiOffset = FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber); if ((ReadISOSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Currupted Pattern is not there. Hence won't write sig"); return STATUS_FAILURE; @@ -4148,7 +4148,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned if (uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1) || uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2)) { offsetToProtect = 0; - HeaderSizeToProtect = sizeof(ISO_HEADER); + HeaderSizeToProtect = sizeof(struct bcm_iso_header); bHasHeader = TRUE; } /* If Header is present overwrite passed buffer with this */ @@ -4348,7 +4348,7 @@ int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_ { unsigned int uiISOsig = 0; /* unsigned int sigoffsetInMap = 0; - * ISO_HEADER ISOHeader = {0}; + * struct bcm_iso_header ISOHeader = {0}; * sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader; */ if (iso != ISO_IMAGE1 && iso != ISO_IMAGE2) { @@ -4358,7 +4358,7 @@ int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_ BcmFlash2xBulkRead(Adapter, &uiISOsig, iso, - 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber), + 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber), SIGNATURE_SIZE); uiISOsig = ntohl(uiISOsig); @@ -4375,7 +4375,7 @@ int ReadISOPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v BcmFlash2xBulkRead(Adapter, &ISOPri, iso, - 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority), + 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority), 4); ISOPri = ntohl(ISOPri); diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 7aed263..8554f73 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -141,14 +141,14 @@ typedef struct _DSD_HEADER { u32 DSDImageMagicNumber; } DSD_HEADER, *PDSD_HEADER; -typedef struct _ISO_HEADER { +struct bcm_iso_header { u32 ISOImageMagicNumber; u32 ISOImageSize; u32 ISOImageCRC; u32 ISOImagePriority; /* We should not consider right now. Reading reserve is worthless. */ u32 Reserved[60]; /* Resvd for ISO Header extension */ -} ISO_HEADER, *PISO_HEADER; +}; #define EEPROM_BEGIN_CIS (0) #define EEPROM_BEGIN_NON_CIS (0x200) -- cgit v0.10.2 From 77b54101b548791bab732e93d6caa7d427204f19 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:52 -0500 Subject: Staging: bcm: Remove typedef for _DSD_HEADER and call directly. This patch removes typedef for _DSD_HEADER, and changes the name of the struct to bcm_dsd_header. In addition, any calls to typedefs DSD_HEADER, or *PDSD_HEADER are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 3a77db3..8c72e7d 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -472,7 +472,7 @@ static int BeceemFlashBulkRead(struct bcm_mini_adapter *Adapter, static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter) { if (IsFlash2x(Adapter)) - return Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER); + return Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header); else return 32 * 1024; } @@ -2446,7 +2446,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter) switch (i) { case DSD0: - if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) && + if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) && (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)) Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = VENDOR_PTR_IN_CS; else @@ -2454,7 +2454,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter) break; case DSD1: - if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) && + if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) && (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)) Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = VENDOR_PTR_IN_CS; else @@ -2462,7 +2462,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter) break; case DSD2: - if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) && + if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) && (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)) Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = VENDOR_PTR_IN_CS; else @@ -3354,7 +3354,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti unsigned int SectImagePriority = 0; int Status = STATUS_SUCCESS; - /* DSD_HEADER sDSD = {0}; + /* struct bcm_dsd_header sDSD = {0}; * struct bcm_iso_header sISO = {0}; */ int HighestPriDSD = 0 ; @@ -3452,7 +3452,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti Status = BcmFlash2xBulkWrite(Adapter, &SectImagePriority, HighestPriDSD, - Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), + Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority), SIGNATURE_SIZE, TRUE); if (Status) { @@ -3472,7 +3472,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti Status = BcmFlash2xBulkWrite(Adapter, &SectImagePriority, HighestPriDSD, - Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), + Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority), SIGNATURE_SIZE, TRUE); if (Status) { @@ -3492,7 +3492,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti Status = BcmFlash2xBulkWrite(Adapter, &SectImagePriority, eFlash2xSectVal, - Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), + Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority), SIGNATURE_SIZE, TRUE); if (Status) { @@ -3846,7 +3846,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio unsigned int uiSignature = 0; unsigned int uiOffset = 0; - /* DSD_HEADER dsdHeader = {0}; */ + /* struct bcm_dsd_header dsdHeader = {0}; */ if (Adapter->bSigCorrupted == FALSE) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is not corrupted by driver, hence not restoring\n"); return STATUS_SUCCESS; @@ -3863,7 +3863,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio uiSignature = htonl(DSD_IMAGE_MAGIC_NUMBER); uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader; - uiOffset += FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber); + uiOffset += FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber); if ((ReadDSDSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Corrupted Pattern is not there. Hence won't write sig"); @@ -4141,7 +4141,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter, DSD0) - Adapter->uiSectorSize)) { /* offset from the sector boundary having the header map */ offsetToProtect = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader % Adapter->uiSectorSize; - HeaderSizeToProtect = sizeof(DSD_HEADER); + HeaderSizeToProtect = sizeof(struct bcm_dsd_header); bHasHeader = TRUE; } @@ -4167,7 +4167,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned kfree(pTempBuff); } if (bHasHeader && Adapter->bSigCorrupted) { - sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber))); + sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber))); sig = ntohl(sig); if ((sig & 0xFF000000) != CORRUPTED_PATTERN) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Desired pattern is not at sig offset. Hence won't restore"); @@ -4175,7 +4175,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned return STATUS_SUCCESS; } BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Corrupted sig is :%X", sig); - *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber))) = htonl(DSD_IMAGE_MAGIC_NUMBER); + *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber))) = htonl(DSD_IMAGE_MAGIC_NUMBER); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature in Header Write only"); Adapter->bSigCorrupted = FALSE; } @@ -4268,7 +4268,7 @@ int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_ { unsigned int uiDSDsig = 0; /* unsigned int sigoffsetInMap = 0; - * DSD_HEADER dsdHeader = {0}; + * struct bcm_dsd_header dsdHeader = {0}; */ /* sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader; */ @@ -4280,7 +4280,7 @@ int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_ BcmFlash2xBulkRead(Adapter, &uiDSDsig, dsd, - Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber), + Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber), SIGNATURE_SIZE); uiDSDsig = ntohl(uiDSDsig); @@ -4293,7 +4293,7 @@ int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v { /* unsigned int priOffsetInMap = 0 ; */ unsigned int uiDSDPri = STATUS_FAILURE; - /* DSD_HEADER dsdHeader = {0}; + /* struct bcm_dsd_header dsdHeader = {0}; * priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader; */ if (IsSectionWritable(Adapter, dsd)) { @@ -4301,7 +4301,7 @@ int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v BcmFlash2xBulkRead(Adapter, &uiDSDPri, dsd, - Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), + Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority), 4); uiDSDPri = ntohl(uiDSDPri); @@ -4568,7 +4568,7 @@ static int CorruptDSDSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect return -ENOMEM; } - uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER); + uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header); uiOffset -= MAX_RW_SIZE; BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, eFlash2xSectionVal, uiOffset, MAX_RW_SIZE); diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 8554f73..de99864 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -132,14 +132,14 @@ typedef struct _FLASH2X_VENDORSPECIFIC_INFO { u32 Reserved[16]; } FLASH2X_VENDORSPECIFIC_INFO, *PFLASH2X_VENDORSPECIFIC_INFO; -typedef struct _DSD_HEADER { +struct bcm_dsd_header { u32 DSDImageSize; u32 DSDImageCRC; u32 DSDImagePriority; /* We should not consider right now. Reading reserve is worthless. */ u32 Reserved[252]; /* Resvd for DSD Header */ u32 DSDImageMagicNumber; -} DSD_HEADER, *PDSD_HEADER; +}; struct bcm_iso_header { u32 ISOImageMagicNumber; -- cgit v0.10.2 From 2fe119fd351870b1b159d4e117f77369475f150a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:53 -0500 Subject: Staging: bcm: Remove typedef for _FLASH2X_VENDORSPECIFIC_INFO and call directly. This patch removes typedef for _FLASH2X_VENDORSPECIFIC_INFO, and changes the name of the struct to bcm_flash2x_vendor_info. In addition, any calls to typedefs FLASH2X_VENDORSPECIFIC_INFO, or *PFLASH2X_VENDORSPECIFIC_INFO are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index f577948..4231b67 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -368,7 +368,7 @@ struct bcm_mini_adapter { /* BOOLEAN InterfaceUpStatus; */ PFLASH2X_CS_INFO psFlash2xCSInfo; PFLASH_CS_INFO psFlashCSInfo; - PFLASH2X_VENDORSPECIFIC_INFO psFlash2xVendorInfo; + struct bcm_flash2x_vendor_info *psFlash2xVendorInfo; UINT uiFlashBaseAdd; /* Flash start address */ UINT uiActiveISOOffset; /* Active ISO offset chosen before f/w download */ enum bcm_flash2x_section_val eActiveISO; /* Active ISO section val */ diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 8c72e7d..468b316 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -2241,7 +2241,7 @@ int BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter) return -ENOMEM; } - psAdapter->psFlash2xVendorInfo = (PFLASH2X_VENDORSPECIFIC_INFO)kzalloc(sizeof(FLASH2X_VENDORSPECIFIC_INFO), GFP_KERNEL); + psAdapter->psFlash2xVendorInfo = (struct bcm_flash2x_vendor_info *)kzalloc(sizeof(struct bcm_flash2x_vendor_info), GFP_KERNEL); if (!psAdapter->psFlash2xVendorInfo) { BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate Vendor Info Memory for Flash 2.x"); kfree(psAdapter->psFlashCSInfo); diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index de99864..849ff00 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -127,10 +127,10 @@ typedef struct _VENDOR_SECTION_INFO { u32 Reserved[16]; } VENDOR_SECTION_INFO, *PVENDOR_SECTION_INFO; -typedef struct _FLASH2X_VENDORSPECIFIC_INFO { +struct bcm_flash2x_vendor_info { VENDOR_SECTION_INFO VendorSection[TOTAL_SECTIONS]; u32 Reserved[16]; -} FLASH2X_VENDORSPECIFIC_INFO, *PFLASH2X_VENDORSPECIFIC_INFO; +}; struct bcm_dsd_header { u32 DSDImageSize; diff --git a/drivers/staging/bcm/vendorspecificextn.c b/drivers/staging/bcm/vendorspecificextn.c index 40be60a..be1f91d 100644 --- a/drivers/staging/bcm/vendorspecificextn.c +++ b/drivers/staging/bcm/vendorspecificextn.c @@ -11,7 +11,7 @@ // STATUS_SUCCESS/STATUS_FAILURE // //----------------------------------------------------------------------------- -INT vendorextnGetSectionInfo(PVOID pContext,PFLASH2X_VENDORSPECIFIC_INFO pVendorInfo) +INT vendorextnGetSectionInfo(PVOID pContext, struct bcm_flash2x_vendor_info *pVendorInfo) { return STATUS_FAILURE; } diff --git a/drivers/staging/bcm/vendorspecificextn.h b/drivers/staging/bcm/vendorspecificextn.h index 834410e..52890d2 100644 --- a/drivers/staging/bcm/vendorspecificextn.h +++ b/drivers/staging/bcm/vendorspecificextn.h @@ -4,7 +4,7 @@ #define CONTINUE_COMMON_PATH 0xFFFF -INT vendorextnGetSectionInfo(PVOID pContext,PFLASH2X_VENDORSPECIFIC_INFO pVendorInfo); +INT vendorextnGetSectionInfo(PVOID pContext, struct bcm_flash2x_vendor_info *pVendorInfo); INT vendorextnExit(struct bcm_mini_adapter *Adapter); INT vendorextnInit(struct bcm_mini_adapter *Adapter); INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg); -- cgit v0.10.2 From ad2f522cc6ff6db7dc4b650353739247debc293d Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:54 -0500 Subject: Staging: bcm: Remove typedef for _VENDOR_SECTION_INFO and call directly. This patch removes typedef for _VENDOR_SECTION_INFO, and changes the name of the struct to bcm_vendor_section_info. In addition, any calls to typedefs VENDOR_SECTION_INFO, or *PVENDOR_SECTION_INFO are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 849ff00..728a632 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -120,15 +120,15 @@ typedef struct _FLASH_2X_CS_INFO { /* All expansions to the control data structure should add here */ } FLASH2X_CS_INFO, *PFLASH2X_CS_INFO; -typedef struct _VENDOR_SECTION_INFO { +struct bcm_vendor_section_info { u32 OffsetFromZeroForSectionStart; u32 OffsetFromZeroForSectionEnd; u32 AccessFlags; u32 Reserved[16]; -} VENDOR_SECTION_INFO, *PVENDOR_SECTION_INFO; +}; struct bcm_flash2x_vendor_info { - VENDOR_SECTION_INFO VendorSection[TOTAL_SECTIONS]; + struct bcm_vendor_section_info VendorSection[TOTAL_SECTIONS]; u32 Reserved[16]; }; -- cgit v0.10.2 From 08391731e08d9e0d48664680e7b174e6f61d00e3 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:55 -0500 Subject: Staging: bcm: Remove typedef for _FLASH_2X_CS_INFO and call directly. This patch removes typedef for _FLASH_2X_CS_INFO, and changes the name of the struct to bcm_flash2x_cs_info. In addition, any calls to typedefs FLASH2X_CS_INFO, or *PFLASH2X_CS_INFO are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index 4231b67..d002aea 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -366,7 +366,7 @@ struct bcm_mini_adapter { struct device *pstCreatedClassDevice; /* BOOLEAN InterfaceUpStatus; */ - PFLASH2X_CS_INFO psFlash2xCSInfo; + struct bcm_flash2x_cs_info *psFlash2xCSInfo; PFLASH_CS_INFO psFlashCSInfo; struct bcm_flash2x_vendor_info *psFlash2xVendorInfo; UINT uiFlashBaseAdd; /* Flash start address */ diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index efad33e..300d60a 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -1783,16 +1783,16 @@ cntrlEnd: } if (IsFlash2x(Adapter) == TRUE) { - if (IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO)) + if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info)) return -EINVAL; - if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO))) + if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info))) return -EFAULT; } else { if (IoBuffer.OutputLength < sizeof(FLASH_CS_INFO)) return -EINVAL; - if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO))) + if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash2x_cs_info))) return -EFAULT; } } diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 468b316..2c3944c 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -2234,7 +2234,7 @@ int BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter) return -ENOMEM; } - psAdapter->psFlash2xCSInfo = (PFLASH2X_CS_INFO)kzalloc(sizeof(FLASH2X_CS_INFO), GFP_KERNEL); + psAdapter->psFlash2xCSInfo = (struct bcm_flash2x_cs_info *)kzalloc(sizeof(struct bcm_flash2x_cs_info), GFP_KERNEL); if (!psAdapter->psFlash2xCSInfo) { BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 2.x"); kfree(psAdapter->psFlashCSInfo); @@ -2264,7 +2264,7 @@ int BcmDeAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter) return STATUS_SUCCESS; } -static int BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo, struct bcm_mini_adapter *Adapter) +static int BcmDumpFlash2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSInfo, struct bcm_mini_adapter *Adapter) { unsigned int Index = 0; @@ -2324,7 +2324,7 @@ static int BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo, struct bc return STATUS_SUCCESS; } -static int ConvertEndianOf2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo) +static int ConvertEndianOf2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSInfo) { unsigned int Index = 0; @@ -2523,7 +2523,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) Adapter->uiFlashBaseAdd = 0; Adapter->ulFlashCalStart = 0; memset(Adapter->psFlashCSInfo, 0 , sizeof(FLASH_CS_INFO)); - memset(Adapter->psFlash2xCSInfo, 0 , sizeof(FLASH2X_CS_INFO)); + memset(Adapter->psFlash2xCSInfo, 0 , sizeof(struct bcm_flash2x_cs_info)); if (!Adapter->bDDRInitDone) { value = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT; @@ -2576,7 +2576,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) Adapter->uiFlashBaseAdd = Adapter->psFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF; } else { if (BcmFlash2xBulkRead(Adapter, (PUINT)Adapter->psFlash2xCSInfo, NO_SECTION_VAL, - Adapter->ulFlashControlSectionStart, sizeof(FLASH2X_CS_INFO))) { + Adapter->ulFlashControlSectionStart, sizeof(struct bcm_flash2x_cs_info))) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to read CS structure\n"); return STATUS_FAILURE; } @@ -3101,7 +3101,7 @@ static int BcmDumpFlash2xSectionBitMap(struct bcm_flash2x_bitmap *psFlash2xBitMa int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_bitmap *psFlash2xBitMap) { - PFLASH2X_CS_INFO psFlash2xCSInfo = Adapter->psFlash2xCSInfo; + struct bcm_flash2x_cs_info *psFlash2xCSInfo = Adapter->psFlash2xCSInfo; enum bcm_flash2x_section_val uiHighestPriDSD = 0; enum bcm_flash2x_section_val uiHighestPriISO = 0; BOOLEAN SetActiveDSDDone = FALSE; diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index 728a632..e64a620 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -58,7 +58,7 @@ typedef struct _FLASH_CS_INFO { #define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024) #define DEFAULT_SECTOR_SIZE (64 * 1024) -typedef struct _FLASH_2X_CS_INFO { +struct bcm_flash2x_cs_info { /* magic number as 0xBECE-F1A5 - F1A5 for "flas-h" */ u32 MagicNumber; u32 FlashLayoutVersion; @@ -118,7 +118,7 @@ typedef struct _FLASH_2X_CS_INFO { */ u32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)]; /* All expansions to the control data structure should add here */ -} FLASH2X_CS_INFO, *PFLASH2X_CS_INFO; +}; struct bcm_vendor_section_info { u32 OffsetFromZeroForSectionStart; -- cgit v0.10.2 From 168b14009a135d669cb68fa9839cf3b796dd6382 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:56 -0500 Subject: Staging: bcm: Remove typedef for _FLASH_CS_INFO and call directly. This patch removes typedef for _FLASH_CS_INFO, and changes the name of the struct to bcm_flash_cs_info. In addition, any calls to typedefs FLASH_CS_INFO, or *PFLASH_CS_INFO are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index d002aea..1f7005d 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -367,7 +367,7 @@ struct bcm_mini_adapter { /* BOOLEAN InterfaceUpStatus; */ struct bcm_flash2x_cs_info *psFlash2xCSInfo; - PFLASH_CS_INFO psFlashCSInfo; + struct bcm_flash_cs_info *psFlashCSInfo; struct bcm_flash2x_vendor_info *psFlash2xVendorInfo; UINT uiFlashBaseAdd; /* Flash start address */ UINT uiActiveISOOffset; /* Active ISO offset chosen before f/w download */ diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index 300d60a..fd7c974 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -1789,7 +1789,7 @@ cntrlEnd: if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info))) return -EFAULT; } else { - if (IoBuffer.OutputLength < sizeof(FLASH_CS_INFO)) + if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info)) return -EINVAL; if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash2x_cs_info))) diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 2c3944c..8960a18 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -1978,7 +1978,7 @@ int BeceemNVMWrite(struct bcm_mini_adapter *Adapter, int BcmUpdateSectorSize(struct bcm_mini_adapter *Adapter, unsigned int uiSectorSize) { int Status = -1; - FLASH_CS_INFO sFlashCsInfo = {0}; + struct bcm_flash_cs_info sFlashCsInfo = {0}; unsigned int uiTemp = 0; unsigned int uiSectorSig = 0; unsigned int uiCurrentSectorSize = 0; @@ -2228,7 +2228,7 @@ int BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter) BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL"); return -EINVAL; } - psAdapter->psFlashCSInfo = (PFLASH_CS_INFO)kzalloc(sizeof(FLASH_CS_INFO), GFP_KERNEL); + psAdapter->psFlashCSInfo = (struct bcm_flash_cs_info *)kzalloc(sizeof(struct bcm_flash_cs_info), GFP_KERNEL); if (psAdapter->psFlashCSInfo == NULL) { BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 1.x"); return -ENOMEM; @@ -2381,7 +2381,7 @@ static int ConvertEndianOf2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSI return STATUS_SUCCESS; } -static int ConvertEndianOfCSStructure(PFLASH_CS_INFO psFlashCSInfo) +static int ConvertEndianOfCSStructure(struct bcm_flash_cs_info *psFlashCSInfo) { /* unsigned int Index = 0; */ psFlashCSInfo->MagicNumber = ntohl(psFlashCSInfo->MagicNumber); @@ -2509,7 +2509,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter) static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) { - /* FLASH_CS_INFO sFlashCsInfo = {0}; */ + /* struct bcm_flash_cs_info sFlashCsInfo = {0}; */ #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS) unsigned int value; @@ -2522,7 +2522,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) Adapter->uiFlashBaseAdd = 0; Adapter->ulFlashCalStart = 0; - memset(Adapter->psFlashCSInfo, 0 , sizeof(FLASH_CS_INFO)); + memset(Adapter->psFlashCSInfo, 0 , sizeof(struct bcm_flash_cs_info)); memset(Adapter->psFlash2xCSInfo, 0 , sizeof(struct bcm_flash2x_cs_info)); if (!Adapter->bDDRInitDone) { @@ -2551,7 +2551,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion); if (uiFlashLayoutMajorVersion < FLASH_2X_MAJOR_NUMBER) { - BeceemFlashBulkRead(Adapter, (PUINT)Adapter->psFlashCSInfo, Adapter->ulFlashControlSectionStart, sizeof(FLASH_CS_INFO)); + BeceemFlashBulkRead(Adapter, (PUINT)Adapter->psFlashCSInfo, Adapter->ulFlashControlSectionStart, sizeof(struct bcm_flash_cs_info)); ConvertEndianOfCSStructure(Adapter->psFlashCSInfo); Adapter->ulFlashCalStart = (Adapter->psFlashCSInfo->OffsetFromZeroForCalibrationStart); diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index e64a620..b262a11 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -26,7 +26,7 @@ typedef struct _FLASH_SECTOR_INFO { unsigned int uiSectorSize; } FLASH_SECTOR_INFO, *PFLASH_SECTOR_INFO; -typedef struct _FLASH_CS_INFO { +struct bcm_flash_cs_info { u32 MagicNumber; /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */ u32 FlashLayoutVersion; @@ -53,7 +53,7 @@ typedef struct _FLASH_CS_INFO { u32 IsCDLessDeviceBootSig; /* MSC Timeout after reset to switch from MSC to NW Mode */ u32 MassStorageTimeout; -} FLASH_CS_INFO, *PFLASH_CS_INFO; +}; #define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024) #define DEFAULT_SECTOR_SIZE (64 * 1024) -- cgit v0.10.2 From 44d8311272c0d67ce135fc5cc985ff6f399a75a5 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 1 Dec 2012 01:15:57 -0500 Subject: Staging: bcm: Remove typedef for _FLASH_SECTOR_INFO. This patch removes typedef for _FLASH_SECTOR_INFO because it is not being used. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h index b262a11..e765cca 100644 --- a/drivers/staging/bcm/nvm.h +++ b/drivers/staging/bcm/nvm.h @@ -21,11 +21,6 @@ #ifndef _NVM_H_ #define _NVM_H_ -typedef struct _FLASH_SECTOR_INFO { - unsigned int uiSectorSig; - unsigned int uiSectorSize; -} FLASH_SECTOR_INFO, *PFLASH_SECTOR_INFO; - struct bcm_flash_cs_info { u32 MagicNumber; /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */ -- cgit v0.10.2 From 1fb14c4276fb59f3523fc33a1acf63c1af64f793 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 3 Dec 2012 22:36:24 -0500 Subject: Staging: bcm: Replace unsigned long long with u64 in Ioctl.h This patch replaces "unsigned long long" with u64" in Ioctl.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Ioctl.h b/drivers/staging/bcm/Ioctl.h index 8c70af9..8650d13 100644 --- a/drivers/staging/bcm/Ioctl.h +++ b/drivers/staging/bcm/Ioctl.h @@ -202,8 +202,8 @@ struct bcm_flash2x_bitmap { }; struct bcm_time_elapsed { - unsigned long long ul64TimeElapsedSinceNetEntry; - u32 uiReserved[4]; + u64 ul64TimeElapsedSinceNetEntry; + u32 uiReserved[4]; }; enum { -- cgit v0.10.2 From 7e5df051d44d9505c518831ff4522becd32384c7 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 3 Dec 2012 22:36:25 -0500 Subject: Staging: bcm: Remove unnecessary comments in CmHost.h This patch removes unnecessary comments that appear to be added as part of an annotation system. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/CmHost.h b/drivers/staging/bcm/CmHost.h index eecad8d..4ddfc3d4 100644 --- a/drivers/staging/bcm/CmHost.h +++ b/drivers/staging/bcm/CmHost.h @@ -27,32 +27,28 @@ struct bcm_add_indication_alt { u8 u8Type; u8 u8Direction; u16 u16TID; - /* brief 16bitCID */ u16 u16CID; - /* brief 16bitVCID */ u16 u16VCID; struct bcm_connect_mgr_params sfAuthorizedSet; struct bcm_connect_mgr_params sfAdmittedSet; struct bcm_connect_mgr_params sfActiveSet; u8 u8CC; /* < Confirmation Code */ - u8 u8Padd; /* < 8-bit Padding */ - u16 u16Padd; /* < 16 bit Padding */ + u8 u8Padd; + u16 u16Padd; }; struct bcm_change_indication { u8 u8Type; u8 u8Direction; u16 u16TID; - /* brief 16bitCID */ u16 u16CID; - /* brief 16bitVCID */ u16 u16VCID; struct bcm_connect_mgr_params sfAuthorizedSet; struct bcm_connect_mgr_params sfAdmittedSet; struct bcm_connect_mgr_params sfActiveSet; u8 u8CC; /* < Confirmation Code */ - u8 u8Padd; /* < 8-bit Padding */ - u16 u16Padd; /* < 16 bit */ + u8 u8Padd; + u16 u16Padd; }; unsigned long StoreCmControlResponseMessage(struct bcm_mini_adapter *Adapter, void *pvBuffer, unsigned int *puBufferLength); -- cgit v0.10.2 From d83beb86f4aa32721e907fe4c5772a679f5a2a9a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:54:54 -0500 Subject: Staging: bcm: Fix all white space issues in IPv6ProtocolHdr.h This patch fixes all white space issues in IPv6ProtocolHdr.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 8ba88a5..478cf3f 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -1,7 +1,6 @@ #ifndef _IPV6_PROTOCOL_DEFINES_ #define _IPV6_PROTOCOL_DEFINES_ - #define IPV6HDR_TYPE_HOPBYHOP 0x0 #define IPV6HDR_TYPE_ROUTING 0x2B #define IPV6HDR_TYPE_FRAGMENTATION 0x2C @@ -10,9 +9,8 @@ #define IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD 0x34 #define MASK_IPV6_CS_SPEC 0x2 - -#define TCP_HEADER_TYPE 0x6 -#define UDP_HEADER_TYPE 0x11 +#define TCP_HEADER_TYPE 0x6 +#define UDP_HEADER_TYPE 0x11 #define IPV6_ICMP_HDR_TYPE 0x2 #define IPV6_FLOWLABEL_BITOFFSET 9 @@ -36,7 +34,7 @@ typedef struct IPV6HeaderFormatTag UCHAR ucHopLimit; ULONG ulSrcIpAddress[4]; ULONG ulDestIpAddress[4]; -}IPV6Header; +} IPV6Header; typedef struct IPV6RoutingHeaderFormatTag { @@ -47,15 +45,15 @@ typedef struct IPV6RoutingHeaderFormatTag ULONG ulReserved; //UCHAR aucAddressList[0]; -}IPV6RoutingHeader; +} IPV6RoutingHeader; typedef struct IPV6FragmentHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucReserved; + UCHAR ucNextHeader; + UCHAR ucReserved; USHORT usFragmentOffset; ULONG ulIdentification; -}IPV6FragmentHeader; +} IPV6FragmentHeader; typedef struct IPV6DestOptionsHeaderFormatTag { @@ -63,54 +61,48 @@ typedef struct IPV6DestOptionsHeaderFormatTag UCHAR ucHdrExtLen; UCHAR ucDestOptions[6]; //UCHAR udExtDestOptions[0]; -}IPV6DestOptionsHeader; +} IPV6DestOptionsHeader; typedef struct IPV6HopByHopOptionsHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucMisc[3]; ULONG ulJumboPayloadLen; -}IPV6HopByHopOptionsHeader; +} IPV6HopByHopOptionsHeader; typedef struct IPV6AuthenticationHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucLength; + UCHAR ucNextHeader; + UCHAR ucLength; USHORT usReserved; ULONG ulSecurityParametersIndex; //UCHAR ucAuthenticationData[0]; - -}IPV6AuthenticationHeader; +} IPV6AuthenticationHeader; typedef struct IPV6IcmpHeaderFormatTag { - UCHAR ucType; - UCHAR ucCode; + UCHAR ucType; + UCHAR ucCode; USHORT usChecksum; //UCHAR ucIcmpMsg[0]; - -}IPV6IcmpHeader; +} IPV6IcmpHeader; typedef enum _E_IPADDR_CONTEXT { eSrcIpAddress, eDestIpAddress - -}E_IPADDR_CONTEXT; - - +} E_IPADDR_CONTEXT; //Function Prototypes -USHORT IpVersion6(struct bcm_mini_adapter *Adapter, /**< Pointer to the driver control structure */ +USHORT IpVersion6(struct bcm_mini_adapter *Adapter, /**< Pointer to the driver control structure */ PVOID pcIpHeader, /** Date: Mon, 10 Dec 2012 21:54:55 -0500 Subject: Staging: bcm: Properly format and remove comments as needed in IPv6ProtocolHdr.h This patch formats all comments and removes them as needed. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 478cf3f..f936f21 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -16,15 +16,11 @@ #define IPV6_MAX_CHAINEDHDR_BUFFBYTES 0x64 /* -// Size of Dest Options field of Destinations Options Header -// in bytes. -*/ + * Size of Dest Options field of Destinations Options Header + * in bytes. + */ #define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8 -//typedef unsigned char UCHAR; -//typedef unsigned short USHORT; -//typedef unsigned long int ULONG; - typedef struct IPV6HeaderFormatTag { UCHAR ucVersionPrio; @@ -43,8 +39,6 @@ typedef struct IPV6RoutingHeaderFormatTag UCHAR ucNumAddresses; UCHAR ucNextAddress; ULONG ulReserved; - //UCHAR aucAddressList[0]; - } IPV6RoutingHeader; typedef struct IPV6FragmentHeaderFormatTag @@ -60,7 +54,6 @@ typedef struct IPV6DestOptionsHeaderFormatTag UCHAR ucNextHeader; UCHAR ucHdrExtLen; UCHAR ucDestOptions[6]; - //UCHAR udExtDestOptions[0]; } IPV6DestOptionsHeader; typedef struct IPV6HopByHopOptionsHeaderFormatTag @@ -76,7 +69,6 @@ typedef struct IPV6AuthenticationHeaderFormatTag UCHAR ucLength; USHORT usReserved; ULONG ulSecurityParametersIndex; - //UCHAR ucAuthenticationData[0]; } IPV6AuthenticationHeader; typedef struct IPV6IcmpHeaderFormatTag @@ -84,7 +76,6 @@ typedef struct IPV6IcmpHeaderFormatTag UCHAR ucType; UCHAR ucCode; USHORT usChecksum; - //UCHAR ucIcmpMsg[0]; } IPV6IcmpHeader; typedef enum _E_IPADDR_CONTEXT @@ -93,10 +84,10 @@ typedef enum _E_IPADDR_CONTEXT eDestIpAddress } E_IPADDR_CONTEXT; -//Function Prototypes +/* Function Prototypes */ -USHORT IpVersion6(struct bcm_mini_adapter *Adapter, /**< Pointer to the driver control structure */ - PVOID pcIpHeader, /** Date: Mon, 10 Dec 2012 21:54:56 -0500 Subject: Staging: bcm: Properly format braces in IPv6ProtocolHdr.h This patch properly formats braces in IPv6ProtocolHdr.h as reported by checkpath.pl Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index f936f21..ababafc 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -21,8 +21,7 @@ */ #define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8 -typedef struct IPV6HeaderFormatTag -{ +typedef struct IPV6HeaderFormatTag { UCHAR ucVersionPrio; UCHAR aucFlowLabel[3]; USHORT usPayloadLength; @@ -32,8 +31,7 @@ typedef struct IPV6HeaderFormatTag ULONG ulDestIpAddress[4]; } IPV6Header; -typedef struct IPV6RoutingHeaderFormatTag -{ +typedef struct IPV6RoutingHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucRoutingType; UCHAR ucNumAddresses; @@ -41,45 +39,39 @@ typedef struct IPV6RoutingHeaderFormatTag ULONG ulReserved; } IPV6RoutingHeader; -typedef struct IPV6FragmentHeaderFormatTag -{ +typedef struct IPV6FragmentHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucReserved; USHORT usFragmentOffset; ULONG ulIdentification; } IPV6FragmentHeader; -typedef struct IPV6DestOptionsHeaderFormatTag -{ +typedef struct IPV6DestOptionsHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucHdrExtLen; UCHAR ucDestOptions[6]; } IPV6DestOptionsHeader; -typedef struct IPV6HopByHopOptionsHeaderFormatTag -{ +typedef struct IPV6HopByHopOptionsHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucMisc[3]; ULONG ulJumboPayloadLen; } IPV6HopByHopOptionsHeader; -typedef struct IPV6AuthenticationHeaderFormatTag -{ +typedef struct IPV6AuthenticationHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucLength; USHORT usReserved; ULONG ulSecurityParametersIndex; } IPV6AuthenticationHeader; -typedef struct IPV6IcmpHeaderFormatTag -{ +typedef struct IPV6IcmpHeaderFormatTag { UCHAR ucType; UCHAR ucCode; USHORT usChecksum; } IPV6IcmpHeader; -typedef enum _E_IPADDR_CONTEXT -{ +typedef enum _E_IPADDR_CONTEXT { eSrcIpAddress, eDestIpAddress } E_IPADDR_CONTEXT; -- cgit v0.10.2 From 5ef43c3bf6f1d963e888275780281bfec79c4bad Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:54:57 -0500 Subject: Staging: bcm: Replace USHORT with unsigned short in IPv6ProtocolHdr.h This patch replace "USHORT" with "unsigned short" in IPv6ProtocolHdr.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index ababafc..2ce49ae 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -24,7 +24,7 @@ typedef struct IPV6HeaderFormatTag { UCHAR ucVersionPrio; UCHAR aucFlowLabel[3]; - USHORT usPayloadLength; + unsigned short usPayloadLength; UCHAR ucNextHeader; UCHAR ucHopLimit; ULONG ulSrcIpAddress[4]; @@ -42,7 +42,7 @@ typedef struct IPV6RoutingHeaderFormatTag { typedef struct IPV6FragmentHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucReserved; - USHORT usFragmentOffset; + unsigned short usFragmentOffset; ULONG ulIdentification; } IPV6FragmentHeader; @@ -61,14 +61,14 @@ typedef struct IPV6HopByHopOptionsHeaderFormatTag { typedef struct IPV6AuthenticationHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucLength; - USHORT usReserved; + unsigned short usReserved; ULONG ulSecurityParametersIndex; } IPV6AuthenticationHeader; typedef struct IPV6IcmpHeaderFormatTag { UCHAR ucType; UCHAR ucCode; - USHORT usChecksum; + unsigned short usChecksum; } IPV6IcmpHeader; typedef enum _E_IPADDR_CONTEXT { @@ -78,14 +78,14 @@ typedef enum _E_IPADDR_CONTEXT { /* Function Prototypes */ -USHORT IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the driver control structure */ +unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the driver control structure */ PVOID pcIpHeader, /* Date: Mon, 10 Dec 2012 21:54:58 -0500 Subject: Staging: bcm: Replace ULONG with unsigned long in IPv6ProtocolHdr.h This patch replaces "ULONG" with "unsigned long" in IPv6ProtocolHdr.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 2ce49ae..5bbe4ef 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -27,8 +27,8 @@ typedef struct IPV6HeaderFormatTag { unsigned short usPayloadLength; UCHAR ucNextHeader; UCHAR ucHopLimit; - ULONG ulSrcIpAddress[4]; - ULONG ulDestIpAddress[4]; + unsigned long ulSrcIpAddress[4]; + unsigned long ulDestIpAddress[4]; } IPV6Header; typedef struct IPV6RoutingHeaderFormatTag { @@ -36,14 +36,14 @@ typedef struct IPV6RoutingHeaderFormatTag { UCHAR ucRoutingType; UCHAR ucNumAddresses; UCHAR ucNextAddress; - ULONG ulReserved; + unsigned long ulReserved; } IPV6RoutingHeader; typedef struct IPV6FragmentHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucReserved; unsigned short usFragmentOffset; - ULONG ulIdentification; + unsigned long ulIdentification; } IPV6FragmentHeader; typedef struct IPV6DestOptionsHeaderFormatTag { @@ -55,14 +55,14 @@ typedef struct IPV6DestOptionsHeaderFormatTag { typedef struct IPV6HopByHopOptionsHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucMisc[3]; - ULONG ulJumboPayloadLen; + unsigned long ulJumboPayloadLen; } IPV6HopByHopOptionsHeader; typedef struct IPV6AuthenticationHeaderFormatTag { UCHAR ucNextHeader; UCHAR ucLength; unsigned short usReserved; - ULONG ulSecurityParametersIndex; + unsigned long ulSecurityParametersIndex; } IPV6AuthenticationHeader; typedef struct IPV6IcmpHeaderFormatTag { @@ -82,7 +82,7 @@ unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the PVOID pcIpHeader, /* Date: Mon, 10 Dec 2012 21:54:59 -0500 Subject: Staging: bcm: Replace UCHAR with unsigned char in IPv6ProtocolHdr.h This patch replaces "UCHAR" with "unsigned char" in IPv6ProtocolHdr.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 5bbe4ef..e966f7e 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -22,52 +22,52 @@ #define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8 typedef struct IPV6HeaderFormatTag { - UCHAR ucVersionPrio; - UCHAR aucFlowLabel[3]; + unsigned char ucVersionPrio; + unsigned char aucFlowLabel[3]; unsigned short usPayloadLength; - UCHAR ucNextHeader; - UCHAR ucHopLimit; + unsigned char ucNextHeader; + unsigned char ucHopLimit; unsigned long ulSrcIpAddress[4]; unsigned long ulDestIpAddress[4]; } IPV6Header; typedef struct IPV6RoutingHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucRoutingType; - UCHAR ucNumAddresses; - UCHAR ucNextAddress; + unsigned char ucNextHeader; + unsigned char ucRoutingType; + unsigned char ucNumAddresses; + unsigned char ucNextAddress; unsigned long ulReserved; } IPV6RoutingHeader; typedef struct IPV6FragmentHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucReserved; + unsigned char ucNextHeader; + unsigned char ucReserved; unsigned short usFragmentOffset; unsigned long ulIdentification; } IPV6FragmentHeader; typedef struct IPV6DestOptionsHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucHdrExtLen; - UCHAR ucDestOptions[6]; + unsigned char ucNextHeader; + unsigned char ucHdrExtLen; + unsigned char ucDestOptions[6]; } IPV6DestOptionsHeader; typedef struct IPV6HopByHopOptionsHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucMisc[3]; + unsigned char ucNextHeader; + unsigned char ucMisc[3]; unsigned long ulJumboPayloadLen; } IPV6HopByHopOptionsHeader; typedef struct IPV6AuthenticationHeaderFormatTag { - UCHAR ucNextHeader; - UCHAR ucLength; + unsigned char ucNextHeader; + unsigned char ucLength; unsigned short usReserved; unsigned long ulSecurityParametersIndex; } IPV6AuthenticationHeader; typedef struct IPV6IcmpHeaderFormatTag { - UCHAR ucType; - UCHAR ucCode; + unsigned char ucType; + unsigned char ucCode; unsigned short usChecksum; } IPV6IcmpHeader; @@ -86,6 +86,6 @@ VOID DumpIpv6Address(unsigned long *puIpv6Address); extern BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort); extern BOOLEAN MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort); -extern BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, UCHAR ucProtocol); +extern BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, unsigned char ucProtocol); #endif -- cgit v0.10.2 From 3ee5afde0e66823201346cdf6e0eb2f6ed1f5af1 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:00 -0500 Subject: Staging: bcm: Replace PVOID with void * in IPv6ProtocolHdr.h This patch replaces "PVOID" with "void *" in IPv6ProtocolHdr.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index e966f7e..a218040 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -79,7 +79,7 @@ typedef enum _E_IPADDR_CONTEXT { /* Function Prototypes */ unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the driver control structure */ - PVOID pcIpHeader, /* Date: Mon, 10 Dec 2012 21:55:01 -0500 Subject: Staging: bcm: Replace VOID with void in IPv6ProtocolHdr.h This patch replaces "VOID" with "void" in IPv6ProtocolHdr.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index a218040..ea35ac5 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -82,7 +82,7 @@ unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the void *pcIpHeader, /* Date: Mon, 10 Dec 2012 21:55:02 -0500 Subject: Staging: bcm: Replace BOOLEAN with bool in IPv6ProtocolHdr.h This patch replaces "BOOLEAN" with "bool" in IPv6ProtocolHdr.h, and any other required files. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index ea35ac5..a4d2f84 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -84,8 +84,8 @@ unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the void DumpIpv6Address(unsigned long *puIpv6Address); -extern BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort); -extern BOOLEAN MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort); -extern BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, unsigned char ucProtocol); +extern bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort); +extern bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort); +extern bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, unsigned char ucProtocol); #endif diff --git a/drivers/staging/bcm/Prototypes.h b/drivers/staging/bcm/Prototypes.h index 90dbe0f..2a673b1 100644 --- a/drivers/staging/bcm/Prototypes.h +++ b/drivers/staging/bcm/Prototypes.h @@ -33,9 +33,9 @@ INT SearchSfid(struct bcm_mini_adapter *Adapter,UINT uiSfid); USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb); -BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); -BOOLEAN MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); -BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol); +bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); +bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); +bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol); INT SetupNextSend(struct bcm_mini_adapter *Adapter, /** Date: Mon, 10 Dec 2012 21:55:03 -0500 Subject: Staging: bcm: Remove typedef for _E_IPADDR_CONTEXT and call directly. This patch removes typedef for _E_IPADDR_CONTEXT, and changes the name of the enum to bcm_ipaddr_context. In addition, any calls to enum E_IPADDR_CONTEXT are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/CmHost.c b/drivers/staging/bcm/CmHost.c index 23ddc3d..78335f9 100644 --- a/drivers/staging/bcm/CmHost.c +++ b/drivers/staging/bcm/CmHost.c @@ -113,7 +113,7 @@ static VOID deleteSFBySfid(struct bcm_mini_adapter *Adapter, UINT uiSearchRuleIn static inline VOID CopyIpAddrToClassifier(struct bcm_classifier_rule *pstClassifierEntry, B_UINT8 u8IpAddressLen, B_UINT8 *pu8IpAddressMaskSrc, - BOOLEAN bIpVersion6, E_IPADDR_CONTEXT eIpAddrContext) + BOOLEAN bIpVersion6, enum bcm_ipaddr_context eIpAddrContext) { int i = 0; UINT nSizeOfIPAddressInBytes = IP_LENGTH_OF_ADDRESS; diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index a4d2f84..c319680 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -71,10 +71,10 @@ typedef struct IPV6IcmpHeaderFormatTag { unsigned short usChecksum; } IPV6IcmpHeader; -typedef enum _E_IPADDR_CONTEXT { +enum bcm_ipaddr_context { eSrcIpAddress, eDestIpAddress -} E_IPADDR_CONTEXT; +}; /* Function Prototypes */ -- cgit v0.10.2 From ceebf54d2edd1706ad3493f705ac7526fbbe55b4 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:04 -0500 Subject: Staging: bcm: Remove typedef for IPV6IcmpHeaderFormatTag. This patch removes typedef for IPV6IcmpHeaderFormatTag because it is not being used. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index c319680..4ab3a6d 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -65,12 +65,6 @@ typedef struct IPV6AuthenticationHeaderFormatTag { unsigned long ulSecurityParametersIndex; } IPV6AuthenticationHeader; -typedef struct IPV6IcmpHeaderFormatTag { - unsigned char ucType; - unsigned char ucCode; - unsigned short usChecksum; -} IPV6IcmpHeader; - enum bcm_ipaddr_context { eSrcIpAddress, eDestIpAddress -- cgit v0.10.2 From 5601bb9da56602a4faa387c9cc6b1bb929393de5 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:05 -0500 Subject: Staging: bcm: Remove typedef for IPV6AuthenticationHeaderFormatTag and call directly. This patch removes typedef for IPV6AuthenticationHeaderFormatTag, and changes the name of the struct to bcm_ipv6_authentication_hdr In addition, any calls to typedef IPV6AuthenticationHeader, are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c index 4745ddd..f3ab390 100644 --- a/drivers/staging/bcm/IPv6Protocol.c +++ b/drivers/staging/bcm/IPv6Protocol.c @@ -76,7 +76,7 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, break; case IPV6HDR_TYPE_AUTHENTICATION: { - IPV6AuthenticationHeader *pstIpv6AuthHdr = (IPV6AuthenticationHeader *)pucPayloadPtr; + struct bcm_ipv6_authentication_hdr *pstIpv6AuthHdr = (struct bcm_ipv6_authentication_hdr *)pucPayloadPtr; int nHdrLen = pstIpv6AuthHdr->ucLength; BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 4ab3a6d..1c49119 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -58,12 +58,12 @@ typedef struct IPV6HopByHopOptionsHeaderFormatTag { unsigned long ulJumboPayloadLen; } IPV6HopByHopOptionsHeader; -typedef struct IPV6AuthenticationHeaderFormatTag { +struct bcm_ipv6_authentication_hdr { unsigned char ucNextHeader; unsigned char ucLength; unsigned short usReserved; unsigned long ulSecurityParametersIndex; -} IPV6AuthenticationHeader; +}; enum bcm_ipaddr_context { eSrcIpAddress, -- cgit v0.10.2 From bc25b751537e9481bf41d2718969f9356e31fb4f Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:06 -0500 Subject: Staging: bcm: Remove typedef for IPV6HopByHopOptionsHeaderFormatTag and call directly. This patch removes typedef IPV6HopByHopOptionsHeaderFormatTag, and changes the name of the struct to bcm_ipv6_options_hdr. In addition, any calls to typedef IPV6HopByHopOptionsHeader are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c index f3ab390..723fe4b 100644 --- a/drivers/staging/bcm/IPv6Protocol.c +++ b/drivers/staging/bcm/IPv6Protocol.c @@ -38,7 +38,7 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 HopByHop Header"); - usNextHeaderOffset += sizeof(IPV6HopByHopOptionsHeader); + usNextHeaderOffset += sizeof(struct bcm_ipv6_options_hdr); } break; diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 1c49119..f53c536 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -52,11 +52,11 @@ typedef struct IPV6DestOptionsHeaderFormatTag { unsigned char ucDestOptions[6]; } IPV6DestOptionsHeader; -typedef struct IPV6HopByHopOptionsHeaderFormatTag { +struct bcm_ipv6_options_hdr { unsigned char ucNextHeader; unsigned char ucMisc[3]; unsigned long ulJumboPayloadLen; -} IPV6HopByHopOptionsHeader; +}; struct bcm_ipv6_authentication_hdr { unsigned char ucNextHeader; -- cgit v0.10.2 From d69438df32834cf7f7da2294bce34e840244abf8 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:07 -0500 Subject: Staging: bcm: Remove typedef for IPV6DestOptionsHeaderFormatTag and call directly. This patch removes typedef IPV6DestOptionsHeaderFormatTag, and changes the name of the struct to bcm_ipv6_dest_options_hdr. In addition, any calls to typedef IPV6DestOptionsHeader are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c index 723fe4b..46eddbb 100644 --- a/drivers/staging/bcm/IPv6Protocol.c +++ b/drivers/staging/bcm/IPv6Protocol.c @@ -64,12 +64,12 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, break; case IPV6HDR_TYPE_DESTOPTS: { - IPV6DestOptionsHeader *pstIpv6DestOptsHdr = (IPV6DestOptionsHeader *)pucPayloadPtr; + struct bcm_ipv6_dest_options_hdr *pstIpv6DestOptsHdr = (struct bcm_ipv6_dest_options_hdr *)pucPayloadPtr; int nTotalOptions = pstIpv6DestOptsHdr->ucHdrExtLen; BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 DestOpts Header Header"); - usNextHeaderOffset += sizeof(IPV6DestOptionsHeader); + usNextHeaderOffset += sizeof(struct bcm_ipv6_dest_options_hdr); usNextHeaderOffset += nTotalOptions * IPV6_DESTOPTS_HDR_OPTIONSIZE ; } diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index f53c536..942e1fb 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -46,11 +46,11 @@ typedef struct IPV6FragmentHeaderFormatTag { unsigned long ulIdentification; } IPV6FragmentHeader; -typedef struct IPV6DestOptionsHeaderFormatTag { +struct bcm_ipv6_dest_options_hdr { unsigned char ucNextHeader; unsigned char ucHdrExtLen; unsigned char ucDestOptions[6]; -} IPV6DestOptionsHeader; +}; struct bcm_ipv6_options_hdr { unsigned char ucNextHeader; -- cgit v0.10.2 From 17d7fd271a13b72a0fe452c4a7992c65dc479b23 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:08 -0500 Subject: Staging: bcm: Remove typedef for IPV6FragmentHeaderFormatTag and call directly. This patch removes typedef IPV6FragmentHeaderFormatTag, and changes the name of the struct to bcm_ipv6_fragment_hdr. In addition, any calls to typedef IPV6FragmentHeader are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c index 46eddbb..04d1b2d 100644 --- a/drivers/staging/bcm/IPv6Protocol.c +++ b/drivers/staging/bcm/IPv6Protocol.c @@ -58,7 +58,7 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Fragmentation Header"); - usNextHeaderOffset += sizeof(IPV6FragmentHeader); + usNextHeaderOffset += sizeof(struct bcm_ipv6_fragment_hdr); } break; diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index 942e1fb..d3f471a 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -39,12 +39,12 @@ typedef struct IPV6RoutingHeaderFormatTag { unsigned long ulReserved; } IPV6RoutingHeader; -typedef struct IPV6FragmentHeaderFormatTag { +struct bcm_ipv6_fragment_hdr { unsigned char ucNextHeader; unsigned char ucReserved; unsigned short usFragmentOffset; unsigned long ulIdentification; -} IPV6FragmentHeader; +}; struct bcm_ipv6_dest_options_hdr { unsigned char ucNextHeader; -- cgit v0.10.2 From 8f0652c25559e6757a0258aa241a23c187494d5e Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:09 -0500 Subject: Staging: bcm: Remove typedef for IPV6RoutingHeaderFormatTag and call directly. This patch removes typedef IPV6RoutingHeaderFormatTag, and changes the name of the struct to bcm_ipv6_routing_hdr. In addition, any calls to typedef IPV6RoutingHeader are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c index 04d1b2d..03f1dd4 100644 --- a/drivers/staging/bcm/IPv6Protocol.c +++ b/drivers/staging/bcm/IPv6Protocol.c @@ -44,11 +44,11 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, case IPV6HDR_TYPE_ROUTING: { - IPV6RoutingHeader *pstIpv6RoutingHeader; + struct bcm_ipv6_routing_hdr *pstIpv6RoutingHeader; BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Routing Header"); - pstIpv6RoutingHeader = (IPV6RoutingHeader *)pucPayloadPtr; - usNextHeaderOffset += sizeof(IPV6RoutingHeader); + pstIpv6RoutingHeader = (struct bcm_ipv6_routing_hdr *)pucPayloadPtr; + usNextHeaderOffset += sizeof(struct bcm_ipv6_routing_hdr); usNextHeaderOffset += pstIpv6RoutingHeader->ucNumAddresses * IPV6_ADDRESS_SIZEINBYTES; } diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index d3f471a..cdcfc34 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -31,13 +31,13 @@ typedef struct IPV6HeaderFormatTag { unsigned long ulDestIpAddress[4]; } IPV6Header; -typedef struct IPV6RoutingHeaderFormatTag { +struct bcm_ipv6_routing_hdr { unsigned char ucNextHeader; unsigned char ucRoutingType; unsigned char ucNumAddresses; unsigned char ucNextAddress; unsigned long ulReserved; -} IPV6RoutingHeader; +}; struct bcm_ipv6_fragment_hdr { unsigned char ucNextHeader; -- cgit v0.10.2 From 9d4cf71fbd153ded47d0a61813942e7ef7fa09c4 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 10 Dec 2012 21:55:10 -0500 Subject: Staging: bcm: Remove typedef for IPV6HeaderFormatTag and call directly. This patch removes typedef IPV6HeaderFormatTag, and changes the name of the struct to bcm_ipv6_hdr. In addition, any calls to typedef IPV6Header are changed to call the struct directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c index 03f1dd4..6d803e7 100644 --- a/drivers/staging/bcm/IPv6Protocol.c +++ b/drivers/staging/bcm/IPv6Protocol.c @@ -1,10 +1,10 @@ #include "headers.h" static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule, - IPV6Header *pstIpv6Header); + struct bcm_ipv6_hdr *pstIpv6Header); static BOOLEAN MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule, - IPV6Header *pstIpv6Header); -static VOID DumpIpv6Header(IPV6Header *pstIpv6Header); + struct bcm_ipv6_hdr *pstIpv6Header); +static VOID DumpIpv6Header(struct bcm_ipv6_hdr *pstIpv6Header); static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, UCHAR *pucNextHeader, BOOLEAN *bParseDone, USHORT *pusPayloadLength) @@ -186,13 +186,13 @@ USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader, USHORT ushDestPort = 0; USHORT ushSrcPort = 0; UCHAR ucNextProtocolAboveIP = 0; - IPV6Header *pstIpv6Header = NULL; + struct bcm_ipv6_hdr *pstIpv6Header = NULL; BOOLEAN bClassificationSucceed = FALSE; BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "IpVersion6 ==========>\n"); - pstIpv6Header = (IPV6Header *)pcIpHeader; + pstIpv6Header = (struct bcm_ipv6_hdr *)pcIpHeader; DumpIpv6Header(pstIpv6Header); @@ -200,7 +200,7 @@ USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader, * Try to get the next higher layer protocol * and the Ports Nos if TCP or UDP */ - ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader + sizeof(IPV6Header)), + ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader + sizeof(struct bcm_ipv6_hdr)), &ushSrcPort, &ushDestPort, pstIpv6Header->usPayloadLength, @@ -289,7 +289,7 @@ USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader, static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule, - IPV6Header *pstIpv6Header) + struct bcm_ipv6_hdr *pstIpv6Header) { UINT uiLoopIndex = 0; UINT uiIpv6AddIndex = 0; @@ -345,7 +345,7 @@ static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule } static BOOLEAN MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule, - IPV6Header *pstIpv6Header) + struct bcm_ipv6_hdr *pstIpv6Header) { UINT uiLoopIndex = 0; UINT uiIpv6AddIndex = 0; @@ -414,7 +414,7 @@ VOID DumpIpv6Address(ULONG *puIpv6Address) } -static VOID DumpIpv6Header(IPV6Header *pstIpv6Header) +static VOID DumpIpv6Header(struct bcm_ipv6_hdr *pstIpv6Header) { UCHAR ucVersion; UCHAR ucPrio; diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h index cdcfc34..96b36a5 100644 --- a/drivers/staging/bcm/IPv6ProtocolHdr.h +++ b/drivers/staging/bcm/IPv6ProtocolHdr.h @@ -21,7 +21,7 @@ */ #define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8 -typedef struct IPV6HeaderFormatTag { +struct bcm_ipv6_hdr { unsigned char ucVersionPrio; unsigned char aucFlowLabel[3]; unsigned short usPayloadLength; @@ -29,7 +29,7 @@ typedef struct IPV6HeaderFormatTag { unsigned char ucHopLimit; unsigned long ulSrcIpAddress[4]; unsigned long ulDestIpAddress[4]; -} IPV6Header; +}; struct bcm_ipv6_routing_hdr { unsigned char ucNextHeader; -- cgit v0.10.2 From 67c6603827f2583f758515ffeaffaaaeed07b34f Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:44 -0500 Subject: Staging: bcm: Fix all white space issues in led_control.h This patch fixes all white space issues in led_control.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index ed8fbc0..1f6c11d 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -2,70 +2,60 @@ #define _LED_CONTROL_H /*************************TYPE DEF**********************/ -#define NUM_OF_LEDS 4 - +#define NUM_OF_LEDS 4 #define DSD_START_OFFSET 0x0200 #define EEPROM_VERSION_OFFSET 0x020E #define EEPROM_HW_PARAM_POINTER_ADDRESS 0x0218 #define EEPROM_HW_PARAM_POINTER_ADDRRES_MAP5 0x0220 #define GPIO_SECTION_START_OFFSET 0x03 - -#define COMPATIBILITY_SECTION_LENGTH 42 -#define COMPATIBILITY_SECTION_LENGTH_MAP5 84 - - -#define EEPROM_MAP5_MAJORVERSION 5 -#define EEPROM_MAP5_MINORVERSION 0 - - +#define COMPATIBILITY_SECTION_LENGTH 42 +#define COMPATIBILITY_SECTION_LENGTH_MAP5 84 +#define EEPROM_MAP5_MAJORVERSION 5 +#define EEPROM_MAP5_MINORVERSION 0 #define MAX_NUM_OF_BLINKS 10 #define NUM_OF_GPIO_PINS 16 - #define DISABLE_GPIO_NUM 0xFF #define EVENT_SIGNALED 1 - #define MAX_FILE_NAME_BUFFER_SIZE 100 -#define TURN_ON_LED(GPIO, index) do { \ - UINT gpio_val = GPIO; \ - (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ - wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \ - wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \ - } while (0); +#define TURN_ON_LED(GPIO, index) do { \ + UINT gpio_val = GPIO; \ + (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ + wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \ + wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \ + } while (0); -#define TURN_OFF_LED(GPIO, index) do { \ - UINT gpio_val = GPIO; \ - (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ - wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \ - wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \ - } while (0); +#define TURN_OFF_LED(GPIO, index) do { \ + UINT gpio_val = GPIO; \ + (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ + wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \ + wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \ + } while (0); #define B_ULONG32 unsigned long /*******************************************************/ - - -typedef enum _LEDColors{ - RED_LED = 1, - BLUE_LED = 2, - YELLOW_LED = 3, - GREEN_LED = 4 +typedef enum _LEDColors { + RED_LED = 1, + BLUE_LED = 2, + YELLOW_LED = 3, + GREEN_LED = 4 } LEDColors; /*Enumerated values of different LED types*/ typedef enum LedEvents { - SHUTDOWN_EXIT = 0x00, - DRIVER_INIT = 0x1, - FW_DOWNLOAD = 0x2, - FW_DOWNLOAD_DONE = 0x4, - NO_NETWORK_ENTRY = 0x8, - NORMAL_OPERATION = 0x10, - LOWPOWER_MODE_ENTER = 0x20, - IDLEMODE_CONTINUE = 0x40, - IDLEMODE_EXIT = 0x80, - LED_THREAD_INACTIVE = 0x100, /* Makes the LED thread Inactivce. It wil be equivallent to putting the thread on hold. */ - LED_THREAD_ACTIVE = 0x200, /* Makes the LED Thread Active back. */ - DRIVER_HALT = 0xff -} LedEventInfo_t; /* Enumerated values of different driver states */ + SHUTDOWN_EXIT = 0x00, + DRIVER_INIT = 0x1, + FW_DOWNLOAD = 0x2, + FW_DOWNLOAD_DONE = 0x4, + NO_NETWORK_ENTRY = 0x8, + NORMAL_OPERATION = 0x10, + LOWPOWER_MODE_ENTER = 0x20, + IDLEMODE_CONTINUE = 0x40, + IDLEMODE_EXIT = 0x80, + LED_THREAD_INACTIVE = 0x100, /* Makes the LED thread Inactivce. It wil be equivallent to putting the thread on hold. */ + LED_THREAD_ACTIVE = 0x200, /* Makes the LED Thread Active back. */ + DRIVER_HALT = 0xff +} LedEventInfo_t; /* Enumerated values of different driver states */ /* * Structure which stores the information of different LED types @@ -79,24 +69,21 @@ typedef struct LedStateInfo_t { UCHAR BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */ } LEDStateInfo, *pLEDStateInfo; - typedef struct _LED_INFO_STRUCT { LEDStateInfo LEDState[NUM_OF_LEDS]; BOOLEAN bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target*/ - BOOLEAN bIdle_led_off; - wait_queue_head_t notify_led_event; + BOOLEAN bIdle_led_off; + wait_queue_head_t notify_led_event; wait_queue_head_t idleModeSyncEvent; - struct task_struct *led_cntrl_threadid; - int led_thread_running; - BOOLEAN bLedInitDone; + struct task_struct *led_cntrl_threadid; + int led_thread_running; + BOOLEAN bLedInitDone; } LED_INFO_STRUCT, *PLED_INFO_STRUCT; + /* LED Thread state. */ #define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */ #define BCM_LED_THREAD_RUNNING_ACTIVELY 1 /* LED thread is running. */ #define BCM_LED_THREAD_RUNNING_INACTIVELY 2 /*LED thread has been put on hold*/ - - #endif - -- cgit v0.10.2 From 48ac0ca5ae8ad232d1a9007f61f5a754bb63b49f Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:45 -0500 Subject: Staging: bcm: Properly format comments as needed in led_control.h This patch formats all comments, and remove them as needed in led_control.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index 1f6c11d..3eef21c 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -1,7 +1,6 @@ #ifndef _LED_CONTROL_H #define _LED_CONTROL_H -/*************************TYPE DEF**********************/ #define NUM_OF_LEDS 4 #define DSD_START_OFFSET 0x0200 #define EEPROM_VERSION_OFFSET 0x020E @@ -34,13 +33,12 @@ #define B_ULONG32 unsigned long -/*******************************************************/ typedef enum _LEDColors { RED_LED = 1, BLUE_LED = 2, YELLOW_LED = 3, GREEN_LED = 4 -} LEDColors; /*Enumerated values of different LED types*/ +} LEDColors; /* Enumerated values of different LED types */ typedef enum LedEvents { SHUTDOWN_EXIT = 0x00, @@ -71,7 +69,7 @@ typedef struct LedStateInfo_t { typedef struct _LED_INFO_STRUCT { LEDStateInfo LEDState[NUM_OF_LEDS]; - BOOLEAN bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target*/ + BOOLEAN bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */ BOOLEAN bIdle_led_off; wait_queue_head_t notify_led_event; wait_queue_head_t idleModeSyncEvent; @@ -82,8 +80,8 @@ typedef struct _LED_INFO_STRUCT { } LED_INFO_STRUCT, *PLED_INFO_STRUCT; /* LED Thread state. */ -#define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */ -#define BCM_LED_THREAD_RUNNING_ACTIVELY 1 /* LED thread is running. */ -#define BCM_LED_THREAD_RUNNING_INACTIVELY 2 /*LED thread has been put on hold*/ +#define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */ +#define BCM_LED_THREAD_RUNNING_ACTIVELY 1 /* LED thread is running. */ +#define BCM_LED_THREAD_RUNNING_INACTIVELY 2 /* LED thread has been put on hold */ #endif -- cgit v0.10.2 From 20dcfc53580b67521a8f6a3375998975955e866e Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:46 -0500 Subject: Staging: bcm: Fix warning: "do {} while (0) macros should not be semicolon terminated" in led_control.h This patch properly fixes the warning "do {} while (0) macros should not be semicolon terminated" as reported by checkpath.pl Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index 3eef21c..8ae8e43 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -22,14 +22,14 @@ (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \ - } while (0); + } while (0) #define TURN_OFF_LED(GPIO, index) do { \ UINT gpio_val = GPIO; \ (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \ - } while (0); + } while (0) #define B_ULONG32 unsigned long -- cgit v0.10.2 From 3549a173dc3b2c94ab55b606aa6e6ccdc7357c3a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:47 -0500 Subject: Staging: bcm: Replace UCHAR with unsigned char in led_control.h This patch replace "UCHAR" with "unsigned char" in led_control.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index 8ae8e43..b670d0d 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -60,11 +60,11 @@ typedef enum LedEvents { * and corresponding LED state information of driver states */ typedef struct LedStateInfo_t { - UCHAR LED_Type; /* specify GPIO number - use 0xFF if not used */ - UCHAR LED_On_State; /* Bits set or reset for different states */ - UCHAR LED_Blink_State; /* Bits set or reset for blinking LEDs for different states */ - UCHAR GPIO_Num; - UCHAR BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */ + unsigned char LED_Type; /* specify GPIO number - use 0xFF if not used */ + unsigned char LED_On_State; /* Bits set or reset for different states */ + unsigned char LED_Blink_State; /* Bits set or reset for blinking LEDs for different states */ + unsigned char GPIO_Num; + unsigned char BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */ } LEDStateInfo, *pLEDStateInfo; typedef struct _LED_INFO_STRUCT { -- cgit v0.10.2 From df3d870f57fef53aa8e90ee9f6170bb7181ff44b Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:48 -0500 Subject: Staging: bcm: Replace BOOLEAN with bool in led_control.h This patch replaces "BOOLEAN" with "bool" in led_control.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index b670d0d..50a6d7d 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -69,13 +69,13 @@ typedef struct LedStateInfo_t { typedef struct _LED_INFO_STRUCT { LEDStateInfo LEDState[NUM_OF_LEDS]; - BOOLEAN bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */ - BOOLEAN bIdle_led_off; + bool bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */ + bool bIdle_led_off; wait_queue_head_t notify_led_event; wait_queue_head_t idleModeSyncEvent; struct task_struct *led_cntrl_threadid; int led_thread_running; - BOOLEAN bLedInitDone; + bool bLedInitDone; } LED_INFO_STRUCT, *PLED_INFO_STRUCT; -- cgit v0.10.2 From a6f0b530e56d8b7ee428d92af1c7da88e4d9d583 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:49 -0500 Subject: Staging: bcm: Replace UINT with unsigned int in led_control.h This patch replaces "UINT" with "unsigned int" in led_control.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index 50a6d7d..c44dd02 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -18,14 +18,14 @@ #define MAX_FILE_NAME_BUFFER_SIZE 100 #define TURN_ON_LED(GPIO, index) do { \ - UINT gpio_val = GPIO; \ + unsigned int gpio_val = GPIO; \ (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \ } while (0) #define TURN_OFF_LED(GPIO, index) do { \ - UINT gpio_val = GPIO; \ + unsigned int gpio_val = GPIO; \ (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \ -- cgit v0.10.2 From 684fb7e6f0ff07f7d9ad513beabe44efed5bf882 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:50 -0500 Subject: Staging: bcm: Remove typedef for _LED_INFO_STRUCT and call directly. This patch removes typedef for _LED_INFO_STRUCT, and changes the name of the struct to bcm_led_info. In addition, any calls to struct LED_INFO_STRUCT, or *PLED_INFO_STRUCT are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index 1f7005d..8bce936 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -303,7 +303,7 @@ struct bcm_mini_adapter { struct task_struct *transmit_packet_thread; /* LED Related Structures */ - LED_INFO_STRUCT LEDInfo; + struct bcm_led_info LEDInfo; /* Driver State for LED Blinking */ LedEventInfo_t DriverState; diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index c44dd02..8b7dcdf 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -67,7 +67,7 @@ typedef struct LedStateInfo_t { unsigned char BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */ } LEDStateInfo, *pLEDStateInfo; -typedef struct _LED_INFO_STRUCT { +struct bcm_led_info { LEDStateInfo LEDState[NUM_OF_LEDS]; bool bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */ bool bIdle_led_off; @@ -76,8 +76,7 @@ typedef struct _LED_INFO_STRUCT { struct task_struct *led_cntrl_threadid; int led_thread_running; bool bLedInitDone; - -} LED_INFO_STRUCT, *PLED_INFO_STRUCT; +}; /* LED Thread state. */ #define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */ -- cgit v0.10.2 From dbe9a7d2d54123af46ad6eb541be5557690604a3 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:51 -0500 Subject: Staging: bcm: Remove typedef for LedStateInfo_t and call directly. This patch removes typedef for LedStateInfo_t, and changes the name of the struct to bcm_led_state_info. In addition, any calls to struct LEDStateInfo, or *pLEDStateInfo are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index 8b7dcdf..318932d 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -59,16 +59,16 @@ typedef enum LedEvents { * Structure which stores the information of different LED types * and corresponding LED state information of driver states */ -typedef struct LedStateInfo_t { +struct bcm_led_state_info { unsigned char LED_Type; /* specify GPIO number - use 0xFF if not used */ unsigned char LED_On_State; /* Bits set or reset for different states */ unsigned char LED_Blink_State; /* Bits set or reset for blinking LEDs for different states */ unsigned char GPIO_Num; unsigned char BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */ -} LEDStateInfo, *pLEDStateInfo; +}; struct bcm_led_info { - LEDStateInfo LEDState[NUM_OF_LEDS]; + struct bcm_led_state_info LEDState[NUM_OF_LEDS]; bool bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */ bool bIdle_led_off; wait_queue_head_t notify_led_event; -- cgit v0.10.2 From b3d9a8f727d25f08cfccc68b64667085f403e54a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:52 -0500 Subject: Staging: bcm: Remove typedef for LedEvents and call directly. This patch removes typedef for LedEvents, and changes the name of the enum to bcm_led_events. In addition, any calls to LedEventInfo_t are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index 8bce936..f13afe7 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -306,7 +306,7 @@ struct bcm_mini_adapter { struct bcm_led_info LEDInfo; /* Driver State for LED Blinking */ - LedEventInfo_t DriverState; + enum bcm_led_events DriverState; /* Interface Specific */ PVOID pvInterfaceAdapter; int (*bcm_file_download)(PVOID, diff --git a/drivers/staging/bcm/led_control.c b/drivers/staging/bcm/led_control.c index 252a1b3..05a948a 100644 --- a/drivers/staging/bcm/led_control.c +++ b/drivers/staging/bcm/led_control.c @@ -24,7 +24,7 @@ BOOLEAN IsReqGpioIsLedInNVM(struct bcm_mini_adapter *Adapter, UINT gpios) } static INT LED_Blink(struct bcm_mini_adapter *Adapter, UINT GPIO_Num, UCHAR uiLedIndex, - ULONG timeout, INT num_of_time, LedEventInfo_t currdriverstate) + ULONG timeout, INT num_of_time, enum bcm_led_events currdriverstate) { int Status = STATUS_SUCCESS; BOOLEAN bInfinite = FALSE; @@ -97,7 +97,7 @@ static INT ScaleRateofTransfer(ULONG rate) static INT LED_Proportional_Blink(struct bcm_mini_adapter *Adapter, UCHAR GPIO_Num_tx, UCHAR uiTxLedIndex, UCHAR GPIO_Num_rx, UCHAR uiRxLedIndex, - LedEventInfo_t currdriverstate) + enum bcm_led_events currdriverstate) { /* Initial values of TX and RX packets */ ULONG64 Initial_num_of_packts_tx = 0, Initial_num_of_packts_rx = 0; @@ -607,7 +607,7 @@ static VOID LedGpioInit(struct bcm_mini_adapter *Adapter) static INT BcmGetGPIOPinInfo(struct bcm_mini_adapter *Adapter, UCHAR *GPIO_num_tx, UCHAR *GPIO_num_rx, UCHAR *uiLedTxIndex, UCHAR *uiLedRxIndex, - LedEventInfo_t currdriverstate) + enum bcm_led_events currdriverstate) { UINT uiIndex = 0; @@ -651,7 +651,7 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter) UCHAR GPIO_num = 0; UCHAR uiLedIndex = 0; UINT uiResetValue = 0; - LedEventInfo_t currdriverstate = 0; + enum bcm_led_events currdriverstate = 0; ulong timeout = 0; INT Status = 0; diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index 318932d..a06ee71 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -40,7 +40,7 @@ typedef enum _LEDColors { GREEN_LED = 4 } LEDColors; /* Enumerated values of different LED types */ -typedef enum LedEvents { +enum bcm_led_events { SHUTDOWN_EXIT = 0x00, DRIVER_INIT = 0x1, FW_DOWNLOAD = 0x2, @@ -53,7 +53,7 @@ typedef enum LedEvents { LED_THREAD_INACTIVE = 0x100, /* Makes the LED thread Inactivce. It wil be equivallent to putting the thread on hold. */ LED_THREAD_ACTIVE = 0x200, /* Makes the LED Thread Active back. */ DRIVER_HALT = 0xff -} LedEventInfo_t; /* Enumerated values of different driver states */ +}; /* Enumerated values of different driver states */ /* * Structure which stores the information of different LED types -- cgit v0.10.2 From d078fde369d175eb188c92df07c3163079d8beab Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:53 -0500 Subject: Staging: bcm: Remove typedef for _LEDColors and call directly. This patch removes typedef for _LEDColors, and changes the name of the enum to bcm_led_colors. In addition, any calls to LEDColors are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index a06ee71..c1b44b6 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -33,12 +33,12 @@ #define B_ULONG32 unsigned long -typedef enum _LEDColors { +enum bcm_led_colors { RED_LED = 1, BLUE_LED = 2, YELLOW_LED = 3, GREEN_LED = 4 -} LEDColors; /* Enumerated values of different LED types */ +}; enum bcm_led_events { SHUTDOWN_EXIT = 0x00, -- cgit v0.10.2 From f91d7665f8ed34b1c798ab1fe419a25573bb65bf Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 14 Dec 2012 19:26:54 -0500 Subject: Staging: bcm: Remove macro B_ULONG32 in led_control.h. This patch removes macro B_ULONG32 in led_control.h because it is not being used. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h index c1b44b6..bae40e2 100644 --- a/drivers/staging/bcm/led_control.h +++ b/drivers/staging/bcm/led_control.h @@ -31,8 +31,6 @@ wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \ } while (0) -#define B_ULONG32 unsigned long - enum bcm_led_colors { RED_LED = 1, BLUE_LED = 2, -- cgit v0.10.2 From 9f1c824ed01dd54fb14ea8542b60b79bc1c2d043 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 17 Dec 2012 17:35:16 -0500 Subject: Staging: bcm: Fix all white space issues in target_params.h This patch fixes all white space issues in target_parms.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h index ad7ec00..cff6a12 100644 --- a/drivers/staging/bcm/target_params.h +++ b/drivers/staging/bcm/target_params.h @@ -3,79 +3,59 @@ typedef struct _TARGET_PARAMS { - B_UINT32 m_u32CfgVersion; - - // Scanning Related Params - B_UINT32 m_u32CenterFrequency; - B_UINT32 m_u32BandAScan; - B_UINT32 m_u32BandBScan; - B_UINT32 m_u32BandCScan; - - - // QoS Params - B_UINT32 m_u32ErtpsOptions; - - B_UINT32 m_u32PHSEnable; - - - // HO Params - B_UINT32 m_u32HoEnable; - - B_UINT32 m_u32HoReserved1; - B_UINT32 m_u32HoReserved2; - // Power Control Params - - B_UINT32 m_u32MimoEnable; - - B_UINT32 m_u32SecurityEnable; - - B_UINT32 m_u32PowerSavingModesEnable; //bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable - /* PowerSaving Mode Options: - bit 0 = 1: CPE mode - to keep pcmcia if alive; - bit 1 = 1: CINR reporting in Idlemode Msg - bit 2 = 1: Default PSC Enable in sleepmode*/ - B_UINT32 m_u32PowerSavingModeOptions; - - B_UINT32 m_u32ArqEnable; - - // From Version #3, the HARQ section renamed as general - B_UINT32 m_u32HarqEnable; - // EEPROM Param Location - B_UINT32 m_u32EEPROMFlag; - // BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte - // Unused - LSByte - B_UINT32 m_u32Customize; - B_UINT32 m_u32ConfigBW; /* In Hz */ - B_UINT32 m_u32ShutDownInitThresholdTimer; - - B_UINT32 m_u32RadioParameter; - B_UINT32 m_u32PhyParameter1; - B_UINT32 m_u32PhyParameter2; - B_UINT32 m_u32PhyParameter3; - - B_UINT32 m_u32TestOptions; // in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack - + B_UINT32 m_u32CfgVersion; + // Scanning Related Params + B_UINT32 m_u32CenterFrequency; + B_UINT32 m_u32BandAScan; + B_UINT32 m_u32BandBScan; + B_UINT32 m_u32BandCScan; + // QoS Params + B_UINT32 m_u32ErtpsOptions; + B_UINT32 m_u32PHSEnable; + // HO Params + B_UINT32 m_u32HoEnable; + B_UINT32 m_u32HoReserved1; + B_UINT32 m_u32HoReserved2; + // Power Control Params + B_UINT32 m_u32MimoEnable; + B_UINT32 m_u32SecurityEnable; + B_UINT32 m_u32PowerSavingModesEnable; //bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable + /* PowerSaving Mode Options: + bit 0 = 1: CPE mode - to keep pcmcia if alive; + bit 1 = 1: CINR reporting in Idlemode Msg + bit 2 = 1: Default PSC Enable in sleepmode*/ + B_UINT32 m_u32PowerSavingModeOptions; + B_UINT32 m_u32ArqEnable; + // From Version #3, the HARQ section renamed as general + B_UINT32 m_u32HarqEnable; + // EEPROM Param Location + B_UINT32 m_u32EEPROMFlag; + // BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte + // Unused - LSByte + B_UINT32 m_u32Customize; + B_UINT32 m_u32ConfigBW; /* In Hz */ + B_UINT32 m_u32ShutDownInitThresholdTimer; + B_UINT32 m_u32RadioParameter; + B_UINT32 m_u32PhyParameter1; + B_UINT32 m_u32PhyParameter2; + B_UINT32 m_u32PhyParameter3; + B_UINT32 m_u32TestOptions; // in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack B_UINT32 m_u32MaxMACDataperDLFrame; B_UINT32 m_u32MaxMACDataperULFrame; - B_UINT32 m_u32Corr2MacFlags; - - //adding driver params. + //adding driver params. B_UINT32 HostDrvrConfig1; - B_UINT32 HostDrvrConfig2; - B_UINT32 HostDrvrConfig3; - B_UINT32 HostDrvrConfig4; - B_UINT32 HostDrvrConfig5; - B_UINT32 HostDrvrConfig6; - B_UINT32 m_u32SegmentedPUSCenable; - + B_UINT32 HostDrvrConfig2; + B_UINT32 HostDrvrConfig3; + B_UINT32 HostDrvrConfig4; + B_UINT32 HostDrvrConfig5; + B_UINT32 HostDrvrConfig6; + B_UINT32 m_u32SegmentedPUSCenable; // removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files.. - - //BAMC Related Parameters - //Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling. - //bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support. + //BAMC Related Parameters + //Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling. + //bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support. B_UINT32 m_u32BandAMCEnable; - -} stTargetParams,TARGET_PARAMS,*PTARGET_PARAMS, STARGETPARAMS, *PSTARGETPARAMS; +} stTargetParams, TARGET_PARAMS, *PTARGET_PARAMS, STARGETPARAMS, *PSTARGETPARAMS; #endif -- cgit v0.10.2 From 2eb0642f15b880d3029771d967830e8788c649ac Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 17 Dec 2012 17:35:17 -0500 Subject: Staging: bcm: Properly format comments as needed in target_params.h This patch formats all comments, and removes them as needed in target_params.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h index cff6a12..548bfd6 100644 --- a/drivers/staging/bcm/target_params.h +++ b/drivers/staging/bcm/target_params.h @@ -4,34 +4,31 @@ typedef struct _TARGET_PARAMS { B_UINT32 m_u32CfgVersion; - // Scanning Related Params B_UINT32 m_u32CenterFrequency; B_UINT32 m_u32BandAScan; B_UINT32 m_u32BandBScan; B_UINT32 m_u32BandCScan; - // QoS Params B_UINT32 m_u32ErtpsOptions; B_UINT32 m_u32PHSEnable; - // HO Params B_UINT32 m_u32HoEnable; B_UINT32 m_u32HoReserved1; B_UINT32 m_u32HoReserved2; - // Power Control Params B_UINT32 m_u32MimoEnable; B_UINT32 m_u32SecurityEnable; - B_UINT32 m_u32PowerSavingModesEnable; //bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable + B_UINT32 m_u32PowerSavingModesEnable; /* bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable */ /* PowerSaving Mode Options: - bit 0 = 1: CPE mode - to keep pcmcia if alive; - bit 1 = 1: CINR reporting in Idlemode Msg - bit 2 = 1: Default PSC Enable in sleepmode*/ + * bit 0 = 1: CPE mode - to keep pcmcia if alive; + * bit 1 = 1: CINR reporting in Idlemode Msg + * bit 2 = 1: Default PSC Enable in sleepmode + */ B_UINT32 m_u32PowerSavingModeOptions; B_UINT32 m_u32ArqEnable; - // From Version #3, the HARQ section renamed as general + /* From Version #3, the HARQ section renamed as general */ B_UINT32 m_u32HarqEnable; - // EEPROM Param Location B_UINT32 m_u32EEPROMFlag; - // BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte - // Unused - LSByte + /* BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte + * Unused - LSByte + */ B_UINT32 m_u32Customize; B_UINT32 m_u32ConfigBW; /* In Hz */ B_UINT32 m_u32ShutDownInitThresholdTimer; @@ -39,11 +36,10 @@ typedef struct _TARGET_PARAMS B_UINT32 m_u32PhyParameter1; B_UINT32 m_u32PhyParameter2; B_UINT32 m_u32PhyParameter3; - B_UINT32 m_u32TestOptions; // in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack + B_UINT32 m_u32TestOptions; /* in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack */ B_UINT32 m_u32MaxMACDataperDLFrame; B_UINT32 m_u32MaxMACDataperULFrame; B_UINT32 m_u32Corr2MacFlags; - //adding driver params. B_UINT32 HostDrvrConfig1; B_UINT32 HostDrvrConfig2; B_UINT32 HostDrvrConfig3; @@ -51,10 +47,11 @@ typedef struct _TARGET_PARAMS B_UINT32 HostDrvrConfig5; B_UINT32 HostDrvrConfig6; B_UINT32 m_u32SegmentedPUSCenable; - // removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files.. - //BAMC Related Parameters - //Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling. - //bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support. + /* removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files.. + * BAMC Related Parameters + * Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling. + * bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support. + */ B_UINT32 m_u32BandAMCEnable; } stTargetParams, TARGET_PARAMS, *PTARGET_PARAMS, STARGETPARAMS, *PSTARGETPARAMS; -- cgit v0.10.2 From 4e241d7b9179a0ddde4e2f64710077e5baed22cf Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 17 Dec 2012 17:35:18 -0500 Subject: Staging: bcm: Properly format braces in target_params.h This patch formats braces in target_params.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h index 548bfd6..86069ce 100644 --- a/drivers/staging/bcm/target_params.h +++ b/drivers/staging/bcm/target_params.h @@ -1,8 +1,7 @@ #ifndef TARGET_PARAMS_H #define TARGET_PARAMS_H -typedef struct _TARGET_PARAMS -{ +typedef struct _TARGET_PARAMS { B_UINT32 m_u32CfgVersion; B_UINT32 m_u32CenterFrequency; B_UINT32 m_u32BandAScan; -- cgit v0.10.2 From a637f9041a164088c03b1a8b2ed0b6e65ad24e0e Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 17 Dec 2012 17:35:19 -0500 Subject: Staging: bcm: Replace B_UINT32 with u32 in target_params.h This patch replace "B_UINT32" with "u32" in target_params.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h index 86069ce..e416dac 100644 --- a/drivers/staging/bcm/target_params.h +++ b/drivers/staging/bcm/target_params.h @@ -2,56 +2,56 @@ #define TARGET_PARAMS_H typedef struct _TARGET_PARAMS { - B_UINT32 m_u32CfgVersion; - B_UINT32 m_u32CenterFrequency; - B_UINT32 m_u32BandAScan; - B_UINT32 m_u32BandBScan; - B_UINT32 m_u32BandCScan; - B_UINT32 m_u32ErtpsOptions; - B_UINT32 m_u32PHSEnable; - B_UINT32 m_u32HoEnable; - B_UINT32 m_u32HoReserved1; - B_UINT32 m_u32HoReserved2; - B_UINT32 m_u32MimoEnable; - B_UINT32 m_u32SecurityEnable; - B_UINT32 m_u32PowerSavingModesEnable; /* bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable */ + u32 m_u32CfgVersion; + u32 m_u32CenterFrequency; + u32 m_u32BandAScan; + u32 m_u32BandBScan; + u32 m_u32BandCScan; + u32 m_u32ErtpsOptions; + u32 m_u32PHSEnable; + u32 m_u32HoEnable; + u32 m_u32HoReserved1; + u32 m_u32HoReserved2; + u32 m_u32MimoEnable; + u32 m_u32SecurityEnable; + u32 m_u32PowerSavingModesEnable; /* bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable */ /* PowerSaving Mode Options: * bit 0 = 1: CPE mode - to keep pcmcia if alive; * bit 1 = 1: CINR reporting in Idlemode Msg * bit 2 = 1: Default PSC Enable in sleepmode */ - B_UINT32 m_u32PowerSavingModeOptions; - B_UINT32 m_u32ArqEnable; + u32 m_u32PowerSavingModeOptions; + u32 m_u32ArqEnable; /* From Version #3, the HARQ section renamed as general */ - B_UINT32 m_u32HarqEnable; - B_UINT32 m_u32EEPROMFlag; + u32 m_u32HarqEnable; + u32 m_u32EEPROMFlag; /* BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte * Unused - LSByte */ - B_UINT32 m_u32Customize; - B_UINT32 m_u32ConfigBW; /* In Hz */ - B_UINT32 m_u32ShutDownInitThresholdTimer; - B_UINT32 m_u32RadioParameter; - B_UINT32 m_u32PhyParameter1; - B_UINT32 m_u32PhyParameter2; - B_UINT32 m_u32PhyParameter3; - B_UINT32 m_u32TestOptions; /* in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack */ - B_UINT32 m_u32MaxMACDataperDLFrame; - B_UINT32 m_u32MaxMACDataperULFrame; - B_UINT32 m_u32Corr2MacFlags; - B_UINT32 HostDrvrConfig1; - B_UINT32 HostDrvrConfig2; - B_UINT32 HostDrvrConfig3; - B_UINT32 HostDrvrConfig4; - B_UINT32 HostDrvrConfig5; - B_UINT32 HostDrvrConfig6; - B_UINT32 m_u32SegmentedPUSCenable; + u32 m_u32Customize; + u32 m_u32ConfigBW; /* In Hz */ + u32 m_u32ShutDownInitThresholdTimer; + u32 m_u32RadioParameter; + u32 m_u32PhyParameter1; + u32 m_u32PhyParameter2; + u32 m_u32PhyParameter3; + u32 m_u32TestOptions; /* in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack */ + u32 m_u32MaxMACDataperDLFrame; + u32 m_u32MaxMACDataperULFrame; + u32 m_u32Corr2MacFlags; + u32 HostDrvrConfig1; + u32 HostDrvrConfig2; + u32 HostDrvrConfig3; + u32 HostDrvrConfig4; + u32 HostDrvrConfig5; + u32 HostDrvrConfig6; + u32 m_u32SegmentedPUSCenable; /* removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files.. * BAMC Related Parameters * Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling. * bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support. */ - B_UINT32 m_u32BandAMCEnable; + u32 m_u32BandAMCEnable; } stTargetParams, TARGET_PARAMS, *PTARGET_PARAMS, STARGETPARAMS, *PSTARGETPARAMS; #endif -- cgit v0.10.2 From c81823340a7eaa3dfdd4c5a244deff30231d2e5c Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Mon, 17 Dec 2012 17:35:20 -0500 Subject: Staging: bcm: Remove typedef for _TARGET_PARAMS and call directly. This patch removes typedef for _TARGET_PARAMS, and changes the name of the struct to bcm_target_params. In addition, any calls to struct "stTargetParams, TARGET_PARAMS, *PTARGET_PARAMS, STARGETPARAMS, or *PSTARGETPARAMS are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index f13afe7..6e43c61 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -288,7 +288,7 @@ struct bcm_mini_adapter { wait_queue_head_t ioctl_fw_dnld_wait_queue; BOOLEAN waiting_to_fw_download_done; pid_t fw_download_process_pid; - PSTARGETPARAMS pstargetparams; + struct bcm_target_params *pstargetparams; BOOLEAN device_removed; BOOLEAN DeviceAccess; BOOLEAN bIsAutoCorrectEnabled; diff --git a/drivers/staging/bcm/InterfaceDld.c b/drivers/staging/bcm/InterfaceDld.c index 87117a7..64ea6ed 100644 --- a/drivers/staging/bcm/InterfaceDld.c +++ b/drivers/staging/bcm/InterfaceDld.c @@ -138,12 +138,12 @@ static int bcm_download_config_file(struct bcm_mini_adapter *Adapter, struct bcm B_UINT32 value = 0; if (Adapter->pstargetparams == NULL) { - Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL); + Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL); if (Adapter->pstargetparams == NULL) return -ENOMEM; } - if (psFwInfo->u32FirmwareLength != sizeof(STARGETPARAMS)) + if (psFwInfo->u32FirmwareLength != sizeof(struct bcm_target_params)) return -EIO; retval = copy_from_user(Adapter->pstargetparams, psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength); @@ -195,7 +195,7 @@ static int bcm_download_config_file(struct bcm_mini_adapter *Adapter, struct bcm } } - retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams, sizeof(STARGETPARAMS), CONFIG_BEGIN_ADDR); + retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams, sizeof(struct bcm_target_params), CONFIG_BEGIN_ADDR); if (retval) BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "configuration file not downloaded properly"); diff --git a/drivers/staging/bcm/Misc.c b/drivers/staging/bcm/Misc.c index c92078e..21b739a 100644 --- a/drivers/staging/bcm/Misc.c +++ b/drivers/staging/bcm/Misc.c @@ -956,7 +956,7 @@ int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter) /* Download cfg file */ status = buffDnldVerify(ps_adapter, (PUCHAR)ps_adapter->pstargetparams, - sizeof(STARGETPARAMS), + sizeof(struct bcm_target_params), CONFIG_BEGIN_ADDR); if (status) { BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file"); @@ -1053,7 +1053,7 @@ static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter) if (!buff) return -ENOMEM; - Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL); + Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL); if (Adapter->pstargetparams == NULL) { kfree(buff); return -ENOMEM; @@ -1070,7 +1070,7 @@ static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter) len = kernel_read(flp, 0, buff, BUFFER_1K); filp_close(flp, NULL); - if (len != sizeof(STARGETPARAMS)) { + if (len != sizeof(struct bcm_target_params)) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n"); kfree(buff); kfree(Adapter->pstargetparams); @@ -1082,7 +1082,7 @@ static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter) /* * Values in Adapter->pstargetparams are in network byte order */ - memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS)); + memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params)); kfree(buff); beceem_parse_target_struct(Adapter); return STATUS_SUCCESS; diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h index e416dac..dc45f9a 100644 --- a/drivers/staging/bcm/target_params.h +++ b/drivers/staging/bcm/target_params.h @@ -1,7 +1,7 @@ #ifndef TARGET_PARAMS_H #define TARGET_PARAMS_H -typedef struct _TARGET_PARAMS { +struct bcm_target_params { u32 m_u32CfgVersion; u32 m_u32CenterFrequency; u32 m_u32BandAScan; @@ -52,6 +52,6 @@ typedef struct _TARGET_PARAMS { * bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support. */ u32 m_u32BandAMCEnable; -} stTargetParams, TARGET_PARAMS, *PTARGET_PARAMS, STARGETPARAMS, *PSTARGETPARAMS; +}; #endif -- cgit v0.10.2 From f0393b9ec763e630926d4b09c138bf6f5e4101cd Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:21 -0500 Subject: Staging: bcm: Fix all white space issues in PHSDefines.h This patch fixes all white space issues in PHSDefines.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 6016fc5..4cc1078 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -1,80 +1,71 @@ #ifndef BCM_PHS_DEFINES_H #define BCM_PHS_DEFINES_H -#define PHS_INVALID_TABLE_INDEX 0xffffffff - +#define PHS_INVALID_TABLE_INDEX 0xffffffff /************************* MACROS **********************************************/ #define PHS_MEM_TAG "_SHP" - - - //PHS Defines -#define STATUS_PHS_COMPRESSED 0xa1 -#define STATUS_PHS_NOCOMPRESSION 0xa2 -#define APPLY_PHS 1 -#define MAX_NO_BIT 7 -#define ZERO_PHSI 0 -#define VERIFY 0 -#define SIZE_MULTIPLE_32 4 -#define UNCOMPRESSED_PACKET 0 -#define DYNAMIC 0 -#define SUPPRESS 0x80 -#define NO_CLASSIFIER_MATCH 0 -#define SEND_PACKET_UNCOMPRESSED 0 -#define PHSI_IS_ZERO 0 -#define PHSI_LEN 1 -#define ERROR_LEN 0 -#define PHS_BUFFER_SIZE 1532 - - -#define MAX_PHSRULE_PER_SF 20 -#define MAX_SERVICEFLOWS 17 +#define STATUS_PHS_COMPRESSED 0xa1 +#define STATUS_PHS_NOCOMPRESSION 0xa2 +#define APPLY_PHS 1 +#define MAX_NO_BIT 7 +#define ZERO_PHSI 0 +#define VERIFY 0 +#define SIZE_MULTIPLE_32 4 +#define UNCOMPRESSED_PACKET 0 +#define DYNAMIC 0 +#define SUPPRESS 0x80 +#define NO_CLASSIFIER_MATCH 0 +#define SEND_PACKET_UNCOMPRESSED 0 +#define PHSI_IS_ZERO 0 +#define PHSI_LEN 1 +#define ERROR_LEN 0 +#define PHS_BUFFER_SIZE 1532 +#define MAX_PHSRULE_PER_SF 20 +#define MAX_SERVICEFLOWS 17 //PHS Error Defines -#define PHS_SUCCESS 0 -#define ERR_PHS_INVALID_DEVICE_EXETENSION 0x800 -#define ERR_PHS_INVALID_PHS_RULE 0x801 -#define ERR_PHS_RULE_ALREADY_EXISTS 0x802 -#define ERR_SF_MATCH_FAIL 0x803 -#define ERR_INVALID_CLASSIFIERTABLE_FOR_SF 0x804 -#define ERR_SFTABLE_FULL 0x805 -#define ERR_CLSASSIFIER_TABLE_FULL 0x806 -#define ERR_PHSRULE_MEMALLOC_FAIL 0x807 -#define ERR_CLSID_MATCH_FAIL 0x808 -#define ERR_PHSRULE_MATCH_FAIL 0x809 +#define PHS_SUCCESS 0 +#define ERR_PHS_INVALID_DEVICE_EXETENSION 0x800 +#define ERR_PHS_INVALID_PHS_RULE 0x801 +#define ERR_PHS_RULE_ALREADY_EXISTS 0x802 +#define ERR_SF_MATCH_FAIL 0x803 +#define ERR_INVALID_CLASSIFIERTABLE_FOR_SF 0x804 +#define ERR_SFTABLE_FULL 0x805 +#define ERR_CLSASSIFIER_TABLE_FULL 0x806 +#define ERR_PHSRULE_MEMALLOC_FAIL 0x807 +#define ERR_CLSID_MATCH_FAIL 0x808 +#define ERR_PHSRULE_MATCH_FAIL 0x809 typedef struct _S_PHS_RULE { - /// brief 8bit PHSI Of The Service Flow - B_UINT8 u8PHSI; - /// brief PHSF Of The Service Flow - B_UINT8 u8PHSFLength; - B_UINT8 u8PHSF[MAX_PHS_LENGTHS]; - /// brief PHSM Of The Service Flow - B_UINT8 u8PHSMLength; - B_UINT8 u8PHSM[MAX_PHS_LENGTHS]; - /// brief 8bit PHSS Of The Service Flow - B_UINT8 u8PHSS; - /// brief 8bit PHSV Of The Service Flow - B_UINT8 u8PHSV; - //Reference Count for this PHS Rule - B_UINT8 u8RefCnt; - //Flag to Store Unclassified PHS rules only in DL - B_UINT8 bUnclassifiedPHSRule; - - B_UINT8 u8Reserved[3]; - - LONG PHSModifiedBytes; - ULONG PHSModifiedNumPackets; - ULONG PHSErrorNumPackets; -}S_PHS_RULE; - + /// brief 8bit PHSI Of The Service Flow + B_UINT8 u8PHSI; + /// brief PHSF Of The Service Flow + B_UINT8 u8PHSFLength; + B_UINT8 u8PHSF[MAX_PHS_LENGTHS]; + /// brief PHSM Of The Service Flow + B_UINT8 u8PHSMLength; + B_UINT8 u8PHSM[MAX_PHS_LENGTHS]; + /// brief 8bit PHSS Of The Service Flow + B_UINT8 u8PHSS; + /// brief 8bit PHSV Of The Service Flow + B_UINT8 u8PHSV; + //Reference Count for this PHS Rule + B_UINT8 u8RefCnt; + //Flag to Store Unclassified PHS rules only in DL + B_UINT8 bUnclassifiedPHSRule; + B_UINT8 u8Reserved[3]; + LONG PHSModifiedBytes; + ULONG PHSModifiedNumPackets; + ULONG PHSErrorNumPackets; +} S_PHS_RULE; typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { eActiveClassifierRuleContext, eOldClassifierRuleContext -}E_CLASSIFIER_ENTRY_CONTEXT; +} E_CLASSIFIER_ENTRY_CONTEXT; typedef struct _S_CLASSIFIER_ENTRY { @@ -82,43 +73,37 @@ typedef struct _S_CLASSIFIER_ENTRY B_UINT16 uiClassifierRuleId; B_UINT8 u8PHSI; S_PHS_RULE *pstPhsRule; - B_UINT8 bUnclassifiedPHSRule; - -}S_CLASSIFIER_ENTRY; - + B_UINT8 bUnclassifiedPHSRule; +} S_CLASSIFIER_ENTRY; typedef struct _S_CLASSIFIER_TABLE { B_UINT16 uiTotalClassifiers; S_CLASSIFIER_ENTRY stActivePhsRulesList[MAX_PHSRULE_PER_SF]; S_CLASSIFIER_ENTRY stOldPhsRulesList[MAX_PHSRULE_PER_SF]; - B_UINT16 uiOldestPhsRuleIndex; - -}S_CLASSIFIER_TABLE; + B_UINT16 uiOldestPhsRuleIndex; +} S_CLASSIFIER_TABLE; typedef struct _S_SERVICEFLOW_ENTRY { - B_UINT8 bUsed; - B_UINT16 uiVcid; + B_UINT8 bUsed; + B_UINT16 uiVcid; S_CLASSIFIER_TABLE *pstClassifierTable; -}S_SERVICEFLOW_ENTRY; +} S_SERVICEFLOW_ENTRY; typedef struct _S_SERVICEFLOW_TABLE { B_UINT16 uiTotalServiceFlows; S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; - -}S_SERVICEFLOW_TABLE; - +} S_SERVICEFLOW_TABLE; typedef struct _PHS_DEVICE_EXTENSION { /* PHS Specific data*/ S_SERVICEFLOW_TABLE *pstServiceFlowPhsRulesTable; - void *CompressedTxBuffer; - void *UnCompressedRxBuffer; -}PHS_DEVICE_EXTENSION,*PPHS_DEVICE_EXTENSION; - + void *CompressedTxBuffer; + void *UnCompressedRxBuffer; +} PHS_DEVICE_EXTENSION, *PPHS_DEVICE_EXTENSION; #endif -- cgit v0.10.2 From bb1c74e58339e9e5b5a00f052c3cecf894877d63 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:22 -0500 Subject: Staging: bcm: Properly format comments in PHSDefines.h This patch properly formats comments, and removes them as needed in PHSDefines.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 4cc1078..bb3f83d 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -1,10 +1,10 @@ #ifndef BCM_PHS_DEFINES_H #define BCM_PHS_DEFINES_H -#define PHS_INVALID_TABLE_INDEX 0xffffffff -/************************* MACROS **********************************************/ +#define PHS_INVALID_TABLE_INDEX 0xffffffff #define PHS_MEM_TAG "_SHP" -//PHS Defines + +/* PHS Defines */ #define STATUS_PHS_COMPRESSED 0xa1 #define STATUS_PHS_NOCOMPRESSION 0xa2 #define APPLY_PHS 1 @@ -24,7 +24,7 @@ #define MAX_PHSRULE_PER_SF 20 #define MAX_SERVICEFLOWS 17 -//PHS Error Defines +/* PHS Error Defines */ #define PHS_SUCCESS 0 #define ERR_PHS_INVALID_DEVICE_EXETENSION 0x800 #define ERR_PHS_INVALID_PHS_RULE 0x801 @@ -39,21 +39,14 @@ typedef struct _S_PHS_RULE { - /// brief 8bit PHSI Of The Service Flow B_UINT8 u8PHSI; - /// brief PHSF Of The Service Flow B_UINT8 u8PHSFLength; B_UINT8 u8PHSF[MAX_PHS_LENGTHS]; - /// brief PHSM Of The Service Flow B_UINT8 u8PHSMLength; B_UINT8 u8PHSM[MAX_PHS_LENGTHS]; - /// brief 8bit PHSS Of The Service Flow B_UINT8 u8PHSS; - /// brief 8bit PHSV Of The Service Flow B_UINT8 u8PHSV; - //Reference Count for this PHS Rule B_UINT8 u8RefCnt; - //Flag to Store Unclassified PHS rules only in DL B_UINT8 bUnclassifiedPHSRule; B_UINT8 u8Reserved[3]; LONG PHSModifiedBytes; @@ -100,7 +93,7 @@ typedef struct _S_SERVICEFLOW_TABLE typedef struct _PHS_DEVICE_EXTENSION { - /* PHS Specific data*/ + /* PHS Specific data */ S_SERVICEFLOW_TABLE *pstServiceFlowPhsRulesTable; void *CompressedTxBuffer; void *UnCompressedRxBuffer; -- cgit v0.10.2 From acd4ab258f5fc2a8942f5b96be6f7e2f9b4164f2 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:23 -0500 Subject: Staging: bcm: Properly format braces in PHSDefines.h This patch formats braces in PHSDefines.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index bb3f83d..ec29ee7 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -37,8 +37,7 @@ #define ERR_CLSID_MATCH_FAIL 0x808 #define ERR_PHSRULE_MATCH_FAIL 0x809 -typedef struct _S_PHS_RULE -{ +typedef struct _S_PHS_RULE { B_UINT8 u8PHSI; B_UINT8 u8PHSFLength; B_UINT8 u8PHSF[MAX_PHS_LENGTHS]; @@ -54,14 +53,12 @@ typedef struct _S_PHS_RULE ULONG PHSErrorNumPackets; } S_PHS_RULE; -typedef enum _E_CLASSIFIER_ENTRY_CONTEXT -{ +typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { eActiveClassifierRuleContext, eOldClassifierRuleContext } E_CLASSIFIER_ENTRY_CONTEXT; -typedef struct _S_CLASSIFIER_ENTRY -{ +typedef struct _S_CLASSIFIER_ENTRY { B_UINT8 bUsed; B_UINT16 uiClassifierRuleId; B_UINT8 u8PHSI; @@ -69,30 +66,25 @@ typedef struct _S_CLASSIFIER_ENTRY B_UINT8 bUnclassifiedPHSRule; } S_CLASSIFIER_ENTRY; -typedef struct _S_CLASSIFIER_TABLE -{ +typedef struct _S_CLASSIFIER_TABLE { B_UINT16 uiTotalClassifiers; S_CLASSIFIER_ENTRY stActivePhsRulesList[MAX_PHSRULE_PER_SF]; S_CLASSIFIER_ENTRY stOldPhsRulesList[MAX_PHSRULE_PER_SF]; B_UINT16 uiOldestPhsRuleIndex; } S_CLASSIFIER_TABLE; - -typedef struct _S_SERVICEFLOW_ENTRY -{ +typedef struct _S_SERVICEFLOW_ENTRY { B_UINT8 bUsed; B_UINT16 uiVcid; S_CLASSIFIER_TABLE *pstClassifierTable; } S_SERVICEFLOW_ENTRY; -typedef struct _S_SERVICEFLOW_TABLE -{ +typedef struct _S_SERVICEFLOW_TABLE { B_UINT16 uiTotalServiceFlows; S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; } S_SERVICEFLOW_TABLE; -typedef struct _PHS_DEVICE_EXTENSION -{ +typedef struct _PHS_DEVICE_EXTENSION { /* PHS Specific data */ S_SERVICEFLOW_TABLE *pstServiceFlowPhsRulesTable; void *CompressedTxBuffer; -- cgit v0.10.2 From 3efa535669a63d10f9b1c5f17ee6014224cc2d26 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:24 -0500 Subject: Staging: bcm: Replace B_UINT8 with u8 in PHSDefines.h This patch replace "B_UINT8" with "u8" in PHSDefines.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index ec29ee7..52033c4 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -38,16 +38,16 @@ #define ERR_PHSRULE_MATCH_FAIL 0x809 typedef struct _S_PHS_RULE { - B_UINT8 u8PHSI; - B_UINT8 u8PHSFLength; - B_UINT8 u8PHSF[MAX_PHS_LENGTHS]; - B_UINT8 u8PHSMLength; - B_UINT8 u8PHSM[MAX_PHS_LENGTHS]; - B_UINT8 u8PHSS; - B_UINT8 u8PHSV; - B_UINT8 u8RefCnt; - B_UINT8 bUnclassifiedPHSRule; - B_UINT8 u8Reserved[3]; + u8 u8PHSI; + u8 u8PHSFLength; + u8 u8PHSF[MAX_PHS_LENGTHS]; + u8 u8PHSMLength; + u8 u8PHSM[MAX_PHS_LENGTHS]; + u8 u8PHSS; + u8 u8PHSV; + u8 u8RefCnt; + u8 bUnclassifiedPHSRule; + u8 u8Reserved[3]; LONG PHSModifiedBytes; ULONG PHSModifiedNumPackets; ULONG PHSErrorNumPackets; @@ -59,11 +59,11 @@ typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { } E_CLASSIFIER_ENTRY_CONTEXT; typedef struct _S_CLASSIFIER_ENTRY { - B_UINT8 bUsed; + u8 bUsed; B_UINT16 uiClassifierRuleId; - B_UINT8 u8PHSI; + u8 u8PHSI; S_PHS_RULE *pstPhsRule; - B_UINT8 bUnclassifiedPHSRule; + u8 bUnclassifiedPHSRule; } S_CLASSIFIER_ENTRY; typedef struct _S_CLASSIFIER_TABLE { @@ -74,7 +74,7 @@ typedef struct _S_CLASSIFIER_TABLE { } S_CLASSIFIER_TABLE; typedef struct _S_SERVICEFLOW_ENTRY { - B_UINT8 bUsed; + u8 bUsed; B_UINT16 uiVcid; S_CLASSIFIER_TABLE *pstClassifierTable; } S_SERVICEFLOW_ENTRY; -- cgit v0.10.2 From 72ccb86354f909bebac7722aa378d4409684a4d3 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:25 -0500 Subject: Staging: bcm: Replace B_UINT16 with u16 in PHSDefines.h This patch replace "B_UINT16" with "u16" in PHSDefines.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 52033c4..e72212e 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -60,27 +60,27 @@ typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { typedef struct _S_CLASSIFIER_ENTRY { u8 bUsed; - B_UINT16 uiClassifierRuleId; + u16 uiClassifierRuleId; u8 u8PHSI; S_PHS_RULE *pstPhsRule; u8 bUnclassifiedPHSRule; } S_CLASSIFIER_ENTRY; typedef struct _S_CLASSIFIER_TABLE { - B_UINT16 uiTotalClassifiers; + u16 uiTotalClassifiers; S_CLASSIFIER_ENTRY stActivePhsRulesList[MAX_PHSRULE_PER_SF]; S_CLASSIFIER_ENTRY stOldPhsRulesList[MAX_PHSRULE_PER_SF]; - B_UINT16 uiOldestPhsRuleIndex; + u16 uiOldestPhsRuleIndex; } S_CLASSIFIER_TABLE; typedef struct _S_SERVICEFLOW_ENTRY { u8 bUsed; - B_UINT16 uiVcid; + u16 uiVcid; S_CLASSIFIER_TABLE *pstClassifierTable; } S_SERVICEFLOW_ENTRY; typedef struct _S_SERVICEFLOW_TABLE { - B_UINT16 uiTotalServiceFlows; + u16 uiTotalServiceFlows; S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; } S_SERVICEFLOW_TABLE; -- cgit v0.10.2 From 11f49a2346244c9005189fb16ffd9a7f66c3e97c Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:26 -0500 Subject: Staging: bcm: Replace ULONG with unsigned long in PHSDefines.h This patch replaces "ULONG" with "unsigned long" in PHSDefines.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index e72212e..0de969a 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -49,8 +49,8 @@ typedef struct _S_PHS_RULE { u8 bUnclassifiedPHSRule; u8 u8Reserved[3]; LONG PHSModifiedBytes; - ULONG PHSModifiedNumPackets; - ULONG PHSErrorNumPackets; + unsigned long PHSModifiedNumPackets; + unsigned long PHSErrorNumPackets; } S_PHS_RULE; typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { -- cgit v0.10.2 From 86773aa91240d9361b38a41706b9c1b09be75da3 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:27 -0500 Subject: Staging: bcm: Replace LONG with long in PHSDefines.h This patch replaces "LONG" with "long" in PHSDefines.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 0de969a..6f2607c 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -48,7 +48,7 @@ typedef struct _S_PHS_RULE { u8 u8RefCnt; u8 bUnclassifiedPHSRule; u8 u8Reserved[3]; - LONG PHSModifiedBytes; + long PHSModifiedBytes; unsigned long PHSModifiedNumPackets; unsigned long PHSErrorNumPackets; } S_PHS_RULE; -- cgit v0.10.2 From 60dadf9def544665a696ee9b25ff12de32b51a3a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:28 -0500 Subject: Staging: bcm: Remove typedef for _PHS_DEVICE_EXTENSION and call directly. This patch removes typedef for _PHS_DEVICE_EXTENSION, and changes the name of the struct to bcm_phs_extension. In addition, any calls to struct "PHS_DEVICE_EXTENSION, or *PPHS_DEVICE_EXTENSION;" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index 6e43c61..675cfdd 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -333,7 +333,7 @@ struct bcm_mini_adapter { /* BOOLEAN bTriedToWakeUpFromShutdown; */ BOOLEAN bLinkDownRequested; int downloadDDR; - PHS_DEVICE_EXTENSION stBCMPhsContext; + struct bcm_phs_extension stBCMPhsContext; struct bcm_hdr_suppression_contextinfo stPhsTxContextInfo; uint8_t ucaPHSPktRestoreBuf[2048]; uint8_t bPHSEnabled; diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 6f2607c..93df374 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -84,11 +84,11 @@ typedef struct _S_SERVICEFLOW_TABLE { S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; } S_SERVICEFLOW_TABLE; -typedef struct _PHS_DEVICE_EXTENSION { +struct bcm_phs_extension { /* PHS Specific data */ S_SERVICEFLOW_TABLE *pstServiceFlowPhsRulesTable; void *CompressedTxBuffer; void *UnCompressedRxBuffer; -} PHS_DEVICE_EXTENSION, *PPHS_DEVICE_EXTENSION; +}; #endif diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index 6dc0bbc..9d23b62 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -291,7 +291,7 @@ void DumpFullPacket(UCHAR *pBuf,UINT nPktLen) // TRUE(1) -If allocation of memory was success full. // FALSE -If allocation of memory fails. //----------------------------------------------------------------------------- -int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension, struct bcm_mini_adapter *Adapter) +int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adapter *Adapter) { int i; S_SERVICEFLOW_TABLE *pstServiceFlowTable; @@ -351,7 +351,7 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension, struct bcm_mini_adapter } -int PhsCleanup(IN PPHS_DEVICE_EXTENSION pPHSDeviceExt) +int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt) { if(pPHSDeviceExt->pstServiceFlowPhsRulesTable) { @@ -402,7 +402,7 @@ ULONG PhsUpdateClassifierRule(IN void* pvContext, - PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; + struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"PHS With Corr2 Changes \n"); @@ -465,7 +465,7 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI) struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); - PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; + struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n"); @@ -529,7 +529,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); - PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; + struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; if(pDeviceExtension) { @@ -593,7 +593,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid) S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); - PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; + struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"====> \n"); if(pDeviceExtension) @@ -688,7 +688,7 @@ ULONG PhsCompress(IN void* pvContext, - PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; + struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; if(pDeviceExtension == NULL) @@ -779,8 +779,8 @@ ULONG PhsDeCompress(IN void* pvContext, S_PHS_RULE *pstPhsRule = NULL; UINT phsi; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); - PPHS_DEVICE_EXTENSION pDeviceExtension= - (PPHS_DEVICE_EXTENSION)pvContext; + struct bcm_phs_extension *pDeviceExtension= + (struct bcm_phs_extension *)pvContext; *pInHeaderSize = 0; @@ -1331,7 +1331,7 @@ static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifi } } -void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension) +void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension) { int i,j,k,l; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h index b5f2115..0095691 100644 --- a/drivers/staging/bcm/PHSModule.h +++ b/drivers/staging/bcm/PHSModule.h @@ -22,12 +22,12 @@ void DumpDataPacketHeader(PUCHAR pPkt); void DumpFullPacket(UCHAR *pBuf,UINT nPktLen); -void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension); +void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension); -int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,struct bcm_mini_adapter *Adapter); +int phs_init(struct bcm_phs_extension *pPhsdeviceExtension,struct bcm_mini_adapter *Adapter); -int PhsCleanup(PPHS_DEVICE_EXTENSION pPHSDeviceExt); +int PhsCleanup(struct bcm_phs_extension *pPHSDeviceExt); //Utility Functions ULONG PhsUpdateClassifierRule(void* pvContext,B_UINT16 uiVcid,B_UINT16 uiClsId,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI ); @@ -44,7 +44,7 @@ BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule); UINT GetServiceFlowEntry(S_SERVICEFLOW_TABLE *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry); -void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension); +void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension); #endif diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c index 3c5f4a5..93888b3 100644 --- a/drivers/staging/bcm/hostmibs.c +++ b/drivers/staging/bcm/hostmibs.c @@ -15,7 +15,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_m S_PHS_RULE *pstPhsRule = NULL; S_CLASSIFIER_TABLE *pstClassifierTable = NULL; S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; - PPHS_DEVICE_EXTENSION pDeviceExtension = (PPHS_DEVICE_EXTENSION) &Adapter->stBCMPhsContext; + struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *) &Adapter->stBCMPhsContext; UINT nClassifierIndex = 0, nPhsTableIndex = 0, nSfIndex = 0, uiIndex = 0; -- cgit v0.10.2 From da4d1504559aef87c8d2deb671d5d27ecc3f4ae0 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:29 -0500 Subject: Staging: bcm: Remove typedef for _S_SERVICEFLOW_TABLE and call directly. This patch removes typedef for _S_SERVICEFLOW_TABLE, and changes the name of the struct to bcm_phs_table. In addition, any calls to struct "S_SERVICEFLOW_TABLE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 93df374..4a2edf1 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -79,14 +79,14 @@ typedef struct _S_SERVICEFLOW_ENTRY { S_CLASSIFIER_TABLE *pstClassifierTable; } S_SERVICEFLOW_ENTRY; -typedef struct _S_SERVICEFLOW_TABLE { +struct bcm_phs_table { u16 uiTotalServiceFlows; S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; -} S_SERVICEFLOW_TABLE; +}; struct bcm_phs_extension { /* PHS Specific data */ - S_SERVICEFLOW_TABLE *pstServiceFlowPhsRulesTable; + struct bcm_phs_table *pstServiceFlowPhsRulesTable; void *CompressedTxBuffer; void *UnCompressedRxBuffer; }; diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index 9d23b62..cc40868 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -1,6 +1,6 @@ #include "headers.h" -static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_TABLE *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_ENTRY *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); @@ -16,7 +16,7 @@ static UINT GetClassifierEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 u static UINT GetPhsRuleEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule); -static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable); +static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable); static int phs_compress(S_PHS_RULE *phs_members,unsigned char *in_buf, unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size ); @@ -294,14 +294,14 @@ void DumpFullPacket(UCHAR *pBuf,UINT nPktLen) int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adapter *Adapter) { int i; - S_SERVICEFLOW_TABLE *pstServiceFlowTable; + struct bcm_phs_table *pstServiceFlowTable; BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function "); if(pPhsdeviceExtension->pstServiceFlowPhsRulesTable) return -EINVAL; pPhsdeviceExtension->pstServiceFlowPhsRulesTable = - kzalloc(sizeof(S_SERVICEFLOW_TABLE), GFP_KERNEL); + kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL); if(!pPhsdeviceExtension->pstServiceFlowPhsRulesTable) { @@ -844,7 +844,7 @@ ULONG PhsDeCompress(IN void* pvContext, // Does not return any value. //----------------------------------------------------------------------------- -static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable) +static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable) { int i,j; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -927,7 +927,7 @@ static BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule) } } -UINT GetServiceFlowEntry(IN S_SERVICEFLOW_TABLE *psServiceFlowTable, +UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable, IN B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry) { int i; @@ -1013,7 +1013,7 @@ static UINT GetPhsRuleEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, } UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId, - IN S_SERVICEFLOW_TABLE *psServiceFlowTable,S_PHS_RULE *psPhsRule, + IN struct bcm_phs_table *psServiceFlowTable,S_PHS_RULE *psPhsRule, B_UINT8 u8AssociatedPHSI) { diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h index 0095691..6973cba 100644 --- a/drivers/staging/bcm/PHSModule.h +++ b/drivers/staging/bcm/PHSModule.h @@ -41,7 +41,7 @@ ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ; BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule); -UINT GetServiceFlowEntry(S_SERVICEFLOW_TABLE *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry); +UINT GetServiceFlowEntry(struct bcm_phs_table *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry); void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension); -- cgit v0.10.2 From db134a63cfcd2386a3506f85fbdf906df17f886a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:30 -0500 Subject: Staging: bcm: Remove typedef for _S_SERVICEFLOW_ENTRY and call directly. This patch removes typedef for _S_SERVICEFLOW_ENTRY, and changes the name of the struct to bcm_phs_entry. In addition, any calls to struct "_S_SERVICEFLOW_ENTRY" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index 4a2edf1..cd42953 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -73,15 +73,15 @@ typedef struct _S_CLASSIFIER_TABLE { u16 uiOldestPhsRuleIndex; } S_CLASSIFIER_TABLE; -typedef struct _S_SERVICEFLOW_ENTRY { +struct bcm_phs_entry { u8 bUsed; u16 uiVcid; S_CLASSIFIER_TABLE *pstClassifierTable; -} S_SERVICEFLOW_ENTRY; +}; struct bcm_phs_table { u16 uiTotalServiceFlows; - S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; + struct bcm_phs_entry stSFList[MAX_SERVICEFLOWS]; }; struct bcm_phs_extension { diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index cc40868..f900a2c 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -2,7 +2,7 @@ static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); -static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_ENTRY *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); static UINT CreateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI); @@ -312,7 +312,7 @@ int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adap pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable; for(i=0;istSFList[i]; + struct bcm_phs_entry sServiceFlow = pstServiceFlowTable->stSFList[i]; sServiceFlow.pstClassifierTable = kzalloc(sizeof(S_CLASSIFIER_TABLE), GFP_KERNEL); if(!sServiceFlow.pstClassifierTable) { @@ -397,7 +397,7 @@ ULONG PhsUpdateClassifierRule(IN void* pvContext, { ULONG lStatus =0; UINT nSFIndex =0 ; - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -460,7 +460,7 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI) { ULONG lStatus =0; UINT nSFIndex =0, nClsidIndex =0 ; - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -526,7 +526,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16 { ULONG lStatus =0; UINT nSFIndex =0, nClsidIndex =0 ; - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; @@ -590,7 +590,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid) ULONG lStatus =0; UINT nSFIndex =0, nClsidIndex =0 ; - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; @@ -680,7 +680,7 @@ ULONG PhsCompress(IN void* pvContext, OUT UINT *pNewHeaderSize ) { UINT nSFIndex =0, nClsidIndex =0 ; - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; S_PHS_RULE *pstPhsRule = NULL; ULONG lStatus =0; @@ -775,7 +775,7 @@ ULONG PhsDeCompress(IN void* pvContext, OUT UINT *pOutHeaderSize ) { UINT nSFIndex =0, nPhsRuleIndex =0 ; - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_PHS_RULE *pstPhsRule = NULL; UINT phsi; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -854,7 +854,7 @@ static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesT { for(i=0;istSFList[i]; S_CLASSIFIER_TABLE *pstClassifierRulesTable = stServiceFlowEntry.pstClassifierTable; @@ -928,7 +928,7 @@ static BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule) } UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable, - IN B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry) + IN B_UINT16 uiVcid, struct bcm_phs_entry **ppstServiceFlowEntry) { int i; for(i=0;ipstServiceFlowPhsRulesTable->stSFList[i]; if(stServFlowEntry.bUsed) { diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h index 6973cba..5da3fa4 100644 --- a/drivers/staging/bcm/PHSModule.h +++ b/drivers/staging/bcm/PHSModule.h @@ -41,7 +41,7 @@ ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ; BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule); -UINT GetServiceFlowEntry(struct bcm_phs_table *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry); +UINT GetServiceFlowEntry(struct bcm_phs_table *psServiceFlowTable,B_UINT16 uiVcid, struct bcm_phs_entry **ppstServiceFlowEntry); void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension); diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c index 93888b3..4ce34ac 100644 --- a/drivers/staging/bcm/hostmibs.c +++ b/drivers/staging/bcm/hostmibs.c @@ -11,7 +11,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_mibs *pstHostMibs) { - S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; + struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_PHS_RULE *pstPhsRule = NULL; S_CLASSIFIER_TABLE *pstClassifierTable = NULL; S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; -- cgit v0.10.2 From a700dbd3d4af0c380145ca9e36e30b74f2a95ecf Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:31 -0500 Subject: Staging: bcm: Remove typedef for _S_CLASSIFIER_TABLE and call directly. This patch removes typedef for _S_CLASSIFIER_TABLE, and changes the name of the struct to bcm_phs_classifier_table. In addition, any calls to struct "S_CLASSIFIER_TABLE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index cd42953..fd7dd7f 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -66,17 +66,17 @@ typedef struct _S_CLASSIFIER_ENTRY { u8 bUnclassifiedPHSRule; } S_CLASSIFIER_ENTRY; -typedef struct _S_CLASSIFIER_TABLE { +struct bcm_phs_classifier_table { u16 uiTotalClassifiers; S_CLASSIFIER_ENTRY stActivePhsRulesList[MAX_PHSRULE_PER_SF]; S_CLASSIFIER_ENTRY stOldPhsRulesList[MAX_PHSRULE_PER_SF]; u16 uiOldestPhsRuleIndex; -} S_CLASSIFIER_TABLE; +}; struct bcm_phs_entry { u8 bUsed; u16 uiVcid; - S_CLASSIFIER_TABLE *pstClassifierTable; + struct bcm_phs_classifier_table *pstClassifierTable; }; struct bcm_phs_table { diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index f900a2c..ff0247b 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -4,17 +4,17 @@ static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, s static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); -static UINT CreateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI); +static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI); -static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_ENTRY *pstClassifierEntry,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_ENTRY *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); static BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule); -static BOOLEAN DerefPhsRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule); +static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable,S_PHS_RULE *pstPhsRule); -static UINT GetClassifierEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, S_CLASSIFIER_ENTRY **ppstClassifierEntry); +static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, S_CLASSIFIER_ENTRY **ppstClassifierEntry); -static UINT GetPhsRuleEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule); +static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule); static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable); @@ -313,7 +313,7 @@ int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adap for(i=0;istSFList[i]; - sServiceFlow.pstClassifierTable = kzalloc(sizeof(S_CLASSIFIER_TABLE), GFP_KERNEL); + sServiceFlow.pstClassifierTable = kzalloc(sizeof(struct bcm_phs_classifier_table), GFP_KERNEL); if(!sServiceFlow.pstClassifierTable) { BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); @@ -461,7 +461,7 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI) ULONG lStatus =0; UINT nSFIndex =0, nClsidIndex =0 ; struct bcm_phs_entry *pstServiceFlowEntry = NULL; - S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; + struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -591,7 +591,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid) ULONG lStatus =0; UINT nSFIndex =0, nClsidIndex =0 ; struct bcm_phs_entry *pstServiceFlowEntry = NULL; - S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; + struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"====> \n"); @@ -856,7 +856,7 @@ static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesT { struct bcm_phs_entry stServiceFlowEntry = psServiceFlowRulesTable->stSFList[i]; - S_CLASSIFIER_TABLE *pstClassifierRulesTable = + struct bcm_phs_classifier_table *pstClassifierRulesTable = stServiceFlowEntry.pstClassifierTable; if(pstClassifierRulesTable) @@ -948,7 +948,7 @@ UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable, } -UINT GetClassifierEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, +UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, IN B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, OUT S_CLASSIFIER_ENTRY **ppstClassifierEntry) { @@ -981,7 +981,7 @@ UINT GetClassifierEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, return PHS_INVALID_TABLE_INDEX; } -static UINT GetPhsRuleEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, +static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, IN B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, OUT S_PHS_RULE **ppstPhsRule) { @@ -1017,7 +1017,7 @@ UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId, B_UINT8 u8AssociatedPHSI) { - S_CLASSIFIER_TABLE *psaClassifiertable = NULL; + struct bcm_phs_classifier_table *psaClassifiertable = NULL; UINT uiStatus = 0; int iSfIndex; BOOLEAN bFreeEntryFound =FALSE; @@ -1056,7 +1056,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; UINT uiStatus =PHS_SUCCESS; UINT nClassifierIndex = 0; - S_CLASSIFIER_TABLE *psaClassifiertable = NULL; + struct bcm_phs_classifier_table *psaClassifiertable = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); psaClassifiertable = pstServiceFlowEntry->pstClassifierTable; @@ -1141,7 +1141,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, } static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, - S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule, + struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI) { UINT iClassifierIndex = 0; @@ -1253,7 +1253,7 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, IN S_CLASSIFIER_ENTRY *pstClassifierEntry, - S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule, + struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, B_UINT8 u8AssociatedPHSI) { S_PHS_RULE *pstAddPhsRule = NULL; @@ -1312,7 +1312,7 @@ static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, } -static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule) +static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable,S_PHS_RULE *pstPhsRule) { if(pstPhsRule==NULL) return FALSE; diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c index 4ce34ac..7769535 100644 --- a/drivers/staging/bcm/hostmibs.c +++ b/drivers/staging/bcm/hostmibs.c @@ -13,7 +13,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_m { struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_PHS_RULE *pstPhsRule = NULL; - S_CLASSIFIER_TABLE *pstClassifierTable = NULL; + struct bcm_phs_classifier_table *pstClassifierTable = NULL; S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *) &Adapter->stBCMPhsContext; -- cgit v0.10.2 From 2212e9374b5d8131785ba8a6e7948a6fed4dd1d5 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:32 -0500 Subject: Staging: bcm: Remove typedef for _S_CLASSIFIER_ENTRY and call directly. This patch removes typedef for _S_CLASSIFIER_ENTRY, and changes the name of the struct to bcm_phs_classifier_entry. In addition, any calls to struct "_S_CLASSIFIER_ENTRY" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index fd7dd7f..db570d4 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -58,18 +58,18 @@ typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { eOldClassifierRuleContext } E_CLASSIFIER_ENTRY_CONTEXT; -typedef struct _S_CLASSIFIER_ENTRY { +struct bcm_phs_classifier_entry { u8 bUsed; u16 uiClassifierRuleId; u8 u8PHSI; S_PHS_RULE *pstPhsRule; u8 bUnclassifiedPHSRule; -} S_CLASSIFIER_ENTRY; +}; struct bcm_phs_classifier_table { u16 uiTotalClassifiers; - S_CLASSIFIER_ENTRY stActivePhsRulesList[MAX_PHSRULE_PER_SF]; - S_CLASSIFIER_ENTRY stOldPhsRulesList[MAX_PHSRULE_PER_SF]; + struct bcm_phs_classifier_entry stActivePhsRulesList[MAX_PHSRULE_PER_SF]; + struct bcm_phs_classifier_entry stOldPhsRulesList[MAX_PHSRULE_PER_SF]; u16 uiOldestPhsRuleIndex; }; diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index ff0247b..bec3bac 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -6,13 +6,13 @@ static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, s static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI); -static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_ENTRY *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); static BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule); static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable,S_PHS_RULE *pstPhsRule); -static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, S_CLASSIFIER_ENTRY **ppstClassifierEntry); +static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry); static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule); @@ -495,7 +495,7 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI) if(0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule); memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, - sizeof(S_CLASSIFIER_ENTRY)); + sizeof(struct bcm_phs_classifier_entry)); } } } @@ -527,7 +527,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16 ULONG lStatus =0; UINT nSFIndex =0, nClsidIndex =0 ; struct bcm_phs_entry *pstServiceFlowEntry = NULL; - S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; + struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext; @@ -554,7 +554,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16 kfree(pstClassifierEntry->pstPhsRule); } - memset(pstClassifierEntry, 0, sizeof(S_CLASSIFIER_ENTRY)); + memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry)); } nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable, @@ -563,7 +563,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16 if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) { kfree(pstClassifierEntry->pstPhsRule); - memset(pstClassifierEntry, 0, sizeof(S_CLASSIFIER_ENTRY)); + memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry)); } } return lStatus; @@ -624,7 +624,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid) pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex] .pstPhsRule = NULL; } - memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(S_CLASSIFIER_ENTRY)); + memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry)); if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule) { if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] @@ -638,7 +638,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid) pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] .pstPhsRule = NULL; } - memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(S_CLASSIFIER_ENTRY)); + memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry)); } } pstServiceFlowEntry->bUsed = FALSE; @@ -681,7 +681,7 @@ ULONG PhsCompress(IN void* pvContext, { UINT nSFIndex =0, nClsidIndex =0 ; struct bcm_phs_entry *pstServiceFlowEntry = NULL; - S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; + struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; S_PHS_RULE *pstPhsRule = NULL; ULONG lStatus =0; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -950,10 +950,10 @@ UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable, UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, IN B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, - OUT S_CLASSIFIER_ENTRY **ppstClassifierEntry) + OUT struct bcm_phs_classifier_entry **ppstClassifierEntry) { int i; - S_CLASSIFIER_ENTRY *psClassifierRules = NULL; + struct bcm_phs_classifier_entry *psClassifierRules = NULL; for(i=0;istActivePhsRulesList[j]; diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c index 7769535..44bc11d 100644 --- a/drivers/staging/bcm/hostmibs.c +++ b/drivers/staging/bcm/hostmibs.c @@ -14,7 +14,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_m struct bcm_phs_entry *pstServiceFlowEntry = NULL; S_PHS_RULE *pstPhsRule = NULL; struct bcm_phs_classifier_table *pstClassifierTable = NULL; - S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; + struct bcm_phs_classifier_entry *pstClassifierRule = NULL; struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *) &Adapter->stBCMPhsContext; UINT nClassifierIndex = 0, nPhsTableIndex = 0, nSfIndex = 0, uiIndex = 0; -- cgit v0.10.2 From 37fed6ac26c7637bce6e60c17f5d2bb468c8ffd0 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:33 -0500 Subject: Staging: bcm: Remove typedef for _E_CLASSIFIER_ENTRY_CONTEXT and call directly. This patch removes typedef for _E_CLASSIFIER_ENTRY_CONTEXT, and changes the name of the enum to bcm_phs_classifier_context. In addition, any calls to enum "_E_CLASSIFIER_ENTRY_CONTEXT" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index db570d4..a65f5b5 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -53,10 +53,10 @@ typedef struct _S_PHS_RULE { unsigned long PHSErrorNumPackets; } S_PHS_RULE; -typedef enum _E_CLASSIFIER_ENTRY_CONTEXT { +enum bcm_phs_classifier_context { eActiveClassifierRuleContext, eOldClassifierRuleContext -} E_CLASSIFIER_ENTRY_CONTEXT; +}; struct bcm_phs_classifier_entry { u8 bUsed; diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index bec3bac..245462e 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -4,7 +4,7 @@ static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, s static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); -static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI); +static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI); static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); @@ -12,9 +12,9 @@ static BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule); static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable,S_PHS_RULE *pstPhsRule); -static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry); +static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry); -static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule); +static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext,S_PHS_RULE **ppstPhsRule); static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable); @@ -949,7 +949,7 @@ UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable, UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, - IN B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, + IN B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, OUT struct bcm_phs_classifier_entry **ppstClassifierEntry) { int i; @@ -982,7 +982,7 @@ UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, } static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, - IN B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, + IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, OUT S_PHS_RULE **ppstPhsRule) { int i; @@ -1142,7 +1142,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, - E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI) + enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI) { UINT iClassifierIndex = 0; BOOLEAN bFreeEntryFound = FALSE; -- cgit v0.10.2 From a903d65055199bfad94ae3af598d45970f62f8c2 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Thu, 20 Dec 2012 00:31:34 -0500 Subject: Staging: bcm: Remove typedef for _S_PHS_RULE and call directly. This patch removes typedef for _S_PHS_RULE, and changes the name of the struct to bcm_phs_rule. In addition, any calls to struct "S_PHS_RULE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index 675cfdd..91367ce 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -95,7 +95,7 @@ struct bcm_classifier_rule { UCHAR ucDirection; BOOLEAN bIpv6Protocol; UINT32 u32PHSRuleID; - S_PHS_RULE sPhsRule; + struct bcm_phs_rule sPhsRule; UCHAR u8AssociatedPHSI; /* Classification fields for ETH CS */ diff --git a/drivers/staging/bcm/CmHost.c b/drivers/staging/bcm/CmHost.c index 78335f9..9765145 100644 --- a/drivers/staging/bcm/CmHost.c +++ b/drivers/staging/bcm/CmHost.c @@ -440,7 +440,7 @@ static VOID CopyToAdapter(register struct bcm_mini_adapter *Adapter, /* PackInfo[uiSearchRuleIndex].usVCID_Value; UINT UGIValue = 0; @@ -703,7 +703,7 @@ static VOID CopyToAdapter(register struct bcm_mini_adapter *Adapter, /* astClassifierTable[uiClassifierIndex].u32PHSRuleID = sPhsRule.u8PHSI; - memcpy(&Adapter->astClassifierTable[uiClassifierIndex].sPhsRule, &sPhsRule, sizeof(S_PHS_RULE)); + memcpy(&Adapter->astClassifierTable[uiClassifierIndex].sPhsRule, &sPhsRule, sizeof(struct bcm_phs_rule)); } } } diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h index a65f5b5..cd78ee4 100644 --- a/drivers/staging/bcm/PHSDefines.h +++ b/drivers/staging/bcm/PHSDefines.h @@ -37,7 +37,7 @@ #define ERR_CLSID_MATCH_FAIL 0x808 #define ERR_PHSRULE_MATCH_FAIL 0x809 -typedef struct _S_PHS_RULE { +struct bcm_phs_rule { u8 u8PHSI; u8 u8PHSFLength; u8 u8PHSF[MAX_PHS_LENGTHS]; @@ -51,7 +51,7 @@ typedef struct _S_PHS_RULE { long PHSModifiedBytes; unsigned long PHSModifiedNumPackets; unsigned long PHSErrorNumPackets; -} S_PHS_RULE; +}; enum bcm_phs_classifier_context { eActiveClassifierRuleContext, @@ -62,7 +62,7 @@ struct bcm_phs_classifier_entry { u8 bUsed; u16 uiClassifierRuleId; u8 u8PHSI; - S_PHS_RULE *pstPhsRule; + struct bcm_phs_rule *pstPhsRule; u8 bUnclassifiedPHSRule; }; diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c index 245462e..7028bc9 100644 --- a/drivers/staging/bcm/PHSModule.c +++ b/drivers/staging/bcm/PHSModule.c @@ -1,24 +1,24 @@ #include "headers.h" -static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI); -static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI); -static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI); +static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI); -static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); +static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI); -static BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule); +static BOOLEAN ValidatePHSRuleComplete(struct bcm_phs_rule *psPhsRule); -static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable,S_PHS_RULE *pstPhsRule); +static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule); static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry); -static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext,S_PHS_RULE **ppstPhsRule); +static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_rule **ppstPhsRule); static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable); -static int phs_compress(S_PHS_RULE *phs_members,unsigned char *in_buf, +static int phs_compress(struct bcm_phs_rule *phs_members, unsigned char *in_buf, unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size ); @@ -26,7 +26,7 @@ static int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buff unsigned char *phsf,unsigned char *phsm,unsigned int phss,unsigned int phsv,UINT *new_header_size ); static int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,\ - S_PHS_RULE *phs_rules,UINT *header_size); + struct bcm_phs_rule *phs_rules, UINT *header_size); static ULONG PhsCompress(void* pvContext, @@ -381,7 +381,7 @@ Arguments: IN void* pvContext - PHS Driver Specific Context IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies. - IN S_PHS_RULE *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table. + IN struct bcm_phs_rule *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table. Return Value: @@ -392,7 +392,7 @@ Return Value: ULONG PhsUpdateClassifierRule(IN void* pvContext, IN B_UINT16 uiVcid , IN B_UINT16 uiClsId , - IN S_PHS_RULE *psPhsRule, + IN struct bcm_phs_rule *psPhsRule, IN B_UINT8 u8AssociatedPHSI) { ULONG lStatus =0; @@ -682,7 +682,7 @@ ULONG PhsCompress(IN void* pvContext, UINT nSFIndex =0, nClsidIndex =0 ; struct bcm_phs_entry *pstServiceFlowEntry = NULL; struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; - S_PHS_RULE *pstPhsRule = NULL; + struct bcm_phs_rule *pstPhsRule = NULL; ULONG lStatus =0; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -776,7 +776,7 @@ ULONG PhsDeCompress(IN void* pvContext, { UINT nSFIndex =0, nPhsRuleIndex =0 ; struct bcm_phs_entry *pstServiceFlowEntry = NULL; - S_PHS_RULE *pstPhsRule = NULL; + struct bcm_phs_rule *pstPhsRule = NULL; UINT phsi; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); struct bcm_phs_extension *pDeviceExtension= @@ -898,7 +898,7 @@ static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesT -static BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule) +static BOOLEAN ValidatePHSRuleComplete(IN struct bcm_phs_rule *psPhsRule) { if(psPhsRule) { @@ -983,7 +983,7 @@ UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, - OUT S_PHS_RULE **ppstPhsRule) + OUT struct bcm_phs_rule **ppstPhsRule) { int i; struct bcm_phs_classifier_entry *pstClassifierRule = NULL; @@ -1013,7 +1013,7 @@ static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTab } UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId, - IN struct bcm_phs_table *psServiceFlowTable,S_PHS_RULE *psPhsRule, + IN struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI) { @@ -1051,7 +1051,7 @@ UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId, UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, IN B_UINT16 uiClsId,IN struct bcm_phs_entry *pstServiceFlowEntry, - S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI) + struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI) { struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; UINT uiStatus =PHS_SUCCESS; @@ -1141,7 +1141,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, } static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, - struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, + struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI) { UINT iClassifierIndex = 0; @@ -1227,7 +1227,7 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, { if(psClassifierRules->pstPhsRule == NULL) { - psClassifierRules->pstPhsRule = kmalloc(sizeof(S_PHS_RULE),GFP_KERNEL); + psClassifierRules->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule),GFP_KERNEL); if(NULL == psClassifierRules->pstPhsRule) return ERR_PHSRULE_MEMALLOC_FAIL; @@ -1240,7 +1240,7 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, /* Update The PHS rule */ memcpy(psClassifierRules->pstPhsRule, - psPhsRule, sizeof(S_PHS_RULE)); + psPhsRule, sizeof(struct bcm_phs_rule)); } else { @@ -1253,10 +1253,10 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, IN struct bcm_phs_classifier_entry *pstClassifierEntry, - struct bcm_phs_classifier_table *psaClassifiertable ,S_PHS_RULE *psPhsRule, + struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI) { - S_PHS_RULE *pstAddPhsRule = NULL; + struct bcm_phs_rule *pstAddPhsRule = NULL; UINT nPhsRuleIndex = 0; BOOLEAN bPHSRuleOrphaned = FALSE; struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); @@ -1281,13 +1281,13 @@ static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, //Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId if(FALSE == bPHSRuleOrphaned) { - pstClassifierEntry->pstPhsRule = kmalloc(sizeof(S_PHS_RULE), GFP_KERNEL); + pstClassifierEntry->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL); if(NULL == pstClassifierEntry->pstPhsRule) { return ERR_PHSRULE_MEMALLOC_FAIL; } } - memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(S_PHS_RULE)); + memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule)); } else @@ -1312,7 +1312,7 @@ static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, } -static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable,S_PHS_RULE *pstPhsRule) +static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule) { if(pstPhsRule==NULL) return FALSE; @@ -1408,10 +1408,10 @@ void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension) //----------------------------------------------------------------------------- int phs_decompress(unsigned char *in_buf,unsigned char *out_buf, - S_PHS_RULE *decomp_phs_rules,UINT *header_size) + struct bcm_phs_rule *decomp_phs_rules, UINT *header_size) { int phss,size=0; - S_PHS_RULE *tmp_memb; + struct bcm_phs_rule *tmp_memb; int bit,i=0; unsigned char *phsf,*phsm; int in_buf_len = *header_size-1; @@ -1490,7 +1490,7 @@ int phs_decompress(unsigned char *in_buf,unsigned char *out_buf, // size-The number of bytes copied into the output buffer i.e dynamic fields // 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails. //----------------------------------------------------------------------------- -static int phs_compress(S_PHS_RULE *phs_rule,unsigned char *in_buf +static int phs_compress(struct bcm_phs_rule *phs_rule, unsigned char *in_buf ,unsigned char *out_buf,UINT *header_size,UINT *new_header_size) { unsigned char *old_addr = out_buf; diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h index 5da3fa4..82d8682 100644 --- a/drivers/staging/bcm/PHSModule.h +++ b/drivers/staging/bcm/PHSModule.h @@ -30,7 +30,7 @@ int phs_init(struct bcm_phs_extension *pPhsdeviceExtension,struct bcm_mini_adapt int PhsCleanup(struct bcm_phs_extension *pPHSDeviceExt); //Utility Functions -ULONG PhsUpdateClassifierRule(void* pvContext,B_UINT16 uiVcid,B_UINT16 uiClsId,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI ); +ULONG PhsUpdateClassifierRule(void* pvContext,B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_rule *psPhsRule,B_UINT8 u8AssociatedPHSI ); ULONG PhsDeletePHSRule(void* pvContext,B_UINT16 uiVcid,B_UINT8 u8PHSI); @@ -39,7 +39,7 @@ ULONG PhsDeleteClassifierRule(void* pvContext, B_UINT16 uiVcid ,B_UINT16 uiClsI ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ; -BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule); +BOOLEAN ValidatePHSRule(struct bcm_phs_rule *psPhsRule); UINT GetServiceFlowEntry(struct bcm_phs_table *psServiceFlowTable,B_UINT16 uiVcid, struct bcm_phs_entry **ppstServiceFlowEntry); diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c index 44bc11d..f55300d 100644 --- a/drivers/staging/bcm/hostmibs.c +++ b/drivers/staging/bcm/hostmibs.c @@ -12,7 +12,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_mibs *pstHostMibs) { struct bcm_phs_entry *pstServiceFlowEntry = NULL; - S_PHS_RULE *pstPhsRule = NULL; + struct bcm_phs_rule *pstPhsRule = NULL; struct bcm_phs_classifier_table *pstClassifierTable = NULL; struct bcm_phs_classifier_entry *pstClassifierRule = NULL; struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *) &Adapter->stBCMPhsContext; @@ -70,7 +70,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_m memcpy(&pstHostMibs-> astPhsRulesTable[nPhsTableIndex].u8PHSI, - &pstPhsRule->u8PHSI, sizeof(S_PHS_RULE)); + &pstPhsRule->u8PHSI, sizeof(struct bcm_phs_rule)); nPhsTableIndex++; } -- cgit v0.10.2 From 38414104db2afdc4d4d0d5d65cbe0e0fdbede30e Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 21 Dec 2012 15:10:35 -0500 Subject: Staging: bcm: Remove typedef for ePMU_MODES and call directly. This patch removes typedef for ePMU_MODES, and changes the name of the enum to bcm_pmu_modes. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h index 46f5f0f..7592643 100644 --- a/drivers/staging/bcm/Macros.h +++ b/drivers/staging/bcm/Macros.h @@ -331,11 +331,11 @@ typedef enum eNVM_TYPE { NVM_UNKNOWN } NVM_TYPE; -typedef enum ePMU_MODES { +enum bcm_pmu_modes { HYBRID_MODE_7C = 0, INTERNAL_MODE_6 = 1, HYBRID_MODE_6 = 2 -} PMU_MODE; +}; #define MAX_RDM_WRM_RETIRES 1 -- cgit v0.10.2 From af72c617944784575126899eb603c9fc711341dc Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 21 Dec 2012 15:10:36 -0500 Subject: Staging: bcm: Remove typedef for eNVM_TYPE and call directly. This patch removes typedef for eNVM_TYPE, and changes the name of the enum to bcm_nvm_type. In addition, any calls to enum "NVM_TYPE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index 91367ce..ade7bfd 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -345,7 +345,7 @@ struct bcm_mini_adapter { struct bcm_fragmented_packet_info astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES]; atomic_t uiMBupdate; UINT32 PmuMode; - NVM_TYPE eNVMType; + enum bcm_nvm_type eNVMType; UINT uiSectorSize; UINT uiSectorSizeInCFG; BOOLEAN bSectorSizeOverride; diff --git a/drivers/staging/bcm/Ioctl.h b/drivers/staging/bcm/Ioctl.h index 8650d13..e253c08 100644 --- a/drivers/staging/bcm/Ioctl.h +++ b/drivers/staging/bcm/Ioctl.h @@ -108,7 +108,7 @@ enum bcm_interface_type { }; struct bcm_driver_info { - NVM_TYPE u32NVMType; + enum bcm_nvm_type u32NVMType; unsigned int MaxRDMBufferSize; enum bcm_interface_type u32InterfaceType; unsigned int u32DSDStartOffset; diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h index 7592643..015e094 100644 --- a/drivers/staging/bcm/Macros.h +++ b/drivers/staging/bcm/Macros.h @@ -324,12 +324,12 @@ typedef enum _E_PHS_DSC_ACTION { #define HPM_CONFIG_MSW 0x0F000D58 #define T3B 0xbece0310 -typedef enum eNVM_TYPE { +enum bcm_nvm_type { NVM_AUTODETECT = 0, NVM_EEPROM, NVM_FLASH, NVM_UNKNOWN -} NVM_TYPE; +}; enum bcm_pmu_modes { HYBRID_MODE_7C = 0, diff --git a/drivers/staging/bcm/Misc.c b/drivers/staging/bcm/Misc.c index 21b739a..b5c2c4c 100644 --- a/drivers/staging/bcm/Misc.c +++ b/drivers/staging/bcm/Misc.c @@ -1134,7 +1134,7 @@ void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter) uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag); pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag); - Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3); + Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3); Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1; Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4)); Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1; diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 8960a18..4283753 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -12,7 +12,7 @@ static unsigned int BcmGetFlashSectorSize(struct bcm_mini_adapter *Adapter, unsi static VOID BcmValidateNvmType(struct bcm_mini_adapter *Adapter); static int BcmGetNvmSize(struct bcm_mini_adapter *Adapter); static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter); -static NVM_TYPE BcmGetNvmType(struct bcm_mini_adapter *Adapter); +static enum bcm_nvm_type BcmGetNvmType(struct bcm_mini_adapter *Adapter); static int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal); @@ -2629,7 +2629,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) * */ -static NVM_TYPE BcmGetNvmType(struct bcm_mini_adapter *Adapter) +static enum bcm_nvm_type BcmGetNvmType(struct bcm_mini_adapter *Adapter) { unsigned int uiData = 0; -- cgit v0.10.2 From c081e78bd41786dc7144757bfa4a7e477cb4da38 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 21 Dec 2012 15:10:37 -0500 Subject: Staging: bcm: Remove typedef for _E_PHS_DSC_ACTION and call directly. This patch removes typedef for _E_PHS_DSC_ACTION, and changes the name of the enum to bcm_phs_dsc_action. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h index 015e094..224a156 100644 --- a/drivers/staging/bcm/Macros.h +++ b/drivers/staging/bcm/Macros.h @@ -182,13 +182,12 @@ enum enLinkStatus { COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW = 9 }; -typedef enum _E_PHS_DSC_ACTION { +enum bcm_phs_dsc_action { eAddPHSRule = 0, eSetPHSRule, eDeletePHSRule, eDeleteAllPHSRules -} E_PHS_DSC_ACTION; - +}; #define CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ 0x89 /* Host to Mac */ #define CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP 0xA9 /* Mac to Host */ -- cgit v0.10.2 From a23e67f1a26bef151595cd3373d489683cf1fe80 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 21 Dec 2012 15:10:38 -0500 Subject: Staging: bcm: Remove typedef for _LINK_STATE and call directly. This patch removes typedef for _LINK_STATE, and changes the name of the struct to bcm_link_state. In addition, any calls to struct "LINK_STATE, or PLINK_STATE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index fd7c974..b034ace 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -1013,7 +1013,7 @@ cntrlEnd: } case IOCTL_BCM_GET_CURRENT_STATUS: { - LINK_STATE link_state; + struct bcm_link_state link_state; /* Copy Ioctl Buffer structure */ if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) { diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h index 224a156..1fae5d9 100644 --- a/drivers/staging/bcm/Macros.h +++ b/drivers/staging/bcm/Macros.h @@ -162,13 +162,11 @@ #define GPIO_MODE_REGISTER 0x0F000034 #define GPIO_PIN_STATE_REGISTER 0x0F000038 - -typedef struct _LINK_STATE { +struct bcm_link_state { UCHAR ucLinkStatus; UCHAR bIdleMode; UCHAR bShutdownMode; -} LINK_STATE, *PLINK_STATE; - +}; enum enLinkStatus { WAIT_FOR_SYNC = 1, -- cgit v0.10.2 From 8c4f88a8644be48212a5f70cbf5c1e2f8900e029 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 21 Dec 2012 15:10:39 -0500 Subject: Staging: bcm: Replace UCHAR with unsigned char in Macros.h This patch replaces "UCHAR" with "unsigned char" in Macros.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h index 1fae5d9..dc01e30 100644 --- a/drivers/staging/bcm/Macros.h +++ b/drivers/staging/bcm/Macros.h @@ -163,9 +163,9 @@ #define GPIO_PIN_STATE_REGISTER 0x0F000038 struct bcm_link_state { - UCHAR ucLinkStatus; - UCHAR bIdleMode; - UCHAR bShutdownMode; + unsigned char ucLinkStatus; + unsigned char bIdleMode; + unsigned char bShutdownMode; }; enum enLinkStatus { -- cgit v0.10.2 From bd33dd31f755331141a71b082c5f15b5ee722b37 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:39 -0500 Subject: Staging: bcm: Fix all white space issues in Protocol.h This patch fixes all white space issues in Protocol.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 562d4dd..d113ed4 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -1,22 +1,19 @@ /************************************ -* Protocol.h +* Protocol.h *************************************/ #ifndef __PROTOCOL_H__ #define __PROTOCOL_H__ - -#define IPV4 4 -#define IPV6 6 - +#define IPV4 4 +#define IPV6 6 struct ArpHeader { - struct arphdr arp; - unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ - unsigned char ar_sip[4]; /* sender IP address */ - unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ - unsigned char ar_tip[4]; /* target IP address */ -}/*__attribute__((packed))*/; - + struct arphdr arp; + unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ + unsigned char ar_sip[4]; /* sender IP address */ + unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ + unsigned char ar_tip[4]; /* target IP address */ +} /*__attribute__((packed))*/; struct TransportHeaderT { @@ -28,13 +25,12 @@ struct TransportHeaderT } __attribute__((packed)); typedef struct TransportHeaderT xporthdr; - typedef enum _E_NWPKT_IPFRAME_TYPE { eNonIPPacket, eIPv4Packet, eIPv6Packet -}E_NWPKT_IPFRAME_TYPE; +} E_NWPKT_IPFRAME_TYPE; typedef enum _E_NWPKT_ETHFRAME_TYPE { @@ -51,7 +47,7 @@ typedef struct _S_ETHCS_PKT_INFO E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; USHORT usEtherType; UCHAR ucDSAP; -}S_ETHCS_PKT_INFO,*PS_ETHCS_PKT_INFO; +} S_ETHCS_PKT_INFO, *PS_ETHCS_PKT_INFO; typedef struct _ETH_CS_802_Q_FRAME { @@ -68,7 +64,7 @@ typedef struct _ETH_CS_802_LLC_FRAME unsigned char DSAP; unsigned char SSAP; unsigned char Control; -}__attribute__((packed)) ETH_CS_802_LLC_FRAME; +} __attribute__((packed)) ETH_CS_802_LLC_FRAME; typedef struct _ETH_CS_802_LLC_SNAP_FRAME { @@ -86,13 +82,13 @@ typedef struct _ETH_CS_ETH2_FRAME } __attribute__((packed)) ETH_CS_ETH2_FRAME; #define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800) -#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd) -#define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100) +#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd) +#define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100) //Per SF CS Specification Encodings typedef enum _E_SERVICEFLOW_CS_SPEC_ { - eCSSpecUnspecified =0, + eCSSpecUnspecified = 0, eCSPacketIPV4, eCSPacketIPV6, eCS802_3PacketEthernet, @@ -102,33 +98,26 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ eCSPacketIPV4Over802_1QVLAN, eCSPacketIPV6Over802_1QVLAN, eCSPacketUnsupported -}E_SERVICEFLOW_CS_SPEC; - - -#define IP6_HEADER_LEN 40 - -#define IP_VERSION(byte) (((byte&0xF0)>>4)) - +} E_SERVICEFLOW_CS_SPEC; +#define IP6_HEADER_LEN 40 +#define IP_VERSION(byte) (((byte&0xF0)>>4)) #define MAC_ADDRESS_SIZE 6 #define ETH_AND_IP_HEADER_LEN 14 + 20 -#define L4_SRC_PORT_LEN 2 -#define L4_DEST_PORT_LEN 2 - - - +#define L4_SRC_PORT_LEN 2 +#define L4_DEST_PORT_LEN 2 #define CTRL_PKT_LEN 8 + ETH_AND_IP_HEADER_LEN -#define ETH_ARP_FRAME 0x806 -#define ETH_IPV4_FRAME 0x800 -#define ETH_IPV6_FRAME 0x86DD -#define UDP 0x11 -#define TCP 0x06 +#define ETH_ARP_FRAME 0x806 +#define ETH_IPV4_FRAME 0x800 +#define ETH_IPV6_FRAME 0x86DD +#define UDP 0x11 +#define TCP 0x06 -#define ARP_OP_REQUEST 0x01 -#define ARP_OP_REPLY 0x02 -#define ARP_PKT_SIZE 60 +#define ARP_OP_REQUEST 0x01 +#define ARP_OP_REPLY 0x02 +#define ARP_PKT_SIZE 60 // This is the format for the TCP packet header typedef struct _TCP_HEADER @@ -138,14 +127,14 @@ typedef struct _TCP_HEADER ULONG ulSeqNumber; ULONG ulAckNumber; UCHAR HeaderLength; - UCHAR ucFlags; + UCHAR ucFlags; USHORT usWindowsSize; USHORT usChkSum; USHORT usUrgetPtr; -} TCP_HEADER,*PTCP_HEADER; -#define TCP_HEADER_LEN sizeof(TCP_HEADER) -#define TCP_ACK 0x10 //Bit 4 in tcpflags field. -#define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4) +} TCP_HEADER, *PTCP_HEADER; +#define TCP_HEADER_LEN sizeof(TCP_HEADER) +#define TCP_ACK 0x10 //Bit 4 in tcpflags field. +#define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4) #endif //__PROTOCOL_H__ -- cgit v0.10.2 From a3489276ec02e0d3dbc6723f89041187d9a6cf76 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:40 -0500 Subject: Staging: bcm: Properly format comments in Protocol.h This patch properly formats comments, and removes them as needed in Protocol.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index d113ed4..7803ce5 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -13,7 +13,7 @@ struct ArpHeader { unsigned char ar_sip[4]; /* sender IP address */ unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ unsigned char ar_tip[4]; /* target IP address */ -} /*__attribute__((packed))*/; +}; struct TransportHeaderT { @@ -85,7 +85,7 @@ typedef struct _ETH_CS_ETH2_FRAME #define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd) #define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100) -//Per SF CS Specification Encodings +/* Per SF CS Specification Encodings */ typedef enum _E_SERVICEFLOW_CS_SPEC_ { eCSSpecUnspecified = 0, @@ -119,7 +119,7 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ #define ARP_OP_REPLY 0x02 #define ARP_PKT_SIZE 60 -// This is the format for the TCP packet header +/* This is the format for the TCP packet header */ typedef struct _TCP_HEADER { USHORT usSrcPort; @@ -134,7 +134,7 @@ typedef struct _TCP_HEADER } TCP_HEADER, *PTCP_HEADER; #define TCP_HEADER_LEN sizeof(TCP_HEADER) -#define TCP_ACK 0x10 //Bit 4 in tcpflags field. +#define TCP_ACK 0x10 /* Bit 4 in tcpflags field. */ #define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4) -#endif //__PROTOCOL_H__ +#endif /* __PROTOCOL_H__ */ -- cgit v0.10.2 From 3df56e1066f88f97a602de2182a9236b8464f41b Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:41 -0500 Subject: Staging: bcm: Properly format braces in Protocol.h This patch formats braces in Protocol.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 7803ce5..184d215 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -15,25 +15,21 @@ struct ArpHeader { unsigned char ar_tip[4]; /* target IP address */ }; -struct TransportHeaderT -{ - union - { +struct TransportHeaderT { + union { struct udphdr uhdr; struct tcphdr thdr; }; } __attribute__((packed)); typedef struct TransportHeaderT xporthdr; -typedef enum _E_NWPKT_IPFRAME_TYPE -{ +typedef enum _E_NWPKT_IPFRAME_TYPE { eNonIPPacket, eIPv4Packet, eIPv6Packet } E_NWPKT_IPFRAME_TYPE; -typedef enum _E_NWPKT_ETHFRAME_TYPE -{ +typedef enum _E_NWPKT_ETHFRAME_TYPE { eEthUnsupportedFrame, eEth802LLCFrame, eEth802LLCSNAPFrame, @@ -41,16 +37,14 @@ typedef enum _E_NWPKT_ETHFRAME_TYPE eEthOtherFrame } E_NWPKT_ETHFRAME_TYPE; -typedef struct _S_ETHCS_PKT_INFO -{ +typedef struct _S_ETHCS_PKT_INFO { E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; USHORT usEtherType; UCHAR ucDSAP; } S_ETHCS_PKT_INFO, *PS_ETHCS_PKT_INFO; -typedef struct _ETH_CS_802_Q_FRAME -{ +typedef struct _ETH_CS_802_Q_FRAME { struct bcm_eth_header EThHdr; USHORT UserPriority:3; USHORT CFI:1; @@ -58,16 +52,14 @@ typedef struct _ETH_CS_802_Q_FRAME USHORT EthType; } __attribute__((packed)) ETH_CS_802_Q_FRAME; -typedef struct _ETH_CS_802_LLC_FRAME -{ +typedef struct _ETH_CS_802_LLC_FRAME { struct bcm_eth_header EThHdr; unsigned char DSAP; unsigned char SSAP; unsigned char Control; } __attribute__((packed)) ETH_CS_802_LLC_FRAME; -typedef struct _ETH_CS_802_LLC_SNAP_FRAME -{ +typedef struct _ETH_CS_802_LLC_SNAP_FRAME { struct bcm_eth_header EThHdr; unsigned char DSAP; unsigned char SSAP; @@ -76,8 +68,7 @@ typedef struct _ETH_CS_802_LLC_SNAP_FRAME unsigned short usEtherType; } __attribute__((packed)) ETH_CS_802_LLC_SNAP_FRAME; -typedef struct _ETH_CS_ETH2_FRAME -{ +typedef struct _ETH_CS_ETH2_FRAME { struct bcm_eth_header EThHdr; } __attribute__((packed)) ETH_CS_ETH2_FRAME; @@ -86,8 +77,7 @@ typedef struct _ETH_CS_ETH2_FRAME #define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100) /* Per SF CS Specification Encodings */ -typedef enum _E_SERVICEFLOW_CS_SPEC_ -{ +typedef enum _E_SERVICEFLOW_CS_SPEC_ { eCSSpecUnspecified = 0, eCSPacketIPV4, eCSPacketIPV6, @@ -120,8 +110,7 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ #define ARP_PKT_SIZE 60 /* This is the format for the TCP packet header */ -typedef struct _TCP_HEADER -{ +typedef struct _TCP_HEADER { USHORT usSrcPort; USHORT usDestPort; ULONG ulSeqNumber; -- cgit v0.10.2 From 5f8797b64f62662f36814db36409720eac02a5a4 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:42 -0500 Subject: Staging: bcm: Fix warning: "__packed is preferred over __attribute__((packed))" in Protocol.h This patch fixes the following warning: "__packed is preferred over __attribute__((packed))" as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 184d215..bb62e17 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -20,7 +20,7 @@ struct TransportHeaderT { struct udphdr uhdr; struct tcphdr thdr; }; -} __attribute__((packed)); +} __packed; typedef struct TransportHeaderT xporthdr; typedef enum _E_NWPKT_IPFRAME_TYPE { @@ -50,14 +50,14 @@ typedef struct _ETH_CS_802_Q_FRAME { USHORT CFI:1; USHORT VLANID:12; USHORT EthType; -} __attribute__((packed)) ETH_CS_802_Q_FRAME; +} __packed ETH_CS_802_Q_FRAME; typedef struct _ETH_CS_802_LLC_FRAME { struct bcm_eth_header EThHdr; unsigned char DSAP; unsigned char SSAP; unsigned char Control; -} __attribute__((packed)) ETH_CS_802_LLC_FRAME; +} __packed ETH_CS_802_LLC_FRAME; typedef struct _ETH_CS_802_LLC_SNAP_FRAME { struct bcm_eth_header EThHdr; @@ -66,11 +66,11 @@ typedef struct _ETH_CS_802_LLC_SNAP_FRAME { unsigned char Control; unsigned char OUI[3]; unsigned short usEtherType; -} __attribute__((packed)) ETH_CS_802_LLC_SNAP_FRAME; +} __packed ETH_CS_802_LLC_SNAP_FRAME; typedef struct _ETH_CS_ETH2_FRAME { struct bcm_eth_header EThHdr; -} __attribute__((packed)) ETH_CS_ETH2_FRAME; +} __packed ETH_CS_ETH2_FRAME; #define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800) #define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd) -- cgit v0.10.2 From 5a88304e568e0c6176ebd85fc08d535a4f02a97a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:43 -0500 Subject: Staging: bcm: Fix issue: "Macros with complex values should be enclosed in parenthesis" in Protocol.h This patch fixes the following issue: "Macros with complex values should be enclosed in parenthesis" as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index bb62e17..a7028d5 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -94,10 +94,10 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ { #define IP_VERSION(byte) (((byte&0xF0)>>4)) #define MAC_ADDRESS_SIZE 6 -#define ETH_AND_IP_HEADER_LEN 14 + 20 +#define ETH_AND_IP_HEADER_LEN (14 + 20) #define L4_SRC_PORT_LEN 2 #define L4_DEST_PORT_LEN 2 -#define CTRL_PKT_LEN 8 + ETH_AND_IP_HEADER_LEN +#define CTRL_PKT_LEN (8 + ETH_AND_IP_HEADER_LEN) #define ETH_ARP_FRAME 0x806 #define ETH_IPV4_FRAME 0x800 -- cgit v0.10.2 From 963fa3e62969e59c66875091710b5ea4ac68b065 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:44 -0500 Subject: Staging: bcm: Replace USHORT with unsigned short in Protocol.h This patch replaces "USHORT" with "unsigned short" in Protocol.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index a7028d5..040689b 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -40,16 +40,16 @@ typedef enum _E_NWPKT_ETHFRAME_TYPE { typedef struct _S_ETHCS_PKT_INFO { E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; - USHORT usEtherType; + unsigned short usEtherType; UCHAR ucDSAP; } S_ETHCS_PKT_INFO, *PS_ETHCS_PKT_INFO; typedef struct _ETH_CS_802_Q_FRAME { struct bcm_eth_header EThHdr; - USHORT UserPriority:3; - USHORT CFI:1; - USHORT VLANID:12; - USHORT EthType; + unsigned short UserPriority:3; + unsigned short CFI:1; + unsigned short VLANID:12; + unsigned short EthType; } __packed ETH_CS_802_Q_FRAME; typedef struct _ETH_CS_802_LLC_FRAME { @@ -111,15 +111,15 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ { /* This is the format for the TCP packet header */ typedef struct _TCP_HEADER { - USHORT usSrcPort; - USHORT usDestPort; + unsigned short usSrcPort; + unsigned short usDestPort; ULONG ulSeqNumber; ULONG ulAckNumber; UCHAR HeaderLength; UCHAR ucFlags; - USHORT usWindowsSize; - USHORT usChkSum; - USHORT usUrgetPtr; + unsigned short usWindowsSize; + unsigned short usChkSum; + unsigned short usUrgetPtr; } TCP_HEADER, *PTCP_HEADER; #define TCP_HEADER_LEN sizeof(TCP_HEADER) -- cgit v0.10.2 From edb9ebb098e1f60ba1575ba171189ca38c039805 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:45 -0500 Subject: Staging: bcm: Replace ULONG with unsigned long in Protocol.h This patch replaces "ULONG" with "unsigned long" in Protocol.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 040689b..7070ce6 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -113,8 +113,8 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ { typedef struct _TCP_HEADER { unsigned short usSrcPort; unsigned short usDestPort; - ULONG ulSeqNumber; - ULONG ulAckNumber; + unsigned long ulSeqNumber; + unsigned long ulAckNumber; UCHAR HeaderLength; UCHAR ucFlags; unsigned short usWindowsSize; -- cgit v0.10.2 From 57b49adaf1b10f45440b22487ca2027c0cb0a6c8 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:46 -0500 Subject: Staging: bcm: Replace UCHAR with unsigned char in Protocol.h This patch replaces "UCHAR" with "unsigned char" in Protocol.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 7070ce6..51d1133 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -41,7 +41,7 @@ typedef struct _S_ETHCS_PKT_INFO { E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; unsigned short usEtherType; - UCHAR ucDSAP; + unsigned char ucDSAP; } S_ETHCS_PKT_INFO, *PS_ETHCS_PKT_INFO; typedef struct _ETH_CS_802_Q_FRAME { @@ -115,8 +115,8 @@ typedef struct _TCP_HEADER { unsigned short usDestPort; unsigned long ulSeqNumber; unsigned long ulAckNumber; - UCHAR HeaderLength; - UCHAR ucFlags; + unsigned char HeaderLength; + unsigned char ucFlags; unsigned short usWindowsSize; unsigned short usChkSum; unsigned short usUrgetPtr; -- cgit v0.10.2 From 16c3f8b04c13a722aa82110bb982fe71f1d58918 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:47 -0500 Subject: Staging: bcm: Remove typedef for _TCP_HEADER and call directly. This patch removes typedef for _TCP_HEADER, and changes the name of the struct to bcm_tcp_header. In addition, any calls to struct "TCP_HEADER, or *PTCP_HEADER" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 51d1133..b20d857 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -110,7 +110,7 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ { #define ARP_PKT_SIZE 60 /* This is the format for the TCP packet header */ -typedef struct _TCP_HEADER { +struct bcm_tcp_header { unsigned short usSrcPort; unsigned short usDestPort; unsigned long ulSeqNumber; @@ -120,9 +120,9 @@ typedef struct _TCP_HEADER { unsigned short usWindowsSize; unsigned short usChkSum; unsigned short usUrgetPtr; -} TCP_HEADER, *PTCP_HEADER; +}; -#define TCP_HEADER_LEN sizeof(TCP_HEADER) +#define TCP_HEADER_LEN sizeof(struct bcm_tcp_header) #define TCP_ACK 0x10 /* Bit 4 in tcpflags field. */ #define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4) diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index cde96a3..438e73d 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -454,7 +454,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) BOOLEAN bFragmentedPkt=FALSE,bClassificationSucceed=FALSE; USHORT usCurrFragment =0; - PTCP_HEADER pTcpHeader; + struct bcm_tcp_header *pTcpHeader; UCHAR IpHeaderLength; UCHAR TcpHeaderLength; @@ -614,7 +614,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) if((TCP == pIpHeader->protocol ) && !bFragmentedPkt && (ETH_AND_IP_HEADER_LEN + TCP_HEADER_LEN <= skb->len) ) { IpHeaderLength = pIpHeader->ihl; - pTcpHeader = (PTCP_HEADER)(((PUCHAR)pIpHeader)+(IpHeaderLength*4)); + pTcpHeader = (struct bcm_tcp_header *)(((PUCHAR)pIpHeader)+(IpHeaderLength*4)); TcpHeaderLength = GET_TCP_HEADER_LEN(pTcpHeader->HeaderLength); if((pTcpHeader->ucFlags & TCP_ACK) && -- cgit v0.10.2 From 4a19aaa7cb8f20be2ab66922b1c56b649c4a06cf Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:48 -0500 Subject: Staging: bcm: Remove typedef for _E_SERVICEFLOW_CS_SPEC_ and call directly. This patch removes typedef for _E_SERVICEFLOW_CS_SPEC_, and changes the name of the enum to bcm_spec_encoding. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index b20d857..89246b1 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -77,7 +77,7 @@ typedef struct _ETH_CS_ETH2_FRAME { #define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100) /* Per SF CS Specification Encodings */ -typedef enum _E_SERVICEFLOW_CS_SPEC_ { +enum bcm_spec_encoding { eCSSpecUnspecified = 0, eCSPacketIPV4, eCSPacketIPV6, @@ -88,7 +88,7 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_ { eCSPacketIPV4Over802_1QVLAN, eCSPacketIPV6Over802_1QVLAN, eCSPacketUnsupported -} E_SERVICEFLOW_CS_SPEC; +}; #define IP6_HEADER_LEN 40 #define IP_VERSION(byte) (((byte&0xF0)>>4)) -- cgit v0.10.2 From 30f5b4c2e12be1a07fbd0286ebd8c97e14fa7f1e Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:49 -0500 Subject: Staging: bcm: Remove typedef for _ETH_CS_ETH2_FRAME and call directly. This patch removes typedef for _ETH_CS_ETH2_FRAME, and changes the name of the struct to bcm_ethernet2_frame. In addition, any calls to struct "ETH_CS_ETH2_FRAME" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 89246b1..79e3b24 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -68,9 +68,9 @@ typedef struct _ETH_CS_802_LLC_SNAP_FRAME { unsigned short usEtherType; } __packed ETH_CS_802_LLC_SNAP_FRAME; -typedef struct _ETH_CS_ETH2_FRAME { +struct bcm_ethernet2_frame { struct bcm_eth_header EThHdr; -} __packed ETH_CS_ETH2_FRAME; +} __packed; #define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800) #define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd) diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index 438e73d..11a3650 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -486,13 +486,13 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) case eEthOtherFrame: { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : ETH Other Frame\n"); - pIpHeader = pvEThPayload + sizeof(ETH_CS_ETH2_FRAME); + pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame); break; } default: { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : Unrecognized ETH Frame\n"); - pIpHeader = pvEThPayload + sizeof(ETH_CS_ETH2_FRAME); + pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame); break; } } -- cgit v0.10.2 From 9bcacc2975d03ea5f952bfd71ac9c33726a1804e Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:50 -0500 Subject: Staging: bcm: Remove typedef for _ETH_CS_802_LLC_SNAP_FRAME and call directly. This patch removes typedef for _ETH_CS_802_LLC_SNAP_FRAME, and changes the name of the struct to bcm_eth_llc_snap_frame. In addition, any calls to struct "ETH_CS_802_LLC_SNAP_FRAME" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 79e3b24..c9a2429 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -59,14 +59,14 @@ typedef struct _ETH_CS_802_LLC_FRAME { unsigned char Control; } __packed ETH_CS_802_LLC_FRAME; -typedef struct _ETH_CS_802_LLC_SNAP_FRAME { +struct bcm_eth_llc_snap_frame { struct bcm_eth_header EThHdr; unsigned char DSAP; unsigned char SSAP; unsigned char Control; unsigned char OUI[3]; unsigned short usEtherType; -} __packed ETH_CS_802_LLC_SNAP_FRAME; +} __packed; struct bcm_ethernet2_frame { struct bcm_eth_header EThHdr; diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index 11a3650..2608aec 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -474,7 +474,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) case eEth802LLCSNAPFrame: { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLC SNAP Frame\n"); - pIpHeader = pvEThPayload + sizeof(ETH_CS_802_LLC_SNAP_FRAME); + pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_snap_frame); break; } case eEth802QVLANFrame: @@ -835,7 +835,7 @@ static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, { //SNAP Frame pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCSNAPFrame; - u16Etype = ((ETH_CS_802_LLC_SNAP_FRAME*)pvEthPayload)->usEtherType; + u16Etype = ((struct bcm_eth_llc_snap_frame *)pvEthPayload)->usEtherType; } } if(u16Etype == ETHERNET_FRAMETYPE_IPV4) -- cgit v0.10.2 From 620fac923c8a1aa53f6fd1e1e332c53415b56df8 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:51 -0500 Subject: Staging: bcm: Remove typedef for _ETH_CS_802_LLC_FRAME and call directly. This patch removes typedef for _ETH_CS_802_LLC_FRAME, and changes the name of the struct to bcm_eth_llc_frame. In addition, any calls to struct "ETH_CS_802_LLC_FRAME" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index c9a2429..842539d 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -52,12 +52,12 @@ typedef struct _ETH_CS_802_Q_FRAME { unsigned short EthType; } __packed ETH_CS_802_Q_FRAME; -typedef struct _ETH_CS_802_LLC_FRAME { +struct bcm_eth_llc_frame { struct bcm_eth_header EThHdr; unsigned char DSAP; unsigned char SSAP; unsigned char Control; -} __packed ETH_CS_802_LLC_FRAME; +} __packed; struct bcm_eth_llc_snap_frame { struct bcm_eth_header EThHdr; diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index 2608aec..d53151b 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -467,7 +467,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) case eEth802LLCFrame: { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLCFrame\n"); - pIpHeader = pvEThPayload + sizeof(ETH_CS_802_LLC_FRAME); + pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_frame); break; } @@ -830,8 +830,8 @@ static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, //802.2 LLC BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "802.2 LLC Frame \n"); pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCFrame; - pstEthCsPktInfo->ucDSAP = ((ETH_CS_802_LLC_FRAME*)pvEthPayload)->DSAP; - if(pstEthCsPktInfo->ucDSAP == 0xAA && ((ETH_CS_802_LLC_FRAME*)pvEthPayload)->SSAP == 0xAA) + pstEthCsPktInfo->ucDSAP = ((struct bcm_eth_llc_frame *)pvEthPayload)->DSAP; + if(pstEthCsPktInfo->ucDSAP == 0xAA && ((struct bcm_eth_llc_frame *)pvEthPayload)->SSAP == 0xAA) { //SNAP Frame pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCSNAPFrame; -- cgit v0.10.2 From d1b37925baf99a39a838c1832a6e8765a8af0ed7 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:52 -0500 Subject: Staging: bcm: Remove typedef for _ETH_CS_802_Q_FRAME and call directly. This patch removes typedef for _ETH_CS_802_Q_FRAME, and changes the name of the struct to bcm_eth_q_frame. In addition, any calls to struct "ETH_CS_802_Q_FRAME" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 842539d..7f66065 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -44,13 +44,13 @@ typedef struct _S_ETHCS_PKT_INFO { unsigned char ucDSAP; } S_ETHCS_PKT_INFO, *PS_ETHCS_PKT_INFO; -typedef struct _ETH_CS_802_Q_FRAME { +struct bcm_eth_q_frame { struct bcm_eth_header EThHdr; unsigned short UserPriority:3; unsigned short CFI:1; unsigned short VLANID:12; unsigned short EthType; -} __packed ETH_CS_802_Q_FRAME; +} __packed; struct bcm_eth_llc_frame { struct bcm_eth_header EThHdr; diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index d53151b..b5f33ba 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -480,7 +480,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) case eEth802QVLANFrame: { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802.1Q VLANFrame\n"); - pIpHeader = pvEThPayload + sizeof(ETH_CS_802_Q_FRAME); + pIpHeader = pvEThPayload + sizeof(struct bcm_eth_q_frame); break; } case eEthOtherFrame: @@ -815,7 +815,7 @@ static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, { //802.1Q VLAN Header pstEthCsPktInfo->eNwpktEthFrameType = eEth802QVLANFrame; - u16Etype = ((ETH_CS_802_Q_FRAME*)pvEthPayload)->EthType; + u16Etype = ((struct bcm_eth_q_frame *)pvEthPayload)->EthType; //((ETH_CS_802_Q_FRAME*)pvEthPayload)->UserPriority } else -- cgit v0.10.2 From 5fa9ac457334a172255d9765b65b9340a085990a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:53 -0500 Subject: Staging: bcm: Remove typedef for _S_ETHCS_PKT_INFO and call directly. This patch removes typedef for _S_ETHCS_PKT_INFO, and changes the name of the struct to bcm_eth_packet_info. In addition, any calls to struct "S_ETHCS_PKT_INFO, or *PS_ETHCS_PKT_INFO" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 7f66065..f6d8d63 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -37,12 +37,12 @@ typedef enum _E_NWPKT_ETHFRAME_TYPE { eEthOtherFrame } E_NWPKT_ETHFRAME_TYPE; -typedef struct _S_ETHCS_PKT_INFO { +struct bcm_eth_packet_info { E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; unsigned short usEtherType; unsigned char ucDSAP; -} S_ETHCS_PKT_INFO, *PS_ETHCS_PKT_INFO; +}; struct bcm_eth_q_frame { struct bcm_eth_header EThHdr; diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index b5f33ba..cc2b154 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -4,8 +4,8 @@ This file contains the routines related to Quality of Service. */ #include "headers.h" -static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload,PS_ETHCS_PKT_INFO pstEthCsPktInfo); -static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo,struct bcm_classifier_rule *pstClassifierRule, B_UINT8 EthCSCupport); +static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, struct bcm_eth_packet_info *pstEthCsPktInfo); +static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo,struct bcm_classifier_rule *pstClassifierRule, B_UINT8 EthCSCupport); static USHORT IpVersion4(struct bcm_mini_adapter *Adapter, struct iphdr *iphd, struct bcm_classifier_rule *pstClassifierRule ); @@ -446,7 +446,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb) { INT uiLoopIndex=0; struct bcm_classifier_rule *pstClassifierRule = NULL; - S_ETHCS_PKT_INFO stEthCsPktInfo; + struct bcm_eth_packet_info stEthCsPktInfo; PVOID pvEThPayload = NULL; struct iphdr *pIpHeader = NULL; INT uiSfIndex=0; @@ -683,7 +683,7 @@ static BOOLEAN EthCSMatchDestMACAddress(struct bcm_classifier_rule *pstClassifie return TRUE; } -static BOOLEAN EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo) +static BOOLEAN EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo) { struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); if((pstClassifierRule->ucEtherTypeLen==0)|| @@ -718,7 +718,7 @@ static BOOLEAN EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRul } -static BOOLEAN EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo) +static BOOLEAN EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo) { BOOLEAN bClassificationSucceed = FALSE; USHORT usVLANID; @@ -769,7 +769,7 @@ static BOOLEAN EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb, - PS_ETHCS_PKT_INFO pstEthCsPktInfo, + struct bcm_eth_packet_info *pstEthCsPktInfo, struct bcm_classifier_rule *pstClassifierRule, B_UINT8 EthCSCupport) { @@ -802,7 +802,7 @@ static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* } static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, - PS_ETHCS_PKT_INFO pstEthCsPktInfo) + struct bcm_eth_packet_info *pstEthCsPktInfo) { USHORT u16Etype = ntohs(((struct bcm_eth_header *)pvEthPayload)->u16Etype); -- cgit v0.10.2 From 1f05da951d41e69d0792922b2ca14342e1c220cd Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:54 -0500 Subject: Staging: bcm: Remove typedef for _E_NWPKT_ETHFRAME_TYPE and call directly. This patch removes typedef for _E_NWPKT_ETHFRAME_TYPE, and changes the name of the enum to bcm_eth_frame_type. In addition, any calls to enum "E_NWPKT_ETHFRAME_TYPE, are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index f6d8d63..494cdb1 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -29,17 +29,17 @@ typedef enum _E_NWPKT_IPFRAME_TYPE { eIPv6Packet } E_NWPKT_IPFRAME_TYPE; -typedef enum _E_NWPKT_ETHFRAME_TYPE { +enum bcm_eth_frame_type { eEthUnsupportedFrame, eEth802LLCFrame, eEth802LLCSNAPFrame, eEth802QVLANFrame, eEthOtherFrame -} E_NWPKT_ETHFRAME_TYPE; +}; struct bcm_eth_packet_info { E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; - E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; + enum bcm_eth_frame_type eNwpktEthFrameType; unsigned short usEtherType; unsigned char ucDSAP; }; -- cgit v0.10.2 From 8ab19921143e69797343e972b16378171f37385a Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:55 -0500 Subject: Staging: bcm: Remove typedef for _E_NWPKT_IPFRAME_TYPE and call directly. This patch removes typedef for _E_NWPKT_IPFRAME_TYPE, and changes the name of the enum to bcm_ip_frame_type. In addition, any calls to enum "E_NWPKT_IPFRAME_TYPE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index 494cdb1..adfa48d 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -23,11 +23,11 @@ struct TransportHeaderT { } __packed; typedef struct TransportHeaderT xporthdr; -typedef enum _E_NWPKT_IPFRAME_TYPE { +enum bcm_ip_frame_type { eNonIPPacket, eIPv4Packet, eIPv6Packet -} E_NWPKT_IPFRAME_TYPE; +}; enum bcm_eth_frame_type { eEthUnsupportedFrame, @@ -38,7 +38,7 @@ enum bcm_eth_frame_type { }; struct bcm_eth_packet_info { - E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; + enum bcm_ip_frame_type eNwpktIPFrameType; enum bcm_eth_frame_type eNwpktEthFrameType; unsigned short usEtherType; unsigned char ucDSAP; -- cgit v0.10.2 From c5485e9ca70b5bd5eabfc7c298f7e367062d4f56 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Sat, 22 Dec 2012 14:27:56 -0500 Subject: Staging: bcm: Remove typedef for TransportHeaderT and call directly. This patch removes typedef for TransportHeaderT, and changes the name of the struct to bcm_transport_header. In addition, any calls to struct "xporthdr" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h index adfa48d..9818128 100644 --- a/drivers/staging/bcm/Protocol.h +++ b/drivers/staging/bcm/Protocol.h @@ -15,13 +15,12 @@ struct ArpHeader { unsigned char ar_tip[4]; /* target IP address */ }; -struct TransportHeaderT { +struct bcm_transport_header { union { struct udphdr uhdr; struct tcphdr thdr; }; } __packed; -typedef struct TransportHeaderT xporthdr; enum bcm_ip_frame_type { eNonIPPacket, diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c index cc2b154..8d142a5 100644 --- a/drivers/staging/bcm/Qos.c +++ b/drivers/staging/bcm/Qos.c @@ -208,12 +208,12 @@ static USHORT IpVersion4(struct bcm_mini_adapter *Adapter, struct iphdr *iphd, struct bcm_classifier_rule *pstClassifierRule) { - xporthdr *xprt_hdr=NULL; + struct bcm_transport_header *xprt_hdr = NULL; BOOLEAN bClassificationSucceed=FALSE; BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "========>"); - xprt_hdr=(xporthdr *)((PUCHAR)iphd + sizeof(struct iphdr)); + xprt_hdr=(struct bcm_transport_header *)((PUCHAR)iphd + sizeof(struct iphdr)); do { BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Trying to see Direction = %d %d", -- cgit v0.10.2 From 4f2e1477bbc44c8cba6ee0d0367ce05b4e545d13 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:02 -0500 Subject: Staging: bcm: Fix all white space issues in Debug.h This patch fixes all white space issues in Debug.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 8018a18..70189d0 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -9,143 +9,132 @@ #include #define NONE 0xFFFF - //-------------------------------------------------------------------------------- - /* TYPE and SUBTYPE * Define valid TYPE (or category or code-path, however you like to think of it) * and SUBTYPE s. * Type and SubType are treated as bitmasks. */ /*-----------------BEGIN TYPEs------------------------------------------*/ -#define DBG_TYPE_INITEXIT (1 << 0) // 1 -#define DBG_TYPE_TX (1 << 1) // 2 -#define DBG_TYPE_RX (1 << 2) // 4 -#define DBG_TYPE_OTHERS (1 << 3) // 8 +#define DBG_TYPE_INITEXIT (1 << 0) // 1 +#define DBG_TYPE_TX (1 << 1) // 2 +#define DBG_TYPE_RX (1 << 2) // 4 +#define DBG_TYPE_OTHERS (1 << 3) // 8 /*-----------------END TYPEs------------------------------------------*/ -#define NUMTYPES 4 // careful! - +#define NUMTYPES 4 // careful! /*-----------------BEGIN SUBTYPEs---------------------------------------*/ /*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----// Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c total 17 macros */ // Transmit.c -#define TX 1 -#define MP_SEND (TX<<0) -#define NEXT_SEND (TX<<1) -#define TX_FIFO (TX<<2) -#define TX_CONTROL (TX<<3) +#define TX 1 +#define MP_SEND (TX << 0) +#define NEXT_SEND (TX << 1) +#define TX_FIFO (TX << 2) +#define TX_CONTROL (TX << 3) // Arp.c -#define IP_ADDR (TX<<4) -#define ARP_REQ (TX<<5) -#define ARP_RESP (TX<<6) +#define IP_ADDR (TX << 4) +#define ARP_REQ (TX << 5) +#define ARP_RESP (TX << 6) // Leakybucket.c -#define TOKEN_COUNTS (TX<<8) -#define CHECK_TOKENS (TX<<9) -#define TX_PACKETS (TX<<10) -#define TIMER (TX<<11) +#define TOKEN_COUNTS (TX << 8) +#define CHECK_TOKENS (TX << 9) +#define TX_PACKETS (TX << 10) +#define TIMER (TX << 11) // Qos.c -#define QOS TX -#define QUEUE_INDEX (QOS<<12) -#define IPV4_DBG (QOS<<13) -#define IPV6_DBG (QOS<<14) -#define PRUNE_QUEUE (QOS<<15) -#define SEND_QUEUE (QOS<<16) +#define QOS TX +#define QUEUE_INDEX (QOS << 12) +#define IPV4_DBG (QOS << 13) +#define IPV6_DBG (QOS << 14) +#define PRUNE_QUEUE (QOS << 15) +#define SEND_QUEUE (QOS << 16) //TX_Misc -#define TX_OSAL_DBG (TX<<17) - +#define TX_OSAL_DBG (TX << 17) //--SUBTYPEs for ------INIT & EXIT--------------------- /*------------ TYPE is DBG_TYPE_INITEXIT -----// DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ -#define MP 1 -#define DRV_ENTRY (MP<<0) -#define MP_INIT (MP<<1) -#define READ_REG (MP<<3) -#define DISPATCH (MP<<2) -#define CLAIM_ADAP (MP<<4) -#define REG_IO_PORT (MP<<5) -#define INIT_DISP (MP<<6) -#define RX_INIT (MP<<7) - +#define MP 1 +#define DRV_ENTRY (MP << 0) +#define MP_INIT (MP << 1) +#define READ_REG (MP << 3) +#define DISPATCH (MP << 2) +#define CLAIM_ADAP (MP << 4) +#define REG_IO_PORT (MP << 5) +#define INIT_DISP (MP << 6) +#define RX_INIT (MP << 7) //-SUBTYPEs for --RX---------------------------------- //------------RX : TYPE is DBG_TYPE_RX -----// // Receive.c -#define RX 1 -#define RX_DPC (RX<<0) -#define RX_CTRL (RX<<3) -#define RX_DATA (RX<<4) -#define MP_RETURN (RX<<1) -#define LINK_MSG (RX<<2) - +#define RX 1 +#define RX_DPC (RX << 0) +#define RX_CTRL (RX << 3) +#define RX_DATA (RX << 4) +#define MP_RETURN (RX << 1) +#define LINK_MSG (RX << 2) //-SUBTYPEs for ----OTHER ROUTINES------------------ //------------OTHERS : TYPE is DBG_TYPE_OTHER -----// // HaltnReset,CheckForHang,PnP,Misc,CmHost // total 12 macros -#define OTHERS 1 +#define OTHERS 1 // ??ISR.C - -#define ISR OTHERS -#define MP_DPC (ISR<<0) +#define ISR OTHERS +#define MP_DPC (ISR << 0) // HaltnReset.c -#define HALT OTHERS -#define MP_HALT (HALT<<1) -#define CHECK_HANG (HALT<<2) -#define MP_RESET (HALT<<3) -#define MP_SHUTDOWN (HALT<<4) +#define HALT OTHERS +#define MP_HALT (HALT << 1) +#define CHECK_HANG (HALT << 2) +#define MP_RESET (HALT << 3) +#define MP_SHUTDOWN (HALT << 4) // pnp.c -#define PNP OTHERS -#define MP_PNP (PNP<<5) +#define PNP OTHERS +#define MP_PNP (PNP << 5) // Misc.c -#define MISC OTHERS -#define DUMP_INFO (MISC<<6) -#define CLASSIFY (MISC<<7) -#define LINK_UP_MSG (MISC<<8) -#define CP_CTRL_PKT (MISC<<9) -#define DUMP_CONTROL (MISC<<10) -#define LED_DUMP_INFO (MISC<<11) +#define MISC OTHERS +#define DUMP_INFO (MISC << 6) +#define CLASSIFY (MISC << 7) +#define LINK_UP_MSG (MISC << 8) +#define CP_CTRL_PKT (MISC << 9) +#define DUMP_CONTROL (MISC << 10) +#define LED_DUMP_INFO (MISC << 11) // CmHost.c -#define CMHOST OTHERS - - -#define SERIAL (OTHERS<<12) -#define IDLE_MODE (OTHERS<<13) - -#define WRM (OTHERS<<14) -#define RDM (OTHERS<<15) +#define CMHOST OTHERS +#define SERIAL (OTHERS << 12) +#define IDLE_MODE (OTHERS << 13) +#define WRM (OTHERS << 14) +#define RDM (OTHERS << 15) // TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ? -#define PHS_SEND (OTHERS<<16) -#define PHS_RECEIVE (OTHERS<<17) -#define PHS_MODULE (OTHERS<<18) - -#define INTF_INIT (OTHERS<<19) -#define INTF_ERR (OTHERS<<20) -#define INTF_WARN (OTHERS<<21) -#define INTF_NORM (OTHERS<<22) - -#define IRP_COMPLETION (OTHERS<<23) -#define SF_DESCRIPTOR_CNTS (OTHERS<<24) -#define PHS_DISPATCH (OTHERS << 25) -#define OSAL_DBG (OTHERS << 26) -#define NVM_RW (OTHERS << 27) - -#define HOST_MIBS (OTHERS << 28) -#define CONN_MSG (CMHOST << 29) +#define PHS_SEND (OTHERS << 16) +#define PHS_RECEIVE (OTHERS << 17) +#define PHS_MODULE (OTHERS << 18) + +#define INTF_INIT (OTHERS << 19) +#define INTF_ERR (OTHERS << 20) +#define INTF_WARN (OTHERS << 21) +#define INTF_NORM (OTHERS << 22) + +#define IRP_COMPLETION (OTHERS << 23) +#define SF_DESCRIPTOR_CNTS (OTHERS << 24) +#define PHS_DISPATCH (OTHERS << 25) +#define OSAL_DBG (OTHERS << 26) +#define NVM_RW (OTHERS << 27) + +#define HOST_MIBS (OTHERS << 28) +#define CONN_MSG (CMHOST << 29) /*-----------------END SUBTYPEs------------------------------------------*/ - /* Debug level * We have 8 debug levels, in (numerical) increasing order of verbosity. * IMP: Currently implementing ONLY DBG_LVL_ALL , i.e. , all debug prints will @@ -157,16 +146,16 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ * You can compile-time change that to any of the below, if you wish to. However, as of now, there's * no dynamic facility to have the userspace 'TestApp' set debug_level. Slated for future expansion. */ -#define BCM_ALL 7 -#define BCM_LOW 6 -#define BCM_PRINT 5 -#define BCM_NORMAL 4 -#define BCM_MEDIUM 3 -#define BCM_SCREAM 2 -#define BCM_ERR 1 +#define BCM_ALL 7 +#define BCM_LOW 6 +#define BCM_PRINT 5 +#define BCM_NORMAL 4 +#define BCM_MEDIUM 3 +#define BCM_SCREAM 2 +#define BCM_ERR 1 /* Not meant for developer in debug prints. * To be used to disable all prints by setting the DBG_LVL_CURR to this value */ -#define BCM_NONE 0 +#define BCM_NONE 0 /* The current driver logging level. * Everything at this level and (numerically) lower (meaning higher prio) @@ -177,7 +166,7 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ */ #define DBG_LVL_CURR (BCM_ALL) -#define DBG_LVL_ALL BCM_ALL +#define DBG_LVL_ALL BCM_ALL /*---Userspace mapping of Debug State. * Delibrately matches that of the Windows driver.. @@ -215,40 +204,39 @@ typedef struct _S_BCM_DEBUG_STATE { if (DBG_TYPE_PRINTK == Type) \ pr_info("%s:" string, __func__, ##args); \ else if (Adapter && \ - (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ - (Type & Adapter->stDebugState.type) && \ - (SubType & Adapter->stDebugState.subtype[Type])) { \ + (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ + (Type & Adapter->stDebugState.type) && \ + (SubType & Adapter->stDebugState.subtype[Type])) { \ if (dbg_level & DBG_NO_FUNC_PRINT) \ printk(KERN_DEBUG string, ##args); \ else \ - printk(KERN_DEBUG "%s:" string, __func__, ##args); \ + printk(KERN_DEBUG "%s:" string, __func__, ##args); \ + } \ + } while (0) + +#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) \ + do { \ + if (DBG_TYPE_PRINTK == Type || \ + (Adapter && \ + (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ + (Type & Adapter->stDebugState.type) && \ + (SubType & Adapter->stDebugState.subtype[Type]))) { \ + printk(KERN_DEBUG "%s:\n", __func__); \ + print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \ + 16, 1, buffer, bufferlen, false); \ } \ } while (0) -#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \ - if (DBG_TYPE_PRINTK == Type || \ - (Adapter && \ - (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ - (Type & Adapter->stDebugState.type) && \ - (SubType & Adapter->stDebugState.subtype[Type]))) { \ - printk(KERN_DEBUG "%s:\n", __func__); \ - print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \ - 16, 1, buffer, bufferlen, false); \ - } \ -} while(0) - - -#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \ - int i; \ - for (i=0; i<(NUMTYPES*2)+1; i++) { \ +#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \ + int i; \ + for (i = 0; i < (NUMTYPES * 2) + 1; i++) { \ if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \ - /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \ - Adapter->stDebugState.subtype[i] = 0xffffffff; */ \ - BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \ - i, Adapter->stDebugState.subtype[i]); \ + /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \ + Adapter->stDebugState.subtype[i] = 0xffffffff; */ \ + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \ + i, Adapter->stDebugState.subtype[i]); \ } \ } \ } while (0) #endif - -- cgit v0.10.2 From 744467eaf0cdc1bb48fcad4f347b393aeb3c1902 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:03 -0500 Subject: Staging: bcm: Properly format comments in Debug.h This patch properly formats comments, and removes them as needed in Debug.h. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 70189d0..2917ed3 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -9,43 +9,40 @@ #include #define NONE 0xFFFF -//-------------------------------------------------------------------------------- /* TYPE and SUBTYPE * Define valid TYPE (or category or code-path, however you like to think of it) * and SUBTYPE s. * Type and SubType are treated as bitmasks. */ -/*-----------------BEGIN TYPEs------------------------------------------*/ -#define DBG_TYPE_INITEXIT (1 << 0) // 1 -#define DBG_TYPE_TX (1 << 1) // 2 -#define DBG_TYPE_RX (1 << 2) // 4 -#define DBG_TYPE_OTHERS (1 << 3) // 8 -/*-----------------END TYPEs------------------------------------------*/ -#define NUMTYPES 4 // careful! -/*-----------------BEGIN SUBTYPEs---------------------------------------*/ - -/*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----// - Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c - total 17 macros */ -// Transmit.c +#define DBG_TYPE_INITEXIT (1 << 0) /* 1 */ +#define DBG_TYPE_TX (1 << 1) /* 2 */ +#define DBG_TYPE_RX (1 << 2) /* 4 */ +#define DBG_TYPE_OTHERS (1 << 3) /* 8 */ +#define NUMTYPES 4 + +/* -SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----// + * Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c + * total 17 macros + */ +/* Transmit.c */ #define TX 1 #define MP_SEND (TX << 0) #define NEXT_SEND (TX << 1) #define TX_FIFO (TX << 2) #define TX_CONTROL (TX << 3) -// Arp.c +/* Arp.c */ #define IP_ADDR (TX << 4) #define ARP_REQ (TX << 5) #define ARP_RESP (TX << 6) -// Leakybucket.c +/* Leakybucket.c */ #define TOKEN_COUNTS (TX << 8) #define CHECK_TOKENS (TX << 9) #define TX_PACKETS (TX << 10) #define TIMER (TX << 11) -// Qos.c +/* Qos.c */ #define QOS TX #define QUEUE_INDEX (QOS << 12) #define IPV4_DBG (QOS << 13) @@ -53,12 +50,13 @@ #define PRUNE_QUEUE (QOS << 15) #define SEND_QUEUE (QOS << 16) -//TX_Misc +/* TX_Misc */ #define TX_OSAL_DBG (TX << 17) -//--SUBTYPEs for ------INIT & EXIT--------------------- -/*------------ TYPE is DBG_TYPE_INITEXIT -----// -DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ +/* --SUBTYPEs for ------INIT & EXIT--------------------- + * ------------ TYPE is DBG_TYPE_INITEXIT -----// + * DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c + */ #define MP 1 #define DRV_ENTRY (MP << 0) #define MP_INIT (MP << 1) @@ -69,9 +67,10 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ #define INIT_DISP (MP << 6) #define RX_INIT (MP << 7) -//-SUBTYPEs for --RX---------------------------------- -//------------RX : TYPE is DBG_TYPE_RX -----// -// Receive.c +/* -SUBTYPEs for --RX---------------------------------- + * ------------RX : TYPE is DBG_TYPE_RX -----// + * Receive.c + */ #define RX 1 #define RX_DPC (RX << 0) #define RX_CTRL (RX << 3) @@ -79,27 +78,27 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ #define MP_RETURN (RX << 1) #define LINK_MSG (RX << 2) -//-SUBTYPEs for ----OTHER ROUTINES------------------ -//------------OTHERS : TYPE is DBG_TYPE_OTHER -----// -// HaltnReset,CheckForHang,PnP,Misc,CmHost -// total 12 macros +/* -SUBTYPEs for ----OTHER ROUTINES------------------ + * ------------OTHERS : TYPE is DBG_TYPE_OTHER -----// + * HaltnReset,CheckForHang,PnP,Misc,CmHost + * total 12 macros + */ #define OTHERS 1 -// ??ISR.C #define ISR OTHERS #define MP_DPC (ISR << 0) -// HaltnReset.c +/* HaltnReset.c */ #define HALT OTHERS #define MP_HALT (HALT << 1) #define CHECK_HANG (HALT << 2) #define MP_RESET (HALT << 3) #define MP_SHUTDOWN (HALT << 4) -// pnp.c +/* pnp.c */ #define PNP OTHERS #define MP_PNP (PNP << 5) -// Misc.c +/* Misc.c */ #define MISC OTHERS #define DUMP_INFO (MISC << 6) #define CLASSIFY (MISC << 7) @@ -108,14 +107,14 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ #define DUMP_CONTROL (MISC << 10) #define LED_DUMP_INFO (MISC << 11) -// CmHost.c +/* CmHost.c */ #define CMHOST OTHERS #define SERIAL (OTHERS << 12) #define IDLE_MODE (OTHERS << 13) #define WRM (OTHERS << 14) #define RDM (OTHERS << 15) -// TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ? +/* TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ? */ #define PHS_SEND (OTHERS << 16) #define PHS_RECEIVE (OTHERS << 17) #define PHS_MODULE (OTHERS << 18) @@ -133,7 +132,6 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ #define HOST_MIBS (OTHERS << 28) #define CONN_MSG (CMHOST << 29) -/*-----------------END SUBTYPEs------------------------------------------*/ /* Debug level * We have 8 debug levels, in (numerical) increasing order of verbosity. @@ -154,13 +152,14 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ #define BCM_SCREAM 2 #define BCM_ERR 1 /* Not meant for developer in debug prints. - * To be used to disable all prints by setting the DBG_LVL_CURR to this value */ + * To be used to disable all prints by setting the DBG_LVL_CURR to this value + */ #define BCM_NONE 0 /* The current driver logging level. * Everything at this level and (numerically) lower (meaning higher prio) * is logged. -* Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired. + * Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired. * For eg. to set the logging level to 'errors only' use: * #define DBG_LVL_CURR (BCM_ERR) */ @@ -168,7 +167,7 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ #define DBG_LVL_CURR (BCM_ALL) #define DBG_LVL_ALL BCM_ALL -/*---Userspace mapping of Debug State. +/* ---Userspace mapping of Debug State. * Delibrately matches that of the Windows driver.. * The TestApp's ioctl passes this struct to us. */ @@ -176,10 +175,10 @@ typedef struct { unsigned int Subtype, Type; unsigned int OnOff; -// unsigned int debug_level; /* future expansion */ +/* unsigned int debug_level; future expansion */ } __attribute__((packed)) USER_BCM_DBG_STATE; -//---Kernel-space mapping of Debug State +/* ---Kernel-space mapping of Debug State */ typedef struct _S_BCM_DEBUG_STATE { UINT type; /* A bitmap of 32 bits for Subtype per Type. @@ -190,13 +189,14 @@ typedef struct _S_BCM_DEBUG_STATE { UINT subtype[(NUMTYPES*2)+1]; UINT debug_level; } S_BCM_DEBUG_STATE; -/* Instantiated in the Adapter structure */ -/* We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not - * we want the function's name printed. */ +/* Instantiated in the Adapter structure + * We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not + * we want the function's name printed. + */ #define DBG_NO_FUNC_PRINT 1 << 31 #define DBG_LVL_BITMASK 0xFF -//--- Only for direct printk's; "hidden" to API. +/* --- Only for direct printk's; "hidden" to API. */ #define DBG_TYPE_PRINTK 3 #define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \ @@ -232,7 +232,8 @@ typedef struct _S_BCM_DEBUG_STATE { for (i = 0; i < (NUMTYPES * 2) + 1; i++) { \ if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \ /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \ - Adapter->stDebugState.subtype[i] = 0xffffffff; */ \ + * Adapter->stDebugState.subtype[i] = 0xffffffff; \ + */ \ BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \ i, Adapter->stDebugState.subtype[i]); \ } \ -- cgit v0.10.2 From 27bc7b2be29441868d8acd5022794339c752dbea Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:04 -0500 Subject: Staging: bcm: Properly format braces in Debug.h This patch formats braces in Debug.h as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 2917ed3..b4ff000 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -171,8 +171,7 @@ * Delibrately matches that of the Windows driver.. * The TestApp's ioctl passes this struct to us. */ -typedef struct -{ +typedef struct { unsigned int Subtype, Type; unsigned int OnOff; /* unsigned int debug_level; future expansion */ -- cgit v0.10.2 From 34bb72b67496ebb9510720a1b9d7663eed1e4116 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:05 -0500 Subject: Staging: bcm: Fix warning: "__packed is preferred over __attribute__((packed))" in Debug.h This patch fixes the following warning: "__packed is preferred over __attribute__((packed))" as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index b4ff000..7a66219 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -175,7 +175,7 @@ typedef struct { unsigned int Subtype, Type; unsigned int OnOff; /* unsigned int debug_level; future expansion */ -} __attribute__((packed)) USER_BCM_DBG_STATE; +} __packed USER_BCM_DBG_STATE; /* ---Kernel-space mapping of Debug State */ typedef struct _S_BCM_DEBUG_STATE { -- cgit v0.10.2 From 79a469136cbd6bc7a91f8e3b785aa793e39a2a75 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:06 -0500 Subject: Staging: bcm: Fix error: "Macros with complex values should be enclosed in parenthesis" in Debug.h This patch fixes the following error: "Macros with complex values should be enclosed in parenthesis" as reported by checkpatch.pl. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 7a66219..4b620d9 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -192,7 +192,7 @@ typedef struct _S_BCM_DEBUG_STATE { * We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not * we want the function's name printed. */ -#define DBG_NO_FUNC_PRINT 1 << 31 +#define DBG_NO_FUNC_PRINT (1 << 31) #define DBG_LVL_BITMASK 0xFF /* --- Only for direct printk's; "hidden" to API. */ -- cgit v0.10.2 From b2a089b7732df4750617c82d390ace61a60ddb0d Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:07 -0500 Subject: Staging: bcm: Replace UINT with unsigned int in Debug.h This patch replaces "UINT" with "unsigned int" in Debug.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 4b620d9..663325b 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -179,14 +179,14 @@ typedef struct { /* ---Kernel-space mapping of Debug State */ typedef struct _S_BCM_DEBUG_STATE { - UINT type; + unsigned int type; /* A bitmap of 32 bits for Subtype per Type. * Valid indexes in 'subtype' array are *only* 1,2,4 and 8, * corresponding to valid Type values. Hence we use the 'Type' field * as the index value, ignoring the array entries 0,3,5,6,7 ! */ - UINT subtype[(NUMTYPES*2)+1]; - UINT debug_level; + unsigned int subtype[(NUMTYPES*2)+1]; + unsigned int debug_level; } S_BCM_DEBUG_STATE; /* Instantiated in the Adapter structure * We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not -- cgit v0.10.2 From 4b388a9e1da7156dbf924e38741beaac1b4e29d1 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:08 -0500 Subject: Staging: bcm: Remove typedef for _S_BCM_DEBUG_STATE and call directly. This patch removes typedef for _S_BCM_DEBUG_STATE, and changes the name of the struct to bcm_debug_state. In addition, any calls to struct "S_BCM_DEBUG_STATE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h index ade7bfd..1d8bf08 100644 --- a/drivers/staging/bcm/Adapter.h +++ b/drivers/staging/bcm/Adapter.h @@ -392,7 +392,7 @@ struct bcm_mini_adapter { struct semaphore LowPowerModeSync; ULONG liDrainCalculated; UINT gpioBitMap; - S_BCM_DEBUG_STATE stDebugState; + struct bcm_debug_state stDebugState; }; #define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev) diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 663325b..e81db0d 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -178,7 +178,7 @@ typedef struct { } __packed USER_BCM_DBG_STATE; /* ---Kernel-space mapping of Debug State */ -typedef struct _S_BCM_DEBUG_STATE { +struct bcm_debug_state { unsigned int type; /* A bitmap of 32 bits for Subtype per Type. * Valid indexes in 'subtype' array are *only* 1,2,4 and 8, @@ -187,7 +187,7 @@ typedef struct _S_BCM_DEBUG_STATE { */ unsigned int subtype[(NUMTYPES*2)+1]; unsigned int debug_level; -} S_BCM_DEBUG_STATE; +}; /* Instantiated in the Adapter structure * We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not * we want the function's name printed. -- cgit v0.10.2 From a049728928b14cadc6ceb128cedde9f8e5af2b3c Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:09 -0500 Subject: Staging: bcm: Change the name of typedef USER_BCM_DBG_STATE to bcm_user_debug_state. This patch removes typedef for USER_BCM_DBG_STATE, and changes the name of the struct to bcm_user_debug_state. In addition, any calls to struct "USER_BCM_DBG_STATE" are changed to call directly. Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index b034ace..4ba1a5d 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -1229,13 +1229,13 @@ cntrlEnd: case IOCTL_BCM_SET_DEBUG: #ifdef DEBUG { - USER_BCM_DBG_STATE sUserDebugState; + struct bcm_user_debug_state sUserDebugState; BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n"); if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) return -EFAULT; - if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE))) + if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(struct bcm_user_debug_state))) return -EFAULT; BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ", diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index e81db0d..03be63f 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -171,11 +171,11 @@ * Delibrately matches that of the Windows driver.. * The TestApp's ioctl passes this struct to us. */ -typedef struct { +struct bcm_user_debug_state { unsigned int Subtype, Type; unsigned int OnOff; /* unsigned int debug_level; future expansion */ -} __packed USER_BCM_DBG_STATE; +} __packed; /* ---Kernel-space mapping of Debug State */ struct bcm_debug_state { -- cgit v0.10.2 From ee39b7879ee89dfbb605681277efdd254e621a71 Mon Sep 17 00:00:00 2001 From: Kevin McKinney Date: Fri, 4 Jan 2013 23:35:10 -0500 Subject: Staging: bcm: Fix warning: "Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ..." This patch fixes the following warning: "WARNING: Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ..." in Debug.h Signed-off-by: Kevin McKinney Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h index 03be63f..7b33121 100644 --- a/drivers/staging/bcm/Debug.h +++ b/drivers/staging/bcm/Debug.h @@ -207,9 +207,9 @@ struct bcm_debug_state { (Type & Adapter->stDebugState.type) && \ (SubType & Adapter->stDebugState.subtype[Type])) { \ if (dbg_level & DBG_NO_FUNC_PRINT) \ - printk(KERN_DEBUG string, ##args); \ + pr_debug("%s:\n", string); \ else \ - printk(KERN_DEBUG "%s:" string, __func__, ##args); \ + pr_debug("%s:\n" string, __func__, ##args); \ } \ } while (0) @@ -220,7 +220,7 @@ struct bcm_debug_state { (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ (Type & Adapter->stDebugState.type) && \ (SubType & Adapter->stDebugState.subtype[Type]))) { \ - printk(KERN_DEBUG "%s:\n", __func__); \ + pr_debug("%s:\n", __func__); \ print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \ 16, 1, buffer, bufferlen, false); \ } \ -- cgit v0.10.2 From 6dc69c2b8301270ed360de62a09276becefeabe8 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:26 +0200 Subject: staging: wlags49_h2: ap_h2: corrects a pointer styling issue This commit correct a pointer styling issue as reported by the checkpatch.pl tool. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/ap_h2.c b/drivers/staging/wlags49_h2/ap_h2.c index e524153..3a08d42 100644 --- a/drivers/staging/wlags49_h2/ap_h2.c +++ b/drivers/staging/wlags49_h2/ap_h2.c @@ -3256,7 +3256,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x0146, /* sizeof(fw_image_1_data), */ 0x00000060, /* Target address in NIC Memory */ 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ - (hcf_8 FAR *) fw_image_1_data + (hcf_8 *)fw_image_1_data }, { 8, @@ -3265,7 +3265,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x1918, /* sizeof(fw_image_2_data), */ 0x00000C16, /* Target address in NIC Memory */ 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ - (hcf_8 FAR *) fw_image_2_data + (hcf_8 *)fw_image_2_data }, { 8, @@ -3274,7 +3274,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x01bc, /* sizeof(fw_image_3_data), */ 0x001E252E, /* Target address in NIC Memory */ 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ - (hcf_8 FAR *) fw_image_3_data + (hcf_8 *)fw_image_3_data }, { 8, @@ -3283,7 +3283,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0xab28, /* sizeof(fw_image_4_data), */ 0x001F4000, /* Target address in NIC Memory */ 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ - (hcf_8 FAR *) fw_image_4_data + (hcf_8 *)fw_image_4_data }, { 5, -- cgit v0.10.2 From ef8271dc6c005388edaa8ea15014b0801a320a4a Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:27 +0200 Subject: staging: wlags49_h2: ap_h25: corrects tabs/spaces syling issues This commit corrects tabs and spaces issues as reported by the checkpatch.pl tool. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/ap_h25.c b/drivers/staging/wlags49_h2/ap_h25.c index f4491cb..f0fd34f 100644 --- a/drivers/staging/wlags49_h2/ap_h25.c +++ b/drivers/staging/wlags49_h2/ap_h25.c @@ -24,10 +24,10 @@ */ -#include "hcfcfg.h" // to get hcf_16 etc defined as well as - // possible settings which inluence mdd.h or dhf.h -#include "mdd.h" //to get COMP_ID_STA etc defined -#include "dhf.h" //used to be "fhfmem.h", to get memblock,plugrecord, +#include "hcfcfg.h" // to get hcf_16 etc defined as well as + // possible settings which inluence mdd.h or dhf.h +#include "mdd.h" // to get COMP_ID_STA etc defined +#include "dhf.h" // used to be "fhfmem.h", to get memblock,plugrecord, static const hcf_8 fw_image_1_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -4048,7 +4048,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { CFG_PROG, CFG_PROG_STOP, // mode 0000, - 0x000F2101, // Start execution address + 0x000F2101, // Start execution address }, { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000} }; @@ -4059,7 +4059,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_SUPL, COMP_ID_APF, { - { 4, 1, 1 } //variant, bottom, top + { 4, 1, 1 } //variant, bottom, top } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4067,8 +4067,8 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_MFI, { - { 7, 3, 3 }, //variant, bottom, top - { 8, 1, 1 } //variant, bottom, top + { 7, 3, 3 }, //variant, bottom, top + { 8, 1, 1 } //variant, bottom, top } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4076,7 +4076,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_CFI, { - { 4, 1, 2 } //variant, bottom, top + { 4, 1, 2 } //variant, bottom, top } }, { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel -- cgit v0.10.2 From ed3125c82a9d02b023b82d6b8a41e9d33c03b96b Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:28 +0200 Subject: staging: wlags49_h2: ap_h25: corrects parentheses styling issue This commit corrects incorrect spaces around parentheses. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/ap_h25.c b/drivers/staging/wlags49_h2/ap_h25.c index f0fd34f..1c8f2be 100644 --- a/drivers/staging/wlags49_h2/ap_h25.c +++ b/drivers/staging/wlags49_h2/ap_h25.c @@ -3996,7 +3996,7 @@ static const hcf_8 fw_image_4_data[] = { static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = { { - sizeof( CFG_IDENTITY_STRCT ) / sizeof(hcf_16) - 1, + sizeof(CFG_IDENTITY_STRCT) / sizeof(hcf_16) - 1, CFG_FW_IDENTITY, COMP_ID_FW_AP, 3, //Variant -- cgit v0.10.2 From d692b695e740c90edb889967a3862fd898deb2d2 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:29 +0200 Subject: staging: wlags49_h2: ap_h25: corrects malformed #include warning This extremely minor commit removes quotation marks from within a comment so that the checkpatch.pl tool won't complain about the line in question anymore. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/ap_h25.c b/drivers/staging/wlags49_h2/ap_h25.c index 1c8f2be..454d01b 100644 --- a/drivers/staging/wlags49_h2/ap_h25.c +++ b/drivers/staging/wlags49_h2/ap_h25.c @@ -27,7 +27,7 @@ #include "hcfcfg.h" // to get hcf_16 etc defined as well as // possible settings which inluence mdd.h or dhf.h #include "mdd.h" // to get COMP_ID_STA etc defined -#include "dhf.h" // used to be "fhfmem.h", to get memblock,plugrecord, +#include "dhf.h" // used to be fhfmem.h, to get memblock,plugrecord, static const hcf_8 fw_image_1_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -- cgit v0.10.2 From 524cb2e503911a252bfeacceb19f6416b25cefb8 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:30 +0200 Subject: staging: wlags49_h2: ap_h25: corrects casting styling issue This commit corrects a casting styling issue as reported by the checkpatch.pl tool. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/ap_h25.c b/drivers/staging/wlags49_h2/ap_h25.c index 454d01b..f578800 100644 --- a/drivers/staging/wlags49_h2/ap_h25.c +++ b/drivers/staging/wlags49_h2/ap_h25.c @@ -4014,7 +4014,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x0148, // sizeof(fw_image_1_data), 0x00000060, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_1_data + (hcf_8 *)fw_image_1_data }, { 8, @@ -4023,7 +4023,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x2432, // sizeof(fw_image_2_data), 0x00000C16, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_2_data + (hcf_8 *)fw_image_2_data }, { 8, @@ -4032,7 +4032,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x194c, // sizeof(fw_image_3_data), 0x001E3048, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_3_data + (hcf_8 *)fw_image_3_data }, { 8, @@ -4041,7 +4041,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0xb7e4, // sizeof(fw_image_4_data), 0x001F4000, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_4_data + (hcf_8 *)fw_image_4_data }, { 5, -- cgit v0.10.2 From 4f55b5d4943816248c20e747872a3dc3cb6fadbe Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:31 +0200 Subject: staging: wlags49_h2: ap_h25: corrects incorrect use of // comments This commit converts C99 // comments to /* */ Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/ap_h25.c b/drivers/staging/wlags49_h2/ap_h25.c index f578800..d3a0faa 100644 --- a/drivers/staging/wlags49_h2/ap_h25.c +++ b/drivers/staging/wlags49_h2/ap_h25.c @@ -24,10 +24,10 @@ */ -#include "hcfcfg.h" // to get hcf_16 etc defined as well as - // possible settings which inluence mdd.h or dhf.h -#include "mdd.h" // to get COMP_ID_STA etc defined -#include "dhf.h" // used to be fhfmem.h, to get memblock,plugrecord, +#include "hcfcfg.h" /* to get hcf_16 etc defined as well as */ + /* possible settings which inluence mdd.h or dhf.h */ +#include "mdd.h" /* to get COMP_ID_STA etc defined */ +#include "dhf.h" /* used to be fhfmem.h, to get memblock,plugrecord, */ static const hcf_8 fw_image_1_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -3999,56 +3999,56 @@ static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = { sizeof(CFG_IDENTITY_STRCT) / sizeof(hcf_16) - 1, CFG_FW_IDENTITY, COMP_ID_FW_AP, - 3, //Variant - 1, //Major - 24 //Minor + 3, /* Variant */ + 1, /* Major */ + 24 /* Minor */ }, - { 0000, 0000, 0000, 0000, 0000, 0000 } //endsentinel + { 0000, 0000, 0000, 0000, 0000, 0000 } /* endsentinel */ }; static const CFG_PROG_STRCT fw_image_code[] = { { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0x0148, // sizeof(fw_image_1_data), - 0x00000060, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0x0148, /* sizeof(fw_image_1_data), */ + 0x00000060, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_1_data }, { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0x2432, // sizeof(fw_image_2_data), - 0x00000C16, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0x2432, /* sizeof(fw_image_2_data), */ + 0x00000C16, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_2_data }, { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0x194c, // sizeof(fw_image_3_data), - 0x001E3048, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0x194c, /* sizeof(fw_image_3_data), */ + 0x001E3048, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_3_data }, { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0xb7e4, // sizeof(fw_image_4_data), - 0x001F4000, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode*/ + 0xb7e4, /* sizeof(fw_image_4_data),*/ + 0x001F4000, /* Target address in NIC Memory*/ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary*/ (hcf_8 *)fw_image_4_data }, { 5, CFG_PROG, - CFG_PROG_STOP, // mode + CFG_PROG_STOP, /* mode*/ 0000, - 0x000F2101, // Start execution address + 0x000F2101, /* Start execution address*/ }, { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000} }; @@ -4059,7 +4059,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_SUPL, COMP_ID_APF, { - { 4, 1, 1 } //variant, bottom, top + { 4, 1, 1 } /* variant, bottom, top*/ } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4067,8 +4067,8 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_MFI, { - { 7, 3, 3 }, //variant, bottom, top - { 8, 1, 1 } //variant, bottom, top + { 7, 3, 3 }, /* variant, bottom, top */ + { 8, 1, 1 } /* variant, bottom, top */ } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4076,18 +4076,18 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_CFI, { - { 4, 1, 2 } //variant, bottom, top + { 4, 1, 2 } /* variant, bottom, top */ } }, - { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel + { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } /* endsentinel */ }; memimage fw_image = { - "FUPU7D37dhfwci\001C", //signature, , C/Bin type + "FUPU7D37dhfwci\001C", /* signature, , C/Bin type */ (CFG_PROG_STRCT *) fw_image_code, 0x000F2101, - 00000000, //(dummy) pdaplug - 00000000, //(dummy) priplug + 00000000, /* (dummy) pdaplug */ + 00000000, /* (dummy) priplug */ (CFG_RANGE20_STRCT *) fw_image_infocompat, (CFG_IDENTITY_STRCT *) fw_image_infoidentity, }; -- cgit v0.10.2 From 9413127a92f7f2607b9b0df13bce3698943413d9 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:32 +0200 Subject: staging: wlags49_h2: wl_enc: converts indentation spaces to tabs This commit converts space-based indentation to tabs. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_enc.c b/drivers/staging/wlags49_h2/wl_enc.c index 4c6f776..a62db46 100644 --- a/drivers/staging/wlags49_h2/wl_enc.c +++ b/drivers/staging/wlags49_h2/wl_enc.c @@ -107,55 +107,55 @@ extern dbg_info_t *DbgInfo; ******************************************************************************/ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) { - int i; - int t; - int k ; - char bits; - char *szData = (char *) Data; - /*------------------------------------------------------------------------*/ + int i; + int t; + int k ; + char bits; + char *szData = (char *) Data; + /*------------------------------------------------------------------------*/ - for( i = bits = 0 ; i < MACADDRESS_STR_LEN; i++ ) { - bits ^= szCrypt[i]; - bits += szCrypt[i]; - } + for( i = bits = 0 ; i < MACADDRESS_STR_LEN; i++ ) { + bits ^= szCrypt[i]; + bits += szCrypt[i]; + } - for( i = t = *szDest = 0; i < nLen; i++, t++ ) { - k = szData[i] ^ ( bits + i ); + for( i = t = *szDest = 0; i < nLen; i++, t++ ) { + k = szData[i] ^ ( bits + i ); - switch( i % 3 ) { + switch( i % 3 ) { - case 0 : + case 0 : - szDest[t] = ((k & 0xFC) >> 2) + CH_START ; - szDest[t+1] = ((k & 0x03) << 4) + CH_START ; - szDest[t+2] = '\0'; + szDest[t] = ((k & 0xFC) >> 2) + CH_START ; + szDest[t+1] = ((k & 0x03) << 4) + CH_START ; + szDest[t+2] = '\0'; - break; + break; - case 1 : + case 1 : - szDest[t] += (( k & 0xF0 ) >> 4 ); - szDest[t+1] = (( k & 0x0F ) << 2 ) + CH_START ; - szDest[t+2] = '\0'; + szDest[t] += (( k & 0xF0 ) >> 4 ); + szDest[t+1] = (( k & 0x0F ) << 2 ) + CH_START ; + szDest[t+2] = '\0'; - break; + break; - case 2 : + case 2 : - szDest[t] += (( k & 0xC0 ) >> 6 ); - szDest[t+1] = ( k & 0x3F ) + CH_START ; - szDest[t+2] = '\0'; - t++; + szDest[t] += (( k & 0xC0 ) >> 6 ); + szDest[t+1] = ( k & 0x3F ) + CH_START ; + szDest[t+2] = '\0'; + t++; - break; - } - } + break; + } + } - return( strlen( szDest )) ; + return( strlen( szDest )) ; } /*============================================================================*/ @@ -184,48 +184,48 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) ******************************************************************************/ int wl_wep_decode( char *szCrypt, void *Dest, char *szData ) { - int i; - int t; - int nLen; - char bits; - char *szDest = Dest; - /*------------------------------------------------------------------------*/ + int i; + int t; + int nLen; + char bits; + char *szDest = Dest; + /*------------------------------------------------------------------------*/ - for( i = bits = 0 ; i < 12; i++ ) { - bits ^= szCrypt[i] ; - bits += szCrypt[i] ; - } + for( i = bits = 0 ; i < 12; i++ ) { + bits ^= szCrypt[i] ; + bits += szCrypt[i] ; + } - nLen = ( strlen( szData ) * 3) / 4 ; + nLen = ( strlen( szData ) * 3) / 4 ; - for( i = t = 0; i < nLen; i++, t++ ) { - switch( i % 3 ) { - case 0 : + for( i = t = 0; i < nLen; i++, t++ ) { + switch( i % 3 ) { + case 0 : - szDest[i] = ((( szData[t]-CH_START ) & 0x3f ) << 2 ) + - ((( szData[t+1]-CH_START ) & 0x30 ) >> 4 ); - break; + szDest[i] = ((( szData[t]-CH_START ) & 0x3f ) << 2 ) + + ((( szData[t+1]-CH_START ) & 0x30 ) >> 4 ); + break; - case 1 : - szDest[i] = ((( szData[t]-CH_START ) & 0x0f ) << 4 ) + - ((( szData[t+1]-CH_START ) & 0x3c ) >> 2 ); - break; + case 1 : + szDest[i] = ((( szData[t]-CH_START ) & 0x0f ) << 4 ) + + ((( szData[t+1]-CH_START ) & 0x3c ) >> 2 ); + break; - case 2 : - szDest[i] = ((( szData[t]-CH_START ) & 0x03 ) << 6 ) + - (( szData[t+1]-CH_START ) & 0x3f ); - t++; - break; - } + case 2 : + szDest[i] = ((( szData[t]-CH_START ) & 0x03 ) << 6 ) + + (( szData[t+1]-CH_START ) & 0x3f ); + t++; + break; + } - szDest[i] ^= ( bits + i ) ; + szDest[i] ^= ( bits + i ) ; - } + } - return( i ) ; + return( i ) ; } /*============================================================================*/ -- cgit v0.10.2 From 2d33309ef901156b0ad8e2185bec3c06d46976ef Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:33 +0200 Subject: staging: wlags49_h2: wl_enc: corrects spacing around parentheses This commit corrects various instances where the use of spaces around parentheses was incorrect. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_enc.c b/drivers/staging/wlags49_h2/wl_enc.c index a62db46..1d143cd 100644 --- a/drivers/staging/wlags49_h2/wl_enc.c +++ b/drivers/staging/wlags49_h2/wl_enc.c @@ -105,7 +105,7 @@ extern dbg_info_t *DbgInfo; * OK * ******************************************************************************/ -int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) +int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) { int i; int t; @@ -115,16 +115,16 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) /*------------------------------------------------------------------------*/ - for( i = bits = 0 ; i < MACADDRESS_STR_LEN; i++ ) { + for (i = bits = 0; i < MACADDRESS_STR_LEN; i++) { bits ^= szCrypt[i]; bits += szCrypt[i]; } - for( i = t = *szDest = 0; i < nLen; i++, t++ ) { - k = szData[i] ^ ( bits + i ); + for (i = t = *szDest = 0; i < nLen; i++, t++) { + k = szData[i] ^ (bits + i); - switch( i % 3 ) { + switch (i % 3) { case 0 : @@ -137,8 +137,8 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) case 1 : - szDest[t] += (( k & 0xF0 ) >> 4 ); - szDest[t+1] = (( k & 0x0F ) << 2 ) + CH_START ; + szDest[t] += ((k & 0xF0) >> 4); + szDest[t+1] = ((k & 0x0F) << 2) + CH_START ; szDest[t+2] = '\0'; break; @@ -146,8 +146,8 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) case 2 : - szDest[t] += (( k & 0xC0 ) >> 6 ); - szDest[t+1] = ( k & 0x3F ) + CH_START ; + szDest[t] += ((k & 0xC0) >> 6); + szDest[t+1] = (k & 0x3F) + CH_START ; szDest[t+2] = '\0'; t++; @@ -155,7 +155,7 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) } } - return( strlen( szDest )) ; + return(strlen(szDest)) ; } /*============================================================================*/ @@ -182,7 +182,7 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) * OK * ******************************************************************************/ -int wl_wep_decode( char *szCrypt, void *Dest, char *szData ) +int wl_wep_decode(char *szCrypt, void *Dest, char *szData) { int i; int t; @@ -192,40 +192,40 @@ int wl_wep_decode( char *szCrypt, void *Dest, char *szData ) /*------------------------------------------------------------------------*/ - for( i = bits = 0 ; i < 12; i++ ) { + for (i = bits = 0; i < 12; i++) { bits ^= szCrypt[i] ; bits += szCrypt[i] ; } - nLen = ( strlen( szData ) * 3) / 4 ; + nLen = (strlen(szData) * 3) / 4 ; - for( i = t = 0; i < nLen; i++, t++ ) { - switch( i % 3 ) { + for (i = t = 0; i < nLen; i++, t++) { + switch (i % 3) { case 0 : - szDest[i] = ((( szData[t]-CH_START ) & 0x3f ) << 2 ) + - ((( szData[t+1]-CH_START ) & 0x30 ) >> 4 ); + szDest[i] = (((szData[t] - CH_START) & 0x3f) << 2) + + (((szData[t+1] - CH_START) & 0x30) >> 4); break; case 1 : - szDest[i] = ((( szData[t]-CH_START ) & 0x0f ) << 4 ) + - ((( szData[t+1]-CH_START ) & 0x3c ) >> 2 ); + szDest[i] = (((szData[t] - CH_START) & 0x0f) << 4) + + (((szData[t+1] - CH_START) & 0x3c) >> 2); break; case 2 : - szDest[i] = ((( szData[t]-CH_START ) & 0x03 ) << 6 ) + - (( szData[t+1]-CH_START ) & 0x3f ); + szDest[i] = (((szData[t] - CH_START) & 0x03) << 6) + + ((szData[t+1] - CH_START) & 0x3f); t++; break; } - szDest[i] ^= ( bits + i ) ; + szDest[i] ^= (bits + i); } - return( i ) ; + return(i) ; } /*============================================================================*/ -- cgit v0.10.2 From f83a7c34d4e57a5afddd94adf39c26f2a09677e1 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:34 +0200 Subject: staging: wlags49_h2: wl_enc: corrects spacing around colons This commit fixes incorrect use of spaces around colons. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_enc.c b/drivers/staging/wlags49_h2/wl_enc.c index 1d143cd..2cf3a113 100644 --- a/drivers/staging/wlags49_h2/wl_enc.c +++ b/drivers/staging/wlags49_h2/wl_enc.c @@ -126,7 +126,7 @@ int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) switch (i % 3) { - case 0 : + case 0: szDest[t] = ((k & 0xFC) >> 2) + CH_START ; szDest[t+1] = ((k & 0x03) << 4) + CH_START ; @@ -135,7 +135,7 @@ int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) break; - case 1 : + case 1: szDest[t] += ((k & 0xF0) >> 4); szDest[t+1] = ((k & 0x0F) << 2) + CH_START ; @@ -144,7 +144,7 @@ int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) break; - case 2 : + case 2: szDest[t] += ((k & 0xC0) >> 6); szDest[t+1] = (k & 0x3F) + CH_START ; @@ -201,20 +201,20 @@ int wl_wep_decode(char *szCrypt, void *Dest, char *szData) for (i = t = 0; i < nLen; i++, t++) { switch (i % 3) { - case 0 : + case 0: szDest[i] = (((szData[t] - CH_START) & 0x3f) << 2) + (((szData[t+1] - CH_START) & 0x30) >> 4); break; - case 1 : + case 1: szDest[i] = (((szData[t] - CH_START) & 0x0f) << 4) + (((szData[t+1] - CH_START) & 0x3c) >> 2); break; - case 2 : + case 2: szDest[i] = (((szData[t] - CH_START) & 0x03) << 6) + ((szData[t+1] - CH_START) & 0x3f); t++; -- cgit v0.10.2 From 13821d96d47098067df59d565f3b98c7694317f5 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:35 +0200 Subject: staging: wlags49_h2: wl_enc: fixes incorrect use of return This commit removes parentheses that were used as part of return statements, seeing as how return is not a function. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_enc.c b/drivers/staging/wlags49_h2/wl_enc.c index 2cf3a113..51293d9 100644 --- a/drivers/staging/wlags49_h2/wl_enc.c +++ b/drivers/staging/wlags49_h2/wl_enc.c @@ -155,7 +155,7 @@ int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) } } - return(strlen(szDest)) ; + return strlen(szDest); } /*============================================================================*/ @@ -225,7 +225,7 @@ int wl_wep_decode(char *szCrypt, void *Dest, char *szData) } - return(i) ; + return i; } /*============================================================================*/ -- cgit v0.10.2 From 00871bc0f8e6534af009c3c071d946efe5195fb8 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:36 +0200 Subject: staging: wlags49_h2: wl_priv.h: fixes spacing around parentheses This commit fixes the incorrect spacing around parentheses. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.h b/drivers/staging/wlags49_h2/wl_priv.h index b647bfd..aa1128a 100644 --- a/drivers/staging/wlags49_h2/wl_priv.h +++ b/drivers/staging/wlags49_h2/wl_priv.h @@ -70,17 +70,17 @@ #ifdef WIRELESS_EXT -int wvlan_set_netname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); +int wvlan_set_netname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); -int wvlan_get_netname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); +int wvlan_get_netname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); -int wvlan_set_station_nickname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); +int wvlan_set_station_nickname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); -int wvlan_get_station_nickname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); +int wvlan_get_station_nickname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); -int wvlan_set_porttype( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); +int wvlan_set_porttype(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); -int wvlan_get_porttype( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); +int wvlan_get_porttype(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); #endif // WIRELESS_EXT @@ -90,7 +90,7 @@ int wvlan_get_porttype( struct net_device *, struct iw_request_info *, union iw #ifdef USE_UIL -int wvlan_uil( struct uilreq *urq, struct wl_private *lp ); +int wvlan_uil(struct uilreq *urq, struct wl_private *lp); // int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); // int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); @@ -109,11 +109,11 @@ int wvlan_uil( struct uilreq *urq, struct wl_private *lp ); #ifdef USE_RTS -int wvlan_rts( struct rtsreq *rrq, __u32 io_base ); -int wvlan_rts_read( __u16 reg, __u16 *val, __u32 io_base ); -int wvlan_rts_write( __u16 reg, __u16 val, __u32 io_base ); -int wvlan_rts_batch_read( struct rtsreq *rrq, __u32 io_base ); -int wvlan_rts_batch_write( struct rtsreq *rrq, __u32 io_base ); +int wvlan_rts(struct rtsreq *rrq, __u32 io_base); +int wvlan_rts_read(__u16 reg, __u16 *val, __u32 io_base); +int wvlan_rts_write(__u16 reg, __u16 val, __u32 io_base); +int wvlan_rts_batch_read(struct rtsreq *rrq, __u32 io_base); +int wvlan_rts_batch_write(struct rtsreq *rrq, __u32 io_base); #endif // USE_RTS -- cgit v0.10.2 From 067f0dc33a1be4c061dce541c53322360bc4726c Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:37 +0200 Subject: staging: wlags49_h2: wl_priv.h: converts C99 // comments This commit converts C99 // comments to /* */ Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.h b/drivers/staging/wlags49_h2/wl_priv.h index aa1128a..daefc6c 100644 --- a/drivers/staging/wlags49_h2/wl_priv.h +++ b/drivers/staging/wlags49_h2/wl_priv.h @@ -83,7 +83,7 @@ int wvlan_set_porttype(struct net_device *, struct iw_request_info *, union iwre int wvlan_get_porttype(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); -#endif // WIRELESS_EXT +#endif /* WIRELESS_EXT */ @@ -92,19 +92,19 @@ int wvlan_get_porttype(struct net_device *, struct iw_request_info *, union iwre int wvlan_uil(struct uilreq *urq, struct wl_private *lp); -// int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ); -// int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ); +/* int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ); */ +/* int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ); */ -//int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ); -//int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ); +/* int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ); */ +/* int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ); */ -#endif // USE_UIL +#endif /* USE_UIL */ #ifdef USE_RTS @@ -115,7 +115,7 @@ int wvlan_rts_write(__u16 reg, __u16 val, __u32 io_base); int wvlan_rts_batch_read(struct rtsreq *rrq, __u32 io_base); int wvlan_rts_batch_write(struct rtsreq *rrq, __u32 io_base); -#endif // USE_RTS +#endif /* USE_RTS */ -#endif // __WL_PRIV_H__ +#endif /* __WL_PRIV_H__ */ -- cgit v0.10.2 From 30b437db2af0b07d80f8f785cb2508366477bc47 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:38 +0200 Subject: staging: wlags49_h2: wl_priv.h: fixes instances of 80+ char lines This commit corrects cases where lines where longer than 80 characters. checkpatch.pl now reports that this file has no further issues. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.h b/drivers/staging/wlags49_h2/wl_priv.h index daefc6c..f35e794 100644 --- a/drivers/staging/wlags49_h2/wl_priv.h +++ b/drivers/staging/wlags49_h2/wl_priv.h @@ -70,17 +70,23 @@ #ifdef WIRELESS_EXT -int wvlan_set_netname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); +int wvlan_set_netname(struct net_device *, struct iw_request_info *, + union iwreq_data *, char *extra); -int wvlan_get_netname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); +int wvlan_get_netname(struct net_device *, struct iw_request_info *, + union iwreq_data *, char *extra); -int wvlan_set_station_nickname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); +int wvlan_set_station_nickname(struct net_device *, struct iw_request_info *, + union iwreq_data *, char *extra); -int wvlan_get_station_nickname(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); +int wvlan_get_station_nickname(struct net_device *, struct iw_request_info *, + union iwreq_data *, char *extra); -int wvlan_set_porttype(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); +int wvlan_set_porttype(struct net_device *, struct iw_request_info *, + union iwreq_data *, char *extra); -int wvlan_get_porttype(struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra); +int wvlan_get_porttype(struct net_device *, struct iw_request_info *, + union iwreq_data *, char *extra); #endif /* WIRELESS_EXT */ -- cgit v0.10.2 From 2dddc56293a4c03a8fe549089aee21f9e63b60c7 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:39 +0200 Subject: staging: wlags49_h2: wl_netdev.h: converts C99 // comments This commit converts C99 // comments to /* */ Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_netdev.h b/drivers/staging/wlags49_h2/wl_netdev.h index 61f040f..78a7057 100644 --- a/drivers/staging/wlags49_h2/wl_netdev.h +++ b/drivers/staging/wlags49_h2/wl_netdev.h @@ -102,7 +102,7 @@ int wl_rx_dma( struct net_device *dev ); void wl_multicast( struct net_device *dev ); #else void wl_multicast( struct net_device *dev, int num_addrs, void *addrs ); -#endif // NEW_MULTICAST +#endif /* NEW_MULTICAST */ int wl_tx_port0( struct sk_buff *skb, struct net_device *dev ); @@ -151,4 +151,4 @@ void wl_wds_netif_carrier_off( struct wl_private *lp ); #endif /* USE_WDS */ -#endif // __WL_NETDEV_H__ +#endif /* __WL_NETDEV_H__ */ -- cgit v0.10.2 From 79249c4b22a56fda44623f449a2893f25629a7d1 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:40 +0200 Subject: staging: wlags49_h2: wl_netdev.h: sorts out spacing issues This commit fixes issues regarding spacing around parentheses. The checkpatch.pl tool reports that this file has no further styling issues. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_netdev.h b/drivers/staging/wlags49_h2/wl_netdev.h index 78a7057..95bfbeb 100644 --- a/drivers/staging/wlags49_h2/wl_netdev.h +++ b/drivers/staging/wlags49_h2/wl_netdev.h @@ -68,85 +68,85 @@ /******************************************************************************* * function prototypes ******************************************************************************/ -int wl_init( struct net_device *dev ); +int wl_init(struct net_device *dev); -int wl_config( struct net_device *dev, struct ifmap *map ); +int wl_config(struct net_device *dev, struct ifmap *map); -struct net_device *wl_device_alloc( void ); +struct net_device *wl_device_alloc(void); -void wl_device_dealloc( struct net_device *dev ); +void wl_device_dealloc(struct net_device *dev); -int wl_open( struct net_device *dev ); +int wl_open(struct net_device *dev); -int wl_close( struct net_device *dev ); +int wl_close(struct net_device *dev); -int wl_ioctl( struct net_device *dev, struct ifreq *rq, int cmd ); +int wl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); -int wl_tx( struct sk_buff *skb, struct net_device *dev, int port ); +int wl_tx(struct sk_buff *skb, struct net_device *dev, int port); -int wl_send( struct wl_private *lp ); +int wl_send(struct wl_private *lp); -int wl_rx( struct net_device *dev ); +int wl_rx(struct net_device *dev); -void wl_tx_timeout( struct net_device *dev ); +void wl_tx_timeout(struct net_device *dev); -struct net_device_stats *wl_stats( struct net_device *dev ); +struct net_device_stats *wl_stats(struct net_device *dev); #ifdef ENABLE_DMA -int wl_send_dma( struct wl_private *lp, struct sk_buff *skb, int port ); -int wl_rx_dma( struct net_device *dev ); +int wl_send_dma(struct wl_private *lp, struct sk_buff *skb, int port); +int wl_rx_dma(struct net_device *dev); #endif #ifdef NEW_MULTICAST -void wl_multicast( struct net_device *dev ); +void wl_multicast(struct net_device *dev); #else -void wl_multicast( struct net_device *dev, int num_addrs, void *addrs ); +void wl_multicast(struct net_device *dev, int num_addrs, void *addrs); #endif /* NEW_MULTICAST */ -int wl_tx_port0( struct sk_buff *skb, struct net_device *dev ); +int wl_tx_port0(struct sk_buff *skb, struct net_device *dev); #ifdef USE_WDS -int wl_tx_port1( struct sk_buff *skb, struct net_device *dev ); -int wl_tx_port2( struct sk_buff *skb, struct net_device *dev ); -int wl_tx_port3( struct sk_buff *skb, struct net_device *dev ); -int wl_tx_port4( struct sk_buff *skb, struct net_device *dev ); -int wl_tx_port5( struct sk_buff *skb, struct net_device *dev ); -int wl_tx_port6( struct sk_buff *skb, struct net_device *dev ); - -void wl_wds_device_alloc( struct wl_private *lp ); -void wl_wds_device_dealloc( struct wl_private *lp ); -void wl_wds_netif_start_queue( struct wl_private *lp ); -void wl_wds_netif_stop_queue( struct wl_private *lp ); -void wl_wds_netif_wake_queue( struct wl_private *lp ); -void wl_wds_netif_carrier_on( struct wl_private *lp ); -void wl_wds_netif_carrier_off( struct wl_private *lp ); +int wl_tx_port1(struct sk_buff *skb, struct net_device *dev); +int wl_tx_port2(struct sk_buff *skb, struct net_device *dev); +int wl_tx_port3(struct sk_buff *skb, struct net_device *dev); +int wl_tx_port4(struct sk_buff *skb, struct net_device *dev); +int wl_tx_port5(struct sk_buff *skb, struct net_device *dev); +int wl_tx_port6(struct sk_buff *skb, struct net_device *dev); + +void wl_wds_device_alloc(struct wl_private *lp); +void wl_wds_device_dealloc(struct wl_private *lp); +void wl_wds_netif_start_queue(struct wl_private *lp); +void wl_wds_netif_stop_queue(struct wl_private *lp); +void wl_wds_netif_wake_queue(struct wl_private *lp); +void wl_wds_netif_carrier_on(struct wl_private *lp); +void wl_wds_netif_carrier_off(struct wl_private *lp); #endif /* USE_WDS */ #ifdef USE_WDS -#define WL_WDS_DEVICE_ALLOC( ARG ) wl_wds_device_alloc( ARG ) -#define WL_WDS_DEVICE_DEALLOC( ARG ) wl_wds_device_dealloc( ARG ) -#define WL_WDS_NETIF_START_QUEUE( ARG ) wl_wds_netif_start_queue( ARG ) -#define WL_WDS_NETIF_STOP_QUEUE( ARG ) wl_wds_netif_stop_queue( ARG ) -#define WL_WDS_NETIF_WAKE_QUEUE( ARG ) wl_wds_netif_wake_queue( ARG ) -#define WL_WDS_NETIF_CARRIER_ON( ARG ) wl_wds_netif_carrier_on( ARG ) -#define WL_WDS_NETIF_CARRIER_OFF( ARG ) wl_wds_netif_carrier_off( ARG ) +#define WL_WDS_DEVICE_ALLOC(ARG) wl_wds_device_alloc(ARG) +#define WL_WDS_DEVICE_DEALLOC(ARG) wl_wds_device_dealloc(ARG) +#define WL_WDS_NETIF_START_QUEUE(ARG) wl_wds_netif_start_queue(ARG) +#define WL_WDS_NETIF_STOP_QUEUE(ARG) wl_wds_netif_stop_queue(ARG) +#define WL_WDS_NETIF_WAKE_QUEUE(ARG) wl_wds_netif_wake_queue(ARG) +#define WL_WDS_NETIF_CARRIER_ON(ARG) wl_wds_netif_carrier_on(ARG) +#define WL_WDS_NETIF_CARRIER_OFF(ARG) wl_wds_netif_carrier_off(ARG) #else -#define WL_WDS_DEVICE_ALLOC( ARG ) -#define WL_WDS_DEVICE_DEALLOC( ARG ) -#define WL_WDS_NETIF_START_QUEUE( ARG ) -#define WL_WDS_NETIF_STOP_QUEUE( ARG ) -#define WL_WDS_NETIF_WAKE_QUEUE( ARG ) -#define WL_WDS_NETIF_CARRIER_ON( ARG ) -#define WL_WDS_NETIF_CARRIER_OFF( ARG ) +#define WL_WDS_DEVICE_ALLOC(ARG) +#define WL_WDS_DEVICE_DEALLOC(ARG) +#define WL_WDS_NETIF_START_QUEUE(ARG) +#define WL_WDS_NETIF_STOP_QUEUE(ARG) +#define WL_WDS_NETIF_WAKE_QUEUE(ARG) +#define WL_WDS_NETIF_CARRIER_ON(ARG) +#define WL_WDS_NETIF_CARRIER_OFF(ARG) #endif /* USE_WDS */ -- cgit v0.10.2 From 497d4140abb8584bdbe86ea75fcd84b847acccee Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:41 +0200 Subject: staging: wlags49_h2: sta_h2: fixes spaces-before-tabs problems This commit various cases where there were spaces before tabs, as reported by the checkpatch.pl tool. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/sta_h2.c b/drivers/staging/wlags49_h2/sta_h2.c index 00dffe2..6fc61ba 100644 --- a/drivers/staging/wlags49_h2/sta_h2.c +++ b/drivers/staging/wlags49_h2/sta_h2.c @@ -25,10 +25,10 @@ */ -#include "hcfcfg.h" // to get hcf_16 etc defined as well as - // possible settings which influence mdd.h or dhf.h -#include "mdd.h" //to get COMP_ID_STA etc defined -#include "dhf.h" //used to be "fhfmem.h", to get memblock,plugrecord, +#include "hcfcfg.h" // to get hcf_16 etc defined as well as + // possible settings which influence mdd.h or dhf.h +#include "mdd.h" // to get COMP_ID_STA etc defined +#include "dhf.h" // used to be "fhfmem.h", to get memblock,plugrecord, static const hcf_8 fw_image_1_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -4433,7 +4433,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { CFG_PROG, CFG_PROG_STOP, // mode 0000, - 0x000F368E, // Start execution address + 0x000F368E, // Start execution address }, { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000} }; @@ -4444,7 +4444,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_SUPL, COMP_ID_STA, { - { 2, 2, 5 } //variant, bottom, top + { 2, 2, 5 } //variant, bottom, top } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4452,9 +4452,9 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_MFI, { - { 4, 6, 7 }, //variant, bottom, top - { 5, 6, 7 }, //variant, bottom, top - { 6, 6, 7 } //variant, bottom, top + { 4, 6, 7 }, //variant, bottom, top + { 5, 6, 7 }, //variant, bottom, top + { 6, 6, 7 } //variant, bottom, top } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4462,7 +4462,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_CFI, { - { 2, 1, 2 } //variant, bottom, top + { 2, 1, 2 } //variant, bottom, top } }, { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel -- cgit v0.10.2 From b7a5b4760f0631fcf6c7e64b9b4fa4c59d73c597 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:42 +0200 Subject: staging: wlags49_h2: sta_h2: fixes malformed #include filename This minor change simply removes quotations from within a comment so that the checkpatch.pl tool won't complain about a malformed include filename anymore. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/sta_h2.c b/drivers/staging/wlags49_h2/sta_h2.c index 6fc61ba..7c50ccd 100644 --- a/drivers/staging/wlags49_h2/sta_h2.c +++ b/drivers/staging/wlags49_h2/sta_h2.c @@ -28,7 +28,7 @@ #include "hcfcfg.h" // to get hcf_16 etc defined as well as // possible settings which influence mdd.h or dhf.h #include "mdd.h" // to get COMP_ID_STA etc defined -#include "dhf.h" // used to be "fhfmem.h", to get memblock,plugrecord, +#include "dhf.h" // used to be fhfmem.h, to get memblock,plugrecord, static const hcf_8 fw_image_1_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -- cgit v0.10.2 From d641f1648863a47902a5cac048e5c8a3cfdaa9fc Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:43 +0200 Subject: staging: wlags49_h2: sta_h2: fixes spaces around parentheses This commit fixes an instance where the spacing around parentheses was incorrect. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/sta_h2.c b/drivers/staging/wlags49_h2/sta_h2.c index 7c50ccd..711c7e0 100644 --- a/drivers/staging/wlags49_h2/sta_h2.c +++ b/drivers/staging/wlags49_h2/sta_h2.c @@ -4381,7 +4381,7 @@ static const hcf_8 fw_image_4_data[] = { static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = { { - sizeof( CFG_IDENTITY_STRCT ) / sizeof(hcf_16) - 1, + sizeof(CFG_IDENTITY_STRCT) / sizeof(hcf_16) - 1, CFG_FW_IDENTITY, COMP_ID_FW_STA, 3, //Variant -- cgit v0.10.2 From de199db35ed06b8f1009d04c197b09fede3a5277 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:44 +0200 Subject: staging: wlags49_h2: sta_h2: fixes casting style issue This commit cleans up a styling issue when casting to "hcf_8 *". Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/sta_h2.c b/drivers/staging/wlags49_h2/sta_h2.c index 711c7e0..f0991c4 100644 --- a/drivers/staging/wlags49_h2/sta_h2.c +++ b/drivers/staging/wlags49_h2/sta_h2.c @@ -4399,7 +4399,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x0186, // sizeof(fw_image_1_data), 0x00000060, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_1_data + (hcf_8 *)fw_image_1_data }, { 8, @@ -4408,7 +4408,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x2518, // sizeof(fw_image_2_data), 0x00000C16, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_2_data + (hcf_8 *)fw_image_2_data }, { 8, @@ -4417,7 +4417,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0x3daa, // sizeof(fw_image_3_data), 0x001E312E, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_3_data + (hcf_8 *)fw_image_3_data }, { 8, @@ -4426,7 +4426,7 @@ static const CFG_PROG_STRCT fw_image_code[] = { 0xaa66, // sizeof(fw_image_4_data), 0x001F4000, // Target address in NIC Memory 0x0000, // CRC: yes/no TYPE: primary/station/tertiary - (hcf_8 FAR *) fw_image_4_data + (hcf_8 *)fw_image_4_data }, { 5, -- cgit v0.10.2 From 61fc9c89b2dd6687a275a031ccc10b3dca483e42 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:45 +0200 Subject: staging: wlags49_h2: sta_h2: corrects C99 // comments This commit converts C99 // comments to /* */ Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/sta_h2.c b/drivers/staging/wlags49_h2/sta_h2.c index f0991c4..19bed81 100644 --- a/drivers/staging/wlags49_h2/sta_h2.c +++ b/drivers/staging/wlags49_h2/sta_h2.c @@ -25,10 +25,10 @@ */ -#include "hcfcfg.h" // to get hcf_16 etc defined as well as - // possible settings which influence mdd.h or dhf.h -#include "mdd.h" // to get COMP_ID_STA etc defined -#include "dhf.h" // used to be fhfmem.h, to get memblock,plugrecord, +#include "hcfcfg.h" /* to get hcf_16 etc defined as well as */ + /* possible settings which influence mdd.h or dhf.h */ +#include "mdd.h" /* to get COMP_ID_STA etc defined */ +#include "dhf.h" /* used to be fhfmem.h, to get memblock,plugrecord, */ static const hcf_8 fw_image_1_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -4384,56 +4384,56 @@ static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = { sizeof(CFG_IDENTITY_STRCT) / sizeof(hcf_16) - 1, CFG_FW_IDENTITY, COMP_ID_FW_STA, - 3, //Variant - 2, //Major - 36 //Minor + 3, /* Variant */ + 2, /* Major */ + 36 /* Minor */ }, - { 0000, 0000, 0000, 0000, 0000, 0000 } //endsentinel + { 0000, 0000, 0000, 0000, 0000, 0000 } /* endsentinel */ }; static const CFG_PROG_STRCT fw_image_code[] = { { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0x0186, // sizeof(fw_image_1_data), - 0x00000060, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0x0186, /* sizeof(fw_image_1_data), */ + 0x00000060, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_1_data }, { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0x2518, // sizeof(fw_image_2_data), - 0x00000C16, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0x2518, /* sizeof(fw_image_2_data), */ + 0x00000C16, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_2_data }, { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0x3daa, // sizeof(fw_image_3_data), - 0x001E312E, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0x3daa, /* sizeof(fw_image_3_data), */ + 0x001E312E, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_3_data }, { 8, CFG_PROG, - CFG_PROG_VOLATILE, // mode - 0xaa66, // sizeof(fw_image_4_data), - 0x001F4000, // Target address in NIC Memory - 0x0000, // CRC: yes/no TYPE: primary/station/tertiary + CFG_PROG_VOLATILE, /* mode */ + 0xaa66, /* sizeof(fw_image_4_data), */ + 0x001F4000, /* Target address in NIC Memory */ + 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ (hcf_8 *)fw_image_4_data }, { 5, CFG_PROG, - CFG_PROG_STOP, // mode + CFG_PROG_STOP, /* mode */ 0000, - 0x000F368E, // Start execution address + 0x000F368E, /* Start execution address */ }, { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000} }; @@ -4444,7 +4444,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_SUPL, COMP_ID_STA, { - { 2, 2, 5 } //variant, bottom, top + { 2, 2, 5 } /* variant, bottom, top */ } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4452,9 +4452,9 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_MFI, { - { 4, 6, 7 }, //variant, bottom, top - { 5, 6, 7 }, //variant, bottom, top - { 6, 6, 7 } //variant, bottom, top + { 4, 6, 7 }, /* variant, bottom, top */ + { 5, 6, 7 }, /* variant, bottom, top */ + { 6, 6, 7 } /* variant, bottom, top */ } }, { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), @@ -4462,18 +4462,18 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = { COMP_ROLE_ACT, COMP_ID_CFI, { - { 2, 1, 2 } //variant, bottom, top + { 2, 1, 2 } /* variant, bottom, top */ } }, - { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel + { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } /* endsentinel */ }; memimage fw_image = { - "FUPU7D37dhfwci\001C", //signature, , C/Bin type + "FUPU7D37dhfwci\001C", /* signature, , C/Bin type */ (CFG_PROG_STRCT *) fw_image_code, 0x000F368E, - 00000000, //(dummy) pdaplug - 00000000, //(dummy) priplug + 00000000, /* (dummy) pdaplug */ + 00000000, /* (dummy) priplug */ (CFG_RANGE20_STRCT *) fw_image_infocompat, (CFG_IDENTITY_STRCT *) fw_image_infoidentity, }; -- cgit v0.10.2 From 580dccd974cb28a5fdf9b2f90efd8fb930334e3a Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:46 +0200 Subject: staging: wlags49_h2: wl_profile.h: fixes spacing around parentheses This commit cleans up the spacing around parentheses. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_profile.h b/drivers/staging/wlags49_h2/wl_profile.h index f81df51..12faba2 100644 --- a/drivers/staging/wlags49_h2/wl_profile.h +++ b/drivers/staging/wlags49_h2/wl_profile.h @@ -73,15 +73,15 @@ /******************************************************************************* * function prototypes ******************************************************************************/ -void parse_config( struct net_device *dev ); +void parse_config(struct net_device *dev); -int readline( int filedesc, char *buffer ); +int readline(int filedesc, char *buffer); -void translate_option( char *buffer, struct wl_private *lp ); +void translate_option(char *buffer, struct wl_private *lp); -int parse_mac_address( char *value, u_char *byte_array ); +int parse_mac_address(char *value, u_char *byte_array); -void ParseConfigLine( char *pszLine, char **ppszLVal, char **ppszRVal ); +void ParseConfigLine(char *pszLine, char **ppszLVal, char **ppszRVal); #endif // __WL_PROFILE_H__ -- cgit v0.10.2 From ba4126a7cd9568dd5587f400a769b923a6a09a35 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:47 +0200 Subject: staging: wlags49_h2: wl_profile.h: fixes C99 // comment This commit converts a C99 // comment to /* */. The checkpatch.pl tool reports that this file has no further styling issues. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_profile.h b/drivers/staging/wlags49_h2/wl_profile.h index 12faba2..d615c83 100644 --- a/drivers/staging/wlags49_h2/wl_profile.h +++ b/drivers/staging/wlags49_h2/wl_profile.h @@ -84,4 +84,4 @@ int parse_mac_address(char *value, u_char *byte_array); void ParseConfigLine(char *pszLine, char **ppszLVal, char **ppszRVal); -#endif // __WL_PROFILE_H__ +#endif /* __WL_PROFILE_H__ */ -- cgit v0.10.2 From ceb121ae22a4c24f3382145e9407ef7322b7cd1c Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:48 +0200 Subject: staging: wlags49_h2: wl_priv: fixes spacing around parentheses This commit fixes many instances where the spacing in and around parentheses was applied incorrectly. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index 87e1e41..df2525f 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -81,17 +81,17 @@ #include #include -int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ); -int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ); +int wvlan_uil_connect(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_disconnect(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_action(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_block(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_unblock(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp); +int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp); -int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ); -int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ); +int cfg_driver_info(struct uilreq *urq, struct wl_private *lp); +int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp); /******************************************************************************* @@ -127,45 +127,45 @@ extern dbg_info_t *DbgInfo; * errno value otherwise * ******************************************************************************/ -int wvlan_uil( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil(struct uilreq *urq, struct wl_private *lp) { int ioctl_ret = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil"); + DBG_ENTER(DbgInfo); - switch( urq->command ) { + switch(urq->command) { case UIL_FUN_CONNECT: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_CONNECT\n"); - ioctl_ret = wvlan_uil_connect( urq, lp ); + ioctl_ret = wvlan_uil_connect(urq, lp); break; case UIL_FUN_DISCONNECT: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_DISCONNECT\n"); - ioctl_ret = wvlan_uil_disconnect( urq, lp ); + ioctl_ret = wvlan_uil_disconnect(urq, lp); break; case UIL_FUN_ACTION: - DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_ACTION\n" ); - ioctl_ret = wvlan_uil_action( urq, lp ); + DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_ACTION\n"); + ioctl_ret = wvlan_uil_action(urq, lp); break; case UIL_FUN_SEND_DIAG_MSG: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_SEND_DIAG_MSG\n"); - ioctl_ret = wvlan_uil_send_diag_msg( urq, lp ); + ioctl_ret = wvlan_uil_send_diag_msg(urq, lp); break; case UIL_FUN_GET_INFO: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_GET_INFO\n"); - ioctl_ret = wvlan_uil_get_info( urq, lp ); + ioctl_ret = wvlan_uil_get_info(urq, lp); break; case UIL_FUN_PUT_INFO: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_PUT_INFO\n"); - ioctl_ret = wvlan_uil_put_info( urq, lp ); + ioctl_ret = wvlan_uil_put_info(urq, lp); break; default: - DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- UNSUPPORTED UIL CODE: 0x%X", urq->command ); + DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- UNSUPPORTED UIL CODE: 0x%X", urq->command); ioctl_ret = -EOPNOTSUPP; break; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ioctl_ret; } // wvlan_uil /*============================================================================*/ @@ -192,26 +192,26 @@ int wvlan_uil( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_connect(struct uilreq *urq, struct wl_private *lp) { int result = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_connect" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_connect"); + DBG_ENTER(DbgInfo); - if( !( lp->flags & WVLAN2_UIL_CONNECTED )) { + if(!(lp->flags & WVLAN2_UIL_CONNECTED)) { lp->flags |= WVLAN2_UIL_CONNECTED; - urq->hcfCtx = &( lp->hcfCtx ); + urq->hcfCtx = &(lp->hcfCtx); urq->result = UIL_SUCCESS; } else { - DBG_WARNING( DbgInfo, "UIL_ERR_IN_USE\n" ); + DBG_WARNING(DbgInfo, "UIL_ERR_IN_USE\n"); urq->result = UIL_ERR_IN_USE; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_connect /*============================================================================*/ @@ -238,17 +238,17 @@ int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_disconnect(struct uilreq *urq, struct wl_private *lp) { int result = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_disconnect" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_disconnect"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { if (lp->flags & WVLAN2_UIL_CONNECTED) { lp->flags &= ~WVLAN2_UIL_CONNECTED; /* @@ -262,11 +262,11 @@ int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ) urq->hcfCtx = NULL; urq->result = UIL_SUCCESS; } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_disconnect /*============================================================================*/ @@ -293,58 +293,58 @@ int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_action(struct uilreq *urq, struct wl_private *lp) { int result = 0; ltv_t *ltv; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_action" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_action"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { /* Make sure there's an LTV in the request buffer */ ltv = (ltv_t *)urq->data; - if( ltv != NULL ) { + if(ltv != NULL) { /* Switch on the Type field of the LTV contained in the request buffer */ - switch( ltv->typ ) { + switch(ltv->typ) { case UIL_ACT_BLOCK: - DBG_TRACE( DbgInfo, "UIL_ACT_BLOCK\n" ); - result = wvlan_uil_block( urq, lp ); + DBG_TRACE(DbgInfo, "UIL_ACT_BLOCK\n"); + result = wvlan_uil_block(urq, lp); break; case UIL_ACT_UNBLOCK: - DBG_TRACE( DbgInfo, "UIL_ACT_UNBLOCK\n" ); - result = wvlan_uil_unblock( urq, lp ); + DBG_TRACE(DbgInfo, "UIL_ACT_UNBLOCK\n"); + result = wvlan_uil_unblock(urq, lp); break; case UIL_ACT_SCAN: - DBG_TRACE( DbgInfo, "UIL_ACT_SCAN\n" ); - urq->result = hcf_action( &( lp->hcfCtx ), MDD_ACT_SCAN ); + DBG_TRACE(DbgInfo, "UIL_ACT_SCAN\n"); + urq->result = hcf_action(&(lp->hcfCtx), MDD_ACT_SCAN); break; case UIL_ACT_APPLY: - DBG_TRACE( DbgInfo, "UIL_ACT_APPLY\n" ); - urq->result = wl_apply( lp ); + DBG_TRACE(DbgInfo, "UIL_ACT_APPLY\n"); + urq->result = wl_apply(lp); break; case UIL_ACT_RESET: - DBG_TRACE( DbgInfo, "UIL_ACT_RESET\n" ); - urq->result = wl_go( lp ); + DBG_TRACE(DbgInfo, "UIL_ACT_RESET\n"); + urq->result = wl_go(lp); break; default: - DBG_WARNING( DbgInfo, "Unknown action code: 0x%x\n", ltv->typ ); + DBG_WARNING(DbgInfo, "Unknown action code: 0x%x\n", ltv->typ); break; } } else { - DBG_ERROR( DbgInfo, "Bad LTV for this action\n" ); + DBG_ERROR(DbgInfo, "Bad LTV for this action\n"); urq->result = UIL_ERR_LEN; } } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_action /*============================================================================*/ @@ -373,32 +373,32 @@ int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ) * ******************************************************************************/ -int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_block(struct uilreq *urq, struct wl_private *lp) { int result = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_block" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_block"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { - if( capable( CAP_NET_ADMIN )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { + if(capable(CAP_NET_ADMIN)) { lp->flags |= WVLAN2_UIL_BUSY; netif_stop_queue(lp->dev); - WL_WDS_NETIF_STOP_QUEUE( lp ); + WL_WDS_NETIF_STOP_QUEUE(lp); urq->result = UIL_SUCCESS; } else { - DBG_ERROR( DbgInfo, "EPERM\n" ); + DBG_ERROR(DbgInfo, "EPERM\n"); urq->result = UIL_FAILURE; result = -EPERM; } } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_block /*============================================================================*/ @@ -425,33 +425,33 @@ int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_unblock(struct uilreq *urq, struct wl_private *lp) { int result = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_unblock" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_unblock"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { - if( capable( CAP_NET_ADMIN )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { + if(capable(CAP_NET_ADMIN)) { if (lp->flags & WVLAN2_UIL_BUSY) { lp->flags &= ~WVLAN2_UIL_BUSY; netif_wake_queue(lp->dev); - WL_WDS_NETIF_WAKE_QUEUE( lp ); + WL_WDS_NETIF_WAKE_QUEUE(lp); } } else { - DBG_ERROR( DbgInfo, "EPERM\n" ); + DBG_ERROR(DbgInfo, "EPERM\n"); urq->result = UIL_FAILURE; result = -EPERM; } } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_unblock /*============================================================================*/ @@ -478,18 +478,18 @@ int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp) { int result = 0; DESC_STRCT Descp[1]; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_send_diag_msg" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_send_diag_msg"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { - if( capable( CAP_NET_ADMIN )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { + if(capable(CAP_NET_ADMIN)) { if ((urq->data != NULL) && (urq->len != 0)) { if (lp->hcfCtx.IFB_RscInd != 0) { u_char *data; @@ -497,28 +497,28 @@ int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ) // Verify the user buffer result = verify_area(VERIFY_READ, urq->data, urq->len); if (result != 0) { - DBG_ERROR( DbgInfo, "verify_area failed, result: %d\n", result ); + DBG_ERROR(DbgInfo, "verify_area failed, result: %d\n", result); urq->result = UIL_FAILURE; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } data = kmalloc(urq->len, GFP_KERNEL); if (data != NULL) { - memset( Descp, 0, sizeof( DESC_STRCT )); - memcpy( data, urq->data, urq->len ); + memset(Descp, 0, sizeof(DESC_STRCT)); + memcpy(data, urq->data, urq->len); Descp[0].buf_addr = (wci_bufp)data; Descp[0].BUF_CNT = urq->len; Descp[0].next_desc_addr = 0; // terminate list - hcf_send_msg( &(lp->hcfCtx), &Descp[0], HCF_PORT_0 ); - kfree( data ); + hcf_send_msg(&(lp->hcfCtx), &Descp[0], HCF_PORT_0); + kfree(data); } else { - DBG_ERROR( DbgInfo, "ENOMEM\n" ); + DBG_ERROR(DbgInfo, "ENOMEM\n"); urq->result = UIL_FAILURE; result = -ENOMEM; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } @@ -530,16 +530,16 @@ int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ) urq->result = UIL_FAILURE; } } else { - DBG_ERROR( DbgInfo, "EPERM\n" ); + DBG_ERROR(DbgInfo, "EPERM\n"); urq->result = UIL_FAILURE; result = -EPERM; } } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_send_diag_msg /*============================================================================*/ @@ -564,7 +564,7 @@ int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) { int result = 0; ltv_t *pLtv; @@ -575,94 +575,94 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) hcf_16 hcfPort = HCF_PORT_0; #endif /* USE_WDS */ /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_put_info" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_put_info"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { - if( capable( CAP_NET_ADMIN )) { - if(( urq->data != NULL ) && ( urq->len != 0 )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { + if(capable(CAP_NET_ADMIN)) { + if((urq->data != NULL) && (urq->len != 0)) { /* Make sure that we have at least a command and length to send. */ - if( urq->len < ( sizeof( hcf_16 ) * 2 )) { - urq->len = sizeof( lp->ltvRecord ); + if(urq->len < (sizeof(hcf_16) * 2)) { + urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; - DBG_ERROR( DbgInfo, "No Length/Type in LTV!!!\n" ); - DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); - DBG_LEAVE( DbgInfo ); + DBG_ERROR(DbgInfo, "No Length/Type in LTV!!!\n"); + DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n"); + DBG_LEAVE(DbgInfo); return result; } /* Verify the user buffer */ - result = verify_area( VERIFY_READ, urq->data, urq->len ); - if( result != 0 ) { + result = verify_area(VERIFY_READ, urq->data, urq->len); + if(result != 0) { urq->result = UIL_FAILURE; - DBG_ERROR( DbgInfo, "verify_area(), VERIFY_READ FAILED\n" ); - DBG_LEAVE( DbgInfo ); + DBG_ERROR(DbgInfo, "verify_area(), VERIFY_READ FAILED\n"); + DBG_LEAVE(DbgInfo); return result; } /* Get only the command and length information. */ - copy_from_user( &( lp->ltvRecord ), urq->data, sizeof( hcf_16 ) * 2 ); + copy_from_user(&(lp->ltvRecord), urq->data, sizeof(hcf_16) * 2); /* Make sure the incoming LTV record length is within the bounds of the IOCTL length */ - if((( lp->ltvRecord.len + 1 ) * sizeof( hcf_16 )) > urq->len ) { - urq->len = sizeof( lp->ltvRecord ); + if(((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) { + urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; - DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); - DBG_LEAVE( DbgInfo ); + DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n"); + DBG_LEAVE(DbgInfo); return result; } /* If the requested length is greater than the size of our local LTV record, try to allocate it from the kernel stack. Otherwise, we just use our local LTV record. */ - if( urq->len > sizeof( lp->ltvRecord )) { + if(urq->len > sizeof(lp->ltvRecord)) { pLtv = kmalloc(urq->len, GFP_KERNEL); if (pLtv != NULL) { ltvAllocated = TRUE; } else { - DBG_ERROR( DbgInfo, "Alloc FAILED\n" ); - urq->len = sizeof( lp->ltvRecord ); + DBG_ERROR(DbgInfo, "Alloc FAILED\n"); + urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; result = -ENOMEM; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } } else { - pLtv = &( lp->ltvRecord ); + pLtv = &(lp->ltvRecord); } /* Copy the data from the user's buffer into the local LTV record data area. */ - copy_from_user( pLtv, urq->data, urq->len ); + copy_from_user(pLtv, urq->data, urq->len); /* We need to snoop the commands to see if there is anything we need to store for the purposes of a reset or start/stop sequence. Perform endian translation as needed */ - switch( pLtv->typ ) { + switch(pLtv->typ) { case CFG_CNF_PORT_TYPE: lp->PortType = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_OWN_MAC_ADDR: /* TODO: determine if we are going to store anything based on this */ break; case CFG_CNF_OWN_CHANNEL: lp->Channel = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; /* CFG_CNF_OWN_SSID currently same as CNF_DESIRED_SSID. Do we need separate storage for this? */ //case CFG_CNF_OWN_SSID: case CFG_CNF_OWN_ATIM_WINDOW: lp->atimWindow = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_SYSTEM_SCALE: lp->DistanceBetweenAPs = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); case CFG_CNF_MAX_DATA_LEN: /* TODO: determine if we are going to store anything based @@ -670,55 +670,55 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) break; case CFG_CNF_PM_ENABLED: lp->PMEnabled = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_MCAST_RX: lp->MulticastReceive = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_MAX_SLEEP_DURATION: lp->MaxSleepDuration = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_HOLDOVER_DURATION: lp->holdoverDuration = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_OWN_NAME: - memset( lp->StationName, 0, sizeof( lp->StationName )); - memcpy( (void *)lp->StationName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + memset(lp->StationName, 0, sizeof(lp->StationName)); + memcpy((void *)lp->StationName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_LOAD_BALANCING: lp->loadBalancing = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_MEDIUM_DISTRIBUTION: lp->mediumDistribution = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #ifdef WARP case CFG_CNF_TX_POW_LVL: lp->txPowLevel = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; //case CFG_CNF_SHORT_RETRY_LIMIT: // Short Retry Limit //case 0xFC33: // Long Retry Limit case CFG_SUPPORTED_RATE_SET_CNTL: // Supported Rate Set Control lp->srsc[0] = pLtv->u.u16[0]; lp->srsc[1] = pLtv->u.u16[1]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); - pLtv->u.u16[1] = CNV_INT_TO_LITTLE( pLtv->u.u16[1] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); + pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]); break; case CFG_BASIC_RATE_SET_CNTL: // Basic Rate Set Control lp->brsc[0] = pLtv->u.u16[0]; lp->brsc[1] = pLtv->u.u16[1]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); - pLtv->u.u16[1] = CNV_INT_TO_LITTLE( pLtv->u.u16[1] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); + pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]); break; case CFG_CNF_CONNECTION_CNTL: lp->connectionControl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; //case CFG_PROBE_DATA_RATE: #endif // HERMES25 @@ -728,76 +728,76 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) case CFG_CNF_OWN_DTIM_PERIOD: lp->DTIMPeriod = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #ifdef WARP case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval lp->ownBeaconInterval = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #endif // WARP case CFG_COEXISTENSE_BEHAVIOUR: // Coexistence behavior lp->coexistence = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #ifdef USE_WDS case CFG_CNF_WDS_ADDR1: - memcpy( &lp->wds_port[0].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); + memcpy(&lp->wds_port[0].wdsAddress, &pLtv->u.u8[0], ETH_ALEN); hcfPort = HCF_PORT_1; break; case CFG_CNF_WDS_ADDR2: - memcpy( &lp->wds_port[1].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); + memcpy(&lp->wds_port[1].wdsAddress, &pLtv->u.u8[0], ETH_ALEN); hcfPort = HCF_PORT_2; break; case CFG_CNF_WDS_ADDR3: - memcpy( &lp->wds_port[2].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); + memcpy(&lp->wds_port[2].wdsAddress, &pLtv->u.u8[0], ETH_ALEN); hcfPort = HCF_PORT_3; break; case CFG_CNF_WDS_ADDR4: - memcpy( &lp->wds_port[3].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); + memcpy(&lp->wds_port[3].wdsAddress, &pLtv->u.u8[0], ETH_ALEN); hcfPort = HCF_PORT_4; break; case CFG_CNF_WDS_ADDR5: - memcpy( &lp->wds_port[4].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); + memcpy(&lp->wds_port[4].wdsAddress, &pLtv->u.u8[0], ETH_ALEN); hcfPort = HCF_PORT_5; break; case CFG_CNF_WDS_ADDR6: - memcpy( &lp->wds_port[5].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); + memcpy(&lp->wds_port[5].wdsAddress, &pLtv->u.u8[0], ETH_ALEN); hcfPort = HCF_PORT_6; break; #endif /* USE_WDS */ case CFG_CNF_MCAST_PM_BUF: lp->multicastPMBuffering = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_REJECT_ANY: lp->RejectAny = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #endif case CFG_CNF_ENCRYPTION: lp->EnableEncryption = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_CNF_AUTHENTICATION: lp->authentication = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #if 1 //;? (HCF_TYPE) & HCF_TYPE_AP //;?should we restore this to allow smaller memory footprint //case CFG_CNF_EXCL_UNENCRYPTED: //lp->ExcludeUnencrypted = pLtv->u.u16[0]; - //pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + //pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); //break; case CFG_CNF_MCAST_RATE: /* TODO: determine if we are going to store anything based on this */ break; case CFG_CNF_INTRA_BSS_RELAY: lp->intraBSSRelay = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #endif @@ -819,14 +819,14 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) case CFG_CNF_OWN_SSID: //case CNF_DESIRED_SSID: case CFG_DESIRED_SSID: - memset( lp->NetworkName, 0, sizeof( lp->NetworkName )); - memcpy( (void *)lp->NetworkName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0] ); - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + memset(lp->NetworkName, 0, sizeof(lp->NetworkName)); + memcpy((void *)lp->NetworkName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); /* take care of the special network name "ANY" case */ - if(( strlen( &pLtv->u.u8[2] ) == 0 ) || - ( strcmp( &pLtv->u.u8[2], "ANY" ) == 0 ) || - ( strcmp( &pLtv->u.u8[2], "any" ) == 0 )) { + if((strlen(&pLtv->u.u8[2] ) == 0) || + (strcmp(&pLtv->u.u8[2], "ANY") == 0) || + (strcmp(&pLtv->u.u8[2], "any") == 0)) { /* set the SSID_STRCT llen field (u16[0]) to zero, and the effectually null the string u8[2] */ pLtv->u.u16[0] = 0; @@ -838,17 +838,17 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) break; case CFG_CREATE_IBSS: lp->CreateIBSS = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_RTS_THRH: lp->RTSThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_TX_RATE_CNTL: lp->TxRateControl[0] = pLtv->u.u16[0]; lp->TxRateControl[1] = pLtv->u.u16[1]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); - pLtv->u.u16[1] = CNV_INT_TO_LITTLE( pLtv->u.u16[1] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); + pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]); break; case CFG_PROMISCUOUS_MODE: /* TODO: determine if we are going to store anything based on this */ @@ -860,71 +860,71 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) //;?should we restore this to allow smaller memory footprint case CFG_RTS_THRH0: lp->RTSThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_TX_RATE_CNTL0: //;?no idea what this should be, get going so comment it out lp->TxRateControl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #ifdef USE_WDS case CFG_RTS_THRH1: lp->wds_port[0].rtsThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_1; break; case CFG_RTS_THRH2: lp->wds_port[1].rtsThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_2; break; case CFG_RTS_THRH3: lp->wds_port[2].rtsThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_3; break; case CFG_RTS_THRH4: lp->wds_port[3].rtsThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_4; break; case CFG_RTS_THRH5: lp->wds_port[4].rtsThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_5; break; case CFG_RTS_THRH6: lp->wds_port[5].rtsThreshold = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_6; break; case CFG_TX_RATE_CNTL1: lp->wds_port[0].txRateCntl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_1; break; case CFG_TX_RATE_CNTL2: lp->wds_port[1].txRateCntl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_2; break; case CFG_TX_RATE_CNTL3: lp->wds_port[2].txRateCntl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_3; break; case CFG_TX_RATE_CNTL4: lp->wds_port[3].txRateCntl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_4; break; case CFG_TX_RATE_CNTL5: lp->wds_port[4].txRateCntl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_5; break; case CFG_TX_RATE_CNTL6: lp->wds_port[5].txRateCntl = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); hcfPort = HCF_PORT_6; break; #endif /* USE_WDS */ @@ -934,18 +934,18 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) { CFG_DEFAULT_KEYS_STRCT *pKeys = (CFG_DEFAULT_KEYS_STRCT *)pLtv; - pKeys->key[0].len = CNV_INT_TO_LITTLE( pKeys->key[0].len ); - pKeys->key[1].len = CNV_INT_TO_LITTLE( pKeys->key[1].len ); - pKeys->key[2].len = CNV_INT_TO_LITTLE( pKeys->key[2].len ); - pKeys->key[3].len = CNV_INT_TO_LITTLE( pKeys->key[3].len ); + pKeys->key[0].len = CNV_INT_TO_LITTLE(pKeys->key[0].len); + pKeys->key[1].len = CNV_INT_TO_LITTLE(pKeys->key[1].len); + pKeys->key[2].len = CNV_INT_TO_LITTLE(pKeys->key[2].len); + pKeys->key[3].len = CNV_INT_TO_LITTLE(pKeys->key[3].len); - memcpy( (void *)&(lp->DefaultKeys), (void *)pKeys, - sizeof( CFG_DEFAULT_KEYS_STRCT )); + memcpy((void *)&(lp->DefaultKeys), (void *)pKeys, + sizeof(CFG_DEFAULT_KEYS_STRCT)); } break; case CFG_TX_KEY_ID: lp->TransmitKeyID = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_SCAN_SSID: /* TODO: determine if we are going to store anything based on this */ @@ -1001,16 +1001,16 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) case CFG_SUPPORTED_DATA_RATES: break; case CFG_AP_MODE: -//;? lp->DownloadFirmware = ( pLtv->u.u16[0] ) + 1; - DBG_ERROR( DbgInfo, "set CFG_AP_MODE no longer supported\n" ); +//;? lp->DownloadFirmware = (pLtv->u.u16[0]) + 1; + DBG_ERROR(DbgInfo, "set CFG_AP_MODE no longer supported\n"); break; case CFG_ENCRYPT_STRING: /* TODO: ENDIAN TRANSLATION HERE??? */ - memset( lp->szEncryption, 0, sizeof( lp->szEncryption )); - memcpy( (void *)lp->szEncryption, (void *)&pLtv->u.u8[0], - ( pLtv->len * sizeof( hcf_16 )) ); - wl_wep_decode( CRYPT_CODE, &sEncryption, - lp->szEncryption ); + memset(lp->szEncryption, 0, sizeof(lp->szEncryption)); + memcpy((void *)lp->szEncryption, (void *)&pLtv->u.u8[0], + (pLtv->len * sizeof(hcf_16))); + wl_wep_decode(CRYPT_CODE, &sEncryption, + lp->szEncryption); /* the Linux driver likes to use 1-4 for the key IDs, and then convert to 0-3 when sending to the card. The Windows code @@ -1022,34 +1022,34 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) lp->TransmitKeyID = sEncryption.wTxKeyID + 1; lp->EnableEncryption = sEncryption.wEnabled; - memcpy( &lp->DefaultKeys, &sEncryption.EncStr, - sizeof( CFG_DEFAULT_KEYS_STRCT )); + memcpy(&lp->DefaultKeys, &sEncryption.EncStr, + sizeof(CFG_DEFAULT_KEYS_STRCT)); break; /*case CFG_COUNTRY_STRING: - memset( lp->countryString, 0, sizeof( lp->countryString )); - memcpy( (void *)lp->countryString, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); + memset(lp->countryString, 0, sizeof(lp->countryString)); + memcpy((void *)lp->countryString, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); break; */ case CFG_DRIVER_ENABLE: lp->driverEnable = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_WOLAS_ENABLE: lp->wolasEnable = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_SET_WPA_AUTH_KEY_MGMT_SUITE: lp->AuthKeyMgmtSuite = pLtv->u.u16[0]; - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_DISASSOCIATE_ADDR: - pLtv->u.u16[ETH_ALEN / 2] = CNV_INT_TO_LITTLE( pLtv->u.u16[ETH_ALEN / 2] ); + pLtv->u.u16[ETH_ALEN / 2] = CNV_INT_TO_LITTLE(pLtv->u.u16[ETH_ALEN / 2]); break; case CFG_ADD_TKIP_DEFAULT_KEY: case CFG_REMOVE_TKIP_DEFAULT_KEY: /* Endian convert the Tx Key Information */ - pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_ADD_TKIP_MAPPED_KEY: break; @@ -1066,7 +1066,7 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) being sent to the card, as they require a call to UIL_ACT_APPLY to take effect. Dynamic Entities will be sent immediately */ - switch( pLtv->typ ) { + switch(pLtv->typ) { case CFG_CNF_PORT_TYPE: case CFG_CNF_OWN_MAC_ADDR: case CFG_CNF_OWN_CHANNEL: @@ -1129,52 +1129,52 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) break; /* Deal with this dynamic MSF RID, as it's required for WPA */ case CFG_DRIVER_ENABLE: - if( lp->driverEnable ) { - //hcf_cntl_port( &( lp->hcfCtx ), - // HCF_PORT_ENABLE | HCF_PORT_0 ); - // //hcf_cntl( &( lp->hcfCtx ), - // // HCF_PORT_ENABLE | HCF_PORT_0 ); - //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_ENABLE ); - // //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_CONNECT ); - - hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_ENABLE | HCF_PORT_0 ); - hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_CONNECT ); + if(lp->driverEnable) { + //hcf_cntl_port(&(lp->hcfCtx), + // HCF_PORT_ENABLE | HCF_PORT_0); + // //hcf_cntl(&(lp->hcfCtx), + // // HCF_PORT_ENABLE | HCF_PORT_0); + //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_ENABLE); + // //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_CONNECT); + + hcf_cntl(&(lp->hcfCtx), HCF_CNTL_ENABLE | HCF_PORT_0); + hcf_cntl(&(lp->hcfCtx), HCF_CNTL_CONNECT); } else { - //hcf_cntl_port( &( lp->hcfCtx ), - // HCF_PORT_DISABLE | HCF_PORT_0 ); - // //hcf_cntl( &( lp->hcfCtx ), - // // HCF_PORT_DISABLE | HCF_PORT_0 ); - //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISABLE ); - // //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISCONNECT ); - - hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISABLE | HCF_PORT_0 ); - hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISCONNECT ); + //hcf_cntl_port(&(lp->hcfCtx), + // HCF_PORT_DISABLE | HCF_PORT_0); + // //hcf_cntl(&(lp->hcfCtx), + // // HCF_PORT_DISABLE | HCF_PORT_0); + //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISABLE); + // //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISCONNECT); + + hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISABLE | HCF_PORT_0); + hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISCONNECT); } break; default: - wl_act_int_off( lp ); + wl_act_int_off(lp); urq->result = hcf_put_info(&(lp->hcfCtx), (LTVP) pLtv); - wl_act_int_on( lp ); + wl_act_int_on(lp); break; } - if( ltvAllocated ) { - kfree( pLtv ); + if(ltvAllocated) { + kfree(pLtv); } } else { urq->result = UIL_FAILURE; } } else { - DBG_ERROR( DbgInfo, "EPERM\n" ); + DBG_ERROR(DbgInfo, "EPERM\n"); urq->result = UIL_FAILURE; result = -EPERM; } } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_put_info /*============================================================================*/ @@ -1199,64 +1199,64 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) +int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) { int result = 0; int i; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_uil_get_info" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_uil_get_info"); + DBG_ENTER(DbgInfo); - if( urq->hcfCtx == &( lp->hcfCtx )) { - if(( urq->data != NULL ) && ( urq->len != 0 )) { + if(urq->hcfCtx == &(lp->hcfCtx)) { + if((urq->data != NULL) && (urq->len != 0)) { ltv_t *pLtv; bool_t ltvAllocated = FALSE; /* Make sure that we have at least a command and length */ - if( urq->len < ( sizeof( hcf_16 ) * 2 )) { - urq->len = sizeof( lp->ltvRecord ); - DBG_ERROR( DbgInfo, "No Length/Type in LTV!!!\n" ); - DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); + if(urq->len < (sizeof(hcf_16) * 2)) { + urq->len = sizeof(lp->ltvRecord); + DBG_ERROR(DbgInfo, "No Length/Type in LTV!!!\n"); + DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n"); urq->result = UIL_ERR_LEN; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } /* Verify the user's LTV record header. */ - result = verify_area( VERIFY_READ, urq->data, sizeof( hcf_16 ) * 2 ); - if( result != 0 ) { - DBG_ERROR( DbgInfo, "verify_area(), VERIFY_READ FAILED\n" ); + result = verify_area(VERIFY_READ, urq->data, sizeof(hcf_16) * 2); + if(result != 0) { + DBG_ERROR(DbgInfo, "verify_area(), VERIFY_READ FAILED\n"); urq->result = UIL_FAILURE; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } /* Get only the command and length information. */ - result = copy_from_user( &( lp->ltvRecord ), urq->data, sizeof( hcf_16 ) * 2 ); + result = copy_from_user(&(lp->ltvRecord), urq->data, sizeof(hcf_16) * 2); /* Make sure the incoming LTV record length is within the bounds of the IOCTL length. */ - if((( lp->ltvRecord.len + 1 ) * sizeof( hcf_16 )) > urq->len ) { - DBG_ERROR( DbgInfo, "Incoming LTV too big\n" ); - urq->len = sizeof( lp->ltvRecord ); + if(((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) { + DBG_ERROR(DbgInfo, "Incoming LTV too big\n"); + urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } /* Determine if hcf_get_info() is needed or not */ - switch ( lp->ltvRecord.typ ) { + switch (lp->ltvRecord.typ) { case CFG_NIC_IDENTITY: - memcpy( &lp->ltvRecord.u.u8[0], &lp->NICIdentity, sizeof( lp->NICIdentity )); + memcpy(&lp->ltvRecord.u.u8[0], &lp->NICIdentity, sizeof(lp->NICIdentity)); break; case CFG_PRI_IDENTITY: - memcpy( &lp->ltvRecord.u.u8[0], &lp->PrimaryIdentity, sizeof( lp->PrimaryIdentity )); + memcpy(&lp->ltvRecord.u.u8[0], &lp->PrimaryIdentity, sizeof(lp->PrimaryIdentity)); break; case CFG_AP_MODE: - DBG_ERROR( DbgInfo, "set CFG_AP_MODE no longer supported, so is get useful ????\n" ); + DBG_ERROR(DbgInfo, "set CFG_AP_MODE no longer supported, so is get useful ????\n"); lp->ltvRecord.u.u16[0] = - CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_AP; + CNV_INT_TO_LITTLE(lp->hcfCtx.IFB_FWIdentity.comp_id) == COMP_ID_FW_AP; break; //case CFG_DRV_INFO: case CFG_ENCRYPT_STRING: @@ -1267,16 +1267,16 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) urq->result = UIL_FAILURE; break; case CFG_DRV_INFO: - DBG_TRACE( DbgInfo, "Intercept CFG_DRV_INFO\n" ); - result = cfg_driver_info( urq, lp ); + DBG_TRACE(DbgInfo, "Intercept CFG_DRV_INFO\n"); + result = cfg_driver_info(urq, lp); break; case CFG_DRV_IDENTITY: - DBG_TRACE( DbgInfo, "Intercept CFG_DRV_IDENTITY\n" ); - result = cfg_driver_identity( urq, lp ); + DBG_TRACE(DbgInfo, "Intercept CFG_DRV_IDENTITY\n"); + result = cfg_driver_identity(urq, lp); break; case CFG_IFB: /* IFB can be a security hole */ - if( !capable( CAP_NET_ADMIN )) { + if(!capable(CAP_NET_ADMIN)) { result = -EPERM; break; } @@ -1287,9 +1287,9 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) default: /* Verify the user buffer */ - result = verify_area( VERIFY_WRITE, urq->data, urq->len ); - if( result != 0 ) { - DBG_ERROR( DbgInfo, "verify_area(), VERIFY_WRITE FAILED\n" ); + result = verify_area(VERIFY_WRITE, urq->data, urq->len); + if(result != 0) { + DBG_ERROR(DbgInfo, "verify_area(), VERIFY_WRITE FAILED\n"); urq->result = UIL_FAILURE; break; } @@ -1297,35 +1297,35 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) /* If the requested length is greater than the size of our local LTV record, try to allocate it from the kernel stack. Otherwise, we just use our local LTV record. */ - if( urq->len > sizeof( lp->ltvRecord )) { + if(urq->len > sizeof(lp->ltvRecord)) { pLtv = kmalloc(urq->len, GFP_KERNEL); if (pLtv != NULL) { ltvAllocated = TRUE; /* Copy the command/length information into the new buffer. */ - memcpy( pLtv, &( lp->ltvRecord ), sizeof( hcf_16 ) * 2 ); + memcpy(pLtv, &(lp->ltvRecord), sizeof(hcf_16) * 2); } else { - urq->len = sizeof( lp->ltvRecord ); + urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; - DBG_ERROR( DbgInfo, "kmalloc FAILED\n" ); - DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); + DBG_ERROR(DbgInfo, "kmalloc FAILED\n"); + DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n"); result = -ENOMEM; break; } } else { - pLtv = &( lp->ltvRecord ); + pLtv = &(lp->ltvRecord); } - wl_act_int_off( lp ); - urq->result = hcf_get_info( &( lp->hcfCtx ), (LTVP) pLtv ); - wl_act_int_on( lp ); + wl_act_int_off(lp); + urq->result = hcf_get_info(&(lp->hcfCtx), (LTVP) pLtv); + wl_act_int_on(lp); // Copy the LTV into the user's buffer. - //copy_to_user( urq->data, pLtv, urq->len ); + //copy_to_user(urq->data, pLtv, urq->len); - //if( ltvAllocated ) + //if(ltvAllocated) //{ - // kfree( pLtv ); + // kfree(pLtv); //} //urq->result = UIL_SUCCESS; @@ -1333,7 +1333,7 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) } /* Handle endian conversion of special fields */ - switch( lp->ltvRecord.typ ) { + switch(lp->ltvRecord.typ) { /* simple int gets just need the first hcf_16 byte flipped */ case CFG_CNF_PORT_TYPE: case CFG_CNF_OWN_CHANNEL: @@ -1406,7 +1406,7 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) case CFG_CUR_CHANNEL: //case CFG_CURRENT_POWER_STATE: //case CFG_CCAMODE: - // lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); + // lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); // break; /* name string gets just need the first hcf_16 byte flipped (length of string) */ case CFG_CNF_OWN_SSID: @@ -1415,7 +1415,7 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) case CFG_DESIRED_SSID: case CFG_SCAN_SSID: case CFG_CUR_SSID: - lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); + lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); break; /* non-length counted strings need no byte flipping */ case CFG_CNF_OWN_MAC_ADDR: @@ -1435,11 +1435,11 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) //case CFG_CNF_COUNTRY_INFO: /* special case, see page 75 of 022486, Rev C. */ //case CFG_CURRENT_COUNTRY_INFO: /* special case, see page 101 of 022486, Rev C. */ /* - lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); - lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[3] ); + lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); + lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]); - for( i = 4; i < lp->ltvRecord.len; i++ ) { - lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[i] ); + for(i = 4; i < lp->ltvRecord.len; i++) { + lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[i]); } break; */ @@ -1448,57 +1448,57 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) { CFG_DEFAULT_KEYS_STRCT *pKeys = (CFG_DEFAULT_KEYS_STRCT *)&lp->ltvRecord.u.u8[0]; - pKeys[0].len = CNV_INT_TO_LITTLE( pKeys[0].len ); - pKeys[1].len = CNV_INT_TO_LITTLE( pKeys[1].len ); - pKeys[2].len = CNV_INT_TO_LITTLE( pKeys[2].len ); - pKeys[3].len = CNV_INT_TO_LITTLE( pKeys[3].len ); + pKeys[0].len = CNV_INT_TO_LITTLE(pKeys[0].len); + pKeys[1].len = CNV_INT_TO_LITTLE(pKeys[1].len); + pKeys[2].len = CNV_INT_TO_LITTLE(pKeys[2].len); + pKeys[3].len = CNV_INT_TO_LITTLE(pKeys[3].len); } break; case CFG_CNF_MCAST_RATE: case CFG_TX_RATE_CNTL: case CFG_SUPPORTED_RATE_SET_CNTL: // Supported Rate Set Control case CFG_BASIC_RATE_SET_CNTL: // Basic Rate Set Control - lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); - lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); + lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); + lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]); break; case CFG_DL_BUF: case CFG_NIC_IDENTITY: case CFG_COMMS_QUALITY: case CFG_PCF_INFO: - lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); - lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); - lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[2] ); + lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); + lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]); + lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]); break; case CFG_FW_IDENTITY: - lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); - lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); - lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[2] ); - lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[3] ); + lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); + lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]); + lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]); + lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]); break; //case CFG_HSI_SUP_RANGE: case CFG_NIC_MFI_SUP_RANGE: case CFG_NIC_CFI_SUP_RANGE: case CFG_NIC_PROFILE: case CFG_FW_SUP_RANGE: - lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); - lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); - lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[2] ); - lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[3] ); - lp->ltvRecord.u.u16[4] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[4] ); + lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); + lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]); + lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]); + lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]); + lp->ltvRecord.u.u16[4] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[4]); break; case CFG_MFI_ACT_RANGES_STA: case CFG_CFI_ACT_RANGES_STA: case CFG_CUR_SCALE_THRH: case CFG_AUTHENTICATION_ALGORITHMS: - for( i = 0; i < ( lp->ltvRecord.len - 1 ); i++ ) { - lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[i] ); + for(i = 0; i < (lp->ltvRecord.len - 1); i++) { + lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[i]); } break; /* done at init time, and endian handled then */ case CFG_PRI_IDENTITY: break; case CFG_MB_INFO: - //wvlanEndianTranslateMailbox( pLtv ); + //wvlanEndianTranslateMailbox(pLtv); break; /* MSF and HCF RIDS */ case CFG_IFB: @@ -1513,10 +1513,10 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) } // Copy the LTV into the user's buffer. - copy_to_user( urq->data, &( lp->ltvRecord ), urq->len ); + copy_to_user(urq->data, &(lp->ltvRecord), urq->len); - if( ltvAllocated ) { - kfree( &( lp->ltvRecord )); + if(ltvAllocated) { + kfree(&(lp->ltvRecord)); } urq->result = UIL_SUCCESS; @@ -1524,11 +1524,11 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) urq->result = UIL_FAILURE; } } else { - DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); + DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n"); urq->result = UIL_ERR_WRONG_IFB; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // wvlan_uil_get_info /*============================================================================*/ @@ -1556,29 +1556,29 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ) +int cfg_driver_info(struct uilreq *urq, struct wl_private *lp) { int result = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "cfg_driver_info" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("cfg_driver_info"); + DBG_ENTER(DbgInfo); /* Make sure that user buffer can handle the driver information buffer */ - if( urq->len < sizeof( lp->driverInfo )) { - urq->len = sizeof( lp->driverInfo ); + if(urq->len < sizeof(lp->driverInfo)) { + urq->len = sizeof(lp->driverInfo); urq->result = UIL_ERR_LEN; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } /* Verify the user buffer. */ - result = verify_area( VERIFY_WRITE, urq->data, sizeof( lp->driverInfo )); - if( result != 0 ) { + result = verify_area(VERIFY_WRITE, urq->data, sizeof(lp->driverInfo)); + if(result != 0) { urq->result = UIL_FAILURE; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } @@ -1586,9 +1586,9 @@ int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ) // Copy the driver information into the user's buffer. urq->result = UIL_SUCCESS; - copy_to_user( urq->data, &( lp->driverInfo ), sizeof( lp->driverInfo )); + copy_to_user(urq->data, &(lp->driverInfo), sizeof(lp->driverInfo)); - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // cfg_driver_info /*============================================================================*/ @@ -1615,37 +1615,37 @@ int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ) * UIL_ERR_xxx value otherwise * ******************************************************************************/ -int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ) +int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp) { int result = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_driver_identity" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_driver_identity"); + DBG_ENTER(DbgInfo); /* Make sure that user buffer can handle the driver identity structure. */ - if( urq->len < sizeof( lp->driverIdentity )) { - urq->len = sizeof( lp->driverIdentity ); + if(urq->len < sizeof(lp->driverIdentity)) { + urq->len = sizeof(lp->driverIdentity); urq->result = UIL_ERR_LEN; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } /* Verify the user buffer. */ - result = verify_area( VERIFY_WRITE, urq->data, sizeof( lp->driverIdentity )); - if( result != 0 ) { + result = verify_area(VERIFY_WRITE, urq->data, sizeof(lp->driverIdentity)); + if(result != 0) { urq->result = UIL_FAILURE; - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } /* Copy the driver identity into the user's buffer. */ urq->result = UIL_SUCCESS; - copy_to_user( urq->data, &( lp->driverIdentity ), sizeof( lp->driverIdentity )); + copy_to_user(urq->data, &(lp->driverIdentity), sizeof(lp->driverIdentity)); - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return result; } // cfg_driver_identity /*============================================================================*/ @@ -1690,19 +1690,19 @@ int wvlan_set_netname(struct net_device *dev, /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_set_netname" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_set_netname"); + DBG_ENTER(DbgInfo); wl_lock(lp, &flags); - memset( lp->NetworkName, 0, sizeof( lp->NetworkName )); - memcpy( lp->NetworkName, extra, wrqu->data.length); + memset(lp->NetworkName, 0, sizeof(lp->NetworkName)); + memcpy(lp->NetworkName, extra, wrqu->data.length); /* Commit the adapter parameters */ wl_apply(lp); wl_unlock(lp, &flags); - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ret; } // wvlan_set_netname /*============================================================================*/ @@ -1742,19 +1742,19 @@ int wvlan_get_netname(struct net_device *dev, /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_get_netname" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_get_netname"); + DBG_ENTER(DbgInfo); wl_lock(lp, &flags); /* Get the current network name */ - lp->ltvRecord.len = 1 + ( sizeof( *pName ) / sizeof( hcf_16 )); + lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16)); lp->ltvRecord.typ = CFG_CUR_SSID; - status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord )); + status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if( status == HCF_SUCCESS ) { - pName = (wvName_t *)&( lp->ltvRecord.u.u32 ); + if(status == HCF_SUCCESS) { + pName = (wvName_t *)&(lp->ltvRecord.u.u32); memset(extra, '\0', HCF_MAX_NAME_LEN); wrqu->data.length = pName->length; @@ -1766,7 +1766,7 @@ int wvlan_get_netname(struct net_device *dev, wl_unlock(lp, &flags); - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ret; } // wvlan_get_netname /*============================================================================*/ @@ -1804,20 +1804,20 @@ int wvlan_set_station_nickname(struct net_device *dev, /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_set_station_nickname" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_set_station_nickname"); + DBG_ENTER(DbgInfo); wl_lock(lp, &flags); - memset( lp->StationName, 0, sizeof( lp->StationName )); + memset(lp->StationName, 0, sizeof(lp->StationName)); - memcpy( lp->StationName, extra, wrqu->data.length); + memcpy(lp->StationName, extra, wrqu->data.length); /* Commit the adapter parameters */ - wl_apply( lp ); + wl_apply(lp); wl_unlock(lp, &flags); - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ret; } // wvlan_set_station_nickname /*============================================================================*/ @@ -1857,19 +1857,19 @@ int wvlan_get_station_nickname(struct net_device *dev, /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_get_station_nickname" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_get_station_nickname"); + DBG_ENTER(DbgInfo); - wl_lock( lp, &flags ); + wl_lock(lp, &flags); /* Get the current station name */ - lp->ltvRecord.len = 1 + ( sizeof( *pName ) / sizeof( hcf_16 )); + lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16)); lp->ltvRecord.typ = CFG_CNF_OWN_NAME; - status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord )); + status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if( status == HCF_SUCCESS ) { - pName = (wvName_t *)&( lp->ltvRecord.u.u32 ); + if(status == HCF_SUCCESS) { + pName = (wvName_t *)&(lp->ltvRecord.u.u32); memset(extra, '\0', HCF_MAX_NAME_LEN); wrqu->data.length = pName->length; @@ -1881,7 +1881,7 @@ int wvlan_get_station_nickname(struct net_device *dev, wl_unlock(lp, &flags); //out: - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ret; } // wvlan_get_station_nickname /*============================================================================*/ @@ -1920,15 +1920,15 @@ int wvlan_set_porttype(struct net_device *dev, /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_set_porttype" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_set_porttype"); + DBG_ENTER(DbgInfo); wl_lock(lp, &flags); /* Validate the new value */ portType = *((__u32 *)extra); - if( !(( portType == 1 ) || ( portType == 3 ))) { + if(!((portType == 1) || (portType == 3))) { ret = -EINVAL; goto out_unlock; } @@ -1936,13 +1936,13 @@ int wvlan_set_porttype(struct net_device *dev, lp->PortType = portType; /* Commit the adapter parameters */ - wl_apply( lp ); + wl_apply(lp); out_unlock: wl_unlock(lp, &flags); //out: - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ret; } @@ -1982,21 +1982,21 @@ int wvlan_get_porttype(struct net_device *dev, /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_get_porttype" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_get_porttype"); + DBG_ENTER(DbgInfo); - wl_lock( lp, &flags ); + wl_lock(lp, &flags); /* Get the current port type */ - lp->ltvRecord.len = 1 + ( sizeof( *pPortType ) / sizeof( hcf_16 )); + lp->ltvRecord.len = 1 + (sizeof(*pPortType) / sizeof(hcf_16)); lp->ltvRecord.typ = CFG_CNF_PORT_TYPE; - status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord )); + status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if( status == HCF_SUCCESS ) { - pPortType = (hcf_16 *)&( lp->ltvRecord.u.u32 ); + if(status == HCF_SUCCESS) { + pPortType = (hcf_16 *)&(lp->ltvRecord.u.u32); - *pData = CNV_LITTLE_TO_INT( *pPortType ); + *pData = CNV_LITTLE_TO_INT(*pPortType); } else { ret = -EFAULT; } @@ -2004,7 +2004,7 @@ int wvlan_get_porttype(struct net_device *dev, wl_unlock(lp, &flags); //out: - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ret; } // wvlan_get_porttype /*============================================================================*/ @@ -2034,47 +2034,47 @@ int wvlan_get_porttype(struct net_device *dev, * errno value otherwise * ******************************************************************************/ -int wvlan_rts( struct rtsreq *rrq, __u32 io_base ) +int wvlan_rts(struct rtsreq *rrq, __u32 io_base) { int ioctl_ret = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC( "wvlan_rts" ); - DBG_ENTER( DbgInfo ); + DBG_FUNC("wvlan_rts"); + DBG_ENTER(DbgInfo); - DBG_PRINT( "io_base: 0x%08x\n", io_base ); + DBG_PRINT("io_base: 0x%08x\n", io_base); - switch( rrq->typ ) { + switch(rrq->typ) { case WL_IOCTL_RTS_READ: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_READ\n"); - rrq->data[0] = IN_PORT_WORD( io_base + rrq->reg ); - DBG_TRACE( DbgInfo, " reg 0x%04x ==> 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT( rrq->data[0] ) ); + rrq->data[0] = IN_PORT_WORD(io_base + rrq->reg); + DBG_TRACE(DbgInfo, " reg 0x%04x ==> 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT(rrq->data[0])); break; case WL_IOCTL_RTS_WRITE: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_WRITE\n"); - OUT_PORT_WORD( io_base + rrq->reg, rrq->data[0] ); - DBG_TRACE( DbgInfo, " reg 0x%04x <== 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT( rrq->data[0] ) ); + OUT_PORT_WORD(io_base + rrq->reg, rrq->data[0]); + DBG_TRACE(DbgInfo, " reg 0x%04x <== 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT(rrq->data[0])); break; case WL_IOCTL_RTS_BATCH_READ: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_READ\n"); - IN_PORT_STRING_16( io_base + rrq->reg, rrq->data, rrq->len ); - DBG_TRACE( DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof (__u16 ) ); + IN_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len); + DBG_TRACE(DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof (__u16)); break; case WL_IOCTL_RTS_BATCH_WRITE: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_WRITE\n"); - OUT_PORT_STRING_16( io_base + rrq->reg, rrq->data, rrq->len ); - DBG_TRACE( DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof (__u16) ); + OUT_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len); + DBG_TRACE(DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof (__u16)); break; default: - DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- UNSUPPORTED RTS CODE: 0x%X", rrq->typ ); + DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- UNSUPPORTED RTS CODE: 0x%X", rrq->typ); ioctl_ret = -EOPNOTSUPP; break; } - DBG_LEAVE( DbgInfo ); + DBG_LEAVE(DbgInfo); return ioctl_ret; } // wvlan_rts /*============================================================================*/ -- cgit v0.10.2 From 0af2d465dde196481e0a998ac82f064074d2af8c Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:49 +0200 Subject: staging: wlags49_h2: wl_priv: fixes parentheses styling issues This commit fixes further parentheses styling issues as identified by the checkpatch.pl tool. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index df2525f..23403e9 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -135,7 +135,7 @@ int wvlan_uil(struct uilreq *urq, struct wl_private *lp) DBG_FUNC("wvlan_uil"); DBG_ENTER(DbgInfo); - switch(urq->command) { + switch (urq->command) { case UIL_FUN_CONNECT: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_CONNECT\n"); ioctl_ret = wvlan_uil_connect(urq, lp); @@ -202,7 +202,7 @@ int wvlan_uil_connect(struct uilreq *urq, struct wl_private *lp) DBG_ENTER(DbgInfo); - if(!(lp->flags & WVLAN2_UIL_CONNECTED)) { + if (!(lp->flags & WVLAN2_UIL_CONNECTED)) { lp->flags |= WVLAN2_UIL_CONNECTED; urq->hcfCtx = &(lp->hcfCtx); urq->result = UIL_SUCCESS; @@ -248,7 +248,7 @@ int wvlan_uil_disconnect(struct uilreq *urq, struct wl_private *lp) DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { if (lp->flags & WVLAN2_UIL_CONNECTED) { lp->flags &= ~WVLAN2_UIL_CONNECTED; /* @@ -304,13 +304,13 @@ int wvlan_uil_action(struct uilreq *urq, struct wl_private *lp) DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { /* Make sure there's an LTV in the request buffer */ ltv = (ltv_t *)urq->data; - if(ltv != NULL) { + if (ltv != NULL) { /* Switch on the Type field of the LTV contained in the request buffer */ - switch(ltv->typ) { + switch (ltv->typ) { case UIL_ACT_BLOCK: DBG_TRACE(DbgInfo, "UIL_ACT_BLOCK\n"); result = wvlan_uil_block(urq, lp); @@ -382,8 +382,8 @@ int wvlan_uil_block(struct uilreq *urq, struct wl_private *lp) DBG_FUNC("wvlan_uil_block"); DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { - if(capable(CAP_NET_ADMIN)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { + if (capable(CAP_NET_ADMIN)) { lp->flags |= WVLAN2_UIL_BUSY; netif_stop_queue(lp->dev); WL_WDS_NETIF_STOP_QUEUE(lp); @@ -434,8 +434,8 @@ int wvlan_uil_unblock(struct uilreq *urq, struct wl_private *lp) DBG_FUNC("wvlan_uil_unblock"); DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { - if(capable(CAP_NET_ADMIN)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { + if (capable(CAP_NET_ADMIN)) { if (lp->flags & WVLAN2_UIL_BUSY) { lp->flags &= ~WVLAN2_UIL_BUSY; netif_wake_queue(lp->dev); @@ -488,8 +488,8 @@ int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp) DBG_FUNC("wvlan_uil_send_diag_msg"); DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { - if(capable(CAP_NET_ADMIN)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { + if (capable(CAP_NET_ADMIN)) { if ((urq->data != NULL) && (urq->len != 0)) { if (lp->hcfCtx.IFB_RscInd != 0) { u_char *data; @@ -579,11 +579,11 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { - if(capable(CAP_NET_ADMIN)) { - if((urq->data != NULL) && (urq->len != 0)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { + if (capable(CAP_NET_ADMIN)) { + if ((urq->data != NULL) && (urq->len != 0)) { /* Make sure that we have at least a command and length to send. */ - if(urq->len < (sizeof(hcf_16) * 2)) { + if (urq->len < (sizeof(hcf_16) * 2)) { urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; DBG_ERROR(DbgInfo, "No Length/Type in LTV!!!\n"); @@ -594,7 +594,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) /* Verify the user buffer */ result = verify_area(VERIFY_READ, urq->data, urq->len); - if(result != 0) { + if (result != 0) { urq->result = UIL_FAILURE; DBG_ERROR(DbgInfo, "verify_area(), VERIFY_READ FAILED\n"); DBG_LEAVE(DbgInfo); @@ -606,7 +606,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) /* Make sure the incoming LTV record length is within the bounds of the IOCTL length */ - if(((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) { + if (((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) { urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n"); @@ -617,7 +617,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) /* If the requested length is greater than the size of our local LTV record, try to allocate it from the kernel stack. Otherwise, we just use our local LTV record. */ - if(urq->len > sizeof(lp->ltvRecord)) { + if (urq->len > sizeof(lp->ltvRecord)) { pLtv = kmalloc(urq->len, GFP_KERNEL); if (pLtv != NULL) { ltvAllocated = TRUE; @@ -641,7 +641,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) /* We need to snoop the commands to see if there is anything we need to store for the purposes of a reset or start/stop sequence. Perform endian translation as needed */ - switch(pLtv->typ) { + switch (pLtv->typ) { case CFG_CNF_PORT_TYPE: lp->PortType = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); @@ -824,7 +824,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); /* take care of the special network name "ANY" case */ - if((strlen(&pLtv->u.u8[2] ) == 0) || + if ((strlen(&pLtv->u.u8[2]) == 0) || (strcmp(&pLtv->u.u8[2], "ANY") == 0) || (strcmp(&pLtv->u.u8[2], "any") == 0)) { /* set the SSID_STRCT llen field (u16[0]) to zero, and the @@ -1066,7 +1066,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) being sent to the card, as they require a call to UIL_ACT_APPLY to take effect. Dynamic Entities will be sent immediately */ - switch(pLtv->typ) { + switch (pLtv->typ) { case CFG_CNF_PORT_TYPE: case CFG_CNF_OWN_MAC_ADDR: case CFG_CNF_OWN_CHANNEL: @@ -1129,7 +1129,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) break; /* Deal with this dynamic MSF RID, as it's required for WPA */ case CFG_DRIVER_ENABLE: - if(lp->driverEnable) { + if (lp->driverEnable) { //hcf_cntl_port(&(lp->hcfCtx), // HCF_PORT_ENABLE | HCF_PORT_0); // //hcf_cntl(&(lp->hcfCtx), @@ -1158,7 +1158,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) break; } - if(ltvAllocated) { + if (ltvAllocated) { kfree(pLtv); } } else { @@ -1208,13 +1208,13 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) DBG_FUNC("wvlan_uil_get_info"); DBG_ENTER(DbgInfo); - if(urq->hcfCtx == &(lp->hcfCtx)) { - if((urq->data != NULL) && (urq->len != 0)) { + if (urq->hcfCtx == &(lp->hcfCtx)) { + if ((urq->data != NULL) && (urq->len != 0)) { ltv_t *pLtv; bool_t ltvAllocated = FALSE; /* Make sure that we have at least a command and length */ - if(urq->len < (sizeof(hcf_16) * 2)) { + if (urq->len < (sizeof(hcf_16) * 2)) { urq->len = sizeof(lp->ltvRecord); DBG_ERROR(DbgInfo, "No Length/Type in LTV!!!\n"); DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n"); @@ -1225,7 +1225,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) /* Verify the user's LTV record header. */ result = verify_area(VERIFY_READ, urq->data, sizeof(hcf_16) * 2); - if(result != 0) { + if (result != 0) { DBG_ERROR(DbgInfo, "verify_area(), VERIFY_READ FAILED\n"); urq->result = UIL_FAILURE; DBG_LEAVE(DbgInfo); @@ -1237,7 +1237,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) /* Make sure the incoming LTV record length is within the bounds of the IOCTL length. */ - if(((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) { + if (((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) { DBG_ERROR(DbgInfo, "Incoming LTV too big\n"); urq->len = sizeof(lp->ltvRecord); urq->result = UIL_ERR_LEN; @@ -1276,7 +1276,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) break; case CFG_IFB: /* IFB can be a security hole */ - if(!capable(CAP_NET_ADMIN)) { + if (!capable(CAP_NET_ADMIN)) { result = -EPERM; break; } @@ -1288,7 +1288,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) /* Verify the user buffer */ result = verify_area(VERIFY_WRITE, urq->data, urq->len); - if(result != 0) { + if (result != 0) { DBG_ERROR(DbgInfo, "verify_area(), VERIFY_WRITE FAILED\n"); urq->result = UIL_FAILURE; break; @@ -1297,7 +1297,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) /* If the requested length is greater than the size of our local LTV record, try to allocate it from the kernel stack. Otherwise, we just use our local LTV record. */ - if(urq->len > sizeof(lp->ltvRecord)) { + if (urq->len > sizeof(lp->ltvRecord)) { pLtv = kmalloc(urq->len, GFP_KERNEL); if (pLtv != NULL) { ltvAllocated = TRUE; @@ -1333,7 +1333,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) } /* Handle endian conversion of special fields */ - switch(lp->ltvRecord.typ) { + switch (lp->ltvRecord.typ) { /* simple int gets just need the first hcf_16 byte flipped */ case CFG_CNF_PORT_TYPE: case CFG_CNF_OWN_CHANNEL: @@ -1490,7 +1490,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) case CFG_CFI_ACT_RANGES_STA: case CFG_CUR_SCALE_THRH: case CFG_AUTHENTICATION_ALGORITHMS: - for(i = 0; i < (lp->ltvRecord.len - 1); i++) { + for (i = 0; i < (lp->ltvRecord.len - 1); i++) { lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[i]); } break; @@ -1515,7 +1515,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) // Copy the LTV into the user's buffer. copy_to_user(urq->data, &(lp->ltvRecord), urq->len); - if(ltvAllocated) { + if (ltvAllocated) { kfree(&(lp->ltvRecord)); } @@ -1567,7 +1567,7 @@ int cfg_driver_info(struct uilreq *urq, struct wl_private *lp) /* Make sure that user buffer can handle the driver information buffer */ - if(urq->len < sizeof(lp->driverInfo)) { + if (urq->len < sizeof(lp->driverInfo)) { urq->len = sizeof(lp->driverInfo); urq->result = UIL_ERR_LEN; DBG_LEAVE(DbgInfo); @@ -1576,7 +1576,7 @@ int cfg_driver_info(struct uilreq *urq, struct wl_private *lp) /* Verify the user buffer. */ result = verify_area(VERIFY_WRITE, urq->data, sizeof(lp->driverInfo)); - if(result != 0) { + if (result != 0) { urq->result = UIL_FAILURE; DBG_LEAVE(DbgInfo); return result; @@ -1626,7 +1626,7 @@ int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp) /* Make sure that user buffer can handle the driver identity structure. */ - if(urq->len < sizeof(lp->driverIdentity)) { + if (urq->len < sizeof(lp->driverIdentity)) { urq->len = sizeof(lp->driverIdentity); urq->result = UIL_ERR_LEN; DBG_LEAVE(DbgInfo); @@ -1635,7 +1635,7 @@ int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp) /* Verify the user buffer. */ result = verify_area(VERIFY_WRITE, urq->data, sizeof(lp->driverIdentity)); - if(result != 0) { + if (result != 0) { urq->result = UIL_FAILURE; DBG_LEAVE(DbgInfo); return result; @@ -1753,7 +1753,7 @@ int wvlan_get_netname(struct net_device *dev, status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if(status == HCF_SUCCESS) { + if (status == HCF_SUCCESS) { pName = (wvName_t *)&(lp->ltvRecord.u.u32); memset(extra, '\0', HCF_MAX_NAME_LEN); @@ -1868,7 +1868,7 @@ int wvlan_get_station_nickname(struct net_device *dev, status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if(status == HCF_SUCCESS) { + if (status == HCF_SUCCESS) { pName = (wvName_t *)&(lp->ltvRecord.u.u32); memset(extra, '\0', HCF_MAX_NAME_LEN); @@ -1928,7 +1928,7 @@ int wvlan_set_porttype(struct net_device *dev, /* Validate the new value */ portType = *((__u32 *)extra); - if(!((portType == 1) || (portType == 3))) { + if (!((portType == 1) || (portType == 3))) { ret = -EINVAL; goto out_unlock; } @@ -1993,7 +1993,7 @@ int wvlan_get_porttype(struct net_device *dev, status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if(status == HCF_SUCCESS) { + if (status == HCF_SUCCESS) { pPortType = (hcf_16 *)&(lp->ltvRecord.u.u32); *pData = CNV_LITTLE_TO_INT(*pPortType); @@ -2046,7 +2046,7 @@ int wvlan_rts(struct rtsreq *rrq, __u32 io_base) DBG_PRINT("io_base: 0x%08x\n", io_base); - switch(rrq->typ) { + switch (rrq->typ) { case WL_IOCTL_RTS_READ: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_READ\n"); rrq->data[0] = IN_PORT_WORD(io_base + rrq->reg); @@ -2060,12 +2060,12 @@ int wvlan_rts(struct rtsreq *rrq, __u32 io_base) case WL_IOCTL_RTS_BATCH_READ: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_READ\n"); IN_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len); - DBG_TRACE(DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof (__u16)); + DBG_TRACE(DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof(__u16)); break; case WL_IOCTL_RTS_BATCH_WRITE: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_WRITE\n"); OUT_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len); - DBG_TRACE(DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof (__u16)); + DBG_TRACE(DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof(__u16)); break; default: -- cgit v0.10.2 From c54a639086b981c606bb2407f61bd880b70a96d5 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:50 +0200 Subject: staging: wlags49_h2: wl_priv: fixes incorrect #include This commit forces the file to use instead of . Everything still compiles a-OK. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index 23403e9..e2615a1 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -67,7 +67,7 @@ #include #include #include -#include +#include #include #include -- cgit v0.10.2 From ac6cf1b8e427068860cf4903215b2e9296e7c981 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:51 +0200 Subject: staging: wlags49_h2: wl_priv: fixes case statement styling issues This commit fixes issues related to the styling of case statements. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index e2615a1..093e1ea 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -136,27 +136,27 @@ int wvlan_uil(struct uilreq *urq, struct wl_private *lp) DBG_ENTER(DbgInfo); switch (urq->command) { - case UIL_FUN_CONNECT: + case UIL_FUN_CONNECT: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_CONNECT\n"); ioctl_ret = wvlan_uil_connect(urq, lp); break; - case UIL_FUN_DISCONNECT: + case UIL_FUN_DISCONNECT: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_DISCONNECT\n"); ioctl_ret = wvlan_uil_disconnect(urq, lp); break; - case UIL_FUN_ACTION: + case UIL_FUN_ACTION: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_ACTION\n"); ioctl_ret = wvlan_uil_action(urq, lp); break; - case UIL_FUN_SEND_DIAG_MSG: + case UIL_FUN_SEND_DIAG_MSG: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_SEND_DIAG_MSG\n"); ioctl_ret = wvlan_uil_send_diag_msg(urq, lp); break; - case UIL_FUN_GET_INFO: + case UIL_FUN_GET_INFO: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_GET_INFO\n"); ioctl_ret = wvlan_uil_get_info(urq, lp); break; - case UIL_FUN_PUT_INFO: + case UIL_FUN_PUT_INFO: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_PUT_INFO\n"); ioctl_ret = wvlan_uil_put_info(urq, lp); break; @@ -2047,22 +2047,22 @@ int wvlan_rts(struct rtsreq *rrq, __u32 io_base) DBG_PRINT("io_base: 0x%08x\n", io_base); switch (rrq->typ) { - case WL_IOCTL_RTS_READ: + case WL_IOCTL_RTS_READ: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_READ\n"); rrq->data[0] = IN_PORT_WORD(io_base + rrq->reg); DBG_TRACE(DbgInfo, " reg 0x%04x ==> 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT(rrq->data[0])); break; - case WL_IOCTL_RTS_WRITE: + case WL_IOCTL_RTS_WRITE: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_WRITE\n"); OUT_PORT_WORD(io_base + rrq->reg, rrq->data[0]); DBG_TRACE(DbgInfo, " reg 0x%04x <== 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT(rrq->data[0])); break; - case WL_IOCTL_RTS_BATCH_READ: + case WL_IOCTL_RTS_BATCH_READ: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_READ\n"); IN_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len); DBG_TRACE(DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof(__u16)); break; - case WL_IOCTL_RTS_BATCH_WRITE: + case WL_IOCTL_RTS_BATCH_WRITE: DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_WRITE\n"); OUT_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len); DBG_TRACE(DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof(__u16)); -- cgit v0.10.2 From 7f622485ee768715719058b5ee9a84434cbc02f7 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:52 +0200 Subject: staging: wlags49_h2: wl_priv: fixes brace placement This commit fixes incorrect brace placements in the file, as indicated by the checkpatch.pl tool. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index 093e1ea..b49ef87 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -1158,9 +1158,8 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) break; } - if (ltvAllocated) { + if (ltvAllocated) kfree(pLtv); - } } else { urq->result = UIL_FAILURE; } @@ -1490,9 +1489,8 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) case CFG_CFI_ACT_RANGES_STA: case CFG_CUR_SCALE_THRH: case CFG_AUTHENTICATION_ALGORITHMS: - for (i = 0; i < (lp->ltvRecord.len - 1); i++) { + for (i = 0; i < (lp->ltvRecord.len - 1); i++) lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[i]); - } break; /* done at init time, and endian handled then */ case CFG_PRI_IDENTITY: @@ -1515,10 +1513,8 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) // Copy the LTV into the user's buffer. copy_to_user(urq->data, &(lp->ltvRecord), urq->len); - if (ltvAllocated) { + if (ltvAllocated) kfree(&(lp->ltvRecord)); - } - urq->result = UIL_SUCCESS; } else { urq->result = UIL_FAILURE; -- cgit v0.10.2 From fdd9e860399145f8e140c427b6346a62482ebdbf Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:53 +0200 Subject: staging: wlags49_h2: wl_priv: converts indentation to tabs This commit converts instances of space-based indentation to tabs. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index b49ef87..193b3cd 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -1152,9 +1152,9 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) } break; default: - wl_act_int_off(lp); + wl_act_int_off(lp); urq->result = hcf_put_info(&(lp->hcfCtx), (LTVP) pLtv); - wl_act_int_on(lp); + wl_act_int_on(lp); break; } @@ -1315,9 +1315,9 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) pLtv = &(lp->ltvRecord); } - wl_act_int_off(lp); + wl_act_int_off(lp); urq->result = hcf_get_info(&(lp->hcfCtx), (LTVP) pLtv); - wl_act_int_on(lp); + wl_act_int_on(lp); // Copy the LTV into the user's buffer. //copy_to_user(urq->data, pLtv, urq->len); @@ -1680,8 +1680,8 @@ int wvlan_set_netname(struct net_device *dev, union iwreq_data *wrqu, char *extra) { - struct wl_private *lp = wl_priv(dev); - unsigned long flags; + struct wl_private *lp = wl_priv(dev); + unsigned long flags; int ret = 0; /*------------------------------------------------------------------------*/ @@ -1689,14 +1689,14 @@ int wvlan_set_netname(struct net_device *dev, DBG_FUNC("wvlan_set_netname"); DBG_ENTER(DbgInfo); - wl_lock(lp, &flags); + wl_lock(lp, &flags); - memset(lp->NetworkName, 0, sizeof(lp->NetworkName)); - memcpy(lp->NetworkName, extra, wrqu->data.length); + memset(lp->NetworkName, 0, sizeof(lp->NetworkName)); + memcpy(lp->NetworkName, extra, wrqu->data.length); /* Commit the adapter parameters */ wl_apply(lp); - wl_unlock(lp, &flags); + wl_unlock(lp, &flags); DBG_LEAVE(DbgInfo); return ret; @@ -1730,40 +1730,40 @@ int wvlan_get_netname(struct net_device *dev, union iwreq_data *wrqu, char *extra) { - struct wl_private *lp = wl_priv(dev); - unsigned long flags; - int ret = 0; - int status = -1; - wvName_t *pName; + struct wl_private *lp = wl_priv(dev); + unsigned long flags; + int ret = 0; + int status = -1; + wvName_t *pName; /*------------------------------------------------------------------------*/ - DBG_FUNC("wvlan_get_netname"); - DBG_ENTER(DbgInfo); + DBG_FUNC("wvlan_get_netname"); + DBG_ENTER(DbgInfo); - wl_lock(lp, &flags); + wl_lock(lp, &flags); - /* Get the current network name */ - lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16)); - lp->ltvRecord.typ = CFG_CUR_SSID; + /* Get the current network name */ + lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16)); + lp->ltvRecord.typ = CFG_CUR_SSID; - status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); + status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if (status == HCF_SUCCESS) { - pName = (wvName_t *)&(lp->ltvRecord.u.u32); + if (status == HCF_SUCCESS) { + pName = (wvName_t *)&(lp->ltvRecord.u.u32); memset(extra, '\0', HCF_MAX_NAME_LEN); wrqu->data.length = pName->length; - memcpy(extra, pName->name, pName->length); - } else { - ret = -EFAULT; + memcpy(extra, pName->name, pName->length); + } else { + ret = -EFAULT; } - wl_unlock(lp, &flags); + wl_unlock(lp, &flags); - DBG_LEAVE(DbgInfo); - return ret; + DBG_LEAVE(DbgInfo); + return ret; } // wvlan_get_netname /*============================================================================*/ @@ -1794,27 +1794,27 @@ int wvlan_set_station_nickname(struct net_device *dev, union iwreq_data *wrqu, char *extra) { - struct wl_private *lp = wl_priv(dev); - unsigned long flags; - int ret = 0; + struct wl_private *lp = wl_priv(dev); + unsigned long flags; + int ret = 0; /*------------------------------------------------------------------------*/ - DBG_FUNC("wvlan_set_station_nickname"); - DBG_ENTER(DbgInfo); + DBG_FUNC("wvlan_set_station_nickname"); + DBG_ENTER(DbgInfo); - wl_lock(lp, &flags); + wl_lock(lp, &flags); - memset(lp->StationName, 0, sizeof(lp->StationName)); + memset(lp->StationName, 0, sizeof(lp->StationName)); - memcpy(lp->StationName, extra, wrqu->data.length); + memcpy(lp->StationName, extra, wrqu->data.length); - /* Commit the adapter parameters */ - wl_apply(lp); - wl_unlock(lp, &flags); + /* Commit the adapter parameters */ + wl_apply(lp); + wl_unlock(lp, &flags); - DBG_LEAVE(DbgInfo); - return ret; + DBG_LEAVE(DbgInfo); + return ret; } // wvlan_set_station_nickname /*============================================================================*/ @@ -1845,39 +1845,39 @@ int wvlan_get_station_nickname(struct net_device *dev, union iwreq_data *wrqu, char *extra) { - struct wl_private *lp = wl_priv(dev); - unsigned long flags; + struct wl_private *lp = wl_priv(dev); + unsigned long flags; int ret = 0; int status = -1; wvName_t *pName; /*------------------------------------------------------------------------*/ - DBG_FUNC("wvlan_get_station_nickname"); - DBG_ENTER(DbgInfo); + DBG_FUNC("wvlan_get_station_nickname"); + DBG_ENTER(DbgInfo); - wl_lock(lp, &flags); + wl_lock(lp, &flags); - /* Get the current station name */ - lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16)); - lp->ltvRecord.typ = CFG_CNF_OWN_NAME; + /* Get the current station name */ + lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16)); + lp->ltvRecord.typ = CFG_CNF_OWN_NAME; - status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); + status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if (status == HCF_SUCCESS) { - pName = (wvName_t *)&(lp->ltvRecord.u.u32); + if (status == HCF_SUCCESS) { + pName = (wvName_t *)&(lp->ltvRecord.u.u32); memset(extra, '\0', HCF_MAX_NAME_LEN); wrqu->data.length = pName->length; memcpy(extra, pName->name, pName->length); - } else { - ret = -EFAULT; - } + } else { + ret = -EFAULT; + } - wl_unlock(lp, &flags); + wl_unlock(lp, &flags); //out: - DBG_LEAVE(DbgInfo); + DBG_LEAVE(DbgInfo); return ret; } // wvlan_get_station_nickname /*============================================================================*/ @@ -1909,37 +1909,37 @@ int wvlan_set_porttype(struct net_device *dev, union iwreq_data *wrqu, char *extra) { - struct wl_private *lp = wl_priv(dev); - unsigned long flags; - int ret = 0; + struct wl_private *lp = wl_priv(dev); + unsigned long flags; + int ret = 0; hcf_16 portType; /*------------------------------------------------------------------------*/ - DBG_FUNC("wvlan_set_porttype"); - DBG_ENTER(DbgInfo); + DBG_FUNC("wvlan_set_porttype"); + DBG_ENTER(DbgInfo); - wl_lock(lp, &flags); + wl_lock(lp, &flags); - /* Validate the new value */ - portType = *((__u32 *)extra); + /* Validate the new value */ + portType = *((__u32 *)extra); - if (!((portType == 1) || (portType == 3))) { - ret = -EINVAL; + if (!((portType == 1) || (portType == 3))) { + ret = -EINVAL; goto out_unlock; - } + } - lp->PortType = portType; + lp->PortType = portType; - /* Commit the adapter parameters */ - wl_apply(lp); + /* Commit the adapter parameters */ + wl_apply(lp); out_unlock: - wl_unlock(lp, &flags); + wl_unlock(lp, &flags); //out: - DBG_LEAVE(DbgInfo); - return ret; + DBG_LEAVE(DbgInfo); + return ret; } /*============================================================================*/ @@ -1969,39 +1969,39 @@ int wvlan_get_porttype(struct net_device *dev, union iwreq_data *wrqu, char *extra) { - struct wl_private *lp = wl_priv(dev); - unsigned long flags; - int ret = 0; - int status = -1; - hcf_16 *pPortType; - __u32 *pData = (__u32 *)extra; + struct wl_private *lp = wl_priv(dev); + unsigned long flags; + int ret = 0; + int status = -1; + hcf_16 *pPortType; + __u32 *pData = (__u32 *)extra; /*------------------------------------------------------------------------*/ - DBG_FUNC("wvlan_get_porttype"); - DBG_ENTER(DbgInfo); + DBG_FUNC("wvlan_get_porttype"); + DBG_ENTER(DbgInfo); - wl_lock(lp, &flags); + wl_lock(lp, &flags); - /* Get the current port type */ - lp->ltvRecord.len = 1 + (sizeof(*pPortType) / sizeof(hcf_16)); - lp->ltvRecord.typ = CFG_CNF_PORT_TYPE; + /* Get the current port type */ + lp->ltvRecord.len = 1 + (sizeof(*pPortType) / sizeof(hcf_16)); + lp->ltvRecord.typ = CFG_CNF_PORT_TYPE; - status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); + status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord)); - if (status == HCF_SUCCESS) { - pPortType = (hcf_16 *)&(lp->ltvRecord.u.u32); + if (status == HCF_SUCCESS) { + pPortType = (hcf_16 *)&(lp->ltvRecord.u.u32); - *pData = CNV_LITTLE_TO_INT(*pPortType); - } else { - ret = -EFAULT; + *pData = CNV_LITTLE_TO_INT(*pPortType); + } else { + ret = -EFAULT; } - wl_unlock(lp, &flags); + wl_unlock(lp, &flags); //out: - DBG_LEAVE(DbgInfo); - return ret; + DBG_LEAVE(DbgInfo); + return ret; } // wvlan_get_porttype /*============================================================================*/ -- cgit v0.10.2 From a52a2e1d095e80a29d90a9fad4f5d21d56837b4c Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:54 +0200 Subject: staging: wlags49_h2: wl_priv: converts C99 // comments This commit converts C99 // comments to /* */ Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c index 193b3cd..c97e0e1 100644 --- a/drivers/staging/wlags49_h2/wl_priv.c +++ b/drivers/staging/wlags49_h2/wl_priv.c @@ -99,7 +99,7 @@ int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp); ******************************************************************************/ #if DBG extern dbg_info_t *DbgInfo; -#endif // DBG +#endif /* DBG */ @@ -167,7 +167,7 @@ int wvlan_uil(struct uilreq *urq, struct wl_private *lp) } DBG_LEAVE(DbgInfo); return ioctl_ret; -} // wvlan_uil +} /* wvlan_uil */ /*============================================================================*/ @@ -213,7 +213,7 @@ int wvlan_uil_connect(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_connect +} /* wvlan_uil_connect */ /*============================================================================*/ @@ -268,7 +268,7 @@ int wvlan_uil_disconnect(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_disconnect +} /* wvlan_uil_disconnect */ /*============================================================================*/ @@ -346,7 +346,7 @@ int wvlan_uil_action(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_action +} /* wvlan_uil_action */ /*============================================================================*/ @@ -400,7 +400,7 @@ int wvlan_uil_block(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_block +} /* wvlan_uil_block */ /*============================================================================*/ @@ -453,7 +453,7 @@ int wvlan_uil_unblock(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_unblock +} /* wvlan_uil_unblock */ /*============================================================================*/ @@ -494,7 +494,7 @@ int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp) if (lp->hcfCtx.IFB_RscInd != 0) { u_char *data; - // Verify the user buffer + /* Verify the user buffer */ result = verify_area(VERIFY_READ, urq->data, urq->len); if (result != 0) { DBG_ERROR(DbgInfo, "verify_area failed, result: %d\n", result); @@ -510,7 +510,7 @@ int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp) Descp[0].buf_addr = (wci_bufp)data; Descp[0].BUF_CNT = urq->len; - Descp[0].next_desc_addr = 0; // terminate list + Descp[0].next_desc_addr = 0; /* terminate list */ hcf_send_msg(&(lp->hcfCtx), &Descp[0], HCF_PORT_0); kfree(data); @@ -541,7 +541,7 @@ int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_send_diag_msg +} /* wvlan_uil_send_diag_msg */ /*============================================================================*/ @@ -655,7 +655,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) break; /* CFG_CNF_OWN_SSID currently same as CNF_DESIRED_SSID. Do we need separate storage for this? */ - //case CFG_CNF_OWN_SSID: + /* case CFG_CNF_OWN_SSID: */ case CFG_CNF_OWN_ATIM_WINDOW: lp->atimWindow = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); @@ -702,15 +702,15 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) lp->txPowLevel = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; - //case CFG_CNF_SHORT_RETRY_LIMIT: // Short Retry Limit - //case 0xFC33: // Long Retry Limit - case CFG_SUPPORTED_RATE_SET_CNTL: // Supported Rate Set Control + /* case CFG_CNF_SHORT_RETRY_LIMIT: */ /* Short Retry Limit */ + /* case 0xFC33: */ /* Long Retry Limit */ + case CFG_SUPPORTED_RATE_SET_CNTL: /* Supported Rate Set Control */ lp->srsc[0] = pLtv->u.u16[0]; lp->srsc[1] = pLtv->u.u16[1]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]); break; - case CFG_BASIC_RATE_SET_CNTL: // Basic Rate Set Control + case CFG_BASIC_RATE_SET_CNTL: /* Basic Rate Set Control */ lp->brsc[0] = pLtv->u.u16[0]; lp->brsc[1] = pLtv->u.u16[1]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); @@ -720,23 +720,23 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) lp->connectionControl = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; - //case CFG_PROBE_DATA_RATE: -#endif // HERMES25 + /* case CFG_PROBE_DATA_RATE: */ +#endif /* HERMES25 */ -#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP - //;?should we restore this to allow smaller memory footprint +#if 1 /* ;? (HCF_TYPE) & HCF_TYPE_AP */ + /* ;?should we restore this to allow smaller memory footprint */ case CFG_CNF_OWN_DTIM_PERIOD: lp->DTIMPeriod = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #ifdef WARP - case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval + case CFG_CNF_OWN_BEACON_INTERVAL: /* Own Beacon Interval */ lp->ownBeaconInterval = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; -#endif // WARP - case CFG_COEXISTENSE_BEHAVIOUR: // Coexistence behavior +#endif /* WARP */ + case CFG_COEXISTENSE_BEHAVIOUR: /* Coexistence behavior */ lp->coexistence = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; @@ -785,13 +785,13 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) lp->authentication = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; -#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP - //;?should we restore this to allow smaller memory footprint +#if 1 /* ;? (HCF_TYPE) & HCF_TYPE_AP */ + /* ;?should we restore this to allow smaller memory footprint */ - //case CFG_CNF_EXCL_UNENCRYPTED: - //lp->ExcludeUnencrypted = pLtv->u.u16[0]; - //pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); - //break; + /* case CFG_CNF_EXCL_UNENCRYPTED: + lp->ExcludeUnencrypted = pLtv->u.u16[0]; + pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); + break; */ case CFG_CNF_MCAST_RATE: /* TODO: determine if we are going to store anything based on this */ break; @@ -804,20 +804,20 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) case CFG_CNF_MICRO_WAVE: /* TODO: determine if we are going to store anything based on this */ break; - //case CFG_CNF_LOAD_BALANCING: + /*case CFG_CNF_LOAD_BALANCING:*/ /* TODO: determine if we are going to store anything based on this */ - //break; - //case CFG_CNF_MEDIUM_DISTRIBUTION: + /* break; */ + /* case CFG_CNF_MEDIUM_DISTRIBUTION: */ /* TODO: determine if we are going to store anything based on this */ - //break; - //case CFG_CNF_RX_ALL_GROUP_ADDRESS: - // TODO: determine if we are going to store anything based on this - //break; - //case CFG_CNF_COUNTRY_INFO: + /* break; */ + /* case CFG_CNF_RX_ALL_GROUP_ADDRESS: */ + /* TODO: determine if we are going to store anything based on this */ + /* break; */ + /* case CFG_CNF_COUNTRY_INFO: */ /* TODO: determine if we are going to store anything based on this */ - //break; + /* break; */ case CFG_CNF_OWN_SSID: - //case CNF_DESIRED_SSID: + /* case CNF_DESIRED_SSID: */ case CFG_DESIRED_SSID: memset(lp->NetworkName, 0, sizeof(lp->NetworkName)); memcpy((void *)lp->NetworkName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); @@ -853,17 +853,17 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) case CFG_PROMISCUOUS_MODE: /* TODO: determine if we are going to store anything based on this */ break; - //case CFG_WAKE_ON_LAN: + /* case CFG_WAKE_ON_LAN: */ /* TODO: determine if we are going to store anything based on this */ - //break; -#if 1 //;? #if (HCF_TYPE) & HCF_TYPE_AP - //;?should we restore this to allow smaller memory footprint + /* break; */ +#if 1 /* ;? #if (HCF_TYPE) & HCF_TYPE_AP */ + /* ;?should we restore this to allow smaller memory footprint */ case CFG_RTS_THRH0: lp->RTSThreshold = pLtv->u.u16[0]; pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; case CFG_TX_RATE_CNTL0: -//;?no idea what this should be, get going so comment it out lp->TxRateControl = pLtv->u.u16[0]; +/*;?no idea what this should be, get going so comment it out lp->TxRateControl = pLtv->u.u16[0];*/ pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); break; #ifdef USE_WDS @@ -956,7 +956,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) /* these RIDS are Info RIDs, and should they be allowed for puts??? */ case CFG_MAX_LOAD_TIME: case CFG_DL_BUF: - //case CFG_HSI_SUP_RANGE: + /* case CFG_HSI_SUP_RANGE: */ case CFG_NIC_SERIAL_NUMBER: case CFG_NIC_IDENTITY: case CFG_NIC_MFI_SUP_RANGE: @@ -982,26 +982,26 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) case CFG_CF_POLLABLE: case CFG_AUTHENTICATION_ALGORITHMS: case CFG_PRIVACY_OPT_IMPLEMENTED: - //case CFG_CURRENT_REMOTE_RATES: - //case CFG_CURRENT_USED_RATES: - //case CFG_CURRENT_SYSTEM_SCALE: - //case CFG_CURRENT_TX_RATE1: - //case CFG_CURRENT_TX_RATE2: - //case CFG_CURRENT_TX_RATE3: - //case CFG_CURRENT_TX_RATE4: - //case CFG_CURRENT_TX_RATE5: - //case CFG_CURRENT_TX_RATE6: + /* case CFG_CURRENT_REMOTE_RATES: */ + /* case CFG_CURRENT_USED_RATES: */ + /* case CFG_CURRENT_SYSTEM_SCALE: */ + /* case CFG_CURRENT_TX_RATE1: */ + /* case CFG_CURRENT_TX_RATE2: */ + /* case CFG_CURRENT_TX_RATE3: */ + /* case CFG_CURRENT_TX_RATE4: */ + /* case CFG_CURRENT_TX_RATE5: */ + /* case CFG_CURRENT_TX_RATE6: */ case CFG_NIC_MAC_ADDR: case CFG_PCF_INFO: - //case CFG_CURRENT_COUNTRY_INFO: + /* case CFG_CURRENT_COUNTRY_INFO: */ case CFG_PHY_TYPE: case CFG_CUR_CHANNEL: - //case CFG_CURRENT_POWER_STATE: - //case CFG_CCAMODE: + /* case CFG_CURRENT_POWER_STATE: */ + /* case CFG_CCAMODE: */ case CFG_SUPPORTED_DATA_RATES: break; case CFG_AP_MODE: -//;? lp->DownloadFirmware = (pLtv->u.u16[0]) + 1; +/*;? lp->DownloadFirmware = (pLtv->u.u16[0]) + 1; */ DBG_ERROR(DbgInfo, "set CFG_AP_MODE no longer supported\n"); break; case CFG_ENCRYPT_STRING: @@ -1084,14 +1084,14 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) #ifdef WARP case CFG_CNF_TX_POW_LVL: case CFG_CNF_CONNECTION_CNTL: - //case CFG_PROBE_DATA_RATE: -#endif // HERMES25 -#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP - //;?should we restore this to allow smaller memory footprint + /*case CFG_PROBE_DATA_RATE: */ +#endif /* HERMES25 */ +#if 1 /*;? (HCF_TYPE) & HCF_TYPE_AP */ + /*;?should we restore this to allow smaller memory footprint */ case CFG_CNF_OWN_DTIM_PERIOD: #ifdef WARP - case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval -#endif // WARP + case CFG_CNF_OWN_BEACON_INTERVAL: /* Own Beacon Interval */ +#endif /* WARP */ #ifdef USE_WDS case CFG_CNF_WDS_ADDR1: case CFG_CNF_WDS_ADDR2: @@ -1106,8 +1106,8 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) case CFG_CNF_ENCRYPTION: case CFG_CNF_AUTHENTICATION: -#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP - //;?should we restore this to allow smaller memory footprint +#if 1 /* ;? (HCF_TYPE) & HCF_TYPE_AP */ + /* ;?should we restore this to allow smaller memory footprint */ case CFG_CNF_EXCL_UNENCRYPTED: case CFG_CNF_MCAST_RATE: @@ -1115,14 +1115,14 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) #endif case CFG_CNF_MICRO_WAVE: - //case CFG_CNF_LOAD_BALANCING: - //case CFG_CNF_MEDIUM_DISTRIBUTION: - //case CFG_CNF_RX_ALL_GROUP_ADDRESS: - //case CFG_CNF_COUNTRY_INFO: - //case CFG_COUNTRY_STRING: + /* case CFG_CNF_LOAD_BALANCING: */ + /* case CFG_CNF_MEDIUM_DISTRIBUTION: */ + /* case CFG_CNF_RX_ALL_GROUP_ADDRESS: */ + /* case CFG_CNF_COUNTRY_INFO: */ + /* case CFG_COUNTRY_STRING: */ case CFG_AP_MODE: case CFG_ENCRYPT_STRING: - //case CFG_DRIVER_ENABLE: + /* case CFG_DRIVER_ENABLE: */ case CFG_WOLAS_ENABLE: case CFG_MB_INFO: case CFG_IFB: @@ -1130,23 +1130,9 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) /* Deal with this dynamic MSF RID, as it's required for WPA */ case CFG_DRIVER_ENABLE: if (lp->driverEnable) { - //hcf_cntl_port(&(lp->hcfCtx), - // HCF_PORT_ENABLE | HCF_PORT_0); - // //hcf_cntl(&(lp->hcfCtx), - // // HCF_PORT_ENABLE | HCF_PORT_0); - //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_ENABLE); - // //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_CONNECT); - hcf_cntl(&(lp->hcfCtx), HCF_CNTL_ENABLE | HCF_PORT_0); hcf_cntl(&(lp->hcfCtx), HCF_CNTL_CONNECT); } else { - //hcf_cntl_port(&(lp->hcfCtx), - // HCF_PORT_DISABLE | HCF_PORT_0); - // //hcf_cntl(&(lp->hcfCtx), - // // HCF_PORT_DISABLE | HCF_PORT_0); - //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISABLE); - // //hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISCONNECT); - hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISABLE | HCF_PORT_0); hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISCONNECT); } @@ -1175,7 +1161,8 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_put_info +} /* wvlan_uil_put_info */ + /*============================================================================*/ /******************************************************************************* @@ -1257,12 +1244,12 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->hcfCtx.IFB_FWIdentity.comp_id) == COMP_ID_FW_AP; break; - //case CFG_DRV_INFO: + /* case CFG_DRV_INFO: */ case CFG_ENCRYPT_STRING: case CFG_COUNTRY_STRING: case CFG_DRIVER_ENABLE: case CFG_WOLAS_ENABLE: - // TODO: determine if we're going to support these + /* TODO: determine if we're going to support these */ urq->result = UIL_FAILURE; break; case CFG_DRV_INFO: @@ -1282,7 +1269,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) /* Else fall through to the default */ - case CFG_FW_IDENTITY: // For Hermes-1, this is cached + case CFG_FW_IDENTITY: /* For Hermes-1, this is cached */ default: /* Verify the user buffer */ @@ -1319,15 +1306,15 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) urq->result = hcf_get_info(&(lp->hcfCtx), (LTVP) pLtv); wl_act_int_on(lp); - // Copy the LTV into the user's buffer. - //copy_to_user(urq->data, pLtv, urq->len); + /* Copy the LTV into the user's buffer. */ + /*copy_to_user(urq->data, pLtv, urq->len); */ - //if(ltvAllocated) - //{ - // kfree(pLtv); - //} + /*if(ltvAllocated) + { + kfree(pLtv); + }*/ - //urq->result = UIL_SUCCESS; + /* urq->result = UIL_SUCCESS; */ break; } @@ -1356,14 +1343,14 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) #ifdef WARP case CFG_CNF_TX_POW_LVL: case CFG_CNF_CONNECTION_CNTL: - case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval - case CFG_COEXISTENSE_BEHAVIOUR: // Coexistence Behavior - //case CFG_CNF_RX_ALL_GROUP_ADDRESS: -#endif // HERMES25 + case CFG_CNF_OWN_BEACON_INTERVAL: /* Own Beacon Interval */ + case CFG_COEXISTENSE_BEHAVIOUR: /* Coexistence Behavior */ + /*case CFG_CNF_RX_ALL_GROUP_ADDRESS: */ +#endif /* HERMES25 */ case CFG_CREATE_IBSS: case CFG_RTS_THRH: case CFG_PROMISCUOUS_MODE: - //case CFG_WAKE_ON_LAN: + /*case CFG_WAKE_ON_LAN: */ case CFG_RTS_THRH0: case CFG_RTS_THRH1: case CFG_RTS_THRH2: @@ -1392,25 +1379,25 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) case CFG_MAX_RX_LIFETIME: case CFG_CF_POLLABLE: case CFG_PRIVACY_OPT_IMPLEMENTED: - //case CFG_CURRENT_REMOTE_RATES: - //case CFG_CURRENT_USED_RATES: - //case CFG_CURRENT_SYSTEM_SCALE: - //case CFG_CURRENT_TX_RATE1: - //case CFG_CURRENT_TX_RATE2: - //case CFG_CURRENT_TX_RATE3: - //case CFG_CURRENT_TX_RATE4: - //case CFG_CURRENT_TX_RATE5: - //case CFG_CURRENT_TX_RATE6: + /* case CFG_CURRENT_REMOTE_RATES: */ + /* case CFG_CURRENT_USED_RATES: */ + /* case CFG_CURRENT_SYSTEM_SCALE: */ + /* case CFG_CURRENT_TX_RATE1: */ + /* case CFG_CURRENT_TX_RATE2: */ + /* case CFG_CURRENT_TX_RATE3: */ + /* case CFG_CURRENT_TX_RATE4: */ + /* case CFG_CURRENT_TX_RATE5: */ + /* case CFG_CURRENT_TX_RATE6: */ case CFG_PHY_TYPE: case CFG_CUR_CHANNEL: - //case CFG_CURRENT_POWER_STATE: - //case CFG_CCAMODE: - // lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); - // break; + /* case CFG_CURRENT_POWER_STATE: */ + /* case CFG_CCAMODE: */ + /* lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); */ + /* break; */ /* name string gets just need the first hcf_16 byte flipped (length of string) */ case CFG_CNF_OWN_SSID: case CFG_CNF_OWN_NAME: - //case CNF_DESIRED_SSID: + /* case CNF_DESIRED_SSID: */ case CFG_DESIRED_SSID: case CFG_SCAN_SSID: case CFG_CUR_SSID: @@ -1431,8 +1418,8 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) case CFG_NIC_MAC_ADDR: case CFG_SUPPORTED_DATA_RATES: /* need to ensure we can treat this as a string */ break; - //case CFG_CNF_COUNTRY_INFO: /* special case, see page 75 of 022486, Rev C. */ - //case CFG_CURRENT_COUNTRY_INFO: /* special case, see page 101 of 022486, Rev C. */ + /* case CFG_CNF_COUNTRY_INFO: */ /* special case, see page 75 of 022486, Rev C. */ + /* case CFG_CURRENT_COUNTRY_INFO: */ /* special case, see page 101 of 022486, Rev C. */ /* lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]); @@ -1455,8 +1442,8 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) break; case CFG_CNF_MCAST_RATE: case CFG_TX_RATE_CNTL: - case CFG_SUPPORTED_RATE_SET_CNTL: // Supported Rate Set Control - case CFG_BASIC_RATE_SET_CNTL: // Basic Rate Set Control + case CFG_SUPPORTED_RATE_SET_CNTL: /* Supported Rate Set Control */ + case CFG_BASIC_RATE_SET_CNTL: /* Basic Rate Set Control */ lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]); break; @@ -1474,7 +1461,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]); lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]); break; - //case CFG_HSI_SUP_RANGE: + /* case CFG_HSI_SUP_RANGE: */ case CFG_NIC_MFI_SUP_RANGE: case CFG_NIC_CFI_SUP_RANGE: case CFG_NIC_PROFILE: @@ -1496,7 +1483,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) case CFG_PRI_IDENTITY: break; case CFG_MB_INFO: - //wvlanEndianTranslateMailbox(pLtv); + /* wvlanEndianTranslateMailbox(pLtv); */ break; /* MSF and HCF RIDS */ case CFG_IFB: @@ -1510,7 +1497,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) break; } - // Copy the LTV into the user's buffer. + /* Copy the LTV into the user's buffer. */ copy_to_user(urq->data, &(lp->ltvRecord), urq->len); if (ltvAllocated) @@ -1526,7 +1513,7 @@ int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // wvlan_uil_get_info +} /* wvlan_uil_get_info */ /*============================================================================*/ @@ -1580,13 +1567,13 @@ int cfg_driver_info(struct uilreq *urq, struct wl_private *lp) lp->driverInfo.card_stat = lp->hcfCtx.IFB_CardStat; - // Copy the driver information into the user's buffer. + /* Copy the driver information into the user's buffer. */ urq->result = UIL_SUCCESS; copy_to_user(urq->data, &(lp->driverInfo), sizeof(lp->driverInfo)); DBG_LEAVE(DbgInfo); return result; -} // cfg_driver_info +} /* cfg_driver_info */ /*============================================================================*/ @@ -1643,7 +1630,7 @@ int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp) DBG_LEAVE(DbgInfo); return result; -} // cfg_driver_identity +} /* cfg_driver_identity */ /*============================================================================*/ @@ -1700,7 +1687,7 @@ int wvlan_set_netname(struct net_device *dev, DBG_LEAVE(DbgInfo); return ret; -} // wvlan_set_netname +} /* wvlan_set_netname */ /*============================================================================*/ @@ -1764,7 +1751,7 @@ int wvlan_get_netname(struct net_device *dev, DBG_LEAVE(DbgInfo); return ret; -} // wvlan_get_netname +} /* wvlan_get_netname */ /*============================================================================*/ @@ -1815,7 +1802,7 @@ int wvlan_set_station_nickname(struct net_device *dev, DBG_LEAVE(DbgInfo); return ret; -} // wvlan_set_station_nickname +} /* wvlan_set_station_nickname */ /*============================================================================*/ @@ -1876,10 +1863,10 @@ int wvlan_get_station_nickname(struct net_device *dev, wl_unlock(lp, &flags); -//out: +/* out: */ DBG_LEAVE(DbgInfo); return ret; -} // wvlan_get_station_nickname +} /* wvlan_get_station_nickname */ /*============================================================================*/ @@ -1937,7 +1924,7 @@ int wvlan_set_porttype(struct net_device *dev, out_unlock: wl_unlock(lp, &flags); -//out: +/* out: */ DBG_LEAVE(DbgInfo); return ret; } @@ -1999,13 +1986,13 @@ int wvlan_get_porttype(struct net_device *dev, wl_unlock(lp, &flags); -//out: +/* out: */ DBG_LEAVE(DbgInfo); return ret; -} // wvlan_get_porttype +} /* wvlan_get_porttype */ /*============================================================================*/ -#endif // WIRELESS_EXT +#endif /* WIRELESS_EXT */ @@ -2072,7 +2059,7 @@ int wvlan_rts(struct rtsreq *rrq, __u32 io_base) DBG_LEAVE(DbgInfo); return ioctl_ret; -} // wvlan_rts +} /* wvlan_rts */ /*============================================================================*/ #endif /* USE_RTS */ -- cgit v0.10.2 From 76abcc51919b2ba34703287b9d3ecb40f70683b0 Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:55 +0200 Subject: staging: wlags49_h2: wl_util: fixes spacing around parentheses This commit corrects the spacing in an and around parentheses in the file. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_util.h b/drivers/staging/wlags49_h2/wl_util.h index 946b1b6..67ee069 100644 --- a/drivers/staging/wlags49_h2/wl_util.h +++ b/drivers/staging/wlags49_h2/wl_util.h @@ -65,32 +65,32 @@ /******************************************************************************* * function prototypes ******************************************************************************/ -int dbm( int value ); +int dbm(int value); -int is_valid_key_string( char *s ); +int is_valid_key_string(char *s); -void key_string2key( char *ks, KEY_STRCT *key ); +void key_string2key(char *ks, KEY_STRCT *key); -void wl_hcf_error( struct net_device *dev, int hcfStatus ); +void wl_hcf_error(struct net_device *dev, int hcfStatus); -void wl_endian_translate_event( ltv_t *pLtv ); +void wl_endian_translate_event(ltv_t *pLtv); -int wl_has_wep( IFBP ifbp ); +int wl_has_wep(IFBP ifbp); -hcf_8 wl_parse_ds_ie( PROBE_RESP *probe_rsp ); -hcf_8 * wl_parse_wpa_ie( PROBE_RESP *probe_rsp, hcf_16 *length ); -hcf_8 * wl_print_wpa_ie( hcf_8 *buffer, int length ); +hcf_8 wl_parse_ds_ie(PROBE_RESP *probe_rsp); +hcf_8 * wl_parse_wpa_ie(PROBE_RESP *probe_rsp, hcf_16 *length); +hcf_8 * wl_print_wpa_ie(hcf_8 *buffer, int length); int wl_get_tallies(struct wl_private *, CFG_HERMES_TALLIES_STRCT *); -int wl_is_a_valid_chan( int channel ); -int wl_is_a_valid_freq( long frequency ); -long wl_get_freq_from_chan( int channel ); -int wl_get_chan_from_freq( long frequency ); +int wl_is_a_valid_chan(int channel); +int wl_is_a_valid_freq(long frequency); +long wl_get_freq_from_chan(int channel); +int wl_get_chan_from_freq(long frequency); -void wl_process_link_status( struct wl_private *lp ); -void wl_process_probe_response( struct wl_private *lp ); -void wl_process_updated_record( struct wl_private *lp ); -void wl_process_assoc_status( struct wl_private *lp ); -void wl_process_security_status( struct wl_private *lp ); +void wl_process_link_status(struct wl_private *lp); +void wl_process_probe_response(struct wl_private *lp); +void wl_process_updated_record(struct wl_private *lp); +void wl_process_assoc_status(struct wl_private *lp); +void wl_process_security_status(struct wl_private *lp); #endif // __WL_UTIL_H__ -- cgit v0.10.2 From 3bba6195bb0ec85141ef0495a612441ae3007e2e Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:56 +0200 Subject: staging: wlags49_h2: wl_util: converts C99 // comment This commit converts a C99 // comment to /* */ Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_util.h b/drivers/staging/wlags49_h2/wl_util.h index 67ee069..9164c30a 100644 --- a/drivers/staging/wlags49_h2/wl_util.h +++ b/drivers/staging/wlags49_h2/wl_util.h @@ -93,4 +93,4 @@ void wl_process_updated_record(struct wl_private *lp); void wl_process_assoc_status(struct wl_private *lp); void wl_process_security_status(struct wl_private *lp); -#endif // __WL_UTIL_H__ +#endif /* __WL_UTIL_H__ */ -- cgit v0.10.2 From e5516fd34eb2f521b1cb0292129c40de46da931a Mon Sep 17 00:00:00 2001 From: Johan Meiring Date: Fri, 30 Nov 2012 18:58:57 +0200 Subject: staging: wlags49_h2: wl_util: corrects asterisk placement This commit fixes incorrect placement of the asterisk character. Signed-off-by: Johan Meiring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_util.h b/drivers/staging/wlags49_h2/wl_util.h index 9164c30a..57bfd7f 100644 --- a/drivers/staging/wlags49_h2/wl_util.h +++ b/drivers/staging/wlags49_h2/wl_util.h @@ -77,9 +77,9 @@ void wl_endian_translate_event(ltv_t *pLtv); int wl_has_wep(IFBP ifbp); -hcf_8 wl_parse_ds_ie(PROBE_RESP *probe_rsp); -hcf_8 * wl_parse_wpa_ie(PROBE_RESP *probe_rsp, hcf_16 *length); -hcf_8 * wl_print_wpa_ie(hcf_8 *buffer, int length); +hcf_8 wl_parse_ds_ie(PROBE_RESP *probe_rsp); +hcf_8 *wl_parse_wpa_ie(PROBE_RESP *probe_rsp, hcf_16 *length); +hcf_8 *wl_print_wpa_ie(hcf_8 *buffer, int length); int wl_get_tallies(struct wl_private *, CFG_HERMES_TALLIES_STRCT *); int wl_is_a_valid_chan(int channel); -- cgit v0.10.2 From 1901ab629279499249dfe3a26b0a31f0af8efca5 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 4 Dec 2012 21:08:36 +0100 Subject: staging: wlags49_h2: remove unneeded memset() in wireless_get_bssid() A few lines after this call, we memcpy over the same memory area, so the call to memset is not necessary. Signed-off-by: Cyril Roelandt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlags49_h2/wl_wext.c b/drivers/staging/wlags49_h2/wl_wext.c index f553366..c731ff2 100644 --- a/drivers/staging/wlags49_h2/wl_wext.c +++ b/drivers/staging/wlags49_h2/wl_wext.c @@ -796,8 +796,6 @@ static int wireless_get_bssid(struct net_device *dev, struct iw_request_info *in wl_act_int_off( lp ); - memset( &ap_addr->sa_data, 0, ETH_ALEN ); - ap_addr->sa_family = ARPHRD_ETHER; /* Assume AP mode here, which means the BSSID is our own MAC address. In -- cgit v0.10.2 From 7c65fa2a4c176c9bfab1ef954c4cef005dd9fb8b Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Wed, 28 Nov 2012 21:11:02 +0000 Subject: staging: vt6656: Remove QWORD from source and replace with u64. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/80211mgr.c b/drivers/staging/vt6656/80211mgr.c index e6ced95..8221d65 100644 --- a/drivers/staging/vt6656/80211mgr.c +++ b/drivers/staging/vt6656/80211mgr.c @@ -96,9 +96,10 @@ vMgrEncodeBeacon( { pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; - /* Fixed Fields */ - pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) - + WLAN_BEACON_OFF_TS); + /* Fixed Fields */ + pFrame->pqwTimestamp = + (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + + WLAN_BEACON_OFF_TS); pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + WLAN_BEACON_OFF_BCN_INT); pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) @@ -130,9 +131,10 @@ vMgrDecodeBeacon( pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; - /* Fixed Fields */ - pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) - + WLAN_BEACON_OFF_TS); + /* Fixed Fields */ + pFrame->pqwTimestamp = + (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + + WLAN_BEACON_OFF_TS); pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + WLAN_BEACON_OFF_BCN_INT); pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) @@ -671,9 +673,10 @@ vMgrEncodeProbeResponse( { pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; - /* Fixed Fields */ - pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) - + WLAN_PROBERESP_OFF_TS); + /* Fixed Fields */ + pFrame->pqwTimestamp = + (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + + WLAN_PROBERESP_OFF_TS); pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + WLAN_PROBERESP_OFF_BCN_INT); pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) @@ -706,9 +709,10 @@ vMgrDecodeProbeResponse( pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; - /* Fixed Fields */ - pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) - + WLAN_PROBERESP_OFF_TS); + /* Fixed Fields */ + pFrame->pqwTimestamp = + (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + + WLAN_PROBERESP_OFF_TS); pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) + WLAN_PROBERESP_OFF_BCN_INT); pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) diff --git a/drivers/staging/vt6656/80211mgr.h b/drivers/staging/vt6656/80211mgr.h index e5db73b..29fad08 100644 --- a/drivers/staging/vt6656/80211mgr.h +++ b/drivers/staging/vt6656/80211mgr.h @@ -526,7 +526,7 @@ typedef struct tagWLAN_FR_BEACON { PBYTE pBuf; PUWLAN_80211HDR pHdr; // fixed fields - PQWORD pqwTimestamp; + u64 *pqwTimestamp; PWORD pwBeaconInterval; PWORD pwCapInfo; /*-- info elements ----------*/ @@ -683,7 +683,7 @@ typedef struct tagWLAN_FR_PROBERESP { PBYTE pBuf; PUWLAN_80211HDR pHdr; /*-- fixed fields -----------*/ - PQWORD pqwTimestamp; + u64 *pqwTimestamp; PWORD pwBeaconInterval; PWORD pwCapInfo; /*-- info elements ----------*/ diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index 6a13941..539bc1d 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -339,7 +339,7 @@ PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext, BOOL BSSbInsertToBSSList(void *hDeviceContext, PBYTE abyBSSIDAddr, - QWORD qwTimestamp, + u64 qwTimestamp, WORD wBeaconInterval, WORD wCapInfo, BYTE byCurrChannel, @@ -380,8 +380,7 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext, // save the BSS info pBSSList->bActive = TRUE; memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN); - HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp)); - LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp)); + pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp); pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval); pBSSList->wCapInfo = cpu_to_le16(wCapInfo); pBSSList->uClearCount = 0; @@ -519,7 +518,7 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext, // TODO: input structure modify BOOL BSSbUpdateToBSSList(void *hDeviceContext, - QWORD qwTimestamp, + u64 qwTimestamp, WORD wBeaconInterval, WORD wCapInfo, BYTE byCurrChannel, @@ -548,8 +547,8 @@ BOOL BSSbUpdateToBSSList(void *hDeviceContext, return FALSE; - HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp)); - LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp)); + pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp); + pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval); pBSSList->wCapInfo = cpu_to_le16(wCapInfo); pBSSList->uClearCount = 0; diff --git a/drivers/staging/vt6656/bssdb.h b/drivers/staging/vt6656/bssdb.h index 6b2ec39..125edc2 100644 --- a/drivers/staging/vt6656/bssdb.h +++ b/drivers/staging/vt6656/bssdb.h @@ -142,8 +142,8 @@ typedef struct tagKnownBSS { unsigned int uClearCount; // BYTE abyIEs[WLAN_BEACON_FR_MAXLEN]; unsigned int uIELength; - QWORD qwBSSTimestamp; - QWORD qwLocalTSF; // local TSF timer + u64 qwBSSTimestamp; + u64 qwLocalTSF;/* local TSF timer */ CARD_PHY_TYPE eNetworkTypeInUse; @@ -239,7 +239,7 @@ void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID); BOOL BSSbInsertToBSSList(void *hDeviceContext, PBYTE abyBSSIDAddr, - QWORD qwTimestamp, + u64 qwTimestamp, WORD wBeaconInterval, WORD wCapInfo, BYTE byCurrChannel, @@ -256,7 +256,7 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext, void *pRxPacketContext); BOOL BSSbUpdateToBSSList(void *hDeviceContext, - QWORD qwTimestamp, + u64 qwTimestamp, WORD wBeaconInterval, WORD wCapInfo, BYTE byCurrChannel, diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 826520b..d89fac5 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -654,28 +654,18 @@ BYTE CARDbyGetPktType(void *pDeviceHandler) * Return Value: TSF Offset value * */ -QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2) +u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2) { - QWORD qwTSFOffset; - WORD wRxBcnTSFOffst = 0; + u64 qwTSFOffset = 0; + WORD wRxBcnTSFOffst = 0; - HIDWORD(qwTSFOffset) = 0; - LODWORD(qwTSFOffset) = 0; + wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE]; - wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE]; - (qwTSF2).u.dwLowDword += (DWORD)(wRxBcnTSFOffst); - if ((qwTSF2).u.dwLowDword < (DWORD)(wRxBcnTSFOffst)) { - (qwTSF2).u.dwHighDword++; - } - LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2); - if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) { - // if borrow needed - HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ; - } - else { - HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2); - }; - return (qwTSFOffset); + qwTSF2 += (u64)wRxBcnTSFOffst; + + qwTSFOffset = qwTSF1 - qwTSF2; + + return qwTSFOffset; } @@ -696,32 +686,26 @@ QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2) * */ void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, - QWORD qwBSSTimestamp, QWORD qwLocalTSF) + u64 qwBSSTimestamp, u64 qwLocalTSF) { PSDevice pDevice = (PSDevice) pDeviceHandler; - QWORD qwTSFOffset; - DWORD dwTSFOffset1,dwTSFOffset2; + u64 qwTSFOffset = 0; BYTE pbyData[8]; - HIDWORD(qwTSFOffset) = 0; - LODWORD(qwTSFOffset) = 0; qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); // adjust TSF // HW's TSF add TSF Offset reg - dwTSFOffset1 = LODWORD(qwTSFOffset); - dwTSFOffset2 = HIDWORD(qwTSFOffset); - - pbyData[0] = (BYTE)dwTSFOffset1; - pbyData[1] = (BYTE)(dwTSFOffset1>>8); - pbyData[2] = (BYTE)(dwTSFOffset1>>16); - pbyData[3] = (BYTE)(dwTSFOffset1>>24); - pbyData[4] = (BYTE)dwTSFOffset2; - pbyData[5] = (BYTE)(dwTSFOffset2>>8); - pbyData[6] = (BYTE)(dwTSFOffset2>>16); - pbyData[7] = (BYTE)(dwTSFOffset2>>24); + pbyData[0] = (u8)qwTSFOffset; + pbyData[1] = (u8)(qwTSFOffset >> 8); + pbyData[2] = (u8)(qwTSFOffset >> 16); + pbyData[3] = (u8)(qwTSFOffset >> 24); + pbyData[4] = (u8)(qwTSFOffset >> 32); + pbyData[5] = (u8)(qwTSFOffset >> 40); + pbyData[6] = (u8)(qwTSFOffset >> 48); + pbyData[7] = (u8)(qwTSFOffset >> 56); CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_SET_TSFTBTT, @@ -745,12 +729,11 @@ void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, * Return Value: TRUE if success; otherwise FALSE * */ -BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF) +BOOL CARDbGetCurrentTSF(void *pDeviceHandler, u64 *pqwCurrTSF) { - PSDevice pDevice = (PSDevice) pDeviceHandler; + PSDevice pDevice = (PSDevice) pDeviceHandler; - LODWORD(*pqwCurrTSF) = LODWORD(pDevice->qwCurrTSF); - HIDWORD(*pqwCurrTSF) = HIDWORD(pDevice->qwCurrTSF); + *pqwCurrTSF = pDevice->qwCurrTSF; return(TRUE); } @@ -773,8 +756,7 @@ BOOL CARDbClearCurrentTSF(void *pDeviceHandler) MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTRST); - LODWORD(pDevice->qwCurrTSF) = 0; - HIDWORD(pDevice->qwCurrTSF) = 0; + pDevice->qwCurrTSF = 0; return(TRUE); } @@ -793,7 +775,7 @@ BOOL CARDbClearCurrentTSF(void *pDeviceHandler) * Return Value: TSF value of next Beacon * */ -QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval) +u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval) { unsigned int uLowNextTBTT; @@ -802,18 +784,19 @@ QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval) uBeaconInterval = wBeaconInterval * 1024; // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval - uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10; - uLowRemain = (uLowNextTBTT) % uBeaconInterval; - uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF)) - % uBeaconInterval; - uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; - uLowRemain = uBeaconInterval - uLowRemain; + uLowNextTBTT = ((qwTSF & 0xffffffffU) >> 10) << 10; + uLowRemain = (uLowNextTBTT) % uBeaconInterval; + uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32)) + % uBeaconInterval; + uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; + uLowRemain = uBeaconInterval - uLowRemain; // check if carry when add one beacon interval - if ((~uLowNextTBTT) < uLowRemain) - HIDWORD(qwTSF) ++ ; + if ((~uLowNextTBTT) < uLowRemain) + qwTSF = ((qwTSF >> 32) + 1) << 32; - LODWORD(qwTSF) = uLowNextTBTT + uLowRemain; + qwTSF = (qwTSF & 0xffffffff00000000U) | + (u64)(uLowNextTBTT + uLowRemain); return (qwTSF); } @@ -837,28 +820,22 @@ void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval) { PSDevice pDevice = (PSDevice) pDeviceHandler; - QWORD qwNextTBTT; - DWORD dwLoTBTT,dwHiTBTT; - BYTE pbyData[8]; + u64 qwNextTBTT = 0; + BYTE pbyData[8]; - HIDWORD(qwNextTBTT) = 0; - LODWORD(qwNextTBTT) = 0; - CARDbClearCurrentTSF(pDevice); + CARDbClearCurrentTSF(pDevice); //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter - qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); + qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); // Set NextTBTT - dwLoTBTT = LODWORD(qwNextTBTT); - dwHiTBTT = HIDWORD(qwNextTBTT); - - pbyData[0] = (BYTE)dwLoTBTT; - pbyData[1] = (BYTE)(dwLoTBTT>>8); - pbyData[2] = (BYTE)(dwLoTBTT>>16); - pbyData[3] = (BYTE)(dwLoTBTT>>24); - pbyData[4] = (BYTE)dwHiTBTT; - pbyData[5] = (BYTE)(dwHiTBTT>>8); - pbyData[6] = (BYTE)(dwHiTBTT>>16); - pbyData[7] = (BYTE)(dwHiTBTT>>24); + pbyData[0] = (u8)qwNextTBTT; + pbyData[1] = (u8)(qwNextTBTT >> 8); + pbyData[2] = (u8)(qwNextTBTT >> 16); + pbyData[3] = (u8)(qwNextTBTT >> 24); + pbyData[4] = (u8)(qwNextTBTT >> 32); + pbyData[5] = (u8)(qwNextTBTT >> 40); + pbyData[6] = (u8)(qwNextTBTT >> 48); + pbyData[7] = (u8)(qwNextTBTT >> 56); CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_SET_TSFTBTT, @@ -887,27 +864,24 @@ void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval) * Return Value: none * */ -void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF, +void CARDvUpdateNextTBTT(void *pDeviceHandler, u64 qwTSF, WORD wBeaconInterval) { PSDevice pDevice = (PSDevice) pDeviceHandler; - DWORD dwLoTBTT,dwHiTBTT; BYTE pbyData[8]; qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); // Set NextTBTT - dwLoTBTT = LODWORD(qwTSF); - dwHiTBTT = HIDWORD(qwTSF); - - pbyData[0] = (BYTE)dwLoTBTT; - pbyData[1] = (BYTE)(dwLoTBTT>>8); - pbyData[2] = (BYTE)(dwLoTBTT>>16); - pbyData[3] = (BYTE)(dwLoTBTT>>24); - pbyData[4] = (BYTE)dwHiTBTT; - pbyData[5] = (BYTE)(dwHiTBTT>>8); - pbyData[6] = (BYTE)(dwHiTBTT>>16); - pbyData[7] = (BYTE)(dwHiTBTT>>24); + + pbyData[0] = (u8)qwTSF; + pbyData[1] = (u8)(qwTSF >> 8); + pbyData[2] = (u8)(qwTSF >> 16); + pbyData[3] = (u8)(qwTSF >> 24); + pbyData[4] = (u8)(qwTSF >> 32); + pbyData[5] = (u8)(qwTSF >> 40); + pbyData[6] = (u8)(qwTSF >> 48); + pbyData[7] = (u8)(qwTSF >> 56); CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_SET_TSFTBTT, @@ -918,7 +892,8 @@ void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF, ); - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",(int)HIDWORD(qwTSF), (int)LODWORD(qwTSF)); + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF); return; } diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h index 55962b1..1059467 100644 --- a/drivers/staging/vt6656/card.h +++ b/drivers/staging/vt6656/card.h @@ -67,14 +67,14 @@ void CARDvUpdateBasicTopRate(void *pDeviceHandler); void CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx); BOOL CARDbIsOFDMinBasicRate(void *pDeviceHandler); void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, - QWORD qwBSSTimestamp, QWORD qwLocalTSF); -BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF); + u64 qwBSSTimestamp, u64 qwLocalTSF); +BOOL CARDbGetCurrentTSF(void *pDeviceHandler, u64 *pqwCurrTSF); BOOL CARDbClearCurrentTSF(void *pDeviceHandler); void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval); -void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF, +void CARDvUpdateNextTBTT(void *pDeviceHandler, u64 qwTSF, WORD wBeaconInterval); -QWORD CARDqGetNextTBTT(QWORD qwTSF, WORD wBeaconInterval); -QWORD CARDqGetTSFOffset(BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2); +u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval); +u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2); BOOL CARDbRadioPowerOff(void *pDeviceHandler); BOOL CARDbRadioPowerOn(void *pDeviceHandler); BYTE CARDbyGetPktType(void *pDeviceHandler); diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index 25bf03a..047f550 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -527,7 +527,7 @@ typedef struct __device_info { // 802.11 management SMgmtObject sMgmtObj; - QWORD qwCurrTSF; + u64 qwCurrTSF; unsigned int cbBulkInMax; BOOL bPSRxBeacon; diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index e94f6a1..8f21bc7 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -328,7 +328,7 @@ RXbBulkInProcessData ( PBYTE pbyRsr; PBYTE pbyNewRsr; PBYTE pbyRSSI; - PQWORD pqwTSFTime; + u64 *pqwTSFTime; PBYTE pbyFrame; BOOL bDeFragRx = FALSE; unsigned int cbHeaderOffset; @@ -411,7 +411,7 @@ RXbBulkInProcessData ( wPLCPwithPadding = ( (*pwPLCP_Length / 4) + ( (*pwPLCP_Length % 4) ? 1:0 ) ) *4; - pqwTSFTime = (PQWORD) (pbyDAddress + 8 + wPLCPwithPadding); + pqwTSFTime = (u64 *)(pbyDAddress + 8 + wPLCPwithPadding); if(pDevice->byBBType == BB_TYPE_11G) { pby3SQ = pbyDAddress + 8 + wPLCPwithPadding + 12; pbySQ = pby3SQ; @@ -598,8 +598,7 @@ RXbBulkInProcessData ( pRxPacket->cbMPDULen = FrameSize; pRxPacket->uRSSI = *pbyRSSI; pRxPacket->bySQ = *pbySQ; - HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime)); - LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime)); + pRxPacket->qwLocalTSF = cpu_to_le64(*pqwTSFTime); if (bIsWEP) { // strip IV pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame); @@ -910,7 +909,7 @@ RXbBulkInProcessData ( RSC = dwRxTSC47_16; RSC <<= 16; RSC += wRxTSC15_0; - memcpy(&(pKey->KeyRSC), &RSC, sizeof(QWORD)); + memcpy(&(pKey->KeyRSC), &RSC, sizeof(u64)); if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) { diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c index 26a7d0e..3322855 100644 --- a/drivers/staging/vt6656/hostap.c +++ b/drivers/staging/vt6656/hostap.c @@ -512,14 +512,12 @@ static int hostap_set_encryption(PSDevice pDevice, } else { // 8021x enable, individual key dwKeyIndex |= (1 << 30); // set pairwise key - if (KeybSetKey(pDevice, - &(pDevice->sKey), - ¶m->sta_addr[0], - dwKeyIndex & ~(USE_KEYRSC), - param->u.crypt.key_len, - (PQWORD) &(KeyRSC), - (PBYTE)abyKey, - KEY_CTL_WEP + if (KeybSetKey(pDevice, &(pDevice->sKey), + ¶m->sta_addr[0], + dwKeyIndex & ~(USE_KEYRSC), + param->u.crypt.key_len, + &KeyRSC, (PBYTE)abyKey, + KEY_CTL_WEP ) == TRUE) { @@ -574,7 +572,7 @@ static int hostap_set_encryption(PSDevice pDevice, &(pDevice->sKey), dwKeyIndex, param->u.crypt.key_len, - (PQWORD) &(KeyRSC), + &KeyRSC, abyKey, byKeyDecMode ); @@ -587,7 +585,7 @@ static int hostap_set_encryption(PSDevice pDevice, ¶m->sta_addr[0], dwKeyIndex, param->u.crypt.key_len, - (PQWORD) &(KeyRSC), + &KeyRSC, (PBYTE)abyKey, byKeyDecMode ) == TRUE) { diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c index bba31ca..7718ac2 100644 --- a/drivers/staging/vt6656/int.c +++ b/drivers/staging/vt6656/int.c @@ -179,8 +179,7 @@ void INTnsProcessData(PSDevice pDevice) NULL); } } - LODWORD(pDevice->qwCurrTSF) = pINTData->dwLoTSF; - HIDWORD(pDevice->qwCurrTSF) = pINTData->dwHiTSF; + pDevice->qwCurrTSF = cpu_to_le64(pINTData->qwTSF); /*DBG_PRN_GRP01(("ISR0 = %02x , LoTsf = %08x, HiTsf = %08x\n", diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h index 5d8faf9..ffc243f 100644 --- a/drivers/staging/vt6656/int.h +++ b/drivers/staging/vt6656/int.h @@ -48,8 +48,7 @@ typedef struct tagSINTData { BYTE byTSR3; BYTE byPkt3; WORD wTime3; - u32 dwLoTSF; - u32 dwHiTSF; + u64 qwTSF; BYTE byISR0; BYTE byISR1; BYTE byRTSSuccess; diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c index 8c78b86..6f6a219 100644 --- a/drivers/staging/vt6656/key.c +++ b/drivers/staging/vt6656/key.c @@ -224,7 +224,7 @@ BOOL KeybSetKey( PBYTE pbyBSSID, DWORD dwKeyIndex, u32 uKeyLength, - PQWORD pKeyRSC, + u64 *KeyRSC, PBYTE pbyKey, BYTE byKeyDecMode ) @@ -286,13 +286,11 @@ BOOL KeybSetKey( } MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey); - if ((dwKeyIndex & USE_KEYRSC) == 0) { - // RSC set by NIC - memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); - } - else { - memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); - } + if ((dwKeyIndex & USE_KEYRSC) == 0) + pKey->KeyRSC = 0; /* RSC set by NIC */ + else + pKey->KeyRSC = *KeyRSC; + pKey->dwTSC47_16 = 0; pKey->wTSC15_0 = 0; @@ -356,13 +354,11 @@ BOOL KeybSetKey( } MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey); - if ((dwKeyIndex & USE_KEYRSC) == 0) { - // RSC set by NIC - memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); - } - else { - memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); - } + if ((dwKeyIndex & USE_KEYRSC) == 0) + pKey->KeyRSC = 0; /* RSC set by NIC */ + else + pKey->KeyRSC = *KeyRSC; + pKey->dwTSC47_16 = 0; pKey->wTSC15_0 = 0; @@ -676,7 +672,7 @@ BOOL KeybSetDefaultKey( PSKeyManagement pTable, DWORD dwKeyIndex, u32 uKeyLength, - PQWORD pKeyRSC, + u64 *KeyRSC, PBYTE pbyKey, BYTE byKeyDecMode ) @@ -742,12 +738,12 @@ BOOL KeybSetDefaultKey( MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey); - if ((dwKeyIndex & USE_KEYRSC) == 0) { - // RSC set by NIC - memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); - } else { - memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); - } + if ((dwKeyIndex & USE_KEYRSC) == 0) + pKey->KeyRSC = 0; /* RSC set by NIC */ + else + pKey->KeyRSC = *KeyRSC; + + pKey->dwTSC47_16 = 0; pKey->wTSC15_0 = 0; @@ -792,7 +788,7 @@ BOOL KeybSetAllGroupKey( PSKeyManagement pTable, DWORD dwKeyIndex, u32 uKeyLength, - PQWORD pKeyRSC, + u64 *KeyRSC, PBYTE pbyKey, BYTE byKeyDecMode ) @@ -847,13 +843,11 @@ BOOL KeybSetAllGroupKey( MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey); - if ((dwKeyIndex & USE_KEYRSC) == 0) { - // RSC set by NIC - memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); - } - else { - memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); - } + if ((dwKeyIndex & USE_KEYRSC) == 0) + pKey->KeyRSC = 0; /* RSC set by NIC */ + else + pKey->KeyRSC = *KeyRSC; + pKey->dwTSC47_16 = 0; pKey->wTSC15_0 = 0; diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h index bd35d39..863db7c 100644 --- a/drivers/staging/vt6656/key.h +++ b/drivers/staging/vt6656/key.h @@ -60,7 +60,7 @@ typedef struct tagSKeyItem BOOL bKeyValid; u32 uKeyLength; BYTE abyKey[MAX_KEY_LEN]; - QWORD KeyRSC; + u64 KeyRSC; DWORD dwTSC47_16; WORD wTSC15_0; BYTE byCipherSuite; @@ -108,7 +108,7 @@ BOOL KeybSetKey( PBYTE pbyBSSID, DWORD dwKeyIndex, u32 uKeyLength, - PQWORD pKeyRSC, + u64 *KeyRSC, PBYTE pbyKey, BYTE byKeyDecMode ); @@ -147,7 +147,7 @@ BOOL KeybSetDefaultKey( PSKeyManagement pTable, DWORD dwKeyIndex, u32 uKeyLength, - PQWORD pKeyRSC, + u64 *KeyRSC, PBYTE pbyKey, BYTE byKeyDecMode ); @@ -157,7 +157,7 @@ BOOL KeybSetAllGroupKey( PSKeyManagement pTable, DWORD dwKeyIndex, u32 uKeyLength, - PQWORD pKeyRSC, + u64 *KeyRSC, PBYTE pbyKey, BYTE byKeyDecMode ); diff --git a/drivers/staging/vt6656/ttype.h b/drivers/staging/vt6656/ttype.h index dfbf747..89ab494 100644 --- a/drivers/staging/vt6656/ttype.h +++ b/drivers/staging/vt6656/ttype.h @@ -48,18 +48,6 @@ typedef u8 BYTE; typedef u16 WORD; typedef u32 DWORD; -// QWORD is for those situation that we want -// an 8-byte-aligned 8 byte long structure -// which is NOT really a floating point number. -typedef union tagUQuadWord { - struct { - u32 dwLowDword; - u32 dwHighDword; - } u; - double DoNotUseThisField; -} UQuadWord; -typedef UQuadWord QWORD; // 64-bit - /****** Common pointer types ***********************************************/ typedef u32 ULONG_PTR; @@ -73,6 +61,4 @@ typedef WORD * PWORD; typedef DWORD * PDWORD; -typedef QWORD * PQWORD; - #endif /* __TTYPE_H__ */ diff --git a/drivers/staging/vt6656/wmgr.c b/drivers/staging/vt6656/wmgr.c index 95ddc83..7a242f7 100644 --- a/drivers/staging/vt6656/wmgr.c +++ b/drivers/staging/vt6656/wmgr.c @@ -1740,7 +1740,7 @@ s_vMgrRxBeacon( PKnownBSS pBSSList; WLAN_FR_BEACON sFrame; - QWORD qwTSFOffset; + u64 qwTSFOffset; BOOL bIsBSSIDEqual = FALSE; BOOL bIsSSIDEqual = FALSE; BOOL bTSFLargeDiff = FALSE; @@ -1752,8 +1752,8 @@ s_vMgrRxBeacon( BYTE byTIMBitOn = 0; WORD wAIDNumber = 0; unsigned int uNodeIndex; - QWORD qwTimestamp, qwLocalTSF; - QWORD qwCurrTSF; + u64 qwTimestamp, qwLocalTSF; + u64 qwCurrTSF; WORD wStartIndex = 0; WORD wAIDIndex = 0; BYTE byCurrChannel = pRxPacket->byRxChannel; @@ -2013,26 +2013,14 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) } } - HIDWORD(qwTimestamp) = cpu_to_le32(HIDWORD(*sFrame.pqwTimestamp)); - LODWORD(qwTimestamp) = cpu_to_le32(LODWORD(*sFrame.pqwTimestamp)); - HIDWORD(qwLocalTSF) = HIDWORD(pRxPacket->qwLocalTSF); - LODWORD(qwLocalTSF) = LODWORD(pRxPacket->qwLocalTSF); + qwTimestamp = cpu_to_le64(*sFrame.pqwTimestamp); + qwLocalTSF = pRxPacket->qwLocalTSF; // check if beacon TSF larger or small than our local TSF - if (HIDWORD(qwTimestamp) == HIDWORD(qwLocalTSF)) { - if (LODWORD(qwTimestamp) >= LODWORD(qwLocalTSF)) { - bTSFOffsetPostive = TRUE; - } - else { - bTSFOffsetPostive = FALSE; - } - } - else if (HIDWORD(qwTimestamp) > HIDWORD(qwLocalTSF)) { - bTSFOffsetPostive = TRUE; - } - else if (HIDWORD(qwTimestamp) < HIDWORD(qwLocalTSF)) { - bTSFOffsetPostive = FALSE; - } + if (qwTimestamp >= qwLocalTSF) + bTSFOffsetPostive = TRUE; + else + bTSFOffsetPostive = FALSE; if (bTSFOffsetPostive) { qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF)); @@ -2041,10 +2029,8 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp)); } - if (HIDWORD(qwTSFOffset) != 0 || - (LODWORD(qwTSFOffset) > TRIVIAL_SYNC_DIFFERENCE )) { - bTSFLargeDiff = TRUE; - } + if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE) + bTSFLargeDiff = TRUE; // if infra mode @@ -2265,7 +2251,7 @@ void vMgrCreateOwnIBSS(void *hDeviceContext, WORD wMaxSuppRate; BYTE byTopCCKBasicRate; BYTE byTopOFDMBasicRate; - QWORD qwCurrTSF; + u64 qwCurrTSF = 0; unsigned int ii; BYTE abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60}; BYTE abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96}; @@ -2274,9 +2260,6 @@ void vMgrCreateOwnIBSS(void *hDeviceContext, - HIDWORD(qwCurrTSF) = 0; - LODWORD(qwCurrTSF) = 0; - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n"); if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) { @@ -2420,12 +2403,12 @@ void vMgrCreateOwnIBSS(void *hDeviceContext, if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { // BSSID selected must be randomized as spec 11.1.3 - pMgmt->abyCurrBSSID[5] = (BYTE) (LODWORD(qwCurrTSF)& 0x000000ff); - pMgmt->abyCurrBSSID[4] = (BYTE)((LODWORD(qwCurrTSF)& 0x0000ff00) >> 8); - pMgmt->abyCurrBSSID[3] = (BYTE)((LODWORD(qwCurrTSF)& 0x00ff0000) >> 16); - pMgmt->abyCurrBSSID[2] = (BYTE)((LODWORD(qwCurrTSF)& 0x00000ff0) >> 4); - pMgmt->abyCurrBSSID[1] = (BYTE)((LODWORD(qwCurrTSF)& 0x000ff000) >> 12); - pMgmt->abyCurrBSSID[0] = (BYTE)((LODWORD(qwCurrTSF)& 0x0ff00000) >> 20); + pMgmt->abyCurrBSSID[5] = (u8)(qwCurrTSF & 0x000000ff); + pMgmt->abyCurrBSSID[4] = (u8)((qwCurrTSF & 0x0000ff00) >> 8); + pMgmt->abyCurrBSSID[3] = (u8)((qwCurrTSF & 0x00ff0000) >> 16); + pMgmt->abyCurrBSSID[2] = (u8)((qwCurrTSF & 0x00000ff0) >> 4); + pMgmt->abyCurrBSSID[1] = (u8)((qwCurrTSF & 0x000ff000) >> 12); + pMgmt->abyCurrBSSID[0] = (u8)((qwCurrTSF & 0x0ff00000) >> 20); pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0]; pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1]; pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2]; diff --git a/drivers/staging/vt6656/wmgr.h b/drivers/staging/vt6656/wmgr.h index 52b1b56..876c352 100644 --- a/drivers/staging/vt6656/wmgr.h +++ b/drivers/staging/vt6656/wmgr.h @@ -232,7 +232,7 @@ typedef struct tagSTxMgmtPacket { typedef struct tagSRxMgmtPacket { PUWLAN_80211HDR p80211Header; - QWORD qwLocalTSF; + u64 qwLocalTSF; unsigned int cbMPDULen; unsigned int cbPayloadLen; unsigned int uRSSI; diff --git a/drivers/staging/vt6656/wpactl.c b/drivers/staging/vt6656/wpactl.c index cc1d48b..3afbb61 100644 --- a/drivers/staging/vt6656/wpactl.c +++ b/drivers/staging/vt6656/wpactl.c @@ -74,7 +74,7 @@ int wpa_set_keys(PSDevice pDevice, void *ctx) DWORD dwKeyIndex = 0; BYTE abyKey[MAX_KEY_LEN]; BYTE abySeq[MAX_KEY_LEN]; - QWORD KeyRSC; + u64 KeyRSC; BYTE byKeyDecMode = KEY_CTL_WEP; int ret = 0; int uu; @@ -136,9 +136,9 @@ int wpa_set_keys(PSDevice pDevice, void *ctx) if (param->u.wpa_key.seq_len > 0) { for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) { if (ii < 4) - LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8)); + KeyRSC |= (abySeq[ii] << (ii * 8)); else - HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8)); + KeyRSC |= (abySeq[ii] << ((ii-4) * 8)); } dwKeyIndex |= 1 << 29; } @@ -203,7 +203,7 @@ int wpa_set_keys(PSDevice pDevice, void *ctx) if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex, param->u.wpa_key.key_len, - (PQWORD) &(KeyRSC), + &KeyRSC, (PBYTE)abyKey, byKeyDecMode ) == TRUE) && @@ -211,7 +211,7 @@ int wpa_set_keys(PSDevice pDevice, void *ctx) &(pDevice->sKey), dwKeyIndex, param->u.wpa_key.key_len, - (PQWORD) &(KeyRSC), + &KeyRSC, (PBYTE)abyKey, byKeyDecMode ) == TRUE) ) { @@ -234,7 +234,7 @@ int wpa_set_keys(PSDevice pDevice, void *ctx) } if (KeybSetKey(pDevice, &(pDevice->sKey), ¶m->addr[0], dwKeyIndex, param->u.wpa_key.key_len, - (PQWORD) &(KeyRSC), (PBYTE)abyKey, byKeyDecMode + &KeyRSC, (PBYTE)abyKey, byKeyDecMode ) == TRUE) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n"); } else { -- cgit v0.10.2 From 4f4a89c9cefeefa58006d02059b9fc7e078ae31a Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Mon, 10 Dec 2012 21:55:59 +0000 Subject: staging: vt6656: create new structure names to remove typedefs. This patch and the next 8 patches remove the old structure names and replace; struct vnt_private for DEVICE_INFO and PSDevice struct vnt_manager for SMgmtObject struct vnt_rx_mgmt for SRxMgmtPacket and PSRxMgmtPacket struct vnt_tx_mgmt for STxMgmtPacket and PSTxMgmtPacket and struct vnt_manager vnt_mgmt to replace SMgmtObject sMgmtObj; Applied after patch staging: vt6656: dpc.c :RXbBulkInProcessData clean up RSC Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index 047f550..37ec234 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -392,7 +392,7 @@ typedef struct __device_opt { } OPTIONS, *POPTIONS; -typedef struct __device_info { +typedef struct vnt_private { // netdev struct usb_device* usb; @@ -525,6 +525,7 @@ typedef struct __device_info { // 802.11 management + struct vnt_manager vnt_mgmt; SMgmtObject sMgmtObj; u64 qwCurrTSF; diff --git a/drivers/staging/vt6656/wmgr.h b/drivers/staging/vt6656/wmgr.h index 876c352..f98309b 100644 --- a/drivers/staging/vt6656/wmgr.h +++ b/drivers/staging/vt6656/wmgr.h @@ -218,8 +218,8 @@ typedef enum tagWMAC_POWER_MODE { -// Tx Management Packet descriptor -typedef struct tagSTxMgmtPacket { +/* Tx Management Packet descriptor */ +typedef struct vnt_tx_mgmt { PUWLAN_80211HDR p80211Header; unsigned int cbMPDULen; @@ -228,8 +228,8 @@ typedef struct tagSTxMgmtPacket { } STxMgmtPacket, *PSTxMgmtPacket; -// Rx Management Packet descriptor -typedef struct tagSRxMgmtPacket { +/* Rx Management Packet descriptor */ +typedef struct vnt_rx_mgmt { PUWLAN_80211HDR p80211Header; u64 qwLocalTSF; @@ -244,7 +244,7 @@ typedef struct tagSRxMgmtPacket { -typedef struct tagSMgmtObject +typedef struct vnt_manager { void *pAdapter; // MAC address -- cgit v0.10.2 From dd0a774fc727ee793780197beb3f2cf80bfefa99 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Mon, 10 Dec 2012 21:59:10 +0000 Subject: staging: vt6656: card/main_usb/device use new structure names This patch also cleans up function declarations, definitions and local variables were appropriate replacing types defined in "ttype.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index d89fac5..93983d9 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -45,6 +45,7 @@ * */ +#include "device.h" #include "tmacro.h" #include "card.h" #include "baseband.h" @@ -91,9 +92,8 @@ const WORD cwRXBCNTSFOff[MAX_RATE] = * Out: * none */ -void CARDbSetMediaChannel(void *pDeviceHandler, unsigned int uConnectionChannel) +void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel) { -PSDevice pDevice = (PSDevice) pDeviceHandler; if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38 if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL)) @@ -149,17 +149,17 @@ PSDevice pDevice = (PSDevice) pDeviceHandler; * Return Value: response Control frame rate * */ -static WORD swGetCCKControlRate(void *pDeviceHandler, WORD wRateIdx) +static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - unsigned int ui = (unsigned int)wRateIdx; - while (ui > RATE_1M) { - if (pDevice->wBasicRate & ((WORD)1 << ui)) { - return (WORD)ui; - } - ui --; - } - return (WORD)RATE_1M; + u16 ui = wRateIdx; + + while (ui > RATE_1M) { + if (pDevice->wBasicRate & (1 << ui)) + return ui; + ui--; + } + + return RATE_1M; } /* @@ -175,28 +175,33 @@ static WORD swGetCCKControlRate(void *pDeviceHandler, WORD wRateIdx) * Return Value: response Control frame rate * */ -static WORD swGetOFDMControlRate(void *pDeviceHandler, WORD wRateIdx) +static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - unsigned int ui = (unsigned int)wRateIdx; - - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate); - - if (!CARDbIsOFDMinBasicRate(pDevice)) { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx); - if (wRateIdx > RATE_24M) - wRateIdx = RATE_24M; - return wRateIdx; - } - while (ui > RATE_11M) { - if (pDevice->wBasicRate & ((WORD)1 << ui)) { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate : %d\n", ui); - return (WORD)ui; - } - ui --; - } - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n"); - return (WORD)RATE_24M; + u16 ui = wRateIdx; + + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", + pDevice->wBasicRate); + + if (!CARDbIsOFDMinBasicRate(pDevice)) { + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx); + if (wRateIdx > RATE_24M) + wRateIdx = RATE_24M; + return wRateIdx; + } + + while (ui > RATE_11M) { + if (pDevice->wBasicRate & (1 << ui)) { + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "swGetOFDMControlRate: %d\n", ui); + return ui; + } + ui--; + } + + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n"); + + return RATE_24M; } /* @@ -325,16 +330,15 @@ CARDvCalculateOFDMRParameter ( * Return Value: None. * */ -void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType) +void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - BYTE abyServ[4] = {0,0,0,0}; // For CCK - BYTE abySignal[4] = {0,0,0,0}; - WORD awLen[4] = {0,0,0,0}; - BYTE abyTxRate[9] = {0,0,0,0,0,0,0,0,0}; // For OFDM - BYTE abyRsvTime[9] = {0,0,0,0,0,0,0,0,0}; - BYTE abyData[34]; - int i; + u8 abyServ[4] = {0, 0, 0, 0}; /* For CCK */ + u8 abySignal[4] = {0, 0, 0, 0}; + u16 awLen[4] = {0, 0, 0, 0}; + u8 abyTxRate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */ + u8 abyRsvTime[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + u8 abyData[34]; + int i; //RSPINF_b_1 BBvCalculateParameter(pDevice, @@ -476,12 +480,10 @@ void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType) * Return Value: None. * */ -void vUpdateIFS(void *pDeviceHandler) +void vUpdateIFS(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - //Set SIFS, DIFS, EIFS, SlotTime, CwMin - BYTE byMaxMin = 0; - BYTE byData[4]; + u8 byMaxMin = 0; + u8 byData[4]; if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a pDevice->uSlot = C_SLOT_SHORT; @@ -561,11 +563,10 @@ void vUpdateIFS(void *pDeviceHandler) &byMaxMin); } -void CARDvUpdateBasicTopRate(void *pDeviceHandler) +void CARDvUpdateBasicTopRate(struct vnt_private *pDevice) { -PSDevice pDevice = (PSDevice) pDeviceHandler; -BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M; -BYTE ii; + u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M; + u8 ii; //Determines the highest basic rate. for (ii = RATE_54M; ii >= RATE_6M; ii --) { @@ -600,10 +601,9 @@ BYTE ii; * Return Value: TRUE if succeeded; FALSE if failed. * */ -void CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx) +void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx) { -PSDevice pDevice = (PSDevice) pDeviceHandler; -WORD wRate = (WORD)(1<wBasicRate |= wRate; @@ -611,10 +611,9 @@ WORD wRate = (WORD)(1<= RATE_6M; ii --) { if ((pDevice->wBasicRate) & ((WORD)(1<byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) { return (BYTE)pDevice->byBBType; @@ -685,13 +683,11 @@ u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2) * Return Value: none * */ -void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, +void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate, u64 qwBSSTimestamp, u64 qwLocalTSF) { - - PSDevice pDevice = (PSDevice) pDeviceHandler; u64 qwTSFOffset = 0; - BYTE pbyData[8]; + u8 pbyData[8]; qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); @@ -729,13 +725,12 @@ void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, * Return Value: TRUE if success; otherwise FALSE * */ -BOOL CARDbGetCurrentTSF(void *pDeviceHandler, u64 *pqwCurrTSF) +int CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF) { - PSDevice pDevice = (PSDevice) pDeviceHandler; *pqwCurrTSF = pDevice->qwCurrTSF; - return(TRUE); + return TRUE; } @@ -750,15 +745,14 @@ BOOL CARDbGetCurrentTSF(void *pDeviceHandler, u64 *pqwCurrTSF) * Return Value: TRUE if success; otherwise FALSE * */ -BOOL CARDbClearCurrentTSF(void *pDeviceHandler) +int CARDbClearCurrentTSF(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTRST); + MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); pDevice->qwCurrTSF = 0; - return(TRUE); + return TRUE; } /* @@ -816,12 +810,10 @@ u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval) * Return Value: none * */ -void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval) +void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval) { - - PSDevice pDevice = (PSDevice) pDeviceHandler; u64 qwNextTBTT = 0; - BYTE pbyData[8]; + u8 pbyData[8]; CARDbClearCurrentTSF(pDevice); //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter @@ -864,11 +856,10 @@ void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval) * Return Value: none * */ -void CARDvUpdateNextTBTT(void *pDeviceHandler, u64 qwTSF, - WORD wBeaconInterval) +void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF, + u16 wBeaconInterval) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - BYTE pbyData[8]; + u8 pbyData[8]; qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); @@ -910,10 +901,9 @@ void CARDvUpdateNextTBTT(void *pDeviceHandler, u64 qwTSF, * Return Value: TRUE if success; otherwise FALSE * */ -BOOL CARDbRadioPowerOff(void *pDeviceHandler) +int CARDbRadioPowerOff(struct vnt_private *pDevice) { -PSDevice pDevice = (PSDevice) pDeviceHandler; -BOOL bResult = TRUE; + int bResult = TRUE; //if (pDevice->bRadioOff == TRUE) // return TRUE; @@ -951,11 +941,9 @@ BOOL bResult = TRUE; * Return Value: TRUE if success; otherwise FALSE * */ -BOOL CARDbRadioPowerOn(void *pDeviceHandler) +int CARDbRadioPowerOn(struct vnt_private *pDevice) { -PSDevice pDevice = (PSDevice) pDeviceHandler; -BOOL bResult = TRUE; - + int bResult = TRUE; if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { return FALSE; @@ -984,9 +972,8 @@ BOOL bResult = TRUE; return bResult; } -void CARDvSetBSSMode(void *pDeviceHandler) +void CARDvSetBSSMode(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice) pDeviceHandler; // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) ) @@ -1043,16 +1030,10 @@ void CARDvSetBSSMode(void *pDeviceHandler) * Return Value: none. * -*/ -BOOL -CARDbChannelSwitch ( - void *pDeviceHandler, - BYTE byMode, - BYTE byNewChannel, - BYTE byCount - ) +int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode, + u8 byNewChannel, u8 byCount) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - BOOL bResult = TRUE; + int bResult = TRUE; if (byCount == 0) { pDevice->sMgmtObj.uCurrChannel = byNewChannel; diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h index 1059467..720643f 100644 --- a/drivers/staging/vt6656/card.h +++ b/drivers/staging/vt6656/card.h @@ -28,7 +28,7 @@ #ifndef __CARD_H__ #define __CARD_H__ - +#include "device.h" #include "ttype.h" /*--------------------- Export Definitions -------------------------*/ @@ -58,31 +58,28 @@ typedef enum _CARD_OP_MODE { /*--------------------- Export Variables --------------------------*/ /*--------------------- Export Functions --------------------------*/ +struct vnt_private; -void CARDbSetMediaChannel(void *pDeviceHandler, - unsigned int uConnectionChannel); -void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType); -void vUpdateIFS(void *pDeviceHandler); -void CARDvUpdateBasicTopRate(void *pDeviceHandler); -void CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx); -BOOL CARDbIsOFDMinBasicRate(void *pDeviceHandler); -void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, +void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel); +void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType); +void vUpdateIFS(struct vnt_private *pDevice); +void CARDvUpdateBasicTopRate(struct vnt_private *pDevice); +void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx); +int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice); +void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate, u64 qwBSSTimestamp, u64 qwLocalTSF); -BOOL CARDbGetCurrentTSF(void *pDeviceHandler, u64 *pqwCurrTSF); -BOOL CARDbClearCurrentTSF(void *pDeviceHandler); -void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval); -void CARDvUpdateNextTBTT(void *pDeviceHandler, u64 qwTSF, +BOOL CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF); +BOOL CARDbClearCurrentTSF(struct vnt_private *pDevice); +void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval); +void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF, WORD wBeaconInterval); u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval); u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2); -BOOL CARDbRadioPowerOff(void *pDeviceHandler); -BOOL CARDbRadioPowerOn(void *pDeviceHandler); -BYTE CARDbyGetPktType(void *pDeviceHandler); -void CARDvSetBSSMode(void *pDeviceHandler); - -BOOL CARDbChannelSwitch(void *pDeviceHandler, - BYTE byMode, - BYTE byNewChannel, - BYTE byCount); +int CARDbRadioPowerOff(struct vnt_private *pDevice); +int CARDbRadioPowerOn(struct vnt_private *pDevice); +u8 CARDbyGetPktType(struct vnt_private *pDevice); +void CARDvSetBSSMode(struct vnt_private *pDevice); +int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode, + u8 byNewChannel, u8 byCount); #endif /* __CARD_H__ */ diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index 37ec234..eb8a311 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -174,13 +174,13 @@ typedef enum _CONTEXT_TYPE { // RCB (Receive Control Block) typedef struct _RCB { - void *Next; - signed long Ref; - void *pDevice; - struct urb *pUrb; - SRxMgmtPacket sMngPacket; - struct sk_buff* skb; - BOOL bBoolInUse; + void *Next; + signed long Ref; + void *pDevice; + struct urb *pUrb; + struct vnt_rx_mgmt sMngPacket; + struct sk_buff *skb; + int bBoolInUse; } RCB, *PRCB; @@ -872,9 +872,6 @@ typedef struct vnt_private { /*--------------------- Export Functions --------------------------*/ -/* BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, - * unsigned int uNodeIndex); - */ -BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF); +int device_alloc_frag_buf(struct vnt_private *, PSDeFragControlBlock pDeF); #endif diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index f33086d..a316d89 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -225,26 +225,27 @@ static void device_set_multi(struct net_device *dev); static int device_close(struct net_device *dev); static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); -static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType); -static BOOL device_init_defrag_cb(PSDevice pDevice); -static void device_init_diversity_timer(PSDevice pDevice); +static int device_init_registers(struct vnt_private *pDevice, + DEVICE_INIT_TYPE InitType); +static BOOL device_init_defrag_cb(struct vnt_private *pDevice); +static void device_init_diversity_timer(struct vnt_private *pDevice); static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev); static int ethtool_ioctl(struct net_device *dev, void *useraddr); -static void device_free_tx_bufs(PSDevice pDevice); -static void device_free_rx_bufs(PSDevice pDevice); -static void device_free_int_bufs(PSDevice pDevice); -static void device_free_frag_bufs(PSDevice pDevice); -static BOOL device_alloc_bufs(PSDevice pDevice); - -static int Read_config_file(PSDevice pDevice); -static unsigned char *Config_FileOperation(PSDevice pDevice); +static void device_free_tx_bufs(struct vnt_private *pDevice); +static void device_free_rx_bufs(struct vnt_private *pDevice); +static void device_free_int_bufs(struct vnt_private *pDevice); +static void device_free_frag_bufs(struct vnt_private *pDevice); +static BOOL device_alloc_bufs(struct vnt_private *pDevice); + +static int Read_config_file(struct vnt_private *pDevice); +static unsigned char *Config_FileOperation(struct vnt_private *pDevice); static int Config_FileGetParameter(unsigned char *string, unsigned char *dest, unsigned char *source); -static void usb_device_reset(PSDevice pDevice); +static void usb_device_reset(struct vnt_private *pDevice); @@ -254,7 +255,7 @@ static void usb_device_reset(PSDevice pDevice); static void -device_set_options(PSDevice pDevice) { +device_set_options(struct vnt_private *pDevice) { BYTE abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; @@ -292,7 +293,7 @@ device_set_options(PSDevice pDevice) { } -static void device_init_diversity_timer(PSDevice pDevice) +static void device_init_diversity_timer(struct vnt_private *pDevice) { init_timer(&pDevice->TimerSQ3Tmax1); pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice; @@ -317,21 +318,21 @@ static void device_init_diversity_timer(PSDevice pDevice) // Initialization of MAC & BBP registers // -static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType) +static int device_init_registers(struct vnt_private *pDevice, + DEVICE_INIT_TYPE InitType) { - u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; - u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; - BYTE byAntenna; - unsigned int ii; - CMD_CARD_INIT sInitCmd; - int ntStatus = STATUS_SUCCESS; - RSP_CARD_INIT sInitRsp; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BYTE byTmp; - BYTE byCalibTXIQ = 0; - BYTE byCalibTXDC = 0; - BYTE byCalibRXIQ = 0; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + u8 abySNAP_RFC1042[ETH_ALEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; + u8 abySNAP_Bridgetunnel[ETH_ALEN] + = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8}; + u8 byAntenna; + int ii; + CMD_CARD_INIT sInitCmd; + int ntStatus = STATUS_SUCCESS; + RSP_CARD_INIT sInitRsp; + u8 byTmp; + u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType); spin_lock_irq(&pDevice->lock); @@ -636,7 +637,7 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType) static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) { - PSDevice device = usb_get_intfdata(intf); + struct vnt_private *device = usb_get_intfdata(intf); if (!device || !device->dev) return -ENODEV; @@ -651,7 +652,7 @@ static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) static int vt6656_resume(struct usb_interface *intf) { - PSDevice device = usb_get_intfdata(intf); + struct vnt_private *device = usb_get_intfdata(intf); if (!device || !device->dev) return -ENODEV; @@ -682,13 +683,13 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) struct usb_device *udev = interface_to_usbdev(intf); int rc = 0; struct net_device *netdev = NULL; - PSDevice pDevice = NULL; + struct vnt_private *pDevice; printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION); printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n"); udev = usb_get_dev(udev); - netdev = alloc_etherdev(sizeof(DEVICE_INFO)); + netdev = alloc_etherdev(sizeof(struct vnt_private)); if (!netdev) { printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n"); rc = -ENOMEM; @@ -696,7 +697,7 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) } pDevice = netdev_priv(netdev); - memset(pDevice, 0, sizeof(DEVICE_INFO)); + memset(pDevice, 0, sizeof(struct vnt_private)); pDevice->dev = netdev; pDevice->usb = udev; @@ -732,7 +733,7 @@ err_nomem: return rc; } -static void device_free_tx_bufs(PSDevice pDevice) +static void device_free_tx_bufs(struct vnt_private *pDevice) { PUSB_SEND_CONTEXT pTxContext; int ii; @@ -751,7 +752,7 @@ static void device_free_tx_bufs(PSDevice pDevice) } -static void device_free_rx_bufs(PSDevice pDevice) +static void device_free_rx_bufs(struct vnt_private *pDevice) { PRCB pRCB; int ii; @@ -773,7 +774,7 @@ static void device_free_rx_bufs(PSDevice pDevice) return; } -static void usb_device_reset(PSDevice pDevice) +static void usb_device_reset(struct vnt_private *pDevice) { int status; status = usb_reset_device(pDevice->usb); @@ -782,14 +783,15 @@ static void usb_device_reset(PSDevice pDevice) return ; } -static void device_free_int_bufs(PSDevice pDevice) +static void device_free_int_bufs(struct vnt_private *pDevice) { kfree(pDevice->intBuf.pDataBuf); return; } -static BOOL device_alloc_bufs(PSDevice pDevice) { +static BOOL device_alloc_bufs(struct vnt_private *pDevice) +{ PUSB_SEND_CONTEXT pTxContext; PRCB pRCB; @@ -888,9 +890,10 @@ free_tx: -static BOOL device_init_defrag_cb(PSDevice pDevice) { - int i; - PSDeFragControlBlock pDeF; +static BOOL device_init_defrag_cb(struct vnt_private *pDevice) +{ + int i; + PSDeFragControlBlock pDeF; /* Init the fragment ctl entries */ for (i = 0; i < CB_MAX_RX_FRAG; i++) { @@ -912,9 +915,10 @@ free_frag: -static void device_free_frag_bufs(PSDevice pDevice) { - PSDeFragControlBlock pDeF; - int i; +static void device_free_frag_bufs(struct vnt_private *pDevice) +{ + PSDeFragControlBlock pDeF; + int i; for (i = 0; i < CB_MAX_RX_FRAG; i++) { @@ -927,7 +931,9 @@ static void device_free_frag_bufs(PSDevice pDevice) { -BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) { +int device_alloc_frag_buf(struct vnt_private *pDevice, + PSDeFragControlBlock pDeF) +{ pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); if (pDeF->skb == NULL) @@ -941,8 +947,9 @@ BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) { /*-----------------------------------------------------------------*/ -static int device_open(struct net_device *dev) { - PSDevice pDevice=(PSDevice) netdev_priv(dev); +static int device_open(struct net_device *dev) +{ + struct vnt_private *pDevice = netdev_priv(dev); pDevice->fWPA_Authened = FALSE; @@ -1061,13 +1068,13 @@ free_rx_tx: -static int device_close(struct net_device *dev) { - PSDevice pDevice=(PSDevice) netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - - int uu; +static int device_close(struct net_device *dev) +{ + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int uu; - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1 \n"); + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n"); if (pDevice == NULL) return -ENODEV; @@ -1136,7 +1143,7 @@ static int device_close(struct net_device *dev) { static void vt6656_disconnect(struct usb_interface *intf) { - PSDevice device = usb_get_intfdata(intf); + struct vnt_private *device = usb_get_intfdata(intf); if (!device) return; @@ -1156,7 +1163,7 @@ static void vt6656_disconnect(struct usb_interface *intf) static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); spin_lock_irq(&pDevice->lock); @@ -1172,7 +1179,7 @@ static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) static int device_xmit(struct sk_buff *skb, struct net_device *dev) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct net_device_stats *stats = &pDevice->stats; spin_lock_irq(&pDevice->lock); @@ -1290,7 +1297,7 @@ static int Config_FileGetParameter(unsigned char *string, } //if read fail,return NULL,or return data pointer; -static unsigned char *Config_FileOperation(PSDevice pDevice) +static unsigned char *Config_FileOperation(struct vnt_private *pDevice) { unsigned char *config_path = CONFIG_PATH; unsigned char *buffer = NULL; @@ -1354,10 +1361,11 @@ if(result!=0) { } //return --->-1:fail; >=0:successful -static int Read_config_file(PSDevice pDevice) { - int result = 0; - unsigned char tmpbuffer[100]; - unsigned char *buffer = NULL; +static int Read_config_file(struct vnt_private *pDevice) +{ + int result = 0; + unsigned char tmpbuffer[100]; + unsigned char *buffer = NULL; //init config setting pDevice->config_file.ZoneType = -1; @@ -1406,15 +1414,16 @@ static int Read_config_file(PSDevice pDevice) { return result; } -static void device_set_multi(struct net_device *dev) { - PSDevice pDevice = (PSDevice) netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - u32 mc_filter[2]; - int ii; - struct netdev_hw_addr *ha; - BYTE pbyData[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; - BYTE byTmpMode = 0; - int rc; +static void device_set_multi(struct net_device *dev) +{ + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct netdev_hw_addr *ha; + u32 mc_filter[2]; + int ii; + u8 pbyData[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + u8 byTmpMode = 0; + int rc; spin_lock_irq(&pDevice->lock); @@ -1472,14 +1481,14 @@ static void device_set_multi(struct net_device *dev) { static struct net_device_stats *device_get_stats(struct net_device *dev) { - PSDevice pDevice=(PSDevice) netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); - return &pDevice->stats; + return &pDevice->stats; } static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { - PSDevice pDevice = (PSDevice)netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iwreq *wrq = (struct iwreq *) rq; int rc = 0; -- cgit v0.10.2 From 98583c095c8abc856ddcc87f341aa4bc0b44b038 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Mon, 10 Dec 2012 22:01:23 +0000 Subject: staging: vt6656: change baseband/mac/wcmd/wctl to new structures. This patch also cleans up function declarations, definitions and local variables were appropriate replacing types defined in "ttype.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c index 3855015..cccd810 100644 --- a/drivers/staging/vt6656/baseband.c +++ b/drivers/staging/vt6656/baseband.c @@ -690,7 +690,7 @@ s_vClearSQ3Value(PSDevice pDevice); * */ unsigned int -BBuGetFrameTime ( +BBuGetFrameTime( BYTE byPreambleType, BYTE byPktType, unsigned int cbFrameLength, @@ -756,23 +756,16 @@ BBuGetFrameTime ( * Return Value: none * */ -void -BBvCalculateParameter ( - PSDevice pDevice, - unsigned int cbFrameLength, - WORD wRate, - BYTE byPacketType, - PWORD pwPhyLen, - PBYTE pbyPhySrv, - PBYTE pbyPhySgn - ) +void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength, + u16 wRate, u8 byPacketType, u16 *pwPhyLen, u8 *pbyPhySrv, + u8 *pbyPhySgn) { - unsigned int cbBitCount; - unsigned int cbUsCount = 0; - unsigned int cbTmp; - BOOL bExtBit; - BYTE byPreambleType = pDevice->byPreambleType; - BOOL bCCK = pDevice->bCCK; + u32 cbBitCount; + u32 cbUsCount = 0; + u32 cbTmp; + int bExtBit; + u8 byPreambleType = pDevice->byPreambleType; + int bCCK = pDevice->bCCK; cbBitCount = cbFrameLength * 8; bExtBit = FALSE; @@ -929,8 +922,7 @@ BBvCalculateParameter ( * Return Value: none * */ -void -BBvSetAntennaMode (PSDevice pDevice, BYTE byAntennaMode) +void BBvSetAntennaMode(struct vnt_private *pDevice, u8 byAntennaMode) { switch (byAntennaMode) { case ANT_TXA: @@ -968,7 +960,7 @@ BBvSetAntennaMode (PSDevice pDevice, BYTE byAntennaMode) * */ -BOOL BBbVT3184Init(PSDevice pDevice) +int BBbVT3184Init(struct vnt_private *pDevice) { int ntStatus; WORD wLength; @@ -1161,7 +1153,7 @@ else { * Return Value: none * */ -void BBvLoopbackOn (PSDevice pDevice) +void BBvLoopbackOn(struct vnt_private *pDevice) { BYTE byData; @@ -1214,9 +1206,9 @@ void BBvLoopbackOn (PSDevice pDevice) * Return Value: none * */ -void BBvLoopbackOff (PSDevice pDevice) +void BBvLoopbackOff(struct vnt_private *pDevice) { - BYTE byData; + u8 byData; ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, pDevice->byBBCRc9);//CR201 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, pDevice->byBBCR88);//CR136 @@ -1249,8 +1241,7 @@ void BBvLoopbackOff (PSDevice pDevice) * Return Value: none * */ -void -BBvSetShortSlotTime (PSDevice pDevice) +void BBvSetShortSlotTime(struct vnt_private *pDevice) { BYTE byBBVGA=0; @@ -1267,7 +1258,7 @@ BBvSetShortSlotTime (PSDevice pDevice) } -void BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData) +void BBvSetVGAGainOffset(struct vnt_private *pDevice, BYTE byData) { ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, byData); @@ -1294,8 +1285,7 @@ void BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData) * Return Value: none * */ -void -BBvSoftwareReset (PSDevice pDevice) +void BBvSoftwareReset(struct vnt_private *pDevice) { ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0x40); ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0); @@ -1315,22 +1305,20 @@ BBvSoftwareReset (PSDevice pDevice) * Return Value: none * */ -void -BBvSetDeepSleep (PSDevice pDevice) +void BBvSetDeepSleep(struct vnt_private *pDevice) { ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);//CR12 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0xB9);//CR13 } -void -BBvExitDeepSleep (PSDevice pDevice) +void BBvExitDeepSleep(struct vnt_private *pDevice) { ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0C, 0x00);//CR12 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0x01);//CR13 } -static unsigned long s_ulGetLowSQ3(PSDevice pDevice) +static unsigned long s_ulGetLowSQ3(struct vnt_private *pDevice) { int ii; unsigned long ulSQ3 = 0; @@ -1349,7 +1337,7 @@ static unsigned long s_ulGetLowSQ3(PSDevice pDevice) return ulSQ3; } -static unsigned long s_ulGetRatio(PSDevice pDevice) +static unsigned long s_ulGetRatio(struct vnt_private *pDevice) { int ii, jj; unsigned long ulRatio = 0; @@ -1377,9 +1365,7 @@ static unsigned long s_ulGetRatio(PSDevice pDevice) } -static -void -s_vClearSQ3Value (PSDevice pDevice) +static void s_vClearSQ3Value(struct vnt_private *pDevice) { int ii; pDevice->uDiversityCnt = 0; @@ -1406,8 +1392,8 @@ s_vClearSQ3Value (PSDevice pDevice) * */ -void -BBvAntennaDiversity (PSDevice pDevice, BYTE byRxRate, BYTE bySQ3) +void BBvAntennaDiversity(struct vnt_private *pDevice, + u8 byRxRate, u8 bySQ3) { pDevice->uDiversityCnt++; @@ -1541,9 +1527,8 @@ BBvAntennaDiversity (PSDevice pDevice, BYTE byRxRate, BYTE bySQ3) * -*/ -void TimerSQ3CallBack(void *hDeviceContext) +void TimerSQ3CallBack(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3CallBack..."); spin_lock_irq(&pDevice->lock); @@ -1579,9 +1564,8 @@ void TimerSQ3CallBack(void *hDeviceContext) * -*/ -void TimerSQ3Tmax3CallBack(void *hDeviceContext) +void TimerSQ3Tmax3CallBack(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3Tmax3CallBack..."); spin_lock_irq(&pDevice->lock); @@ -1607,10 +1591,7 @@ void TimerSQ3Tmax3CallBack(void *hDeviceContext) spin_unlock_irq(&pDevice->lock); } -void -BBvUpdatePreEDThreshold( - PSDevice pDevice, - BOOL bScanning) +void BBvUpdatePreEDThreshold(struct vnt_private *pDevice, int bScanning) { diff --git a/drivers/staging/vt6656/baseband.h b/drivers/staging/vt6656/baseband.h index 844d5a8..df5cf0d 100644 --- a/drivers/staging/vt6656/baseband.h +++ b/drivers/staging/vt6656/baseband.h @@ -104,33 +104,26 @@ BBuGetFrameTime( WORD wRate ); -void BBvCalculateParameter(PSDevice pDevice, - unsigned int cbFrameLength, - WORD wRate, - BYTE byPacketType, - PWORD pwPhyLen, - PBYTE pbyPhySrv, - PBYTE pbyPhySgn); +void BBvCalculateParameter(struct vnt_private *, u32 cbFrameLength, + u16 wRate, u8 byPacketType, u16 *pwPhyLen, u8 *pbyPhySrv, + u8 *pbyPhySgn); // timer for antenna diversity -void TimerSQ3CallBack(void *hDeviceContext); -void TimerSQ3Tmax3CallBack(void *hDeviceContext); - -void BBvAntennaDiversity(PSDevice pDevice, BYTE byRxRate, BYTE bySQ3); -void BBvLoopbackOn(PSDevice pDevice); -void BBvLoopbackOff(PSDevice pDevice); -void BBvSoftwareReset(PSDevice pDevice); - -void BBvSetShortSlotTime(PSDevice pDevice); -void BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData); -void BBvSetAntennaMode(PSDevice pDevice, BYTE byAntennaMode); -BOOL BBbVT3184Init(PSDevice pDevice); -void BBvSetDeepSleep(PSDevice pDevice); -void BBvExitDeepSleep(PSDevice pDevice); -void BBvUpdatePreEDThreshold( - PSDevice pDevice, - BOOL bScanning - ); +void TimerSQ3CallBack(struct vnt_private *); +void TimerSQ3Tmax3CallBack(struct vnt_private *); + +void BBvAntennaDiversity(struct vnt_private *, u8 byRxRate, u8 bySQ3); +void BBvLoopbackOn(struct vnt_private *); +void BBvLoopbackOff(struct vnt_private *); +void BBvSoftwareReset(struct vnt_private *); + +void BBvSetShortSlotTime(struct vnt_private *); +void BBvSetVGAGainOffset(struct vnt_private *, u8 byData); +void BBvSetAntennaMode(struct vnt_private *, u8 byAntennaMode); +int BBbVT3184Init(struct vnt_private *); +void BBvSetDeepSleep(struct vnt_private *); +void BBvExitDeepSleep(struct vnt_private *); +void BBvUpdatePreEDThreshold(struct vnt_private *, int bScanning); #endif /* __BASEBAND_H__ */ diff --git a/drivers/staging/vt6656/mac.c b/drivers/staging/vt6656/mac.c index 8fddc7b..dd732bc 100644 --- a/drivers/staging/vt6656/mac.c +++ b/drivers/staging/vt6656/mac.c @@ -68,11 +68,11 @@ static int msglevel =MSG_LEVEL_INFO; * Return Value: none * */ -void MACvSetMultiAddrByHash (PSDevice pDevice, BYTE byHashIdx) +void MACvSetMultiAddrByHash(struct vnt_private *pDevice, u8 byHashIdx) { - unsigned int uByteIdx; - BYTE byBitMask; - BYTE pbyData[2]; + u8 uByteIdx; + u8 byBitMask; + u8 pbyData[2]; // calculate byte position @@ -110,9 +110,9 @@ void MACvSetMultiAddrByHash (PSDevice pDevice, BYTE byHashIdx) * Return Value: none * */ -void MACvWriteMultiAddr(PSDevice pDevice, unsigned int uByteIdx, BYTE byData) +void MACvWriteMultiAddr(struct vnt_private *pDevice, u32 uByteIdx, u8 byData) { - BYTE byData1; + u8 byData1; byData1 = byData; CONTROLnsRequestOut(pDevice, @@ -135,7 +135,7 @@ void MACvWriteMultiAddr(PSDevice pDevice, unsigned int uByteIdx, BYTE byData) * * */ -void MACbShutdown(PSDevice pDevice) +void MACbShutdown(struct vnt_private *pDevice) { CONTROLnsRequestOutAsyn(pDevice, MESSAGE_TYPE_MACSHUTDOWN, @@ -146,9 +146,9 @@ void MACbShutdown(PSDevice pDevice) ); } -void MACvSetBBType(PSDevice pDevice,BYTE byType) +void MACvSetBBType(struct vnt_private *pDevice, u8 byType) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = byType; @@ -163,9 +163,9 @@ BYTE pbyData[2]; ); } -void MACvSetMISCFifo (PSDevice pDevice, WORD wOffset, DWORD dwData) +void MACvSetMISCFifo(struct vnt_private *pDevice, u16 wOffset, u32 dwData) { -BYTE pbyData[4]; + u8 pbyData[4]; if (wOffset > 273) return; @@ -197,10 +197,10 @@ BYTE pbyData[4]; * Return Value: none * */ -void MACvDisableKeyEntry(PSDevice pDevice, unsigned int uEntryIdx) +void MACvDisableKeyEntry(struct vnt_private *pDevice, u32 uEntryIdx) { -WORD wOffset; -BYTE byData; + u16 wOffset; + u8 byData; byData = (BYTE) uEntryIdx; @@ -237,15 +237,14 @@ BYTE byData; * Return Value: none * */ -void MACvSetKeyEntry(PSDevice pDevice, WORD wKeyCtl, - unsigned int uEntryIdx, unsigned int uKeyIdx, - PBYTE pbyAddr, PDWORD pdwKey) +void MACvSetKeyEntry(struct vnt_private *pDevice, u16 wKeyCtl, u32 uEntryIdx, + u32 uKeyIdx, u8 *pbyAddr, u32 *pdwKey) { -PBYTE pbyKey; -WORD wOffset; -DWORD dwData1,dwData2; -int ii; -BYTE pbyData[24]; + u8 *pbyKey; + u16 wOffset; + u32 dwData1, dwData2; + int ii; + u8 pbyData[24]; if ( pDevice->byLocalID <= MAC_REVISION_A1 ) { if ( pDevice->sMgmtObj.byCSSPK == KEY_CTL_CCMP ) @@ -321,9 +320,9 @@ BYTE pbyData[24]; } -void MACvRegBitsOff(PSDevice pDevice, BYTE byRegOfs, BYTE byBits) +void MACvRegBitsOff(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = 0; pbyData[1] = byBits; @@ -338,9 +337,9 @@ BYTE pbyData[2]; } -void MACvRegBitsOn(PSDevice pDevice, BYTE byRegOfs, BYTE byBits) +void MACvRegBitsOn(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = byBits; @@ -355,9 +354,9 @@ BYTE pbyData[2]; ); } -void MACvWriteWord(PSDevice pDevice, BYTE byRegOfs, WORD wData) +void MACvWriteWord(struct vnt_private *pDevice, u8 byRegOfs, u16 wData) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = (BYTE)(wData & 0xff); @@ -373,9 +372,9 @@ BYTE pbyData[2]; } -void MACvWriteBSSIDAddress(PSDevice pDevice, PBYTE pbyEtherAddr) +void MACvWriteBSSIDAddress(struct vnt_private *pDevice, u8 *pbyEtherAddr) { -BYTE pbyData[6]; + u8 pbyData[6]; pbyData[0] = *((PBYTE)pbyEtherAddr); @@ -394,9 +393,9 @@ BYTE pbyData[6]; ); } -void MACvEnableProtectMD(PSDevice pDevice) +void MACvEnableProtectMD(struct vnt_private *pDevice) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = EnCFG_ProtectMd; @@ -411,9 +410,9 @@ BYTE pbyData[2]; ); } -void MACvDisableProtectMD(PSDevice pDevice) +void MACvDisableProtectMD(struct vnt_private *pDevice) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = 0; @@ -428,9 +427,9 @@ BYTE pbyData[2]; ); } -void MACvEnableBarkerPreambleMd(PSDevice pDevice) +void MACvEnableBarkerPreambleMd(struct vnt_private *pDevice) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = EnCFG_BarkerPream; @@ -445,9 +444,9 @@ BYTE pbyData[2]; ); } -void MACvDisableBarkerPreambleMd(PSDevice pDevice) +void MACvDisableBarkerPreambleMd(struct vnt_private *pDevice) { -BYTE pbyData[2]; + u8 pbyData[2]; pbyData[0] = 0; @@ -463,12 +462,12 @@ BYTE pbyData[2]; } -void MACvWriteBeaconInterval(PSDevice pDevice, WORD wInterval) +void MACvWriteBeaconInterval(struct vnt_private *pDevice, u16 wInterval) { -BYTE pbyData[2]; + u8 pbyData[2]; - pbyData[0] = (BYTE) (wInterval & 0xff); - pbyData[1] = (BYTE) (wInterval >> 8); + pbyData[0] = (u8)(wInterval & 0xff); + pbyData[1] = (u8)(wInterval >> 8); CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_WRITE, diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h index 147ac50..6e28500 100644 --- a/drivers/staging/vt6656/mac.h +++ b/drivers/staging/vt6656/mac.h @@ -420,24 +420,21 @@ /*--------------------- Export Functions --------------------------*/ -void MACvSetMultiAddrByHash(PSDevice pDevice, BYTE byHashIdx); -void MACvWriteMultiAddr(PSDevice pDevice, unsigned int uByteIdx, BYTE byData); -void MACbShutdown(PSDevice pDevice); -void MACvSetBBType(PSDevice pDevice, BYTE byType); -void MACvSetMISCFifo(PSDevice pDevice, WORD wOffset, DWORD dwData); -void MACvDisableKeyEntry(PSDevice pDevice, unsigned int uEntryIdx); -void MACvSetKeyEntry(PSDevice pDevice, WORD wKeyCtl, unsigned int uEntryIdx, - unsigned int uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey); - -void MACvRegBitsOff(PSDevice pDevice, BYTE byRegOfs, BYTE byBits); -void MACvRegBitsOn(PSDevice pDevice, BYTE byRegOfs, BYTE byBits); -void MACvWriteWord(PSDevice pDevice, BYTE byRegOfs, WORD wData); - -void MACvWriteBSSIDAddress(PSDevice pDevice, PBYTE pbyEtherAddr); -void MACvEnableProtectMD(PSDevice pDevice); -void MACvDisableProtectMD(PSDevice pDevice); -void MACvEnableBarkerPreambleMd(PSDevice pDevice); -void MACvDisableBarkerPreambleMd(PSDevice pDevice); -void MACvWriteBeaconInterval(PSDevice pDevice, WORD wInterval); +void MACvSetMultiAddrByHash(struct vnt_private *, u8); +void MACvWriteMultiAddr(struct vnt_private *, u32, u8); +void MACbShutdown(struct vnt_private *); +void MACvSetBBType(struct vnt_private *, u8); +void MACvSetMISCFifo(struct vnt_private *pDevice, u16, u32); +void MACvDisableKeyEntry(struct vnt_private *, u32); +void MACvSetKeyEntry(struct vnt_private *, u16, u32, u32, u8 *, u32 *); +void MACvRegBitsOff(struct vnt_private *, u8, u8); +void MACvRegBitsOn(struct vnt_private *, u8, u8); +void MACvWriteWord(struct vnt_private *, u8, u16); +void MACvWriteBSSIDAddress(struct vnt_private *, u8 *); +void MACvEnableProtectMD(struct vnt_private *); +void MACvDisableProtectMD(struct vnt_private *); +void MACvEnableBarkerPreambleMd(struct vnt_private *); +void MACvDisableBarkerPreambleMd(struct vnt_private *); +void MACvWriteBeaconInterval(struct vnt_private *, u16); #endif /* __MAC_H__ */ diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c index 22f6b41..51f48c1 100644 --- a/drivers/staging/vt6656/wcmd.c +++ b/drivers/staging/vt6656/wcmd.c @@ -68,33 +68,17 @@ static int msglevel =MSG_LEVEL_INFO; //static int msglevel =MSG_LEVEL_DEBUG; /*--------------------- Static Functions --------------------------*/ -static -void -s_vProbeChannel( - PSDevice pDevice - ); +static void s_vProbeChannel(struct vnt_private *); +static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *, + struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID, + PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates); -static -PSTxMgmtPacket -s_MgrMakeProbeRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PBYTE pScanBSSID, - PWLAN_IE_SSID pSSID, - PWLAN_IE_SUPP_RATES pCurrRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ); +static int s_bCommandComplete(struct vnt_private *); -static -BOOL -s_bCommandComplete ( - PSDevice pDevice - ); - -static BOOL s_bClearBSSID_SCAN(void *hDeviceContext); +static int s_bClearBSSID_SCAN(struct vnt_private *); /*--------------------- Export Variables --------------------------*/ @@ -114,13 +98,10 @@ static BOOL s_bClearBSSID_SCAN(void *hDeviceContext); * */ -static -void -vAdHocBeaconStop(PSDevice pDevice) +static void vAdHocBeaconStop(struct vnt_private *pDevice) { - - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BOOL bStop; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int bStop; /* * temporarily stop Beacon packet for AdHoc Server @@ -171,11 +152,9 @@ vAdHocBeaconStop(PSDevice pDevice) * Return Value: none * */ -static -void -vAdHocBeaconRestart(PSDevice pDevice) +static void vAdHocBeaconRestart(struct vnt_private *pDevice) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; /* * Restart Beacon packet for AdHoc Server @@ -204,22 +183,22 @@ vAdHocBeaconRestart(PSDevice pDevice) * -*/ -static -void -s_vProbeChannel( - PSDevice pDevice - ) +static void s_vProbeChannel(struct vnt_private *pDevice) { - //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M - BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; - BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60}; - //6M, 9M, 12M, 48M - BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; - BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16}; - PBYTE pbyRate; - PSTxMgmtPacket pTxPacket; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct vnt_tx_mgmt *pTxPacket; + u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, + 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; + /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/ + u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, + 4, 0x0C, 0x12, 0x18, 0x60}; + /* 6M, 9M, 12M, 48M*/ + u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, + 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; + u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, + 4, 0x02, 0x04, 0x0B, 0x16}; + u8 *pbyRate; + int ii; if (pDevice->byBBType == BB_TYPE_11A) { @@ -268,24 +247,19 @@ s_vProbeChannel( -*/ -PSTxMgmtPacket -s_MgrMakeProbeRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PBYTE pScanBSSID, - PWLAN_IE_SSID pSSID, - PWLAN_IE_SUPP_RATES pCurrRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - - ) +struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID, + PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_PROBEREQ sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_PROBEREQ sFrame; - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_PROBEREQ_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_PROBEREQ_FR_MAXLEN; vMgrEncodeProbeRequest(&sFrame); @@ -316,9 +290,8 @@ s_MgrMakeProbeRequest( return pTxPacket; } -void vCommandTimerWait(void *hDeviceContext, unsigned long MSecond) +void vCommandTimerWait(struct vnt_private *pDevice, unsigned long MSecond) { - PSDevice pDevice = (PSDevice)hDeviceContext; init_timer(&pDevice->sTimerCommand); @@ -331,18 +304,17 @@ void vCommandTimerWait(void *hDeviceContext, unsigned long MSecond) return; } -void vRunCommand(void *hDeviceContext) +void vRunCommand(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PWLAN_IE_SSID pItemSSID; - PWLAN_IE_SSID pItemSSIDCurr; - CMD_STATUS Status; - unsigned int ii; - BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - struct sk_buff *skb; - BYTE byData; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + PWLAN_IE_SSID pItemSSID; + PWLAN_IE_SSID pItemSSIDCurr; + CMD_STATUS Status; + struct sk_buff *skb; union iwreq_data wrqu; + int ii; + u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; + u8 byData; if (pDevice->dwDiagRefCount != 0) @@ -1043,17 +1015,12 @@ void vRunCommand(void *hDeviceContext) } -static -BOOL -s_bCommandComplete ( - PSDevice pDevice - ) +static int s_bCommandComplete(struct vnt_private *pDevice) { - PWLAN_IE_SSID pSSID; - BOOL bRadioCmd = FALSE; - //WORD wDeAuthenReason = 0; - BOOL bForceSCAN = TRUE; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + PWLAN_IE_SSID pSSID; + int bRadioCmd = FALSE; + int bForceSCAN = TRUE; pDevice->eCommandState = WLAN_CMD_IDLE; @@ -1146,18 +1113,15 @@ s_bCommandComplete ( break; } - vCommandTimerWait((void *) pDevice, 0); + vCommandTimerWait(pDevice, 0); } return TRUE; } -BOOL bScheduleCommand(void *hDeviceContext, - CMD_CODE eCommand, - PBYTE pbyItem0) +int bScheduleCommand(struct vnt_private *pDevice, + CMD_CODE eCommand, u8 *pbyItem0) { - PSDevice pDevice = (PSDevice)hDeviceContext; - if (pDevice->cbFreeCmdQueue == 0) { return (FALSE); @@ -1222,11 +1186,10 @@ BOOL bScheduleCommand(void *hDeviceContext, * Return Value: TRUE if success; otherwise FALSE * */ -static BOOL s_bClearBSSID_SCAN(void *hDeviceContext) +static int s_bClearBSSID_SCAN(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx; - unsigned int ii; + unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx; + unsigned int ii; if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) { for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) { @@ -1242,9 +1205,8 @@ static BOOL s_bClearBSSID_SCAN(void *hDeviceContext) //mike add:reset command timer -void vResetCommandTimer(void *hDeviceContext) +void vResetCommandTimer(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; //delete timer del_timer(&pDevice->sTimerCommand); @@ -1261,10 +1223,9 @@ void vResetCommandTimer(void *hDeviceContext) pDevice->bCmdClear = FALSE; } -void BSSvSecondTxData(void *hDeviceContext) +void BSSvSecondTxData(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; pDevice->nTxDataTimeCout++; diff --git a/drivers/staging/vt6656/wcmd.h b/drivers/staging/vt6656/wcmd.h index d24a79d..a3d0323 100644 --- a/drivers/staging/vt6656/wcmd.h +++ b/drivers/staging/vt6656/wcmd.h @@ -28,7 +28,6 @@ #ifndef __WCMD_H__ #define __WCMD_H__ - #include "ttype.h" #include "80211hdr.h" #include "80211mgr.h" @@ -112,14 +111,13 @@ typedef enum tagCMD_STATE { /*--------------------- Export Types ------------------------------*/ /*--------------------- Export Functions --------------------------*/ +struct vnt_private; -void vResetCommandTimer(void *hDeviceContext); +void vResetCommandTimer(struct vnt_private *); -BOOL bScheduleCommand(void *hDeviceContext, - CMD_CODE eCommand, - PBYTE pbyItem0); +int bScheduleCommand(struct vnt_private *, CMD_CODE eCommand, u8 *pbyItem0); -void vRunCommand(void *hDeviceContext); +void vRunCommand(struct vnt_private *); /* void @@ -128,6 +126,6 @@ WCMDvCommandThread( ); */ -void BSSvSecondTxData(void *hDeviceContext); +void BSSvSecondTxData(struct vnt_private *); #endif /* __WCMD_H__ */ diff --git a/drivers/staging/vt6656/wctl.c b/drivers/staging/vt6656/wctl.c index 9249263..18a09a3 100644 --- a/drivers/staging/vt6656/wctl.c +++ b/drivers/staging/vt6656/wctl.c @@ -113,7 +113,8 @@ BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader) * */ -unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader) +unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice, + PS802_11Header pMACHeader) { unsigned int ii; @@ -141,7 +142,8 @@ unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader) * Return Value: index number in Defragment Database * */ -unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader) +unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, + PS802_11Header pMACHeader) { unsigned int ii; @@ -180,10 +182,10 @@ unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader) * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE * */ -BOOL WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, - unsigned int cbFrameLength, BOOL bWEP, BOOL bExtIV) +int WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, + unsigned int cbFrameLength, int bWEP, int bExtIV) { -unsigned int uHeaderSize; + unsigned int uHeaderSize; if (bWEP == TRUE) { diff --git a/drivers/staging/vt6656/wctl.h b/drivers/staging/vt6656/wctl.h index 7270af6..a509f63 100644 --- a/drivers/staging/vt6656/wctl.h +++ b/drivers/staging/vt6656/wctl.h @@ -97,9 +97,9 @@ /*--------------------- Export Functions --------------------------*/ BOOL WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader); -BOOL WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, - unsigned int cbFrameLength, BOOL bWEP, BOOL bExtIV); -unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader); -unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader); +int WCTLbHandleFragment(struct vnt_private *, PS802_11Header pMACHeader, + unsigned int cbFrameLength, BOOL bWEP, BOOL bExtIV); +unsigned int WCTLuSearchDFCB(struct vnt_private *, PS802_11Header pMACHeader); +unsigned int WCTLuInsertDFCB(struct vnt_private *, PS802_11Header pMACHeader); #endif /* __WCTL_H__ */ -- cgit v0.10.2 From 78f41c913e31ed498d463e77301df3408bf9ba08 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Mon, 10 Dec 2012 22:03:56 +0000 Subject: staging: vt6656: change wmgr to new structures This patch cleans up function declarations, definitions and local variables were appropriate replacing types defined in "ttype.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/wmgr.c b/drivers/staging/vt6656/wmgr.c index 7a242f7..89491ae 100644 --- a/drivers/staging/vt6656/wmgr.c +++ b/drivers/staging/vt6656/wmgr.c @@ -93,227 +93,98 @@ static int msglevel =MSG_LEVEL_INFO; /*--------------------- Static Functions --------------------------*/ -static BOOL ChannelExceedZoneType( - PSDevice pDevice, - BYTE byCurrChannel - ); +static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel); -// Association/diassociation functions -static -PSTxMgmtPacket -s_MgrMakeAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PBYTE pDAddr, - WORD wCurrCapInfo, - WORD wListenInterval, - PWLAN_IE_SSID pCurrSSID, - PWLAN_IE_SUPP_RATES pCurrRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ); +/* Association/diassociation functions */ +static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *, + struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo, + u16 wListenInterval, PWLAN_IE_SSID pCurrSSID, + PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates); -static -void -s_vMgrRxAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - unsigned int uNodeIndex - ); +static void s_vMgrRxAssocRequest(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + u32 uNodeIndex); -static -PSTxMgmtPacket -s_MgrMakeReAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PBYTE pDAddr, - WORD wCurrCapInfo, - WORD wListenInterval, - PWLAN_IE_SSID pCurrSSID, - PWLAN_IE_SUPP_RATES pCurrRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ); +static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *, + struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo, + u16 wListenInterval, PWLAN_IE_SSID pCurrSSID, + PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates); -static -void -s_vMgrRxAssocResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - BOOL bReAssocType - ); +static void s_vMgrRxAssocResponse(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + int bReAssocType); -static -void -s_vMgrRxDisassociation( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ); +static void s_vMgrRxDisassociation(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket); -// Authentication/deauthen functions -static -void -s_vMgrRxAuthenSequence_1( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ); +/* Authentication/deauthen functions */ +static void s_vMgrRxAuthenSequence_1(struct vnt_private *, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame); -static -void -s_vMgrRxAuthenSequence_2( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ); +static void s_vMgrRxAuthenSequence_2(struct vnt_private *, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame); -static -void -s_vMgrRxAuthenSequence_3( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ); +static void s_vMgrRxAuthenSequence_3(struct vnt_private *, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame); -static -void -s_vMgrRxAuthenSequence_4( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ); +static void s_vMgrRxAuthenSequence_4(struct vnt_private *, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame); -static -void -s_vMgrRxAuthentication( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ); +static void s_vMgrRxAuthentication(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket); -static -void -s_vMgrRxDeauthentication( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ); +static void s_vMgrRxDeauthentication(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket); -// Scan functions -// probe request/response functions -static -void -s_vMgrRxProbeRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ); +/* Scan functions +* probe request/response functions */ -static -void -s_vMgrRxProbeResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ); +static void s_vMgrRxProbeRequest(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket); -// beacon functions -static -void -s_vMgrRxBeacon( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - BOOL bInScan - ); +static void s_vMgrRxProbeResponse(struct vnt_private *, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket); -static -void -s_vMgrFormatTIM( - PSMgmtObject pMgmt, - PWLAN_IE_TIM pTIM - ); +/* beacon functions */ +static void s_vMgrRxBeacon(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + int bInScan); -static -PSTxMgmtPacket -s_MgrMakeBeacon( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wCurrBeaconPeriod, - unsigned int uCurrChannel, - WORD wCurrATIMWinodw, - PWLAN_IE_SSID pCurrSSID, - PBYTE pCurrBSSID, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ); +static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM); +static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod, + u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID, + u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates); -// Association response -static -PSTxMgmtPacket -s_MgrMakeAssocResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wAssocStatus, - WORD wAssocAID, - PBYTE pDstAddr, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ); -// ReAssociation response -static -PSTxMgmtPacket -s_MgrMakeReAssocResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wAssocStatus, - WORD wAssocAID, - PBYTE pDstAddr, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ); +/* Association response */ +static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus, + u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates); -// Probe response -static -PSTxMgmtPacket -s_MgrMakeProbeResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wCurrBeaconPeriod, - unsigned int uCurrChannel, - WORD wCurrATIMWinodw, - PBYTE pDstAddr, - PWLAN_IE_SSID pCurrSSID, - PBYTE pCurrBSSID, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates, - BYTE byPHYType - ); +/* ReAssociation response */ +static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus, + u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates); -// received status -static -void -s_vMgrLogStatus( - PSMgmtObject pMgmt, - WORD wStatus - ); +/* Probe response */ +static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod, + u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr, + PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID, + PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType); +/* received status */ +static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus); -static -void -s_vMgrSynchBSS ( - PSDevice pDevice, - unsigned int uBSSMode, - PKnownBSS pCurr, - PCMD_STATUS pStatus - ); + +static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode, + PKnownBSS pCurr, PCMD_STATUS pStatus); static BOOL @@ -324,10 +195,7 @@ s_bCipherMatch ( PBYTE pbyCCSGK ); - static void Encyption_Rebuild( - PSDevice pDevice, - PKnownBSS pCurr - ); +static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr); /*--------------------- Export Variables --------------------------*/ @@ -343,11 +211,10 @@ s_bCipherMatch ( * -*/ -void vMgrObjectInit(void *hDeviceContext) +void vMgrObjectInit(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ii; pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0]; @@ -402,12 +269,10 @@ void vMgrObjectInit(void *hDeviceContext) * -*/ -void vMgrAssocBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PCMD_STATUS pStatus) +void vMgrAssocBeginSta(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSTxMgmtPacket pTxPacket; + struct vnt_tx_mgmt *pTxPacket; pMgmt->wCurrCapInfo = 0; @@ -475,14 +340,10 @@ void vMgrAssocBeginSta(void *hDeviceContext, * -*/ -void vMgrReAssocBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PCMD_STATUS pStatus) +void vMgrReAssocBeginSta(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSTxMgmtPacket pTxPacket; - - + struct vnt_tx_mgmt *pTxPacket; pMgmt->wCurrCapInfo = 0; pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1); @@ -551,19 +412,18 @@ void vMgrReAssocBeginSta(void *hDeviceContext, * -*/ -void vMgrDisassocBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PBYTE abyDestAddress, - WORD wReason, - PCMD_STATUS pStatus) +void vMgrDisassocBeginSta(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason, + PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_DISASSOC sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_DISASSOC sFrame; - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_DISASSOC_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); // Setup the sFrame structure sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; @@ -610,23 +470,18 @@ void vMgrDisassocBeginSta(void *hDeviceContext, * -*/ -static -void -s_vMgrRxAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - unsigned int uNodeIndex - ) +static void s_vMgrRxAssocRequest(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + u32 uNodeIndex) { - WLAN_FR_ASSOCREQ sFrame; - CMD_STATUS Status; - PSTxMgmtPacket pTxPacket; - WORD wAssocStatus = 0; - WORD wAssocAID = 0; - unsigned int uRateLen = WLAN_RATES_MAXLEN; - BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; - BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + WLAN_FR_ASSOCREQ sFrame; + CMD_STATUS Status; + struct vnt_tx_mgmt *pTxPacket; + u16 wAssocStatus = 0; + u16 wAssocAID = 0; + u32 uRateLen = WLAN_RATES_MAXLEN; + u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) @@ -766,23 +621,18 @@ s_vMgrRxAssocRequest( * -*/ -static -void -s_vMgrRxReAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - unsigned int uNodeIndex - ) +static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + u32 uNodeIndex) { - WLAN_FR_REASSOCREQ sFrame; - CMD_STATUS Status; - PSTxMgmtPacket pTxPacket; - WORD wAssocStatus = 0; - WORD wAssocAID = 0; - unsigned int uRateLen = WLAN_RATES_MAXLEN; - BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; - BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + WLAN_FR_REASSOCREQ sFrame; + CMD_STATUS Status; + struct vnt_tx_mgmt *pTxPacket; + u16 wAssocStatus = 0; + u16 wAssocAID = 0; + u32 uRateLen = WLAN_RATES_MAXLEN; + u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) return; @@ -913,18 +763,13 @@ s_vMgrRxReAssocRequest( * -*/ -static -void -s_vMgrRxAssocResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - BOOL bReAssocType - ) +static void s_vMgrRxAssocResponse(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + int bReAssocType) { - WLAN_FR_ASSOCRESP sFrame; - PWLAN_IE_SSID pItemSSID; - PBYTE pbyIEs; + WLAN_FR_ASSOCRESP sFrame; + PWLAN_IE_SSID pItemSSID; + u8 *pbyIEs; @@ -1050,17 +895,17 @@ if(pMgmt->eCurrState == WMAC_STATE_ASSOC) * -*/ -void vMgrAuthenBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PCMD_STATUS pStatus) +void vMgrAuthenBeginSta(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - WLAN_FR_AUTHEN sFrame; - PSTxMgmtPacket pTxPacket = NULL; - - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + WLAN_FR_AUTHEN sFrame; + struct vnt_tx_mgmt *pTxPacket = + (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_AUTHEN_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_AUTHEN_FR_MAXLEN; vMgrEncodeAuthen(&sFrame); @@ -1103,20 +948,18 @@ void vMgrAuthenBeginSta(void *hDeviceContext, * -*/ -void vMgrDeAuthenBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PBYTE abyDestAddress, - WORD wReason, - PCMD_STATUS pStatus) +void vMgrDeAuthenBeginSta(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason, + PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - WLAN_FR_DEAUTHEN sFrame; - PSTxMgmtPacket pTxPacket = NULL; - - - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + WLAN_FR_DEAUTHEN sFrame; + struct vnt_tx_mgmt *pTxPacket = + (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_DEAUTHEN_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN; vMgrEncodeDeauthen(&sFrame); @@ -1156,15 +999,10 @@ void vMgrDeAuthenBeginSta(void *hDeviceContext, * -*/ -static -void -s_vMgrRxAuthentication( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ) +static void s_vMgrRxAuthentication(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket) { - WLAN_FR_AUTHEN sFrame; + WLAN_FR_AUTHEN sFrame; // we better be an AP or a STA in AUTHPENDING otherwise ignore if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP || @@ -1214,25 +1052,21 @@ s_vMgrRxAuthentication( -*/ -static -void -s_vMgrRxAuthenSequence_1( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ) +static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame) { - PSTxMgmtPacket pTxPacket = NULL; - unsigned int uNodeIndex; - WLAN_FR_AUTHEN sFrame; - PSKeyItem pTransmitKey; - - // Insert a Node entry - if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) { - BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); - memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2, - WLAN_ADDR_LEN); - } + struct vnt_tx_mgmt *pTxPacket = NULL; + u32 uNodeIndex; + WLAN_FR_AUTHEN sFrame; + PSKeyItem pTransmitKey; + + /* Insert a Node entry */ + if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, + &uNodeIndex)) { + BSSvCreateOneNode(pDevice, &uNodeIndex); + memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, + pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN); + } if (pMgmt->bShareKeyAlgorithm) { pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN; @@ -1243,9 +1077,11 @@ s_vMgrRxAuthenSequence_1( } // send auth reply - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_AUTHEN_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_AUTHEN_FR_MAXLEN; // format buffer structure @@ -1320,16 +1156,11 @@ s_vMgrRxAuthenSequence_1( * -*/ -static -void -s_vMgrRxAuthenSequence_2( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ) +static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame) { - WLAN_FR_AUTHEN sFrame; - PSTxMgmtPacket pTxPacket = NULL; + WLAN_FR_AUTHEN sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm)))) @@ -1355,9 +1186,13 @@ s_vMgrRxAuthenSequence_2( case WLAN_AUTH_ALG_SHAREDKEY: if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) { - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *) + pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_AUTHEN_FR_MAXLEN); + pTxPacket->p80211Header + = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_AUTHEN_FR_MAXLEN; // format buffer structure @@ -1421,18 +1256,13 @@ s_vMgrRxAuthenSequence_2( * -*/ -static -void -s_vMgrRxAuthenSequence_3( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ) +static void s_vMgrRxAuthenSequence_3(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame) { - PSTxMgmtPacket pTxPacket = NULL; - unsigned int uStatusCode = 0 ; - unsigned int uNodeIndex = 0; - WLAN_FR_AUTHEN sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; + u32 uStatusCode = 0 ; + u32 uNodeIndex = 0; + WLAN_FR_AUTHEN sFrame; if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) { uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL; @@ -1462,9 +1292,11 @@ s_vMgrRxAuthenSequence_3( reply: // send auth reply - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_AUTHEN_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_AUTHEN_FR_MAXLEN; // format buffer structure @@ -1509,13 +1341,8 @@ reply: * None. * -*/ -static -void -s_vMgrRxAuthenSequence_4( - PSDevice pDevice, - PSMgmtObject pMgmt, - PWLAN_FR_AUTHEN pFrame - ) +static void s_vMgrRxAuthenSequence_4(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame) { if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){ @@ -1547,17 +1374,12 @@ s_vMgrRxAuthenSequence_4( * -*/ -static -void -s_vMgrRxDisassociation( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ) +static void s_vMgrRxDisassociation(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket) { - WLAN_FR_DISASSOC sFrame; - unsigned int uNodeIndex = 0; - CMD_STATUS CmdStatus; + WLAN_FR_DISASSOC sFrame; + u32 uNodeIndex = 0; + CMD_STATUS CmdStatus; if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){ // if is acting an AP.. @@ -1587,7 +1409,7 @@ s_vMgrRxDisassociation( pDevice->byReAssocCount = 0; pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state! pDevice->eCommandState = WLAN_ASSOCIATE_WAIT; - vMgrReAssocBeginSta((PSDevice)pDevice, pMgmt, &CmdStatus); + vMgrReAssocBeginSta(pDevice, pMgmt, &CmdStatus); if(CmdStatus == CMD_STATUS_PENDING) { pDevice->byReAssocCount ++; return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected! @@ -1620,16 +1442,11 @@ s_vMgrRxDisassociation( * -*/ -static -void -s_vMgrRxDeauthentication( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ) +static void s_vMgrRxDeauthentication(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket) { - WLAN_FR_DEAUTHEN sFrame; - unsigned int uNodeIndex = 0; + WLAN_FR_DEAUTHEN sFrame; + u32 uNodeIndex = 0; if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){ @@ -1692,13 +1509,9 @@ s_vMgrRxDeauthentication( * True:exceed; * False:normal case -*/ -static BOOL -ChannelExceedZoneType( - PSDevice pDevice, - BYTE byCurrChannel - ) +static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel) { - BOOL exceed=FALSE; + int exceed = FALSE; switch(pDevice->byZoneType) { case 0x00: //USA:1~11 @@ -1728,39 +1541,33 @@ ChannelExceedZoneType( * -*/ -static -void -s_vMgrRxBeacon( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket, - BOOL bInScan - ) +static void s_vMgrRxBeacon(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket, + int bInScan) { - - PKnownBSS pBSSList; - WLAN_FR_BEACON sFrame; + PKnownBSS pBSSList; + WLAN_FR_BEACON sFrame; u64 qwTSFOffset; - BOOL bIsBSSIDEqual = FALSE; - BOOL bIsSSIDEqual = FALSE; - BOOL bTSFLargeDiff = FALSE; - BOOL bTSFOffsetPostive = FALSE; - BOOL bUpdateTSF = FALSE; - BOOL bIsAPBeacon = FALSE; - BOOL bIsChannelEqual = FALSE; - unsigned int uLocateByteIndex; - BYTE byTIMBitOn = 0; - WORD wAIDNumber = 0; - unsigned int uNodeIndex; + int bIsBSSIDEqual = FALSE; + int bIsSSIDEqual = FALSE; + int bTSFLargeDiff = FALSE; + int bTSFOffsetPostive = FALSE; + int bUpdateTSF = FALSE; + int bIsAPBeacon = FALSE; + int bIsChannelEqual = FALSE; + u32 uLocateByteIndex; + u8 byTIMBitOn = 0; + u16 wAIDNumber = 0; + u32 uNodeIndex; u64 qwTimestamp, qwLocalTSF; u64 qwCurrTSF; - WORD wStartIndex = 0; - WORD wAIDIndex = 0; - BYTE byCurrChannel = pRxPacket->byRxChannel; - ERPObject sERP; - unsigned int uRateLen = WLAN_RATES_MAXLEN; - BOOL bChannelHit = FALSE; - BYTE byOldPreambleType; + u16 wStartIndex = 0; + u16 wAIDIndex = 0; + u8 byCurrChannel = pRxPacket->byRxChannel; + ERPObject sERP; + u32 uRateLen = WLAN_RATES_MAXLEN; + int bChannelHit = FALSE; + u8 byOldPreambleType; @@ -2071,12 +1878,9 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) if (pMgmt->bInTIM || (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) { pMgmt->bInTIMWake = TRUE; - // send out ps-poll packet -// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:In TIM\n"); - if (pMgmt->bInTIM) { - PSvSendPSPOLL((PSDevice)pDevice); -// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:PS-POLL sent..\n"); - } + /* send out ps-poll packet */ + if (pMgmt->bInTIM) + PSvSendPSPOLL(pDevice); } else { @@ -2130,8 +1934,8 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0; } else { - // Todo, initial Node content - BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); + /* Todo, initial Node content */ + BSSvCreateOneNode(pDevice, &uNodeIndex); pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, @@ -2242,21 +2046,20 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) * -*/ -void vMgrCreateOwnIBSS(void *hDeviceContext, - PCMD_STATUS pStatus) +void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - WORD wMaxBasicRate; - WORD wMaxSuppRate; - BYTE byTopCCKBasicRate; - BYTE byTopOFDMBasicRate; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u16 wMaxBasicRate; + u16 wMaxSuppRate; + u8 byTopCCKBasicRate; + u8 byTopOFDMBasicRate; u64 qwCurrTSF = 0; - unsigned int ii; - BYTE abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60}; - BYTE abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96}; - BYTE abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; - WORD wSuppRate; + int ii; + u8 abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, + 0x12, 0x18, 0x60}; + u8 abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96}; + u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; + u16 wSuppRate; @@ -2494,22 +2297,21 @@ void vMgrCreateOwnIBSS(void *hDeviceContext, * -*/ -void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus) +void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PKnownBSS pCurr = NULL; - unsigned int ii, uu; - PWLAN_IE_SUPP_RATES pItemRates = NULL; - PWLAN_IE_SUPP_RATES pItemExtRates = NULL; - PWLAN_IE_SSID pItemSSID; - unsigned int uRateLen = WLAN_RATES_MAXLEN; - WORD wMaxBasicRate = RATE_1M; - WORD wMaxSuppRate = RATE_1M; - WORD wSuppRate; - BYTE byTopCCKBasicRate = RATE_1M; - BYTE byTopOFDMBasicRate = RATE_1M; - BOOL bShortSlotTime = FALSE; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + PKnownBSS pCurr = NULL; + int ii, uu; + PWLAN_IE_SUPP_RATES pItemRates = NULL; + PWLAN_IE_SUPP_RATES pItemExtRates = NULL; + PWLAN_IE_SSID pItemSSID; + u32 uRateLen = WLAN_RATES_MAXLEN; + u16 wMaxBasicRate = RATE_1M; + u16 wMaxSuppRate = RATE_1M; + u16 wSuppRate; + u8 byTopCCKBasicRate = RATE_1M; + u8 byTopOFDMBasicRate = RATE_1M; + u8 bShortSlotTime = FALSE; for (ii = 0; ii < MAX_BSS_NUM; ii++) { @@ -2819,23 +2621,20 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus) * PCM_STATUS * -*/ -static -void -s_vMgrSynchBSS ( - PSDevice pDevice, - unsigned int uBSSMode, - PKnownBSS pCurr, - PCMD_STATUS pStatus - ) +static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, + PKnownBSS pCurr, PCMD_STATUS pStatus) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M - BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; - BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60}; - //6M, 9M, 12M, 48M - BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; - BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16}; - + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, + 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; + /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/ + u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, + 4, 0x0C, 0x12, 0x18, 0x60}; + /* 6M, 9M, 12M, 48M*/ + u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, + 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; + u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, + 4, 0x02, 0x04, 0x0B, 0x16}; *pStatus = CMD_STATUS_FAILURE; @@ -2974,21 +2773,13 @@ s_vMgrSynchBSS ( return; }; - -//mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption -// ,need reset eAuthenMode and eEncryptionStatus - static void Encyption_Rebuild( - PSDevice pDevice, - PKnownBSS pCurr - ) +static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - /* unsigned int ii, uSameBssidNum=0; */ + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; - // if( uSameBssidNum>=2) { //we only check AP in hidden sssid mode - if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || //networkmanager 0.7.0 does not give the pairwise-key selsection, - (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { // so we need re-selsect it according to real pairwise-key info. - if(pCurr->bWPAValid == TRUE) { //WPA-PSK + if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || + (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { + if (pCurr->bWPAValid == TRUE) { /*WPA-PSK */ pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK; if(pCurr->abyPKType[0] == WPA_TKIP) { pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP @@ -3027,20 +2818,15 @@ s_vMgrSynchBSS ( * -*/ -static -void -s_vMgrFormatTIM( - PSMgmtObject pMgmt, - PWLAN_IE_TIM pTIM - ) +static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM) { - BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - BYTE byMap; - unsigned int ii, jj; - BOOL bStartFound = FALSE; - BOOL bMulticast = FALSE; - WORD wStartIndex = 0; - WORD wEndIndex = 0; + u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; + u8 byMap; + int ii, jj; + int bStartFound = FALSE; + int bMulticast = FALSE; + u16 wStartIndex = 0; + u16 wEndIndex = 0; // Find size of partial virtual bitmap @@ -3102,30 +2888,23 @@ s_vMgrFormatTIM( * -*/ -static -PSTxMgmtPacket -s_MgrMakeBeacon( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wCurrBeaconPeriod, - unsigned int uCurrChannel, - WORD wCurrATIMWinodw, - PWLAN_IE_SSID pCurrSSID, - PBYTE pCurrBSSID, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ) +static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod, + u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID, + u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_BEACON sFrame; - BYTE abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_BEACON sFrame; + u8 abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - // prepare beacon frame - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + /* prepare beacon frame */ + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_BEACON_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); // Setup the sFrame structure. sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_BEACON_FR_MAXLEN; @@ -3277,30 +3056,22 @@ s_MgrMakeBeacon( -PSTxMgmtPacket -s_MgrMakeProbeResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wCurrBeaconPeriod, - unsigned int uCurrChannel, - WORD wCurrATIMWinodw, - PBYTE pDstAddr, - PWLAN_IE_SSID pCurrSSID, - PBYTE pCurrBSSID, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates, - BYTE byPHYType - ) +struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod, + u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr, + PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID, + PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_PROBERESP sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_PROBERESP sFrame; - - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_PROBERESP_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); // Setup the sFrame structure. sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_PROBERESP_FR_MAXLEN; @@ -3409,27 +3180,24 @@ s_MgrMakeProbeResponse( -*/ -PSTxMgmtPacket -s_MgrMakeAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PBYTE pDAddr, - WORD wCurrCapInfo, - WORD wListenInterval, - PWLAN_IE_SSID pCurrSSID, - PWLAN_IE_SUPP_RATES pCurrRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ) +struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo, + u16 wListenInterval, + PWLAN_IE_SSID pCurrSSID, + PWLAN_IE_SUPP_RATES pCurrRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_ASSOCREQ sFrame; - PBYTE pbyIEs; - PBYTE pbyRSN; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_ASSOCREQ sFrame; + u8 *pbyIEs; + u8 *pbyRSN; - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_ASSOCREQ_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); // Setup the sFrame structure. sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN; @@ -3671,27 +3439,23 @@ s_MgrMakeAssocRequest( -*/ -PSTxMgmtPacket -s_MgrMakeReAssocRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PBYTE pDAddr, - WORD wCurrCapInfo, - WORD wListenInterval, - PWLAN_IE_SSID pCurrSSID, - PWLAN_IE_SUPP_RATES pCurrRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ) +struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo, + u16 wListenInterval, PWLAN_IE_SSID pCurrSSID, + PWLAN_IE_SUPP_RATES pCurrRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_REASSOCREQ sFrame; - PBYTE pbyIEs; - PBYTE pbyRSN; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_REASSOCREQ sFrame; + u8 *pbyIEs; + u8 *pbyRSN; - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset( pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_REASSOCREQ_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); /* Setup the sFrame structure. */ sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN; @@ -3925,25 +3689,20 @@ s_MgrMakeReAssocRequest( * -*/ -PSTxMgmtPacket -s_MgrMakeAssocResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wAssocStatus, - WORD wAssocAID, - PBYTE pDstAddr, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ) +struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus, + u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_ASSOCRESP sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_ASSOCRESP sFrame; - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_ASSOCREQ_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); // Setup the sFrame structure sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN; @@ -3999,25 +3758,20 @@ s_MgrMakeAssocResponse( -*/ -PSTxMgmtPacket -s_MgrMakeReAssocResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - WORD wCurrCapInfo, - WORD wAssocStatus, - WORD wAssocAID, - PBYTE pDstAddr, - PWLAN_IE_SUPP_RATES pCurrSuppRates, - PWLAN_IE_SUPP_RATES pCurrExtSuppRates - ) +struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus, + u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates, + PWLAN_IE_SUPP_RATES pCurrExtSuppRates) { - PSTxMgmtPacket pTxPacket = NULL; - WLAN_FR_REASSOCRESP sFrame; + struct vnt_tx_mgmt *pTxPacket = NULL; + WLAN_FR_REASSOCRESP sFrame; - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; - memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN); - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool; + memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_ASSOCREQ_FR_MAXLEN); + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); // Setup the sFrame structure sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN; @@ -4072,19 +3826,14 @@ s_MgrMakeReAssocResponse( * -*/ -static -void -s_vMgrRxProbeResponse( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ) +static void s_vMgrRxProbeResponse(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket) { - PKnownBSS pBSSList = NULL; - WLAN_FR_PROBERESP sFrame; - BYTE byCurrChannel = pRxPacket->byRxChannel; - ERPObject sERP; - BOOL bChannelHit = TRUE; + PKnownBSS pBSSList = NULL; + WLAN_FR_PROBERESP sFrame; + u8 byCurrChannel = pRxPacket->byRxChannel; + ERPObject sERP; + int bChannelHit = TRUE; memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP)); @@ -4204,18 +3953,13 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) -*/ -static -void -s_vMgrRxProbeRequest( - PSDevice pDevice, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket - ) +static void s_vMgrRxProbeRequest(struct vnt_private *pDevice, + struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket) { - WLAN_FR_PROBEREQ sFrame; - CMD_STATUS Status; - PSTxMgmtPacket pTxPacket; - BYTE byPHYType = BB_TYPE_11B; + WLAN_FR_PROBEREQ sFrame; + CMD_STATUS Status; + struct vnt_tx_mgmt *pTxPacket; + u8 byPHYType = BB_TYPE_11B; // STA in Ad-hoc mode: when latest TBTT beacon transmit success, // STA have to response this request. @@ -4290,15 +4034,13 @@ s_vMgrRxProbeRequest( * -*/ -void vMgrRxManagePacket(void *hDeviceContext, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket) +void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, + struct vnt_rx_mgmt *pRxPacket) { - PSDevice pDevice = (PSDevice)hDeviceContext; - BOOL bInScan = FALSE; - unsigned int uNodeIndex = 0; - NODE_STATE eNodeState = 0; - CMD_STATUS Status; + int bInScan = FALSE; + u32 uNodeIndex = 0; + NODE_STATE eNodeState = 0; + CMD_STATUS Status; if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { @@ -4436,10 +4178,10 @@ void vMgrRxManagePacket(void *hDeviceContext, * TRUE if success; FALSE if failed. * -*/ -BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, PSMgmtObject pMgmt) +int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, + struct vnt_manager *pMgmt) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSTxMgmtPacket pTxPacket; + struct vnt_tx_mgmt *pTxPacket; // pDevice->bBeaconBufReady = FALSE; if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){ @@ -4487,12 +4229,7 @@ BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, PSMgmtObject pMgmt) * none. * -*/ -static -void -s_vMgrLogStatus( - PSMgmtObject pMgmt, - WORD wStatus - ) +static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus) { switch( wStatus ){ case WLAN_MGMT_STATUS_UNSPEC_FAILURE: @@ -4557,13 +4294,11 @@ s_vMgrLogStatus( * -*/ -BOOL bAdd_PMKID_Candidate(void *hDeviceContext, - PBYTE pbyBSSID, - PSRSNCapObject psRSNCapObj) +int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID, + PSRSNCapObject psRSNCapObj) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PPMKID_CANDIDATE pCandidateList; - unsigned int ii = 0; + PPMKID_CANDIDATE pCandidateList; + int ii = 0; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); @@ -4619,14 +4354,14 @@ BOOL bAdd_PMKID_Candidate(void *hDeviceContext, * -*/ -void vFlush_PMKID_Candidate(void *hDeviceContext) +void vFlush_PMKID_Candidate(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; + if (pDevice == NULL) + return; - if (pDevice == NULL) - return; + memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent)); - memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent)); + return; } static BOOL diff --git a/drivers/staging/vt6656/wmgr.h b/drivers/staging/vt6656/wmgr.h index f98309b..86c1505 100644 --- a/drivers/staging/vt6656/wmgr.h +++ b/drivers/staging/vt6656/wmgr.h @@ -220,32 +220,26 @@ typedef enum tagWMAC_POWER_MODE { /* Tx Management Packet descriptor */ typedef struct vnt_tx_mgmt { - - PUWLAN_80211HDR p80211Header; - unsigned int cbMPDULen; - unsigned int cbPayloadLen; - + PUWLAN_80211HDR p80211Header; + u32 cbMPDULen; + u32 cbPayloadLen; } STxMgmtPacket, *PSTxMgmtPacket; /* Rx Management Packet descriptor */ typedef struct vnt_rx_mgmt { - - PUWLAN_80211HDR p80211Header; + PUWLAN_80211HDR p80211Header; u64 qwLocalTSF; - unsigned int cbMPDULen; - unsigned int cbPayloadLen; - unsigned int uRSSI; - BYTE bySQ; - BYTE byRxRate; - BYTE byRxChannel; - + u32 cbMPDULen; + u32 cbPayloadLen; + u32 uRSSI; + u8 bySQ; + u8 byRxRate; + u8 byRxChannel; } SRxMgmtPacket, *PSRxMgmtPacket; - -typedef struct vnt_manager -{ +typedef struct vnt_manager { void *pAdapter; // MAC address BYTE abyMACAddr[WLAN_ADDR_LEN]; @@ -334,7 +328,8 @@ typedef struct vnt_manager WORD wCountToWakeUp; BOOL bInTIMWake; PBYTE pbyPSPacketPool; - BYTE byPSPacketPool[sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN]; + u8 byPSPacketPool[sizeof(struct vnt_tx_mgmt) + + WLAN_NULLDATA_FR_MAXLEN]; BOOL bRxBeaconInTBTTWake; BYTE abyPSTxMap[MAX_NODE_NUM + 1]; @@ -344,14 +339,15 @@ typedef struct vnt_manager // management packet pool PBYTE pbyMgmtPacketPool; - BYTE byMgmtPacketPool[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN]; + u8 byMgmtPacketPool[sizeof(struct vnt_tx_mgmt) + + WLAN_A3FR_MAXLEN]; // One second callback timer struct timer_list sTimerSecondCallback; - // Temporarily Rx Mgmt Packet Descriptor - SRxMgmtPacket sRxPacket; + /* Temporarily Rx Mgmt Packet Descriptor */ + struct vnt_rx_mgmt sRxPacket; // link list of known bss's (scan results) KnownBSS sBSSList[MAX_BSS_NUM]; @@ -385,8 +381,10 @@ typedef struct vnt_manager BYTE byNewChannel; PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep; unsigned int uLengthOfRepEIDs; - BYTE abyCurrentMSRReq[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN]; - BYTE abyCurrentMSRRep[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN]; + u8 abyCurrentMSRReq[sizeof(struct vnt_tx_mgmt) + + WLAN_A3FR_MAXLEN]; + u8 abyCurrentMSRRep[sizeof(struct vnt_tx_mgmt) + + WLAN_A3FR_MAXLEN]; BYTE abyIECountry[WLAN_A3FR_MAXLEN]; BYTE abyIBSSDFSOwner[6]; BYTE byIBSSDFSRecovery; @@ -399,35 +397,29 @@ typedef struct vnt_manager /*--------------------- Export Functions --------------------------*/ -void vMgrObjectInit(void *hDeviceContext); +void vMgrObjectInit(struct vnt_private *pDevice); -void vMgrAssocBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PCMD_STATUS pStatus); +void vMgrAssocBeginSta(struct vnt_private *pDevice, + struct vnt_manager *, PCMD_STATUS pStatus); -void vMgrReAssocBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PCMD_STATUS pStatus); +void vMgrReAssocBeginSta(struct vnt_private *pDevice, + struct vnt_manager *, PCMD_STATUS pStatus); -void vMgrDisassocBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PBYTE abyDestAddress, - WORD wReason, - PCMD_STATUS pStatus); +void vMgrDisassocBeginSta(struct vnt_private *pDevice, + struct vnt_manager *, u8 *abyDestAddress, u16 wReason, + PCMD_STATUS pStatus); -void vMgrAuthenBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PCMD_STATUS pStatus); +void vMgrAuthenBeginSta(struct vnt_private *pDevice, + struct vnt_manager *, PCMD_STATUS pStatus); -void vMgrCreateOwnIBSS(void *hDeviceContext, - PCMD_STATUS pStatus); +void vMgrCreateOwnIBSS(struct vnt_private *pDevice, + PCMD_STATUS pStatus); -void vMgrJoinBSSBegin(void *hDeviceContext, - PCMD_STATUS pStatus); +void vMgrJoinBSSBegin(struct vnt_private *pDevice, + PCMD_STATUS pStatus); -void vMgrRxManagePacket(void *hDeviceContext, - PSMgmtObject pMgmt, - PSRxMgmtPacket pRxPacket); +void vMgrRxManagePacket(struct vnt_private *pDevice, + struct vnt_manager *, struct vnt_rx_mgmt *); /* void @@ -437,19 +429,16 @@ vMgrScanBegin( ); */ -void vMgrDeAuthenBeginSta(void *hDeviceContext, - PSMgmtObject pMgmt, - PBYTE abyDestAddress, - WORD wReason, - PCMD_STATUS pStatus); +void vMgrDeAuthenBeginSta(struct vnt_private *pDevice, + struct vnt_manager *, u8 *abyDestAddress, u16 wReason, + PCMD_STATUS pStatus); -BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, - PSMgmtObject pMgmt); +int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, + struct vnt_manager *); -BOOL bAdd_PMKID_Candidate(void *hDeviceContext, - PBYTE pbyBSSID, - PSRSNCapObject psRSNCapObj); +int bAdd_PMKID_Candidate(struct vnt_private *pDevice, + u8 *pbyBSSID, PSRSNCapObject psRSNCapObj); -void vFlush_PMKID_Candidate(void *hDeviceContext); +void vFlush_PMKID_Candidate(struct vnt_private *pDevice); #endif /* __WMGR_H__ */ -- cgit v0.10.2 From da033bfd7a016c0a143db0a2345c4312a35ed896 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Mon, 10 Dec 2012 22:12:07 +0000 Subject: staging: vt6656: iwctl/key/rf use new structures. This patch cleans up function declarations, definitions and local variables were appropriate replacing types defined in "ttype.h" with linux/types.h Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c index 52fce69..880c025 100644 --- a/drivers/staging/vt6656/iwctl.c +++ b/drivers/staging/vt6656/iwctl.c @@ -55,7 +55,7 @@ static int msglevel = MSG_LEVEL_INFO; struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); long ldBm; pDevice->wstats.status = pDevice->eOPMode; @@ -91,9 +91,9 @@ int iwctl_giwname(struct net_device *dev, struct iw_request_info *info, int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_point *wrq = &wrqu->data; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_scan_req *req = (struct iw_scan_req *)extra; BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; PWLAN_IE_SSID pItemSSID = NULL; @@ -169,8 +169,8 @@ int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info, int ii; int jj; int kk; - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PKnownBSS pBSS; PWLAN_IE_SSID pItemSSID; PWLAN_IE_SUPP_RATES pSuppRates; @@ -309,7 +309,7 @@ int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info, int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_freq *wrq = &wrqu->freq; int rc = 0; @@ -348,9 +348,9 @@ int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info, int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_freq *wrq = &wrqu->freq; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ\n"); @@ -379,9 +379,9 @@ int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info, int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); __u32 *wmode = &wrqu->mode; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; int rc = 0; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n"); @@ -492,9 +492,9 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, int iwctl_giwmode(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); __u32 *wmode = &wrqu->mode; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE\n"); @@ -631,9 +631,9 @@ int iwctl_giwrange(struct net_device *dev, struct iw_request_info *info, int iwctl_siwap(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct sockaddr *wrq = &wrqu->ap_addr; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; int rc = 0; BYTE ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -683,9 +683,9 @@ int iwctl_siwap(struct net_device *dev, struct iw_request_info *info, int iwctl_giwap(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct sockaddr *wrq = &wrqu->ap_addr; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP\n"); @@ -713,8 +713,8 @@ int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info, struct iw_point *wrq = &wrqu->data; struct sockaddr *sock; struct iw_quality *qual; - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &pDevice->sMgmtObj; + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PKnownBSS pBSS = &pMgmt->sBSSList[0]; int ii; int jj; @@ -771,9 +771,9 @@ int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info, int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_point *wrq = &wrqu->essid; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PWLAN_IE_SSID pItemSSID; if (pMgmt == NULL) @@ -878,9 +878,9 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info, int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_point *wrq = &wrqu->essid; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PWLAN_IE_SSID pItemSSID; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID\n"); @@ -908,7 +908,7 @@ int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info, int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->bitrate; int rc = 0; u8 brate = 0; @@ -986,9 +986,9 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info, int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->bitrate; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE\n"); @@ -1037,7 +1037,7 @@ int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info, int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->rts; if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled) @@ -1057,7 +1057,7 @@ int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info, int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->rts; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS\n"); @@ -1073,7 +1073,7 @@ int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info, int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->frag; int rc = 0; int fthr = wrq->value; @@ -1097,7 +1097,7 @@ int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info, int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->frag; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG\n"); @@ -1113,7 +1113,7 @@ int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info, int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->retry; int rc = 0; @@ -1146,7 +1146,7 @@ int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info, int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->retry; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY\n"); wrq->disabled = 0; // Can't be disabled @@ -1173,8 +1173,8 @@ int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info, int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_point *wrq = &wrqu->encoding; u32 dwKeyIndex = (u32)(wrq->flags & IW_ENCODE_INDEX); int ii; @@ -1271,8 +1271,8 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_point *wrq = &wrqu->encoding; char abyKey[WLAN_WEP232_KEYLEN]; @@ -1333,8 +1333,8 @@ int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info, int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_param *wrq = &wrqu->power; int rc = 0; @@ -1385,8 +1385,8 @@ int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info, int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_param *wrq = &wrqu->power; int mode = pDevice->ePSMode; @@ -1418,7 +1418,7 @@ int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info, int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); + struct vnt_private *pDevice = netdev_priv(dev); struct iw_param *wrq = &wrqu->sens; long ldBm; @@ -1437,8 +1437,8 @@ int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info, int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_param *wrq = &wrqu->param; int ret = 0; static int wpa_version = 0; // must be static to save the last value, einsn liu @@ -1547,8 +1547,8 @@ int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info, int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_point *wrq = &wrqu->data; int ret = 0; @@ -1582,8 +1582,8 @@ out: // not completely ...not necessary in wpa_supplicant 0.5.8 int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_point *wrq = &wrqu->data; int ret = 0; int space = wrq->length; @@ -1608,8 +1608,8 @@ int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info, int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_point *wrq = &wrqu->encoding; struct iw_encode_ext *ext = (struct iw_encode_ext*)extra; struct viawget_wpa_param *param=NULL; @@ -1741,8 +1741,8 @@ int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info, int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - PSDevice pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_mlme *mlme = (struct iw_mlme *)extra; int ret = 0; diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c index 6f6a219..87eab91 100644 --- a/drivers/staging/vt6656/key.c +++ b/drivers/staging/vt6656/key.c @@ -60,13 +60,12 @@ static int msglevel =MSG_LEVEL_INFO; /*--------------------- Static Variables --------------------------*/ /*--------------------- Static Functions --------------------------*/ -static void s_vCheckKeyTableValid(void *pDeviceHandler, - PSKeyManagement pTable) +static void s_vCheckKeyTableValid(struct vnt_private *pDevice, + PSKeyManagement pTable) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - int i; - WORD wLength = 0; - BYTE pbyData[MAX_KEY_TABLE]; + int i; + u16 wLength = 0; + u8 pbyData[MAX_KEY_TABLE]; for (i=0;iKeyTable[i].bInUse == TRUE) && @@ -112,12 +111,10 @@ static void s_vCheckKeyTableValid(void *pDeviceHandler, * Return Value: none * */ -void KeyvInitTable(void *pDeviceHandler, PSKeyManagement pTable) +void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - int i; - int jj; - BYTE pbyData[MAX_KEY_TABLE+1]; + int i, jj; + u8 pbyData[MAX_KEY_TABLE+1]; spin_lock_irq(&pDevice->lock); for (i=0;iKeyTable[i].bInUse == TRUE) && @@ -514,13 +494,9 @@ BOOL KeybRemoveAllKey( * Return Value: TRUE if success otherwise FALSE * */ -void KeyvRemoveWEPKey( - void *pDeviceHandler, - PSKeyManagement pTable, - DWORD dwKeyIndex - ) +void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable, + u32 dwKeyIndex) { - PSDevice pDevice = (PSDevice) pDeviceHandler; if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) { @@ -537,9 +513,8 @@ void KeyvRemoveWEPKey( return; } -void KeyvRemoveAllWEPKey(void *pDeviceHandler, PSKeyManagement pTable) +void KeyvRemoveAllWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable) { - PSDevice pDevice = (PSDevice) pDeviceHandler; int i; for (i = 0; i < MAX_GROUP_KEY; i++) @@ -559,12 +534,13 @@ void KeyvRemoveAllWEPKey(void *pDeviceHandler, PSKeyManagement pTable) * Return Value: TRUE if found otherwise FALSE * */ -BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType, - PSKeyItem *pKey) +int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, + PSKeyItem *pKey) { - int i, ii; + int i, ii; + + *pKey = NULL; - *pKey = NULL; for (i = 0; i < MAX_KEY_TABLE; i++) { if ((pTable->KeyTable[i].bInUse == TRUE) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { @@ -636,11 +612,12 @@ BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType, * Return Value: TRUE if found otherwise FALSE * */ -BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) +int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) { - int i; + int i; + + *pKey = NULL; - *pKey = NULL; for (i=0;iKeyTable[i].bInUse == TRUE) && (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) { @@ -667,20 +644,14 @@ BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) * Return Value: TRUE if success otherwise FALSE * */ -BOOL KeybSetDefaultKey( - void *pDeviceHandler, - PSKeyManagement pTable, - DWORD dwKeyIndex, - u32 uKeyLength, - u64 *KeyRSC, - PBYTE pbyKey, - BYTE byKeyDecMode - ) + +int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, + u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey, + u8 byKeyDecMode) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - unsigned int ii; - PSKeyItem pKey; - unsigned int uKeyIdx; + int ii; + PSKeyItem pKey; + u32 uKeyIdx; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetDefaultKey: %1x, %d\n", (int) dwKeyIndex, (int) uKeyLength); @@ -783,21 +754,14 @@ BOOL KeybSetDefaultKey( * Return Value: TRUE if success otherwise FALSE * */ -BOOL KeybSetAllGroupKey( - void *pDeviceHandler, - PSKeyManagement pTable, - DWORD dwKeyIndex, - u32 uKeyLength, - u64 *KeyRSC, - PBYTE pbyKey, - BYTE byKeyDecMode - ) + +int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable, + u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey, + u8 byKeyDecMode) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - int i; - unsigned int ii; - PSKeyItem pKey; - unsigned int uKeyIdx; + int i, ii; + PSKeyItem pKey; + u32 uKeyIdx; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %X\n", dwKeyIndex); diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h index 863db7c..8889423 100644 --- a/drivers/staging/vt6656/key.h +++ b/drivers/staging/vt6656/key.h @@ -97,69 +97,37 @@ typedef struct tagSKeyManagement /*--------------------- Export Functions --------------------------*/ -void KeyvInitTable(void *pDeviceHandler, PSKeyManagement pTable); - -BOOL KeybGetKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyIndex, - PSKeyItem *pKey); - -BOOL KeybSetKey( - void *pDeviceHandler, - PSKeyManagement pTable, - PBYTE pbyBSSID, - DWORD dwKeyIndex, - u32 uKeyLength, - u64 *KeyRSC, - PBYTE pbyKey, - BYTE byKeyDecMode - ); - -BOOL KeybRemoveKey( - void *pDeviceHandler, - PSKeyManagement pTable, - PBYTE pbyBSSID, - DWORD dwKeyIndex - ); - -BOOL KeybRemoveAllKey( - void *pDeviceHandler, - PSKeyManagement pTable, - PBYTE pbyBSSID - ); - -void KeyvRemoveWEPKey( - void *pDeviceHandler, - PSKeyManagement pTable, - DWORD dwKeyIndex - ); - -void KeyvRemoveAllWEPKey( - void *pDeviceHandler, - PSKeyManagement pTable - ); - -BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType, - PSKeyItem *pKey); - -BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey); - -BOOL KeybSetDefaultKey( - void *pDeviceHandler, - PSKeyManagement pTable, - DWORD dwKeyIndex, - u32 uKeyLength, - u64 *KeyRSC, - PBYTE pbyKey, - BYTE byKeyDecMode - ); - -BOOL KeybSetAllGroupKey( - void *pDeviceHandler, - PSKeyManagement pTable, - DWORD dwKeyIndex, - u32 uKeyLength, - u64 *KeyRSC, - PBYTE pbyKey, - BYTE byKeyDecMode - ); +void KeyvInitTable(struct vnt_private *, PSKeyManagement pTable); + +int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, + PSKeyItem *pKey); + +int KeybSetKey(struct vnt_private *, PSKeyManagement pTable, u8 *pbyBSSID, + u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey, + u8 byKeyDecMode); + +int KeybRemoveKey(struct vnt_private *, PSKeyManagement pTable, + u8 *pbyBSSID, u32 dwKeyIndex); + +int KeybRemoveAllKey(struct vnt_private *, PSKeyManagement pTable, + u8 *pbyBSSID); + +void KeyvRemoveWEPKey(struct vnt_private *, PSKeyManagement pTable, + u32 dwKeyIndex); + +void KeyvRemoveAllWEPKey(struct vnt_private *, PSKeyManagement pTable); + +int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, + PSKeyItem *pKey); + +int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey); + +int KeybSetDefaultKey(struct vnt_private *, PSKeyManagement pTable, + u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey, + u8 byKeyDecMode); + +int KeybSetAllGroupKey(struct vnt_private *, PSKeyManagement pTable, + u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey, + u8 byKeyDecMode); #endif /* __KEY_H__ */ diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c index 74c0598..06cff8b 100644 --- a/drivers/staging/vt6656/rf.c +++ b/drivers/staging/vt6656/rf.c @@ -69,7 +69,7 @@ static int msglevel =MSG_LEVEL_INFO; -BYTE abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = { +u8 abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = { {0x03, 0xF7, 0x90}, {0x03, 0x33, 0x31}, {0x01, 0xB8, 0x02}, @@ -87,7 +87,7 @@ BYTE abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = { {0x00, 0x58, 0x0F} }; -BYTE abyAL2230ChannelTable0[CB_MAX_CHANNEL_24G][3] = { +u8 abyAL2230ChannelTable0[CB_MAX_CHANNEL_24G][3] = { {0x03, 0xF7, 0x90}, // channel = 1, Tf = 2412MHz {0x03, 0xF7, 0x90}, // channel = 2, Tf = 2417MHz {0x03, 0xE7, 0x90}, // channel = 3, Tf = 2422MHz @@ -104,7 +104,7 @@ BYTE abyAL2230ChannelTable0[CB_MAX_CHANNEL_24G][3] = { {0x03, 0xE7, 0xC0} // channel = 14, Tf = 2412M }; -BYTE abyAL2230ChannelTable1[CB_MAX_CHANNEL_24G][3] = { +u8 abyAL2230ChannelTable1[CB_MAX_CHANNEL_24G][3] = { {0x03, 0x33, 0x31}, // channel = 1, Tf = 2412MHz {0x0B, 0x33, 0x31}, // channel = 2, Tf = 2417MHz {0x03, 0x33, 0x31}, // channel = 3, Tf = 2422MHz @@ -123,7 +123,7 @@ BYTE abyAL2230ChannelTable1[CB_MAX_CHANNEL_24G][3] = { // 40MHz reference frequency // Need to Pull PLLON(PE3) low when writing channel registers through 3-wire. -BYTE abyAL7230InitTable[CB_AL7230_INIT_SEQ][3] = { +u8 abyAL7230InitTable[CB_AL7230_INIT_SEQ][3] = { {0x20, 0x37, 0x90}, // Channel1 // Need modify for 11a {0x13, 0x33, 0x31}, // Channel1 // Need modify for 11a {0x84, 0x1F, 0xF2}, // Need modify for 11a: 451FE2 @@ -146,7 +146,7 @@ BYTE abyAL7230InitTable[CB_AL7230_INIT_SEQ][3] = { {0x1A, 0xBA, 0x8F} // Need modify for 11a: 12BACF }; -BYTE abyAL7230InitTableAMode[CB_AL7230_INIT_SEQ][3] = { +u8 abyAL7230InitTableAMode[CB_AL7230_INIT_SEQ][3] = { {0x2F, 0xF5, 0x20}, // Channel184 // Need modify for 11b/g {0x00, 0x00, 0x01}, // Channel184 // Need modify for 11b/g {0x45, 0x1F, 0xE2}, // Need modify for 11b/g @@ -165,7 +165,7 @@ BYTE abyAL7230InitTableAMode[CB_AL7230_INIT_SEQ][3] = { {0x12, 0xBA, 0xCF} // Need modify for 11b/g }; -BYTE abyAL7230ChannelTable0[CB_MAX_CHANNEL][3] = { +u8 abyAL7230ChannelTable0[CB_MAX_CHANNEL][3] = { {0x20, 0x37, 0x90}, // channel = 1, Tf = 2412MHz {0x20, 0x37, 0x90}, // channel = 2, Tf = 2417MHz {0x20, 0x37, 0x90}, // channel = 3, Tf = 2422MHz @@ -231,7 +231,7 @@ BYTE abyAL7230ChannelTable0[CB_MAX_CHANNEL][3] = { {0x2F, 0xF6, 0x10} // channel = 165, Tf = 5825MHz (56) }; -BYTE abyAL7230ChannelTable1[CB_MAX_CHANNEL][3] = { +u8 abyAL7230ChannelTable1[CB_MAX_CHANNEL][3] = { {0x13, 0x33, 0x31}, // channel = 1, Tf = 2412MHz {0x1B, 0x33, 0x31}, // channel = 2, Tf = 2417MHz {0x03, 0x33, 0x31}, // channel = 3, Tf = 2422MHz @@ -295,7 +295,7 @@ BYTE abyAL7230ChannelTable1[CB_MAX_CHANNEL][3] = { {0x02, 0xAA, 0xB1} // channel = 165, Tf = 5825MHz (56) }; -BYTE abyAL7230ChannelTable2[CB_MAX_CHANNEL][3] = { +u8 abyAL7230ChannelTable2[CB_MAX_CHANNEL][3] = { {0x7F, 0xD7, 0x84}, // channel = 1, Tf = 2412MHz {0x7F, 0xD7, 0x84}, // channel = 2, Tf = 2417MHz {0x7F, 0xD7, 0x84}, // channel = 3, Tf = 2422MHz @@ -360,7 +360,7 @@ BYTE abyAL7230ChannelTable2[CB_MAX_CHANNEL][3] = { }; ///{{RobertYu:20051111 -BYTE abyVT3226_InitTable[CB_VT3226_INIT_SEQ][3] = { +u8 abyVT3226_InitTable[CB_VT3226_INIT_SEQ][3] = { {0x03, 0xFF, 0x80}, {0x02, 0x82, 0xA1}, {0x03, 0xC6, 0xA2}, @@ -374,7 +374,7 @@ BYTE abyVT3226_InitTable[CB_VT3226_INIT_SEQ][3] = { {0x02, 0x00, 0x2A} }; -BYTE abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = { +u8 abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = { {0x03, 0xFF, 0x80}, {0x03, 0x02, 0x21}, //RobertYu:20060327 {0x03, 0xC6, 0xA2}, @@ -389,7 +389,7 @@ BYTE abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = { }; -BYTE abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = { +u8 abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = { {0x01, 0x97, 0x83}, // channel = 1, Tf = 2412MHz {0x01, 0x97, 0x83}, // channel = 2, Tf = 2417MHz {0x01, 0x97, 0x93}, // channel = 3, Tf = 2422MHz @@ -406,7 +406,7 @@ BYTE abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = { {0x03, 0x37, 0xC3} // channel = 14, Tf = 2484MHz }; -BYTE abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = { +u8 abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = { {0x02, 0x66, 0x64}, // channel = 1, Tf = 2412MHz {0x03, 0x66, 0x64}, // channel = 2, Tf = 2417MHz {0x00, 0x66, 0x64}, // channel = 3, Tf = 2422MHz @@ -426,7 +426,7 @@ BYTE abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = { //{{RobertYu:20060502, TWIF 1.14, LO Current for 11b mode -DWORD dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = { +u32 dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = { 0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 0x0235C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz @@ -446,7 +446,7 @@ DWORD dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = { //{{RobertYu:20060609 -BYTE abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { // 11b/g mode +u8 abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { /* 11b/g mode */ {0x03, 0xFF, 0x80}, //update for mode// {0x02, 0x08, 0x81}, {0x00, 0xC6, 0x02}, @@ -469,7 +469,7 @@ BYTE abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { // 11b/g mode // channel56, 5280MHz 0x00C402 for disable Frac // other channels 0x00C602 -BYTE abyVT3342_ChannelTable0[CB_MAX_CHANNEL][3] = { +u8 abyVT3342_ChannelTable0[CB_MAX_CHANNEL][3] = { {0x02, 0x05, 0x03}, // channel = 1, Tf = 2412MHz {0x01, 0x15, 0x03}, // channel = 2, Tf = 2417MHz {0x03, 0xC5, 0x03}, // channel = 3, Tf = 2422MHz @@ -535,7 +535,7 @@ BYTE abyVT3342_ChannelTable0[CB_MAX_CHANNEL][3] = { {0x00, 0x06, 0x03} // channel = 165, Tf = 5825MHz (56), TBD }; -BYTE abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = { +u8 abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = { {0x01, 0x99, 0x94}, // channel = 1, Tf = 2412MHz {0x02, 0x44, 0x44}, // channel = 2, Tf = 2417MHz {0x02, 0xEE, 0xE4}, // channel = 3, Tf = 2422MHz @@ -606,7 +606,7 @@ BYTE abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = { * -*/ -const DWORD dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = { +const u32 dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = { 0x04040900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 0x04041900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 0x04042900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, @@ -682,7 +682,7 @@ const DWORD dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = { // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) -const BYTE RFaby11aChannelIndex[200] = { +const u8 RFaby11aChannelIndex[200] = { // 1 2 3 4 5 6 7 8 9 10 00, 00, 00, 00, 00, 00, 23, 24, 25, 00, // 10 26, 27, 00, 00, 00, 28, 00, 00, 00, 00, // 20 @@ -722,24 +722,20 @@ const BYTE RFaby11aChannelIndex[200] = { * Return Value: TRUE if succeeded; FALSE if failed. * */ -BOOL IFRFbWriteEmbedded (PSDevice pDevice, DWORD dwData) +int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData) { - BYTE pbyData[4]; + u8 pbyData[4]; - pbyData[0] = (BYTE)dwData; - pbyData[1] = (BYTE)(dwData>>8); - pbyData[2] = (BYTE)(dwData>>16); - pbyData[3] = (BYTE)(dwData>>24); - CONTROLnsRequestOut(pDevice, - MESSAGE_TYPE_WRITE_IFRF, - 0, - 0, - 4, - pbyData - ); + pbyData[0] = (u8)dwData; + pbyData[1] = (u8)(dwData >> 8); + pbyData[2] = (u8)(dwData >> 16); + pbyData[3] = (u8)(dwData >> 24); + + CONTROLnsRequestOut(pDevice, + MESSAGE_TYPE_WRITE_IFRF, 0, 0, 4, pbyData); - return TRUE; + return TRUE; } @@ -756,18 +752,13 @@ BOOL IFRFbWriteEmbedded (PSDevice pDevice, DWORD dwData) * Return Value: TRUE if succeeded; FALSE if failed. * */ -BOOL RFbSetPower ( - PSDevice pDevice, - unsigned int uRATE, - unsigned int uCH - ) +int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH) { -BOOL bResult = TRUE; -BYTE byPwr = pDevice->byCCKPwr; + int bResult = TRUE; + u8 byPwr = pDevice->byCCKPwr; - if (pDevice->dwDiagRefCount != 0) { - return TRUE; - } + if (pDevice->dwDiagRefCount) + return TRUE; if (uCH == 0) return -EINVAL; @@ -813,13 +804,10 @@ BYTE byPwr = pDevice->byCCKPwr; * Return Value: TRUE if succeeded; FALSE if failed. * */ -BOOL RFbRawSetPower ( - PSDevice pDevice, - BYTE byPwr, - unsigned int uRATE - ) + +int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) { -BOOL bResult = TRUE; + int bResult = TRUE; if (pDevice->byCurPwr == byPwr) return TRUE; @@ -957,17 +945,12 @@ BOOL bResult = TRUE; * Return Value: none * -*/ -void -RFvRSSITodBm ( - PSDevice pDevice, - BYTE byCurrRSSI, - long * pldBm - ) +void RFvRSSITodBm(struct vnt_private *pDevice, u8 byCurrRSSI, long *pldBm) { - BYTE byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03); - signed long b = (byCurrRSSI & 0x3F); - signed long a = 0; - BYTE abyAIROHARF[4] = {0, 18, 0, 40}; + u8 byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03); + signed long b = (byCurrRSSI & 0x3F); + signed long a = 0; + u8 abyAIROHARF[4] = {0, 18, 0, 40}; switch (pDevice->byRFType) { case RF_AL2230: @@ -987,15 +970,12 @@ RFvRSSITodBm ( -void -RFbRFTableDownload ( - PSDevice pDevice - ) +void RFbRFTableDownload(struct vnt_private *pDevice) { -WORD wLength1 = 0,wLength2 = 0 ,wLength3 = 0; -PBYTE pbyAddr1 = NULL,pbyAddr2 = NULL,pbyAddr3 = NULL; -WORD wLength,wValue; -BYTE abyArray[256]; + u16 wLength1 = 0, wLength2 = 0, wLength3 = 0; + u8 *pbyAddr1 = NULL, *pbyAddr2 = NULL, *pbyAddr3 = NULL; + u16 wLength, wValue; + u8 abyArray[256]; switch ( pDevice->byRFType ) { case RF_AL2230: @@ -1134,21 +1114,19 @@ BYTE abyArray[256]; } -// RobertYu:20060412, TWIF1.11 adjust LO Current for 11b mode -BOOL s_bVT3226D0_11bLoCurrentAdjust( - PSDevice pDevice, - BYTE byChannel, - BOOL b11bMode) +int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *pDevice, u8 byChannel, + int b11bMode) { - BOOL bResult; + int bResult = TRUE; - bResult = TRUE; - if( b11bMode ) - bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226D0LoCurrentTable[byChannel-1]); - else - bResult &= IFRFbWriteEmbedded(pDevice, 0x016BC600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); //RobertYu:20060412 + if (b11bMode) + bResult &= IFRFbWriteEmbedded(pDevice, + dwVT3226D0LoCurrentTable[byChannel-1]); + else + bResult &= IFRFbWriteEmbedded(pDevice, 0x016bc600 + + (BY_VT3226_REG_LEN << 3) + IFREGCTL_REGW); - return bResult; + return bResult; } diff --git a/drivers/staging/vt6656/rf.h b/drivers/staging/vt6656/rf.h index 72eb27a..9f70cf7 100644 --- a/drivers/staging/vt6656/rf.h +++ b/drivers/staging/vt6656/rf.h @@ -60,25 +60,15 @@ /*--------------------- Export Classes ----------------------------*/ /*--------------------- Export Variables --------------------------*/ -extern const BYTE RFaby11aChannelIndex[200]; +extern const u8 RFaby11aChannelIndex[200]; /*--------------------- Export Functions --------------------------*/ -BOOL IFRFbWriteEmbedded(PSDevice pDevice, DWORD dwData); -BOOL RFbSetPower(PSDevice pDevice, unsigned int uRATE, unsigned int uCH); - -BOOL RFbRawSetPower( - PSDevice pDevice, - BYTE byPwr, - unsigned int uRATE - ); - -void RFvRSSITodBm(PSDevice pDevice, BYTE byCurrRSSI, long *pldBm); -void RFbRFTableDownload(PSDevice pDevice); - -BOOL s_bVT3226D0_11bLoCurrentAdjust( - PSDevice pDevice, - BYTE byChannel, - BOOL b11bMode - ); +int IFRFbWriteEmbedded(struct vnt_private *, u32 dwData); +int RFbSetPower(struct vnt_private *, u32 uRATE, u32 uCH); +int RFbRawSetPower(struct vnt_private *, u8 byPwr, u32 uRATE); +void RFvRSSITodBm(struct vnt_private *, u8 byCurrRSSI, long *pldBm); +void RFbRFTableDownload(struct vnt_private *pDevice); +int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *, u8 byChannel, + int b11bMode); #endif /* __RF_H__ */ -- cgit v0.10.2 From fe5d00ebd348621ce34bb4982271f7b1c45e6700 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Mon, 10 Dec 2012 22:14:36 +0000 Subject: staging: vt6656: channel/control/firmware/int/usbpipe to new structures This patch cleans up function declarations, definitions and local variables where appropriate replacing types defined in "ttype.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c index 6502176..95f00ba 100644 --- a/drivers/staging/vt6656/channel.c +++ b/drivers/staging/vt6656/channel.c @@ -436,11 +436,10 @@ CHvChannelGetList ( } -void CHvInitChannelTable(void *pDeviceHandler) +void CHvInitChannelTable(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice) pDeviceHandler; - BOOL bMultiBand = FALSE; - unsigned int ii; + int bMultiBand = FALSE; + int ii; for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) sChannelTbl[ii].bValid = FALSE; diff --git a/drivers/staging/vt6656/channel.h b/drivers/staging/vt6656/channel.h index e7b3c12..8031491 100644 --- a/drivers/staging/vt6656/channel.h +++ b/drivers/staging/vt6656/channel.h @@ -30,6 +30,7 @@ #ifndef _CHANNEL_H_ #define _CHANNEL_H_ +#include "device.h" #include "ttype.h" /*--------------------- Export Definitions -------------------------*/ @@ -47,7 +48,7 @@ typedef struct tagSChannelTblElement { /*--------------------- Export Functions --------------------------*/ BOOL ChannelValid(unsigned int CountryCode, unsigned int ChannelNum); -void CHvInitChannelTable(void *pDeviceHandler); +void CHvInitChannelTable(struct vnt_private *pDevice); BYTE CHbyGetChannelMapping(BYTE byChannelNumber); BOOL CHvChannelGetList(unsigned int uCountryCodeIdx, PBYTE pbyChannelTable); diff --git a/drivers/staging/vt6656/control.c b/drivers/staging/vt6656/control.c index 5d8c571..743ef5f 100644 --- a/drivers/staging/vt6656/control.c +++ b/drivers/staging/vt6656/control.c @@ -56,43 +56,34 @@ /*--------------------- Export Functions --------------------------*/ -void ControlvWriteByte(PSDevice pDevice, BYTE byRegType, BYTE byRegOfs, - BYTE byData) +void ControlvWriteByte(struct vnt_private *pDevice, u8 reg, u8 reg_off, + u8 data) { - BYTE byData1; - byData1 = byData; - CONTROLnsRequestOut(pDevice, - MESSAGE_TYPE_WRITE, - byRegOfs, - byRegType, - 1, - &byData1); + + CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_WRITE, reg_off, reg, + sizeof(u8), &data); + + return; } -void ControlvReadByte(PSDevice pDevice, BYTE byRegType, BYTE byRegOfs, - PBYTE pbyData) +void ControlvReadByte(struct vnt_private *pDevice, u8 reg, u8 reg_off, + u8 *data) { - int ntStatus; - BYTE byData1; - ntStatus = CONTROLnsRequestIn(pDevice, - MESSAGE_TYPE_READ, - byRegOfs, - byRegType, - 1, - &byData1); - *pbyData = byData1; + CONTROLnsRequestIn(pDevice, MESSAGE_TYPE_READ, + reg_off, reg, sizeof(u8), data); + return; } -void ControlvMaskByte(PSDevice pDevice, BYTE byRegType, BYTE byRegOfs, - BYTE byMask, BYTE byData) +void ControlvMaskByte(struct vnt_private *pDevice, u8 reg_type, u8 reg_off, + u8 reg_mask, u8 data) { - BYTE pbyData[2]; - pbyData[0] = byData; - pbyData[1] = byMask; - CONTROLnsRequestOut(pDevice, - MESSAGE_TYPE_WRITE_MASK, - byRegOfs, - byRegType, - 2, - pbyData); + u8 reg_data[2]; + + reg_data[0] = data; + reg_data[1] = reg_mask; + + CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_WRITE_MASK, reg_off, + reg_type, ARRAY_SIZE(reg_data), reg_data); + + return; } diff --git a/drivers/staging/vt6656/control.h b/drivers/staging/vt6656/control.h index bbe610f..76ce024 100644 --- a/drivers/staging/vt6656/control.h +++ b/drivers/staging/vt6656/control.h @@ -51,28 +51,14 @@ /*--------------------- Export Functions --------------------------*/ -void ControlvWriteByte( - PSDevice pDevice, - BYTE byRegType, - BYTE byRegOfs, - BYTE byData - ); +void ControlvWriteByte(struct vnt_private *pDevice, u8 reg, u8 reg_off, + u8 data); +void ControlvReadByte(struct vnt_private *pDevice, u8 reg, u8 reg_off, + u8 *data); -void ControlvReadByte( - PSDevice pDevice, - BYTE byRegType, - BYTE byRegOfs, - PBYTE pbyData - ); +void ControlvMaskByte(struct vnt_private *pDevice, u8 reg_type, u8 reg_off, + u8 reg_mask, u8 data); -void ControlvMaskByte( - PSDevice pDevice, - BYTE byRegType, - BYTE byRegOfs, - BYTE byMask, - BYTE byData - ); - #endif /* __CONTROL_H__ */ diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c index 8831ea0..93d7301 100644 --- a/drivers/staging/vt6656/firmware.c +++ b/drivers/staging/vt6656/firmware.c @@ -56,10 +56,7 @@ static int msglevel =MSG_LEVEL_INFO; /*--------------------- Export Functions --------------------------*/ -BOOL -FIRMWAREbDownload( - PSDevice pDevice - ) +int FIRMWAREbDownload(struct vnt_private *pDevice) { struct device *dev = &pDevice->usb->dev; const struct firmware *fw; @@ -114,12 +111,9 @@ out: } MODULE_FIRMWARE(FIRMWARE_NAME); -BOOL -FIRMWAREbBrach2Sram( - PSDevice pDevice - ) +int FIRMWAREbBrach2Sram(struct vnt_private *pDevice) { - int NdisStatus; + int NdisStatus; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n"); @@ -139,10 +133,7 @@ FIRMWAREbBrach2Sram( } -BOOL -FIRMWAREbCheckVersion( - PSDevice pDevice - ) +int FIRMWAREbCheckVersion(struct vnt_private *pDevice) { int ntStatus; diff --git a/drivers/staging/vt6656/firmware.h b/drivers/staging/vt6656/firmware.h index b2f5b58..ebab3a6 100644 --- a/drivers/staging/vt6656/firmware.h +++ b/drivers/staging/vt6656/firmware.h @@ -41,19 +41,8 @@ /*--------------------- Export Functions --------------------------*/ -BOOL -FIRMWAREbDownload( - PSDevice pDevice - ); - -BOOL -FIRMWAREbBrach2Sram( - PSDevice pDevice - ); - -BOOL -FIRMWAREbCheckVersion( - PSDevice pDevice - ); +int FIRMWAREbDownload(struct vnt_private *); +int FIRMWAREbBrach2Sram(struct vnt_private *); +int FIRMWAREbCheckVersion(struct vnt_private *); #endif /* __FIRMWARE_H__ */ diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c index 7718ac2..97c6896 100644 --- a/drivers/staging/vt6656/int.c +++ b/drivers/staging/vt6656/int.c @@ -75,9 +75,8 @@ static int msglevel = MSG_LEVEL_INFO; /* MSG_LEVEL_DEBUG */ * if we've gotten no data * -*/ -void INTvWorkItem(void *Context) +void INTvWorkItem(struct vnt_private *pDevice) { - PSDevice pDevice = Context; int ntStatus; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Interrupt Polling Thread\n"); @@ -88,10 +87,10 @@ void INTvWorkItem(void *Context) spin_unlock_irq(&pDevice->lock); } -void INTnsProcessData(PSDevice pDevice) +void INTnsProcessData(struct vnt_private *pDevice) { PSINTData pINTData; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct net_device_stats *pStats = &pDevice->stats; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptProcessData\n"); diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h index ffc243f..444b6c2 100644 --- a/drivers/staging/vt6656/int.h +++ b/drivers/staging/vt6656/int.h @@ -65,7 +65,7 @@ SINTData, *PSINTData; /*--------------------- Export Functions --------------------------*/ -void INTvWorkItem(void *Context); -void INTnsProcessData(PSDevice pDevice); +void INTvWorkItem(struct vnt_private *); +void INTnsProcessData(struct vnt_private *); #endif /* __INT_H__ */ diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c index fc68518..2a02067 100644 --- a/drivers/staging/vt6656/usbpipe.c +++ b/drivers/staging/vt6656/usbpipe.c @@ -67,51 +67,18 @@ static int msglevel =MSG_LEVEL_INFO; /*--------------------- Static Variables --------------------------*/ /*--------------------- Static Functions --------------------------*/ -static -void -s_nsInterruptUsbIoCompleteRead( - struct urb *urb - ); - - -static -void -s_nsBulkInUsbIoCompleteRead( - struct urb *urb - ); - - -static -void -s_nsBulkOutIoCompleteWrite( - struct urb *urb - ); - - -static -void -s_nsControlInUsbIoCompleteRead( - struct urb *urb - ); - -static -void -s_nsControlInUsbIoCompleteWrite( - struct urb *urb - ); +static void s_nsInterruptUsbIoCompleteRead(struct urb *urb); +static void s_nsBulkInUsbIoCompleteRead(struct urb *urb); +static void s_nsBulkOutIoCompleteWrite(struct urb *urb); +static void s_nsControlInUsbIoCompleteRead(struct urb *urb); +static void s_nsControlInUsbIoCompleteWrite(struct urb *urb); /*--------------------- Export Variables --------------------------*/ /*--------------------- Export Functions --------------------------*/ -int PIPEnsControlOutAsyn( - PSDevice pDevice, - BYTE byRequest, - WORD wValue, - WORD wIndex, - WORD wLength, - PBYTE pbyBuffer - ) +int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest, + u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer) { int ntStatus; @@ -147,17 +114,11 @@ int PIPEnsControlOutAsyn( return ntStatus; } -int PIPEnsControlOut( - PSDevice pDevice, - BYTE byRequest, - WORD wValue, - WORD wIndex, - WORD wLength, - PBYTE pbyBuffer - ) +int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue, + u16 wIndex, u16 wLength, u8 *pbyBuffer) { int ntStatus = 0; - int ii; + int ii; if (pDevice->Flags & fMP_DISCONNECTED) return STATUS_FAILURE; @@ -206,17 +167,11 @@ int PIPEnsControlOut( return STATUS_SUCCESS; } -int PIPEnsControlIn( - PSDevice pDevice, - BYTE byRequest, - WORD wValue, - WORD wIndex, - WORD wLength, - PBYTE pbyBuffer - ) +int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue, + u16 wIndex, u16 wLength, u8 *pbyBuffer) { int ntStatus = 0; - int ii; + int ii; if (pDevice->Flags & fMP_DISCONNECTED) return STATUS_FAILURE; @@ -263,13 +218,9 @@ int PIPEnsControlIn( return ntStatus; } -static -void -s_nsControlInUsbIoCompleteWrite( - struct urb *urb - ) +static void s_nsControlInUsbIoCompleteWrite(struct urb *urb) { - PSDevice pDevice; + struct vnt_private *pDevice = (struct vnt_private *)urb->context; pDevice = urb->context; switch (urb->status) { @@ -304,15 +255,11 @@ s_nsControlInUsbIoCompleteWrite( * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver * */ -static -void -s_nsControlInUsbIoCompleteRead( - struct urb *urb - ) + +static void s_nsControlInUsbIoCompleteRead(struct urb *urb) { - PSDevice pDevice; + struct vnt_private *pDevice = (struct vnt_private *)urb->context; - pDevice = urb->context; switch (urb->status) { case 0: break; @@ -345,9 +292,10 @@ s_nsControlInUsbIoCompleteRead( * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver * */ -int PIPEnsInterruptRead(PSDevice pDevice) + +int PIPEnsInterruptRead(struct vnt_private *pDevice) { - int ntStatus = STATUS_FAILURE; + int ntStatus = STATUS_FAILURE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n"); @@ -396,21 +344,16 @@ usb_fill_bulk_urb(pDevice->pInterruptURB, * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver * */ -static -void -s_nsInterruptUsbIoCompleteRead( - struct urb *urb - ) +static void s_nsInterruptUsbIoCompleteRead(struct urb *urb) { - PSDevice pDevice; - int ntStatus; + struct vnt_private *pDevice = (struct vnt_private *)urb->context; + int ntStatus; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n"); // // The context given to IoSetCompletionRoutine is the receive buffer object // - pDevice = (PSDevice)urb->context; // // We have a number of cases: @@ -483,10 +426,11 @@ s_nsInterruptUsbIoCompleteRead( * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver * */ -int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB) + +int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, PRCB pRCB) { int ntStatus = 0; - struct urb *pUrb; + struct urb *pUrb; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n"); @@ -543,19 +487,15 @@ int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB) * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver * */ -static -void -s_nsBulkInUsbIoCompleteRead( - struct urb *urb - ) +static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) { - PRCB pRCB = (PRCB)urb->context; - PSDevice pDevice = (PSDevice)pRCB->pDevice; - unsigned long bytesRead; - BOOL bIndicateReceive = FALSE; - BOOL bReAllocSkb = FALSE; - int status; + PRCB pRCB = (PRCB)urb->context; + struct vnt_private *pDevice = pRCB->pDevice; + unsigned long bytesRead; + int bIndicateReceive = FALSE; + int bReAllocSkb = FALSE; + int status; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n"); status = urb->status; @@ -618,14 +558,11 @@ s_nsBulkInUsbIoCompleteRead( * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver * */ -int -PIPEnsSendBulkOut( - PSDevice pDevice, - PUSB_SEND_CONTEXT pContext - ) + +int PIPEnsSendBulkOut(struct vnt_private *pDevice, PUSB_SEND_CONTEXT pContext) { - int status; - struct urb *pUrb; + int status; + struct urb *pUrb; @@ -699,17 +636,14 @@ PIPEnsSendBulkOut( * (IofCompleteRequest) to stop working on the irp. * */ -static -void -s_nsBulkOutIoCompleteWrite( - struct urb *urb - ) + +static void s_nsBulkOutIoCompleteWrite(struct urb *urb) { - PSDevice pDevice; - int status; - CONTEXT_TYPE ContextType; - unsigned long ulBufLen; - PUSB_SEND_CONTEXT pContext; + struct vnt_private *pDevice; + int status; + CONTEXT_TYPE ContextType; + unsigned long ulBufLen; + PUSB_SEND_CONTEXT pContext; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n"); diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h index b367347..b302355 100644 --- a/drivers/staging/vt6656/usbpipe.h +++ b/drivers/staging/vt6656/usbpipe.h @@ -41,35 +41,15 @@ /*--------------------- Export Functions --------------------------*/ -int PIPEnsControlOut( - PSDevice pDevice, - BYTE byRequest, - WORD wValue, - WORD wIndex, - WORD wLength, - PBYTE pbyBuffer - ); - -int PIPEnsControlOutAsyn( - PSDevice pDevice, - BYTE byRequest, - WORD wValue, - WORD wIndex, - WORD wLength, - PBYTE pbyBuffer - ); - -int PIPEnsControlIn( - PSDevice pDevice, - BYTE byRequest, - WORD wValue, - WORD wIndex, - WORD wLength, - PBYTE pbyBuffer - ); - -int PIPEnsInterruptRead(PSDevice pDevice); -int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB); -int PIPEnsSendBulkOut(PSDevice pDevice, PUSB_SEND_CONTEXT pContext); +int PIPEnsControlOut(struct vnt_private *, u8 byRequest, u16 wValue, + u16 wIndex, u16 wLength, u8 *pbyBuffer); +int PIPEnsControlOutAsyn(struct vnt_private *, u8 byRequest, + u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer); +int PIPEnsControlIn(struct vnt_private *, u8 byRequest, u16 wValue, + u16 wIndex, u16 wLength, u8 *pbyBuffer); + +int PIPEnsInterruptRead(struct vnt_private *); +int PIPEnsBulkInUsbRead(struct vnt_private *, PRCB pRCB); +int PIPEnsSendBulkOut(struct vnt_private *, PUSB_SEND_CONTEXT pContext); #endif /* __USBPIPE_H__ */ diff --git a/drivers/staging/vt6656/wpactl.c b/drivers/staging/vt6656/wpactl.c index 3afbb61..569d1a7 100644 --- a/drivers/staging/vt6656/wpactl.c +++ b/drivers/staging/vt6656/wpactl.c @@ -67,10 +67,10 @@ static int msglevel = MSG_LEVEL_INFO; * Return Value: * */ -int wpa_set_keys(PSDevice pDevice, void *ctx) +int wpa_set_keys(struct vnt_private *pDevice, void *ctx) { struct viawget_wpa_param *param = ctx; - PSMgmtObject pMgmt = &pDevice->sMgmtObj; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; DWORD dwKeyIndex = 0; BYTE abyKey[MAX_KEY_LEN]; BYTE abySeq[MAX_KEY_LEN]; diff --git a/drivers/staging/vt6656/wpactl.h b/drivers/staging/vt6656/wpactl.h index b4ec6b0..2235ee9 100644 --- a/drivers/staging/vt6656/wpactl.h +++ b/drivers/staging/vt6656/wpactl.h @@ -52,6 +52,6 @@ typedef unsigned long long NDIS_802_11_KEY_RSC; /*--------------------- Export Functions --------------------------*/ -int wpa_set_keys(PSDevice pDevice, void *ctx); +int wpa_set_keys(struct vnt_private *, void *ctx); #endif /* __WPACL_H__ */ -- cgit v0.10.2 From d4d8bcd945c92c7da4b05f93c060e38b559065f0 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Sun, 2 Dec 2012 03:40:22 +0100 Subject: staging: vt6656: remove a useless call to memset(). This call is followed by a call to memcpy() on the same memory area, so it can be safely removed. Signed-off-by: Cyril Roelandt Acked-by: Marcos Paulo de Souza Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index 539bc1d..d1757cf 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -240,7 +240,6 @@ pDevice->bSameBSSMaxNum = jj; pSelect->bSelected = TRUE; if (pDevice->bRoaming == FALSE) { // Einsn Add @20070907 - memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ; } -- cgit v0.10.2 From 8d915d8c9b8c49ab4725e3d9a6d7b5a8b50751e7 Mon Sep 17 00:00:00 2001 From: Masanari Iida Date: Wed, 26 Dec 2012 01:23:29 +0900 Subject: staging: vt6655: Fix typo in vt6655 driver Correct spelling typo in comments within vt6655 driver. Signed-off-by: Masanari Iida Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c index 875ee44..d66854f 100644 --- a/drivers/staging/vt6655/rxtx.c +++ b/drivers/staging/vt6655/rxtx.c @@ -2421,7 +2421,7 @@ CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) { pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10)); // Notes: - // Although spec says MMPDU can be fragmented; In most case, + // Although spec says MMPDU can be fragmented; In most cases, // no one will send a MMPDU under fragmentation. With RTS may occur. pDevice->bAES = false; //Set FRAGCTL_WEPTYP @@ -2510,7 +2510,7 @@ CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) { pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); //Fill TXKEY - //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet. + //Kyle: Need fix: TKIP and AES did't encrypt Mnt Packet. //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL); //Fill IV(ExtIV,RSNHDR) @@ -2957,7 +2957,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, unsigned char *pbMPDU, un pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10); // Notes: - // Although spec says MMPDU can be fragmented; In most casses, + // Although spec says MMPDU can be fragmented; In most cases, // no one will send a MMPDU under fragmentation. With RTS may occur. pDevice->bAES = false; //Set FRAGCTL_WEPTYP diff --git a/drivers/staging/vt6655/wcmd.c b/drivers/staging/vt6655/wcmd.c index 6d0b87a..101c735 100644 --- a/drivers/staging/vt6655/wcmd.c +++ b/drivers/staging/vt6655/wcmd.c @@ -720,7 +720,7 @@ printk("chester-abyDesireSSID=%s\n",((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySS pDevice->nTxDataTimeCout = 0; } else { - // printk("mike:-->First time triger TimerTxData InSleep\n"); + // printk("mike:-->First time trigger TimerTxData InSleep\n"); } pDevice->IsTxDataTrigger = true; add_timer(&pDevice->sTimerTxData); diff --git a/drivers/staging/vt6655/wmgr.c b/drivers/staging/vt6655/wmgr.c index b6f99ec..b08a611 100644 --- a/drivers/staging/vt6655/wmgr.c +++ b/drivers/staging/vt6655/wmgr.c @@ -2068,7 +2068,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true) if (pBSSList != NULL) { - // Compare PHY paramater setting + // Compare PHY parameter setting if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) { bUpdatePhyParameter = true; pMgmt->wCurrCapInfo = pBSSList->wCapInfo; -- cgit v0.10.2 From 3aa2303a20e3aac5a8445777b665a433d60c2786 Mon Sep 17 00:00:00 2001 From: Ondrej Zary Date: Sun, 2 Dec 2012 12:30:19 +0100 Subject: staging: ft1000: unify struct ft1000_info between USB and PCMCIA drivers Unify struct ft1000_info between ft1000-usb and ft1000-pcmcia and move it to common ft1000.h. Signed-off-by: Ondrej Zary Tested-by: Marek Belisko Review-by: Marek Belisko Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h index adb436e..65f7ab6 100644 --- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h +++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h @@ -31,41 +31,10 @@ #define SUCCESS 0x00 #define FAILURE 0x01 -struct ft1000_info { - struct net_device_stats stats; - u16 DrvErrNum; - u16 AsicID; +struct ft1000_pcmcia { int PktIntfErr; - int CardReady; - int registered; - int mediastate; u16 packetseqnum; - u8 squeseqnum; /* sequence number on slow queue */ - spinlock_t dpram_lock; - u16 fifo_cnt; - u8 DspVer[DSPVERSZ]; /* DSP version number */ - u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */ - u8 Sku[SKUSZ]; /* SKU */ - u8 eui64[EUISZ]; /* EUI64 */ - time_t ConTm; /* Connection Time */ - u16 LedStat; - u16 ConStat; - u16 ProgConStat; - u8 ProductMode[MODESZ]; - u8 RfCalVer[CALVERSZ]; - u8 RfCalDate[CALDATESZ]; - u16 DSP_TIME[4]; - struct list_head prov_list; - u16 DSPInfoBlklen; - int (*ft1000_reset)(void *); void *link; - u16 DSPInfoBlk[MAX_DSP_SESS_REC]; - union { - u16 Rec[MAX_DSP_SESS_REC]; - u32 MagRec[MAX_DSP_SESS_REC/2]; - } DSPSess; - struct proc_dir_entry *proc_ft1000; - char netdevname[IFNAMSIZ]; }; struct pcmcia_device; diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c index 86a680c..3fd499f 100644 --- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c @@ -328,11 +328,12 @@ static void ft1000_disable_interrupts(struct net_device *dev) static void ft1000_reset_asic(struct net_device *dev) { struct ft1000_info *info = netdev_priv(dev); + struct ft1000_pcmcia *pcmcia = info->priv; u16 tempword; DEBUG(1, "ft1000_hw:ft1000_reset_asic called\n"); - (*info->ft1000_reset) (info->link); + (*info->ft1000_reset) (pcmcia->link); // Let's use the register provided by the Magnemite ASIC to reset the // ASIC and DSP. @@ -1397,12 +1398,13 @@ static int ft1000_parse_dpram_msg(struct net_device *dev) static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum) { struct ft1000_info *info = netdev_priv(dev); + struct ft1000_pcmcia *pcmcia = info->priv; u16 i; u32 templong; u16 tempword; DEBUG(1, "ft1000:ft1000_hw:ft1000_flush_fifo called\n"); - if (info->PktIntfErr > MAX_PH_ERR) { + if (pcmcia->PktIntfErr > MAX_PH_ERR) { if (info->AsicID == ELECTRABUZZ_ID) { info->DSP_TIME[0] = ft1000_read_dpram(dev, FT1000_DSP_TIMER0); @@ -1491,7 +1493,7 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum) FIFO_FLUSH_BADCNT; } else { // Let's assume that we really flush the FIFO - info->PktIntfErr++; + pcmcia->PktIntfErr++; return; } } else { @@ -1522,7 +1524,7 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum) DEBUG(0, "FT1000_REG_MAG_DFSR = 0x%x\n", tempword); } if (DrvErrNum) { - info->PktIntfErr++; + pcmcia->PktIntfErr++; } } } @@ -1731,6 +1733,7 @@ static int ft1000_copy_up_pkt(struct net_device *dev) static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len) { struct ft1000_info *info = netdev_priv(dev); + struct ft1000_pcmcia *pcmcia = info->priv; union { struct pseudo_hdr blk; u16 buff[sizeof(struct pseudo_hdr) >> 1]; @@ -1780,7 +1783,7 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len) pseudo.blk.control = 0; pseudo.blk.rsvd1 = 0; pseudo.blk.seq_num = 0; - pseudo.blk.rsvd2 = info->packetseqnum++; + pseudo.blk.rsvd2 = pcmcia->packetseqnum++; pseudo.blk.qos_class = 0; /* Calculate pseudo header checksum */ pseudo.blk.checksum = pseudo.buff[0]; @@ -2058,6 +2061,8 @@ void stop_ft1000_card(struct net_device *dev) kfree(ptr); } + kfree(info->priv); + if (info->registered) { unregister_netdev(dev); info->registered = 0; @@ -2100,6 +2105,7 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link, void *ft1000_reset) { struct ft1000_info *info; + struct ft1000_pcmcia *pcmcia; struct net_device *dev; static const struct net_device_ops ft1000ops = // Slavius 21.10.2009 due to kernel changes @@ -2141,10 +2147,13 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link, memset(&info->stats, 0, sizeof(struct net_device_stats)); + info->priv = kzalloc(sizeof(struct ft1000_pcmcia), GFP_KERNEL); + pcmcia = info->priv; + pcmcia->link = link; + spin_lock_init(&info->dpram_lock); info->DrvErrNum = 0; info->registered = 1; - info->link = link; info->ft1000_reset = ft1000_reset; info->mediastate = 0; info->fifo_cnt = 0; diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c index 72727c6..5337b41 100644 --- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c +++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c @@ -175,8 +175,8 @@ static int ft1000NotifyProc(struct notifier_block *this, unsigned long event, switch (event) { case NETDEV_CHANGENAME: - remove_proc_entry(info->netdevname, info->proc_ft1000); - create_proc_read_entry(dev->name, 0644, info->proc_ft1000, + remove_proc_entry(info->netdevname, info->ft1000_proc_dir); + create_proc_read_entry(dev->name, 0644, info->ft1000_proc_dir, ft1000ReadProc, dev); snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name); break; @@ -194,8 +194,8 @@ void ft1000InitProc(struct net_device *dev) info = netdev_priv(dev); - info->proc_ft1000 = proc_mkdir(FT1000_PROC, init_net.proc_net); - create_proc_read_entry(dev->name, 0644, info->proc_ft1000, + info->ft1000_proc_dir = proc_mkdir(FT1000_PROC, init_net.proc_net); + create_proc_read_entry(dev->name, 0644, info->ft1000_proc_dir, ft1000ReadProc, dev); snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name); register_netdevice_notifier(&ft1000_netdev_notifier); @@ -207,7 +207,7 @@ void ft1000CleanupProc(struct net_device *dev) info = netdev_priv(dev); - remove_proc_entry(dev->name, info->proc_ft1000); + remove_proc_entry(dev->name, info->ft1000_proc_dir); remove_proc_entry(FT1000_PROC, init_net.proc_net); unregister_netdevice_notifier(&ft1000_netdev_notifier); } diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c index 6d911fd..fb197ab 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c @@ -139,27 +139,26 @@ void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist) //--------------------------------------------------------------------------- int ft1000_create_dev(struct ft1000_device *dev) { - struct ft1000_info *info = netdev_priv(dev->net); int result; int i; struct dentry *dir, *file; struct ft1000_debug_dirs *tmp; // make a new device name - sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber); + sprintf(dev->DeviceName, "%s%d", "FT1000_", dev->CardNumber); DEBUG("%s: number of instance = %d\n", __func__, ft1000_flarion_cnt); - DEBUG("DeviceCreated = %x\n", info->DeviceCreated); + DEBUG("DeviceCreated = %x\n", dev->DeviceCreated); - if (info->DeviceCreated) + if (dev->DeviceCreated) { - DEBUG("%s: \"%s\" already registered\n", __func__, info->DeviceName); + DEBUG("%s: \"%s\" already registered\n", __func__, dev->DeviceName); return -EIO; } // register the device - DEBUG("%s: \"%s\" debugfs device registration\n", __func__, info->DeviceName); + DEBUG("%s: \"%s\" debugfs device registration\n", __func__, dev->DeviceName); tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL); if (tmp == NULL) { @@ -167,7 +166,7 @@ int ft1000_create_dev(struct ft1000_device *dev) goto fail; } - dir = debugfs_create_dir(info->DeviceName, NULL); + dir = debugfs_create_dir(dev->DeviceName, NULL); if (IS_ERR(dir)) { result = PTR_ERR(dir); goto debug_dir_fail; @@ -182,27 +181,27 @@ int ft1000_create_dev(struct ft1000_device *dev) tmp->dent = dir; tmp->file = file; - tmp->int_number = info->CardNumber; - list_add(&(tmp->list), &(info->nodes.list)); + tmp->int_number = dev->CardNumber; + list_add(&(tmp->list), &(dev->nodes.list)); - DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, info->DeviceName); + DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, dev->DeviceName); // initialize application information - info->appcnt = 0; + dev->appcnt = 0; for (i=0; iapp_info[i].nTxMsg = 0; - info->app_info[i].nRxMsg = 0; - info->app_info[i].nTxMsgReject = 0; - info->app_info[i].nRxMsgMiss = 0; - info->app_info[i].fileobject = NULL; - info->app_info[i].app_id = i+1; - info->app_info[i].DspBCMsgFlag = 0; - info->app_info[i].NumOfMsg = 0; - init_waitqueue_head(&info->app_info[i].wait_dpram_msg); - INIT_LIST_HEAD (&info->app_info[i].app_sqlist); + dev->app_info[i].nTxMsg = 0; + dev->app_info[i].nRxMsg = 0; + dev->app_info[i].nTxMsgReject = 0; + dev->app_info[i].nRxMsgMiss = 0; + dev->app_info[i].fileobject = NULL; + dev->app_info[i].app_id = i+1; + dev->app_info[i].DspBCMsgFlag = 0; + dev->app_info[i].NumOfMsg = 0; + init_waitqueue_head(&dev->app_info[i].wait_dpram_msg); + INIT_LIST_HEAD (&dev->app_info[i].app_sqlist); } - info->DeviceCreated = TRUE; + dev->DeviceCreated = TRUE; ft1000_flarion_cnt++; return 0; @@ -225,9 +224,10 @@ fail: // Notes: Only called by cleanup_module(). // //--------------------------------------------------------------------------- -void ft1000_destroy_dev(struct net_device *dev) +void ft1000_destroy_dev(struct net_device *netdev) { - struct ft1000_info *info = netdev_priv(dev); + struct ft1000_info *info = netdev_priv(netdev); + struct ft1000_device *dev = info->priv; int i; struct dpram_blk *pdpram_blk; struct dpram_blk *ptr; @@ -238,12 +238,12 @@ void ft1000_destroy_dev(struct net_device *dev) - if (info->DeviceCreated) + if (dev->DeviceCreated) { ft1000_flarion_cnt--; - list_for_each_safe(pos, q, &info->nodes.list) { + list_for_each_safe(pos, q, &dev->nodes.list) { dir = list_entry(pos, struct ft1000_debug_dirs, list); - if (dir->int_number == info->CardNumber) { + if (dir->int_number == dev->CardNumber) { debugfs_remove(dir->file); debugfs_remove(dir->dent); list_del(pos); @@ -251,17 +251,17 @@ void ft1000_destroy_dev(struct net_device *dev) } } DEBUG("%s: unregistered device \"%s\"\n", __func__, - info->DeviceName); + dev->DeviceName); // Make sure we free any memory reserve for slow Queue for (i=0; iapp_info[i].app_sqlist) == 0) { - pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); + while (list_empty(&dev->app_info[i].app_sqlist) == 0) { + pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next, struct dpram_blk, list); list_del(&pdpram_blk->list); ft1000_free_buffer(pdpram_blk, &freercvpool); } - wake_up_interruptible(&info->app_info[i].wait_dpram_msg); + wake_up_interruptible(&dev->app_info[i].wait_dpram_msg); } // Remove buffer allocated for receive command data @@ -273,7 +273,7 @@ void ft1000_destroy_dev(struct net_device *dev) kfree(ptr); } } - info->DeviceCreated = FALSE; + dev->DeviceCreated = FALSE; } @@ -301,17 +301,17 @@ static int ft1000_open (struct inode *inode, struct file *file) info = file->private_data = netdev_priv(dev->net); - DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), info->appcnt ); + DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), dev->appcnt ); // Check if maximum number of application exceeded - if (info->appcnt > MAX_NUM_APP) { + if (dev->appcnt > MAX_NUM_APP) { DEBUG("Maximum number of application exceeded\n"); return -EACCES; } // Search for available application info block for (i=0; iapp_info[i].fileobject == NULL) ) { + if ( (dev->app_info[i].fileobject == NULL) ) { break; } } @@ -322,12 +322,12 @@ static int ft1000_open (struct inode *inode, struct file *file) return -EACCES; } - info->appcnt++; - info->app_info[i].fileobject = &file->f_owner; - info->app_info[i].nTxMsg = 0; - info->app_info[i].nRxMsg = 0; - info->app_info[i].nTxMsgReject = 0; - info->app_info[i].nRxMsgMiss = 0; + dev->appcnt++; + dev->app_info[i].fileobject = &file->f_owner; + dev->app_info[i].nTxMsg = 0; + dev->app_info[i].nRxMsg = 0; + dev->app_info[i].nTxMsgReject = 0; + dev->app_info[i].nRxMsgMiss = 0; nonseekable_open(inode, file); return 0; @@ -347,8 +347,9 @@ static int ft1000_open (struct inode *inode, struct file *file) static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) { - struct net_device *dev = file->private_data; - struct ft1000_info *info; + struct net_device *netdev = file->private_data; + struct ft1000_info *info = netdev_priv(netdev); + struct ft1000_device *dev = info->priv; int i; //DEBUG("ft1000_poll_dev called\n"); @@ -357,12 +358,10 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) return (-EBADF); } - info = netdev_priv(dev); - // Search for matching file object for (i=0; iapp_info[i].fileobject == &file->f_owner) { - //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id); + if ( dev->app_info[i].fileobject == &file->f_owner) { + //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", dev->app_info[i].app_id); break; } } @@ -373,12 +372,12 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) return ( -EACCES ); } - if (list_empty(&info->app_info[i].app_sqlist) == 0) { + if (list_empty(&dev->app_info[i].app_sqlist) == 0) { DEBUG("FT1000:ft1000_poll_dev:Message detected in slow queue\n"); return(POLLIN | POLLRDNORM | POLLPRI); } - poll_wait (file, &info->app_info[i].wait_dpram_msg, wait); + poll_wait (file, &dev->app_info[i].wait_dpram_msg, wait); //DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n"); return (0); @@ -428,7 +427,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, //DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument); info = file->private_data; - ft1000dev = info->pFt1000Dev; + ft1000dev = info->priv; cmd = _IOC_NR(command); //DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd); @@ -444,8 +443,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command, if (tempword == DSPBCMSGID) { // Search for matching file object for (i=0; iapp_info[i].fileobject == &file->f_owner) { - info->app_info[i].DspBCMsgFlag = 1; + if (ft1000dev->app_info[i].fileobject == &file->f_owner) { + ft1000dev->app_info[i].DspBCMsgFlag = 1; DEBUG("FT1000:ft1000_ioctl:Registered for broadcast messages\n"); break; } @@ -534,15 +533,15 @@ static long ft1000_ioctl (struct file *file, unsigned int command, return (-EBADF); } - if (info->DrvMsgPend) { + if (ft1000dev->DrvMsgPend) { return (-ENOTTY); } - if ( (info->DspAsicReset) || (info->fProvComplete == 0) ) { + if (ft1000dev->fProvComplete == 0) { return (-EACCES); } - info->fAppMsgPend = 1; + ft1000dev->fAppMsgPend = 1; if (info->CardReady) { @@ -571,7 +570,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, else { // Check if this message came from a registered application for (i=0; iapp_info[i].fileobject == &file->f_owner) { + if (ft1000dev->app_info[i].fileobject == &file->f_owner) { break; } } @@ -632,7 +631,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, // Insert slow queue sequence number ppseudo_hdr->seq_num = info->squeseqnum++; - ppseudo_hdr->portsrc = info->app_info[app_index].app_id; + ppseudo_hdr->portsrc = ft1000dev->app_info[app_index].app_id; // Calculate new checksum ppseudo_hdr->checksum = *pmsg++; //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); @@ -645,7 +644,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, card_send_command(ft1000dev,(unsigned short*)dpram_data,total_len+2); - info->app_info[app_index].nTxMsg++; + ft1000dev->app_info[app_index].nTxMsg++; } else { result = -EINVAL; @@ -675,8 +674,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command, // Search for matching file object for (i=0; iapp_info[i].fileobject == &file->f_owner) { - //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id); + if (ft1000dev->app_info[i].fileobject == &file->f_owner) { + //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); break; } } @@ -690,13 +689,13 @@ static long ft1000_ioctl (struct file *file, unsigned int command, result = 0; pioctl_dpram = argp; - if (list_empty(&info->app_info[i].app_sqlist) == 0) { + if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) { //DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n"); spin_lock_irqsave(&free_buff_lock, flags); - pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); + pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list); list_del(&pdpram_blk->list); - info->app_info[i].NumOfMsg--; - //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg); + ft1000dev->app_info[i].NumOfMsg--; + //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); spin_unlock_irqrestore(&free_buff_lock, flags); msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ; result = get_user(msglen, &pioctl_dpram->total_len); @@ -723,7 +722,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, result = -ENOTTY; break; } - info->fAppMsgPend = 0; + ft1000dev->fAppMsgPend = 0; return result; } @@ -741,6 +740,7 @@ static int ft1000_release (struct inode *inode, struct file *file) { struct ft1000_info *info; struct net_device *dev; + struct ft1000_device *ft1000dev; int i; struct dpram_blk *pdpram_blk; @@ -748,16 +748,17 @@ static int ft1000_release (struct inode *inode, struct file *file) dev = file->private_data; info = netdev_priv(dev); + ft1000dev = info->priv; if (ft1000_flarion_cnt == 0) { - info->appcnt--; + ft1000dev->appcnt--; return (-EBADF); } // Search for matching file object for (i=0; iapp_info[i].fileobject == &file->f_owner) { - //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id); + if ( ft1000dev->app_info[i].fileobject == &file->f_owner) { + //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); break; } } @@ -765,17 +766,17 @@ static int ft1000_release (struct inode *inode, struct file *file) if (i==MAX_NUM_APP) return 0; - while (list_empty(&info->app_info[i].app_sqlist) == 0) { + while (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) { DEBUG("Remove and free memory queue up on slow queue\n"); - pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); + pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list); list_del(&pdpram_blk->list); ft1000_free_buffer(pdpram_blk, &freercvpool); } // initialize application information - info->appcnt--; - DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt); - info->app_info[i].fileobject = NULL; + ft1000dev->appcnt--; + DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, ft1000dev->appcnt); + ft1000dev->app_info[i].fileobject = NULL; return 0; } diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c index 1972b72..cc00e94 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c @@ -188,7 +188,6 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value) u16 handshake; int loopcnt; u32 status = 0; - struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); loopcnt = 0; @@ -196,10 +195,10 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value) /* Need to clear downloader doorbell if Hartley ASIC */ status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX, FT1000_REG_DOORBELL); - if (pft1000info->fcodeldr) { + if (ft1000dev->fcodeldr) { DEBUG(" get_handshake: fcodeldr is %d\n", - pft1000info->fcodeldr); - pft1000info->fcodeldr = 0; + ft1000dev->fcodeldr); + ft1000dev->fcodeldr = 0; status = check_usb_db(ft1000dev); if (status != STATUS_SUCCESS) { DEBUG("get_handshake: check_usb_db failed\n"); @@ -270,29 +269,28 @@ static u16 get_handshake_usb(struct ft1000_device *ft1000dev, u16 expected_value u16 temp; u32 status = 0; - struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); loopcnt = 0; handshake = 0; while (loopcnt < 100) { - if (pft1000info->usbboot == 2) { + if (ft1000dev->usbboot == 2) { status = ft1000_read_dpram32(ft1000dev, 0, - (u8 *)&(pft1000info->tempbuf[0]), 64); + (u8 *)&(ft1000dev->tempbuf[0]), 64); for (temp = 0; temp < 16; temp++) { DEBUG("tempbuf %d = 0x%x\n", temp, - pft1000info->tempbuf[temp]); + ft1000dev->tempbuf[temp]); } status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1); DEBUG("handshake from read_dpram16 = 0x%x\n", handshake); - if (pft1000info->dspalive == pft1000info->tempbuf[6]) { + if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) { handshake = 0; } else { - handshake = pft1000info->tempbuf[1]; - pft1000info->dspalive = - pft1000info->tempbuf[6]; + handshake = ft1000dev->tempbuf[1]; + ft1000dev->dspalive = + ft1000dev->tempbuf[6]; } } else { status = ft1000_read_dpram16(ft1000dev, @@ -336,9 +334,8 @@ static u16 get_request_type(struct ft1000_device *ft1000dev) u32 status; u16 tempword; u32 tempx; - struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); - if (pft1000info->bootmode == 1) { + if (ft1000dev->bootmode == 1) { status = fix_ft1000_read_dpram32(ft1000dev, DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); tempx = ntohl(tempx); @@ -360,16 +357,15 @@ static u16 get_request_type_usb(struct ft1000_device *ft1000dev) u32 status; u16 tempword; u32 tempx; - struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); - if (pft1000info->bootmode == 1) { + if (ft1000dev->bootmode == 1) { status = fix_ft1000_read_dpram32(ft1000dev, DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); tempx = ntohl(tempx); } else { - if (pft1000info->usbboot == 2) { - tempx = pft1000info->tempbuf[2]; - tempword = pft1000info->tempbuf[3]; + if (ft1000dev->usbboot == 2) { + tempx = ft1000dev->tempbuf[2]; + tempword = ft1000dev->tempbuf[3]; } else { tempx = 0; status = ft1000_read_dpram16(ft1000dev, @@ -401,9 +397,8 @@ static long get_request_value(struct ft1000_device *ft1000dev) u32 value; u16 tempword; u32 status; - struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); - if (pft1000info->bootmode == 1) { + if (ft1000dev->bootmode == 1) { status = fix_ft1000_read_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC, (u8 *)&value); value = ntohl(value); @@ -507,7 +502,6 @@ static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFi u16 tempword; u16 tempbuffer[64]; u16 resultbuffer[64]; - struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); dpram = (u16)DWNLD_MAG1_PS_HDR_LOC; @@ -548,7 +542,7 @@ static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFi //DEBUG("write_blk: loopcnt is %d\n", loopcnt); //DEBUG("write_blk: bootmode = %d\n", bootmode); //DEBUG("write_blk: dpram = %x\n", dpram); - if (pft1000info->bootmode == 0) + if (ft1000dev->bootmode == 0) { if (dpram >= 0x3F4) Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 8); @@ -718,9 +712,9 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, DEBUG("Entered scram_dnldr...\n"); - pft1000info->fcodeldr = 0; - pft1000info->usbboot = 0; - pft1000info->dspalive = 0xffff; + ft1000dev->fcodeldr = 0; + ft1000dev->usbboot = 0; + ft1000dev->dspalive = 0xffff; // // Get version id of file, at first 4 bytes of file, for newer files. @@ -745,7 +739,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, switch (state) { case STATE_START_DWNLD: DEBUG("FT1000:STATE_START_DWNLD\n"); - if (pft1000info->usbboot) + if (ft1000dev->usbboot) handshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY); @@ -771,7 +765,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, case STATE_BOOT_DWNLD: DEBUG("FT1000:STATE_BOOT_DWNLD\n"); - pft1000info->bootmode = 1; + ft1000dev->bootmode = 1; handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST); if (handshake == HANDSHAKE_REQUEST) { /* @@ -797,7 +791,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, //DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file); //DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file); state = STATE_CODE_DWNLD; - pft1000info->fcodeldr = 1; + ft1000dev->fcodeldr = 1; break; case REQUEST_CODE_SEGMENT: //DEBUG("FT1000:REQUEST_CODE_SEGMENT\n"); @@ -842,7 +836,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, status = STATUS_FAILURE; break; } - if (pft1000info->usbboot) + if (ft1000dev->usbboot) put_handshake_usb(ft1000dev, HANDSHAKE_RESPONSE); else @@ -858,8 +852,8 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, case STATE_CODE_DWNLD: //DEBUG("FT1000:STATE_CODE_DWNLD\n"); - pft1000info->bootmode = 0; - if (pft1000info->usbboot) + ft1000dev->bootmode = 0; + if (ft1000dev->usbboot) handshake = get_handshake_usb(ft1000dev, HANDSHAKE_REQUEST); @@ -870,7 +864,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, /* * Get type associated with the request. */ - if (pft1000info->usbboot) + if (ft1000dev->usbboot) request = get_request_type_usb(ft1000dev); else @@ -916,7 +910,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, } break; case REQUEST_DONE_CL: - pft1000info->usbboot = 3; + ft1000dev->usbboot = 3; /* Reposition ptrs to beginning of provisioning section */ s_file = (u16 *) (pFileStart + @@ -965,9 +959,9 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, write_blk_fifo(ft1000dev, &s_file, &c_file, word_length); - if (pft1000info->usbboot == 0) - pft1000info->usbboot++; - if (pft1000info->usbboot == 1) { + if (ft1000dev->usbboot == 0) + ft1000dev->usbboot++; + if (ft1000dev->usbboot == 1) { tempword = 0; ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_PS_HDR_LOC, @@ -1117,7 +1111,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, status = STATUS_FAILURE; break; } - if (pft1000info->usbboot) + if (ft1000dev->usbboot) put_handshake_usb(ft1000dev, HANDSHAKE_RESPONSE); else diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 809fa48..6e2bbed 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -29,7 +29,7 @@ //#define JDEBUG -static int ft1000_reset(struct net_device *ft1000dev); +static int ft1000_reset(void *ft1000dev); static int ft1000_submit_rx_urb(struct ft1000_info *info); static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev); static int ft1000_open (struct net_device *dev); @@ -588,7 +588,7 @@ int dsp_reload(struct ft1000_device *ft1000dev) static void ft1000_reset_asic(struct net_device *dev) { struct ft1000_info *info = netdev_priv(dev); - struct ft1000_device *ft1000dev = info->pFt1000Dev; + struct ft1000_device *ft1000dev = info->priv; u16 tempword; DEBUG("ft1000_hw:ft1000_reset_asic called\n"); @@ -627,15 +627,15 @@ static void ft1000_reset_asic(struct net_device *dev) static int ft1000_reset_card(struct net_device *dev) { struct ft1000_info *info = netdev_priv(dev); - struct ft1000_device *ft1000dev = info->pFt1000Dev; + struct ft1000_device *ft1000dev = info->priv; u16 tempword; struct prov_record *ptr; DEBUG("ft1000_hw:ft1000_reset_card called.....\n"); - info->fCondResetPend = 1; + ft1000dev->fCondResetPend = 1; info->CardReady = 0; - info->fProvComplete = 0; + ft1000dev->fProvComplete = 0; /* Make sure we free any memory reserve for provisioning */ while (list_empty(&info->prov_list) == 0) { @@ -666,7 +666,7 @@ static int ft1000_reset_card(struct net_device *dev) info->CardReady = 1; - info->fCondResetPend = 0; + ft1000dev->fCondResetPend = 0; return TRUE; } @@ -729,8 +729,8 @@ int init_ft1000_netdev(struct ft1000_device *ft1000dev) goto err_net; } - pInfo->CardNumber = gCardIndex; - DEBUG("card number = %d\n", pInfo->CardNumber); + ft1000dev->CardNumber = gCardIndex; + DEBUG("card number = %d\n", ft1000dev->CardNumber); } else { printk(KERN_ERR "ft1000: Invalid device name\n"); ret_val = -ENXIO; @@ -740,27 +740,27 @@ int init_ft1000_netdev(struct ft1000_device *ft1000dev) memset(&pInfo->stats, 0, sizeof(struct net_device_stats)); spin_lock_init(&pInfo->dpram_lock); - pInfo->pFt1000Dev = ft1000dev; + pInfo->priv = ft1000dev; pInfo->DrvErrNum = 0; pInfo->registered = 1; pInfo->ft1000_reset = ft1000_reset; pInfo->mediastate = 0; pInfo->fifo_cnt = 0; - pInfo->DeviceCreated = FALSE; + ft1000dev->DeviceCreated = FALSE; pInfo->CardReady = 0; pInfo->DSP_TIME[0] = 0; pInfo->DSP_TIME[1] = 0; pInfo->DSP_TIME[2] = 0; pInfo->DSP_TIME[3] = 0; - pInfo->fAppMsgPend = 0; - pInfo->fCondResetPend = 0; - pInfo->usbboot = 0; - pInfo->dspalive = 0; - memset(&pInfo->tempbuf[0], 0, sizeof(pInfo->tempbuf)); + ft1000dev->fAppMsgPend = 0; + ft1000dev->fCondResetPend = 0; + ft1000dev->usbboot = 0; + ft1000dev->dspalive = 0; + memset(&ft1000dev->tempbuf[0], 0, sizeof(ft1000dev->tempbuf)); INIT_LIST_HEAD(&pInfo->prov_list); - INIT_LIST_HEAD(&pInfo->nodes.list); + INIT_LIST_HEAD(&ft1000dev->nodes.list); netdev->netdev_ops = &ftnet_ops; @@ -854,7 +854,7 @@ int reg_ft1000_netdev(struct ft1000_device *ft1000dev, return 0; } -static int ft1000_reset(struct net_device *dev) +int ft1000_reset(void *dev) { ft1000_reset_card(dev); return 0; @@ -902,7 +902,7 @@ static void ft1000_usb_transmit_complete(struct urb *urb) static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) { struct ft1000_info *pInfo = netdev_priv(netdev); - struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev; + struct ft1000_device *pFt1000Dev = pInfo->priv; int count, ret; u8 *t; @@ -981,7 +981,7 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct ft1000_info *pInfo = netdev_priv(dev); - struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev; + struct ft1000_device *pFt1000Dev = pInfo->priv; u8 *pdata; int maxlen, pipe; @@ -1039,7 +1039,7 @@ err: static int ft1000_copy_up_pkt(struct urb *urb) { struct ft1000_info *info = urb->context; - struct ft1000_device *ft1000dev = info->pFt1000Dev; + struct ft1000_device *ft1000dev = info->priv; struct net_device *net = ft1000dev->net; u16 tempword; @@ -1134,7 +1134,7 @@ static int ft1000_copy_up_pkt(struct urb *urb) static int ft1000_submit_rx_urb(struct ft1000_info *info) { int result; - struct ft1000_device *pFt1000Dev = info->pFt1000Dev; + struct ft1000_device *pFt1000Dev = info->priv; if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { DEBUG("network driver is closed, return\n"); @@ -1177,9 +1177,10 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info) static int ft1000_open(struct net_device *dev) { struct ft1000_info *pInfo = netdev_priv(dev); + struct ft1000_device *pFt1000Dev = pInfo->priv; struct timeval tv; - DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber); + DEBUG("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber); pInfo->stats.rx_bytes = 0; pInfo->stats.tx_bytes = 0; @@ -1213,7 +1214,7 @@ static int ft1000_open(struct net_device *dev) int ft1000_close(struct net_device *net) { struct ft1000_info *pInfo = netdev_priv(net); - struct ft1000_device *ft1000dev = pInfo->pFt1000Dev; + struct ft1000_device *ft1000dev = pInfo->priv; ft1000dev->status |= FT1000_STATUS_CLOSING; @@ -1251,9 +1252,8 @@ static int ft1000_chkcard(struct ft1000_device *dev) { u16 tempword; u16 status; - struct ft1000_info *info = netdev_priv(dev->net); - if (info->fCondResetPend) { + if (dev->fCondResetPend) { DEBUG ("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n"); return TRUE; @@ -1441,7 +1441,7 @@ static int ft1000_dsp_prov(void *arg) msleep(100); - info->fProvComplete = 1; + dev->fProvComplete = 1; info->CardReady = 1; return STATUS_SUCCESS; @@ -1498,7 +1498,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) if (pmediamsg->state) { DEBUG("Media is up\n"); if (info->mediastate == 0) { - if (info->NetDevRegDone) { + if (dev->NetDevRegDone) { netif_wake_queue(dev-> net); } @@ -1508,7 +1508,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) DEBUG("Media is down\n"); if (info->mediastate == 1) { info->mediastate = 0; - if (info->NetDevRegDone) { + if (dev->NetDevRegDone) { } info->ConTm = 0; } @@ -1567,12 +1567,12 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) * Send provisioning data to DSP */ if (list_empty(&info->prov_list) == 0) { - info->fProvComplete = 0; + dev->fProvComplete = 0; status = ft1000_dsp_prov(dev); if (status != STATUS_SUCCESS) goto out; } else { - info->fProvComplete = 1; + dev->fProvComplete = 1; status = ft1000_write_register(dev, FT1000_DB_HB, FT1000_REG_DOORBELL); @@ -1605,7 +1605,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) case DSP_GET_INFO:{ DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n"); /* copy dsp info block to dsp */ - info->DrvMsgPend = 1; + dev->DrvMsgPend = 1; /* allow any outstanding ioctl to finish */ mdelay(10); status = @@ -1667,7 +1667,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) status = ft1000_write_register(dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL); - info->DrvMsgPend = 0; + dev->DrvMsgPend = 0; break; } @@ -1675,7 +1675,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) case GET_DRV_ERR_RPT_MSG:{ DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n"); /* copy driver error message to dsp */ - info->DrvMsgPend = 1; + dev->DrvMsgPend = 1; /* allow any outstanding ioctl to finish */ mdelay(10); status = @@ -1735,7 +1735,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) (u16) (0x0012 + PSEUDOSZ)); info->DrvErrNum = 0; } - info->DrvMsgPend = 0; + dev->DrvMsgPend = 0; break; } @@ -1804,8 +1804,8 @@ int ft1000_poll(void* dev_id) // Check which application has registered for dsp broadcast messages for (i=0; iapp_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) && - (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) ) + if ( (dev->app_info[i].DspBCMsgFlag) && (dev->app_info[i].fileobject) && + (dev->app_info[i].NumOfMsg < MAX_MSG_LIMIT) ) { nxtph = FT1000_DPRAM_RX_BASE + 2; pdpram_blk = ft1000_get_buffer (&freercvpool); @@ -1813,15 +1813,15 @@ int ft1000_poll(void* dev_id) if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) { ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer; // Put message into the appropriate application block - info->app_info[i].nRxMsg++; + dev->app_info[i].nRxMsg++; spin_lock_irqsave(&free_buff_lock, flags); - list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); - info->app_info[i].NumOfMsg++; + list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist); + dev->app_info[i].NumOfMsg++; spin_unlock_irqrestore(&free_buff_lock, flags); - wake_up_interruptible(&info->app_info[i].wait_dpram_msg); + wake_up_interruptible(&dev->app_info[i].wait_dpram_msg); } else { - info->app_info[i].nRxMsgMiss++; + dev->app_info[i].nRxMsgMiss++; // Put memory back to free pool ft1000_free_buffer(pdpram_blk, &freercvpool); DEBUG("pdpram_blk::ft1000_get_buffer NULL\n"); @@ -1829,7 +1829,7 @@ int ft1000_poll(void* dev_id) } else { DEBUG("Out of memory in free receive command pool\n"); - info->app_info[i].nRxMsgMiss++; + dev->app_info[i].nRxMsgMiss++; } } } @@ -1842,7 +1842,7 @@ int ft1000_poll(void* dev_id) ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer; // Search for correct application block for (i=0; iapp_info[i].app_id == ppseudo_hdr->portdest) { + if (dev->app_info[i].app_id == ppseudo_hdr->portdest) { break; } } @@ -1853,15 +1853,15 @@ int ft1000_poll(void* dev_id) ft1000_free_buffer(pdpram_blk, &freercvpool); } else { - if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) { + if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) { // Put memory back to free pool ft1000_free_buffer(pdpram_blk, &freercvpool); } else { - info->app_info[i].nRxMsg++; + dev->app_info[i].nRxMsg++; // Put message into the appropriate application block - list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); - info->app_info[i].NumOfMsg++; + list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist); + dev->app_info[i].NumOfMsg++; } } } @@ -1921,7 +1921,7 @@ int ft1000_poll(void* dev_id) else if (tempword & FT1000_DB_COND_RESET) { DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n"); - if (info->fAppMsgPend == 0) { + if (dev->fAppMsgPend == 0) { // Reset ASIC and DSP status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); @@ -1934,8 +1934,8 @@ int ft1000_poll(void* dev_id) info->ft1000_reset(dev->net); } else { - info->fProvComplete = 0; - info->fCondResetPend = 1; + dev->fProvComplete = 0; + dev->fCondResetPend = 1; } ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c index 1edaddb..4fbb9e1 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c @@ -94,11 +94,11 @@ ft1000ReadProc(char *page, char **start, off_t off, int count, int *eof, if (info->ProgConStat != 0xFF) { - ft1000_read_dpram16(info->pFt1000Dev, FT1000_MAG_DSP_LED, + ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX); info->LedStat = ntohs(ledStat); - ft1000_read_dpram16(info->pFt1000Dev, FT1000_MAG_DSP_CON_STATE, + ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX); info->ConStat = ntohs(conStat); do_gettimeofday(&tv); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c index b2ecd0e..e97fbc9 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c @@ -171,11 +171,11 @@ static int ft1000_probe(struct usb_interface *interface, } gPollingfailed = FALSE; - pft1000info->pPollThread = + ft1000dev->pPollThread = kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll"); - if (IS_ERR(pft1000info->pPollThread)) { - ret = PTR_ERR(pft1000info->pPollThread); + if (IS_ERR(ft1000dev->pPollThread)) { + ret = PTR_ERR(ft1000dev->pPollThread); goto err_load; } @@ -200,7 +200,7 @@ static int ft1000_probe(struct usb_interface *interface, if (ret) goto err_proc; - pft1000info->NetDevRegDone = 1; + ft1000dev->NetDevRegDone = 1; return 0; @@ -208,7 +208,7 @@ err_proc: unregister_netdev(ft1000dev->net); free_netdev(ft1000dev->net); err_thread: - kthread_stop(pft1000info->pPollThread); + kthread_stop(ft1000dev->pPollThread); err_load: kfree(pFileStart); err_fw: @@ -219,6 +219,7 @@ err_fw: static void ft1000_disconnect(struct usb_interface *interface) { struct ft1000_info *pft1000info; + struct ft1000_device *ft1000dev; DEBUG("ft1000_disconnect is called\n"); @@ -226,28 +227,29 @@ static void ft1000_disconnect(struct usb_interface *interface) DEBUG("In disconnect pft1000info=%p\n", pft1000info); if (pft1000info) { + ft1000dev = pft1000info->priv; ft1000_cleanup_proc(pft1000info); - if (pft1000info->pPollThread) - kthread_stop(pft1000info->pPollThread); + if (ft1000dev->pPollThread) + kthread_stop(ft1000dev->pPollThread); DEBUG("ft1000_disconnect: threads are terminated\n"); - if (pft1000info->pFt1000Dev->net) { + if (ft1000dev->net) { DEBUG("ft1000_disconnect: destroy char driver\n"); - ft1000_destroy_dev(pft1000info->pFt1000Dev->net); - unregister_netdev(pft1000info->pFt1000Dev->net); + ft1000_destroy_dev(ft1000dev->net); + unregister_netdev(ft1000dev->net); DEBUG ("ft1000_disconnect: network device unregistered\n"); - free_netdev(pft1000info->pFt1000Dev->net); + free_netdev(ft1000dev->net); } - usb_free_urb(pft1000info->pFt1000Dev->rx_urb); - usb_free_urb(pft1000info->pFt1000Dev->tx_urb); + usb_free_urb(ft1000dev->rx_urb); + usb_free_urb(ft1000dev->tx_urb); DEBUG("ft1000_disconnect: urb freed\n"); - kfree(pft1000info->pFt1000Dev); + kfree(ft1000dev); } kfree(pFileStart); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h index 2aa6a1c..152fe84 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h @@ -55,6 +55,13 @@ struct app_info_block { #define MAX_BUF_SIZE 4096 +struct ft1000_debug_dirs { + struct list_head list; + struct dentry *dent; + struct dentry *file; + int int_number; +}; + struct ft1000_device { struct usb_device *dev; struct net_device *net; @@ -69,71 +76,26 @@ struct ft1000_device { u8 bulk_in_endpointAddr; u8 bulk_out_endpointAddr; -} __packed; - -struct ft1000_debug_dirs { - struct list_head list; - struct dentry *dent; - struct dentry *file; - int int_number; -}; - -struct ft1000_info { - struct ft1000_device *pFt1000Dev; - struct net_device_stats stats; struct task_struct *pPollThread; - unsigned char fcodeldr; unsigned char bootmode; unsigned char usbboot; unsigned short dspalive; - u16 ASIC_ID; bool fProvComplete; bool fCondResetPend; bool fAppMsgPend; - u16 DrvErrNum; - u16 AsicID; - int DspAsicReset; int DeviceCreated; - int CardReady; int NetDevRegDone; u8 CardNumber; u8 DeviceName[15]; struct ft1000_debug_dirs nodes; - int registered; - int mediastate; - u8 squeseqnum; /* sequence number on slow queue */ - spinlock_t dpram_lock; spinlock_t fifo_lock; - u16 fifo_cnt; - u8 DspVer[DSPVERSZ]; /* DSP version number */ - u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */ - u8 Sku[SKUSZ]; /* SKU */ - u8 eui64[EUISZ]; /* EUI64 */ - time_t ConTm; /* Connection Time */ - u8 ProductMode[MODESZ]; - u8 RfCalVer[CALVERSZ]; - u8 RfCalDate[CALDATESZ]; - u16 DSP_TIME[4]; - u16 LedStat; - u16 ConStat; - u16 ProgConStat; - struct list_head prov_list; int appcnt; struct app_info_block app_info[MAX_NUM_APP]; - u16 DSPInfoBlklen; u16 DrvMsgPend; - int (*ft1000_reset)(struct net_device *dev); - u16 DSPInfoBlk[MAX_DSP_SESS_REC]; - union { - u16 Rec[MAX_DSP_SESS_REC]; - u32 MagRec[MAX_DSP_SESS_REC/2]; - } DSPSess; unsigned short tempbuf[32]; - char netdevname[IFNAMSIZ]; - struct proc_dir_entry *ft1000_proc_dir; -}; +} __packed; struct dpram_blk { diff --git a/drivers/staging/ft1000/ft1000.h b/drivers/staging/ft1000/ft1000.h index 03baa57..175abfa 100644 --- a/drivers/staging/ft1000/ft1000.h +++ b/drivers/staging/ft1000/ft1000.h @@ -250,3 +250,38 @@ struct prov_record { struct list_head list; u8 *pprov_data; }; + +struct ft1000_info { + void *priv; + struct net_device_stats stats; + u16 DrvErrNum; + u16 AsicID; + int CardReady; + int registered; + int mediastate; + u8 squeseqnum; /* sequence number on slow queue */ + spinlock_t dpram_lock; + u16 fifo_cnt; + u8 DspVer[DSPVERSZ]; /* DSP version number */ + u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */ + u8 Sku[SKUSZ]; /* SKU */ + u8 eui64[EUISZ]; /* EUI64 */ + time_t ConTm; /* Connection Time */ + u8 ProductMode[MODESZ]; + u8 RfCalVer[CALVERSZ]; + u8 RfCalDate[CALDATESZ]; + u16 DSP_TIME[4]; + u16 LedStat; + u16 ConStat; + u16 ProgConStat; + struct list_head prov_list; + u16 DSPInfoBlklen; + int (*ft1000_reset)(void *); + u16 DSPInfoBlk[MAX_DSP_SESS_REC]; + union { + u16 Rec[MAX_DSP_SESS_REC]; + u32 MagRec[MAX_DSP_SESS_REC/2]; + } DSPSess; + struct proc_dir_entry *ft1000_proc_dir; + char netdevname[IFNAMSIZ]; +}; -- cgit v0.10.2 From dedbc93318b89c0386670a5c3e1de621311a40b0 Mon Sep 17 00:00:00 2001 From: Ondrej Zary Date: Sun, 2 Dec 2012 18:51:40 +0100 Subject: staging: ft1000: rename struct ft1000_device to ft1000_usb After unifying struct ft1000_info, struct ft1000_device is now wrong name. Rename it to ft1000_usb to match its semantics. Signed-off-by: Ondrej Zary Reviewed-by: Marek Belisko Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c index fb197ab..297389e 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c @@ -137,7 +137,7 @@ void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist) // Notes: Only called by init_module(). // //--------------------------------------------------------------------------- -int ft1000_create_dev(struct ft1000_device *dev) +int ft1000_create_dev(struct ft1000_usb *dev) { int result; int i; @@ -227,7 +227,7 @@ fail: void ft1000_destroy_dev(struct net_device *netdev) { struct ft1000_info *info = netdev_priv(netdev); - struct ft1000_device *dev = info->priv; + struct ft1000_usb *dev = info->priv; int i; struct dpram_blk *pdpram_blk; struct dpram_blk *ptr; @@ -292,7 +292,7 @@ void ft1000_destroy_dev(struct net_device *netdev) static int ft1000_open (struct inode *inode, struct file *file) { struct ft1000_info *info; - struct ft1000_device *dev = (struct ft1000_device *)inode->i_private; + struct ft1000_usb *dev = (struct ft1000_usb *)inode->i_private; int i,num; DEBUG("%s called\n", __func__); @@ -349,7 +349,7 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) { struct net_device *netdev = file->private_data; struct ft1000_info *info = netdev_priv(netdev); - struct ft1000_device *dev = info->priv; + struct ft1000_usb *dev = info->priv; int i; //DEBUG("ft1000_poll_dev called\n"); @@ -398,7 +398,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, { void __user *argp = (void __user *)argument; struct ft1000_info *info; - struct ft1000_device *ft1000dev; + struct ft1000_usb *ft1000dev; int result=0; int cmd; int i; @@ -740,7 +740,7 @@ static int ft1000_release (struct inode *inode, struct file *file) { struct ft1000_info *info; struct net_device *dev; - struct ft1000_device *ft1000dev; + struct ft1000_usb *ft1000dev; int i; struct dpram_blk *pdpram_blk; diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c index cc00e94..5190c8a 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c @@ -114,7 +114,7 @@ struct dsp_image_info { //--------------------------------------------------------------------------- // Function: check_usb_db // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // // Returns: 0 - success // @@ -123,7 +123,7 @@ struct dsp_image_info { // Notes: // //--------------------------------------------------------------------------- -static u32 check_usb_db (struct ft1000_device *ft1000dev) +static u32 check_usb_db (struct ft1000_usb *ft1000dev) { int loopcnt; u16 temp; @@ -172,7 +172,7 @@ static u32 check_usb_db (struct ft1000_device *ft1000dev) //--------------------------------------------------------------------------- // Function: get_handshake // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // u16 expected_value - the handshake value expected // // Returns: handshakevalue - success @@ -183,7 +183,7 @@ static u32 check_usb_db (struct ft1000_device *ft1000dev) // Notes: // //--------------------------------------------------------------------------- -static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value) +static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value) { u16 handshake; int loopcnt; @@ -232,7 +232,7 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value) //--------------------------------------------------------------------------- // Function: put_handshake // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // u16 handshake_value - handshake to be written // // Returns: none @@ -243,7 +243,7 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value) // Notes: // //--------------------------------------------------------------------------- -static void put_handshake(struct ft1000_device *ft1000dev,u16 handshake_value) +static void put_handshake(struct ft1000_usb *ft1000dev,u16 handshake_value) { u32 tempx; u16 tempword; @@ -262,7 +262,7 @@ static void put_handshake(struct ft1000_device *ft1000dev,u16 handshake_value) FT1000_REG_DOORBELL); } -static u16 get_handshake_usb(struct ft1000_device *ft1000dev, u16 expected_value) +static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value) { u16 handshake; int loopcnt; @@ -309,7 +309,7 @@ static u16 get_handshake_usb(struct ft1000_device *ft1000dev, u16 expected_value return HANDSHAKE_TIMEOUT_VALUE; } -static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_value) +static void put_handshake_usb(struct ft1000_usb *ft1000dev,u16 handshake_value) { int i; @@ -319,7 +319,7 @@ static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_valu //--------------------------------------------------------------------------- // Function: get_request_type // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // // Returns: request type - success // @@ -328,7 +328,7 @@ static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_valu // Notes: // //--------------------------------------------------------------------------- -static u16 get_request_type(struct ft1000_device *ft1000dev) +static u16 get_request_type(struct ft1000_usb *ft1000dev) { u16 request_type; u32 status; @@ -351,7 +351,7 @@ static u16 get_request_type(struct ft1000_device *ft1000dev) return request_type; } -static u16 get_request_type_usb(struct ft1000_device *ft1000dev) +static u16 get_request_type_usb(struct ft1000_usb *ft1000dev) { u16 request_type; u32 status; @@ -383,7 +383,7 @@ static u16 get_request_type_usb(struct ft1000_device *ft1000dev) //--------------------------------------------------------------------------- // Function: get_request_value // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // // Returns: request value - success // @@ -392,7 +392,7 @@ static u16 get_request_type_usb(struct ft1000_device *ft1000dev) // Notes: // //--------------------------------------------------------------------------- -static long get_request_value(struct ft1000_device *ft1000dev) +static long get_request_value(struct ft1000_usb *ft1000dev) { u32 value; u16 tempword; @@ -419,7 +419,7 @@ static long get_request_value(struct ft1000_device *ft1000dev) //--------------------------------------------------------------------------- // Function: put_request_value // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // long lvalue - value to be put into DPRAM location DWNLD_MAG1_SIZE_LOC // // Returns: none @@ -429,7 +429,7 @@ static long get_request_value(struct ft1000_device *ft1000dev) // Notes: // //--------------------------------------------------------------------------- -static void put_request_value(struct ft1000_device *ft1000dev, long lvalue) +static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue) { u32 tempx; u32 status; @@ -480,7 +480,7 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset) //--------------------------------------------------------------------------- // Function: write_blk // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // u16 **pUsFile - DSP image file pointer in u16 // u8 **pUcFile - DSP image file pointer in u8 // long word_length - length of the buffer to be written @@ -494,7 +494,7 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset) // Notes: // //--------------------------------------------------------------------------- -static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length) +static u32 write_blk (struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length) { u32 Status = STATUS_SUCCESS; u16 dpram; @@ -619,7 +619,7 @@ static void usb_dnld_complete (struct urb *urb) //--------------------------------------------------------------------------- // Function: write_blk_fifo // -// Parameters: struct ft1000_device - device structure +// Parameters: struct ft1000_usb - device structure // u16 **pUsFile - DSP image file pointer in u16 // u8 **pUcFile - DSP image file pointer in u8 // long word_length - length of the buffer to be written @@ -633,7 +633,7 @@ static void usb_dnld_complete (struct urb *urb) // Notes: // //--------------------------------------------------------------------------- -static u32 write_blk_fifo(struct ft1000_device *ft1000dev, u16 **pUsFile, +static u32 write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length) { u32 Status = STATUS_SUCCESS; @@ -676,7 +676,7 @@ static u32 write_blk_fifo(struct ft1000_device *ft1000dev, u16 **pUsFile, // Returns: status - return code //--------------------------------------------------------------------------- -u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, +u16 scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, u32 FileLength) { u16 status = STATUS_SUCCESS; diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 6e2bbed..fe1e530 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -34,7 +34,7 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info); static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev); static int ft1000_open (struct net_device *dev); static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev); -static int ft1000_chkcard (struct ft1000_device *dev); +static int ft1000_chkcard (struct ft1000_usb *dev); static u8 tempbuffer[1600]; @@ -43,7 +43,7 @@ static u8 tempbuffer[1600]; //--------------------------------------------------------------------------- // Function: ft1000_control // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // pipe - usb control message pipe // request - control request // requesttype - control message request type @@ -61,7 +61,7 @@ static u8 tempbuffer[1600]; // Notes: // //--------------------------------------------------------------------------- -static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe, +static int ft1000_control(struct ft1000_usb *ft1000dev, unsigned int pipe, u8 request, u8 requesttype, u16 value, u16 index, void *data, u16 size, int timeout) { @@ -84,7 +84,7 @@ static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe, //--------------------------------------------------------------------------- // Function: ft1000_read_register // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // Data - data buffer to hold the value read // nRegIndex - register index // @@ -97,7 +97,7 @@ static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe, // //--------------------------------------------------------------------------- -int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, +int ft1000_read_register(struct ft1000_usb *ft1000dev, u16* Data, u16 nRegIndx) { int ret = STATUS_SUCCESS; @@ -118,7 +118,7 @@ int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, //--------------------------------------------------------------------------- // Function: ft1000_write_register // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // value - value to write into a register // nRegIndex - register index // @@ -130,7 +130,7 @@ int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, // Notes: // //--------------------------------------------------------------------------- -int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, +int ft1000_write_register(struct ft1000_usb *ft1000dev, u16 value, u16 nRegIndx) { int ret = STATUS_SUCCESS; @@ -151,7 +151,7 @@ int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, //--------------------------------------------------------------------------- // Function: ft1000_read_dpram32 // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // indx - starting address to read // buffer - data buffer to hold the data read // cnt - number of byte read from DPRAM @@ -165,7 +165,7 @@ int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, // //--------------------------------------------------------------------------- -int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, +int ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u16 cnt) { int ret = STATUS_SUCCESS; @@ -186,7 +186,7 @@ int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, //--------------------------------------------------------------------------- // Function: ft1000_write_dpram32 // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // indx - starting address to write the data // buffer - data buffer to write into DPRAM // cnt - number of bytes to write @@ -199,7 +199,7 @@ int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, // Notes: // //--------------------------------------------------------------------------- -int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, +int ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u16 cnt) { int ret = STATUS_SUCCESS; @@ -223,7 +223,7 @@ int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, //--------------------------------------------------------------------------- // Function: ft1000_read_dpram16 // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // indx - starting address to read // buffer - data buffer to hold the data read // hightlow - high or low 16 bit word @@ -236,7 +236,7 @@ int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, // Notes: // //--------------------------------------------------------------------------- -int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, +int ft1000_read_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u8 highlow) { int ret = STATUS_SUCCESS; @@ -263,7 +263,7 @@ int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, //--------------------------------------------------------------------------- // Function: ft1000_write_dpram16 // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // indx - starting address to write the data // value - 16bits value to write // hightlow - high or low 16 bit word @@ -276,7 +276,7 @@ int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, // Notes: // //--------------------------------------------------------------------------- -int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow) +int ft1000_write_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u16 value, u8 highlow) { int ret = STATUS_SUCCESS; u8 request; @@ -302,7 +302,7 @@ int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u //--------------------------------------------------------------------------- // Function: fix_ft1000_read_dpram32 // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // indx - starting address to read // buffer - data buffer to hold the data read // @@ -315,7 +315,7 @@ int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u // Notes: // //--------------------------------------------------------------------------- -int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, +int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer) { u8 buf[16]; @@ -346,7 +346,7 @@ int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, //--------------------------------------------------------------------------- // Function: fix_ft1000_write_dpram32 // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // indx - starting address to write // buffer - data buffer to write // @@ -359,7 +359,7 @@ int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, // Notes: // //--------------------------------------------------------------------------- -int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer) +int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer) { u16 pos1; u16 pos2; @@ -426,7 +426,7 @@ int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buff // // Returns: None //----------------------------------------------------------------------- -static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value) +static void card_reset_dsp(struct ft1000_usb *ft1000dev, bool value) { u16 status = STATUS_SUCCESS; u16 tempword; @@ -465,7 +465,7 @@ static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value) //--------------------------------------------------------------------------- // Function: card_send_command // -// Parameters: ft1000_device - device structure +// Parameters: ft1000_usb - device structure // ptempbuffer - command buffer // size - command buffer size // @@ -477,7 +477,7 @@ static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value) // Notes: // //--------------------------------------------------------------------------- -void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer, +void card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer, int size) { unsigned short temp; @@ -524,7 +524,7 @@ void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer, // // Returns: None //----------------------------------------------------------------------- -int dsp_reload(struct ft1000_device *ft1000dev) +int dsp_reload(struct ft1000_usb *ft1000dev) { u16 status; u16 tempword; @@ -588,7 +588,7 @@ int dsp_reload(struct ft1000_device *ft1000dev) static void ft1000_reset_asic(struct net_device *dev) { struct ft1000_info *info = netdev_priv(dev); - struct ft1000_device *ft1000dev = info->priv; + struct ft1000_usb *ft1000dev = info->priv; u16 tempword; DEBUG("ft1000_hw:ft1000_reset_asic called\n"); @@ -627,7 +627,7 @@ static void ft1000_reset_asic(struct net_device *dev) static int ft1000_reset_card(struct net_device *dev) { struct ft1000_info *info = netdev_priv(dev); - struct ft1000_device *ft1000dev = info->priv; + struct ft1000_usb *ft1000dev = info->priv; u16 tempword; struct prov_record *ptr; @@ -694,7 +694,7 @@ static const struct net_device_ops ftnet_ops = // Notes: // //--------------------------------------------------------------------------- -int init_ft1000_netdev(struct ft1000_device *ft1000dev) +int init_ft1000_netdev(struct ft1000_usb *ft1000dev) { struct net_device *netdev; struct ft1000_info *pInfo = NULL; @@ -822,7 +822,7 @@ err_net: // Notes: // //--------------------------------------------------------------------------- -int reg_ft1000_netdev(struct ft1000_device *ft1000dev, +int reg_ft1000_netdev(struct ft1000_usb *ft1000dev, struct usb_interface *intf) { struct net_device *netdev; @@ -876,7 +876,7 @@ int ft1000_reset(void *dev) static void ft1000_usb_transmit_complete(struct urb *urb) { - struct ft1000_device *ft1000dev = urb->context; + struct ft1000_usb *ft1000dev = urb->context; if (urb->status) pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status); @@ -902,7 +902,7 @@ static void ft1000_usb_transmit_complete(struct urb *urb) static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) { struct ft1000_info *pInfo = netdev_priv(netdev); - struct ft1000_device *pFt1000Dev = pInfo->priv; + struct ft1000_usb *pFt1000Dev = pInfo->priv; int count, ret; u8 *t; @@ -981,7 +981,7 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct ft1000_info *pInfo = netdev_priv(dev); - struct ft1000_device *pFt1000Dev = pInfo->priv; + struct ft1000_usb *pFt1000Dev = pInfo->priv; u8 *pdata; int maxlen, pipe; @@ -1039,7 +1039,7 @@ err: static int ft1000_copy_up_pkt(struct urb *urb) { struct ft1000_info *info = urb->context; - struct ft1000_device *ft1000dev = info->priv; + struct ft1000_usb *ft1000dev = info->priv; struct net_device *net = ft1000dev->net; u16 tempword; @@ -1134,7 +1134,7 @@ static int ft1000_copy_up_pkt(struct urb *urb) static int ft1000_submit_rx_urb(struct ft1000_info *info) { int result; - struct ft1000_device *pFt1000Dev = info->priv; + struct ft1000_usb *pFt1000Dev = info->priv; if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { DEBUG("network driver is closed, return\n"); @@ -1177,7 +1177,7 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info) static int ft1000_open(struct net_device *dev) { struct ft1000_info *pInfo = netdev_priv(dev); - struct ft1000_device *pFt1000Dev = pInfo->priv; + struct ft1000_usb *pFt1000Dev = pInfo->priv; struct timeval tv; DEBUG("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber); @@ -1214,7 +1214,7 @@ static int ft1000_open(struct net_device *dev) int ft1000_close(struct net_device *net) { struct ft1000_info *pInfo = netdev_priv(net); - struct ft1000_device *ft1000dev = pInfo->priv; + struct ft1000_usb *ft1000dev = pInfo->priv; ft1000dev->status |= FT1000_STATUS_CLOSING; @@ -1248,7 +1248,7 @@ static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev) // TRUE (device is present) // //--------------------------------------------------------------------------- -static int ft1000_chkcard(struct ft1000_device *dev) +static int ft1000_chkcard(struct ft1000_usb *dev) { u16 tempword; u16 status; @@ -1293,7 +1293,7 @@ static int ft1000_chkcard(struct ft1000_device *dev) // = 1 (successful) // //--------------------------------------------------------------------------- -static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer, +static bool ft1000_receive_cmd(struct ft1000_usb *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) { u16 size, ret; @@ -1360,7 +1360,7 @@ static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer, static int ft1000_dsp_prov(void *arg) { - struct ft1000_device *dev = (struct ft1000_device *)arg; + struct ft1000_usb *dev = (struct ft1000_usb *)arg; struct ft1000_info *info = netdev_priv(dev->net); u16 tempword; u16 len; @@ -1447,7 +1447,7 @@ static int ft1000_dsp_prov(void *arg) return STATUS_SUCCESS; } -static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) +static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size) { struct ft1000_info *info = netdev_priv(dev->net); u16 msgtype; @@ -1753,7 +1753,7 @@ out: int ft1000_poll(void* dev_id) { - struct ft1000_device *dev = (struct ft1000_device *)dev_id; + struct ft1000_usb *dev = (struct ft1000_usb *)dev_id; struct ft1000_info *info = netdev_priv(dev->net); u16 tempword; diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c index 4fbb9e1..b996406 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c @@ -51,7 +51,7 @@ #define FTNET_PROC init_net.proc_net -int ft1000_read_dpram16 (struct ft1000_device *ft1000dev, u16 indx, +int ft1000_read_dpram16 (struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u8 highlow); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c index e97fbc9..1bf3792 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c @@ -63,11 +63,11 @@ static int ft1000_probe(struct usb_interface *interface, unsigned numaltsetting; int i, ret = 0, size; - struct ft1000_device *ft1000dev; + struct ft1000_usb *ft1000dev; struct ft1000_info *pft1000info = NULL; const struct firmware *dsp_fw; - ft1000dev = kzalloc(sizeof(struct ft1000_device), GFP_KERNEL); + ft1000dev = kzalloc(sizeof(struct ft1000_usb), GFP_KERNEL); if (!ft1000dev) { pr_err("out of memory allocating device structure\n"); @@ -219,7 +219,7 @@ err_fw: static void ft1000_disconnect(struct usb_interface *interface) { struct ft1000_info *pft1000info; - struct ft1000_device *ft1000dev; + struct ft1000_usb *ft1000dev; DEBUG("ft1000_disconnect is called\n"); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h index 152fe84..bd1da1f 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h @@ -62,7 +62,7 @@ struct ft1000_debug_dirs { int int_number; }; -struct ft1000_device { +struct ft1000_usb { struct usb_device *dev; struct net_device *net; @@ -103,21 +103,21 @@ struct dpram_blk { u16 *pbuffer; } __packed; -int ft1000_read_register(struct ft1000_device *ft1000dev, +int ft1000_read_register(struct ft1000_usb *ft1000dev, u16 *Data, u16 nRegIndx); -int ft1000_write_register(struct ft1000_device *ft1000dev, +int ft1000_write_register(struct ft1000_usb *ft1000dev, u16 value, u16 nRegIndx); -int ft1000_read_dpram32(struct ft1000_device *ft1000dev, +int ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u16 cnt); -int ft1000_write_dpram32(struct ft1000_device *ft1000dev, +int ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u16 cnt); -int ft1000_read_dpram16(struct ft1000_device *ft1000dev, +int ft1000_read_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer, u8 highlow); -int ft1000_write_dpram16(struct ft1000_device *ft1000dev, +int ft1000_write_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u16 value, u8 highlow); -int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, +int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer); -int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, +int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer); extern void *pFileStart; @@ -125,25 +125,25 @@ extern size_t FileLength; extern int numofmsgbuf; int ft1000_close(struct net_device *dev); -u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, +u16 scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, u32 FileLength); extern struct list_head freercvpool; extern spinlock_t free_buff_lock; /* lock to arbitrate free buffer list for receive command data */ -int ft1000_create_dev(struct ft1000_device *dev); +int ft1000_create_dev(struct ft1000_usb *dev); void ft1000_destroy_dev(struct net_device *dev); -extern void card_send_command(struct ft1000_device *ft1000dev, +extern void card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer, int size); struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist); void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist); -int dsp_reload(struct ft1000_device *ft1000dev); -int init_ft1000_netdev(struct ft1000_device *ft1000dev); +int dsp_reload(struct ft1000_usb *ft1000dev); +int init_ft1000_netdev(struct ft1000_usb *ft1000dev); struct usb_interface; -int reg_ft1000_netdev(struct ft1000_device *ft1000dev, +int reg_ft1000_netdev(struct ft1000_usb *ft1000dev, struct usb_interface *intf); int ft1000_poll(void *dev_id); -- cgit v0.10.2 From a11b0e860bff66d20d7d88211df58620619a0fcd Mon Sep 17 00:00:00 2001 From: Kurt Kanzenbach Date: Wed, 5 Dec 2012 20:03:35 +0100 Subject: Staging: ft1000-usb: Fix call to obsolete function strict_strtoul is obsolete and should be replaced with kstrto* function as reported by checkpatch.pl. pInfo->CardNumber is a u8. This is why kstrtou8 should be used here. Signed-off-by: Kurt Kanzenbach Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index fe1e530..9b8fed7 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -702,7 +702,7 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev) int i, ret_val; struct list_head *cur, *tmp; char card_nr[2]; - unsigned long gCardIndex = 0; + u8 gCardIndex = 0; DEBUG("Enter init_ft1000_netdev...\n"); @@ -723,7 +723,7 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev) if (strncmp(netdev->name, "eth", 3) == 0) { card_nr[0] = netdev->name[3]; card_nr[1] = '\0'; - ret_val = strict_strtoul(card_nr, 10, &gCardIndex); + ret_val = kstrtou8(card_nr, 10, &gCardIndex); if (ret_val) { printk(KERN_ERR "Can't parse netdev\n"); goto err_net; -- cgit v0.10.2 From 8a1430a787360e2917f410608a140fc869d10b7a Mon Sep 17 00:00:00 2001 From: Ilija Hadzic Date: Fri, 7 Dec 2012 16:49:40 -0500 Subject: staging: usbip: userspace: fix build breakage in doc directory File doc/usbip_bind_driver.8 does not exist any more but it is listed in dist_man_MANS. This breaks the build of the userspace. Remove the file from the list. Signed-off-by: Ilija Hadzic Acked-by: David Chang Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/userspace/Makefile.am b/drivers/staging/usbip/userspace/Makefile.am index 9ab1949..66f8bf0 100644 --- a/drivers/staging/usbip/userspace/Makefile.am +++ b/drivers/staging/usbip/userspace/Makefile.am @@ -3,4 +3,4 @@ includedir = @includedir@/usbip include_HEADERS := $(addprefix libsrc/, \ usbip_common.h vhci_driver.h usbip_host_driver.h) -dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbip_bind_driver.8) +dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8) -- cgit v0.10.2 From 0d0651d492c5453f5066268fd8e37330f69e3de0 Mon Sep 17 00:00:00 2001 From: Ilija Hadzic Date: Fri, 7 Dec 2012 16:49:41 -0500 Subject: staging: usbip: userspace: add gitignore file There are a bunch of automatically generated files that git should not care about. Signed-off-by: Ilija Hadzic Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/userspace/.gitignore b/drivers/staging/usbip/userspace/.gitignore new file mode 100644 index 0000000..9aad9e3 --- /dev/null +++ b/drivers/staging/usbip/userspace/.gitignore @@ -0,0 +1,28 @@ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +install-sh +libsrc/Makefile +libsrc/Makefile.in +libtool +ltmain.sh +missing +src/Makefile +src/Makefile.in +stamp-h1 +libsrc/libusbip.la +libsrc/libusbip_la-names.lo +libsrc/libusbip_la-usbip_common.lo +libsrc/libusbip_la-usbip_host_driver.lo +libsrc/libusbip_la-vhci_driver.lo +src/usbip +src/usbipd -- cgit v0.10.2 From 328f7f8a0a1cdb25c91109dd9db32efc1c1ae74d Mon Sep 17 00:00:00 2001 From: Ilija Hadzic Date: Fri, 7 Dec 2012 16:49:42 -0500 Subject: staging: usbip: userspace: eliminate glib dependency USBIP daemon relies on functions available in glib2 library to spawn handler code for incoming connection. This makes the whole program dependent on glib2 library, which is a GNOME library that on systems that don't have GNOME results in pulling more dependency, only to be able to run a relatively trivial socket-based program. While this may not seem to be a problem on full-blown desktops that already have the necessary libraries, it is a big issue on small embedded systems (think USB hub with an Ethernet port) that only have bare essentials in their file systems. This patch eliminates glib2 dependency by reworking the code to use lower level system calls to dispatch connection handler. Instead of using glib2-style event loop and dispatching mechanism, just do a ppoll(2) system call in our own loop and call accept(2) followed by fork(2) on the socket that has incoming connection. Stevens' books taught us that more than twenty years ago. No need for anything smarter in a simple server, such as usbipd. Signed-off-by: Ilija Hadzic Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/userspace/README b/drivers/staging/usbip/userspace/README index 63cd107..233d1d7 100644 --- a/drivers/staging/usbip/userspace/README +++ b/drivers/staging/usbip/userspace/README @@ -17,8 +17,6 @@ - gcc >= 4.0 - - libglib2.0-dev >= 2.6.0 - - libtool, automake >= 1.9, autoconf >= 2.5.0, pkg-config diff --git a/drivers/staging/usbip/userspace/configure.ac b/drivers/staging/usbip/userspace/configure.ac index 43e641e..6d52841 100644 --- a/drivers/staging/usbip/userspace/configure.ac +++ b/drivers/staging/usbip/userspace/configure.ac @@ -91,10 +91,5 @@ AC_ARG_WITH([usbids-dir], [USBIDS_DIR=$withval], [USBIDS_DIR="/usr/share/hwdata/"]) AC_SUBST([USBIDS_DIR]) -GLIB2_REQUIRED=2.6.0 -PKG_CHECK_MODULES([PACKAGE], [glib-2.0 >= $GLIB2_REQUIRED]) -AC_SUBST([PACKAGE_CFLAGS]) -AC_SUBST([PACKAGE_LIBS]) - AC_CONFIG_FILES([Makefile libsrc/Makefile src/Makefile]) AC_OUTPUT diff --git a/drivers/staging/usbip/userspace/src/Makefile.am b/drivers/staging/usbip/userspace/src/Makefile.am index c365a3f..a113003 100644 --- a/drivers/staging/usbip/userspace/src/Makefile.am +++ b/drivers/staging/usbip/userspace/src/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' -AM_CFLAGS = @EXTRA_CFLAGS@ @PACKAGE_CFLAGS@ -LDADD = $(top_builddir)/libsrc/libusbip.la @PACKAGE_LIBS@ +AM_CFLAGS = @EXTRA_CFLAGS@ +LDADD = $(top_builddir)/libsrc/libusbip.la sbin_PROGRAMS := usbip usbipd diff --git a/drivers/staging/usbip/userspace/src/usbipd.c b/drivers/staging/usbip/userspace/src/usbipd.c index 8668a80..34760cc 100644 --- a/drivers/staging/usbip/userspace/src/usbipd.c +++ b/drivers/staging/usbip/userspace/src/usbipd.c @@ -20,6 +20,7 @@ #include "../config.h" #endif +#define _GNU_SOURCE #include #include #include @@ -35,10 +36,9 @@ #include #endif -#define _GNU_SOURCE #include -#include #include +#include #include "usbip_host_driver.h" #include "usbip_common.h" @@ -48,7 +48,7 @@ #define PROGNAME "usbipd" #define MAXSOCKFD 20 -GMainLoop *main_loop; +#define MAIN_LOOP_TIMEOUT 10 static const char usbip_version_string[] = PACKAGE_STRING; @@ -310,30 +310,22 @@ static int do_accept(int listenfd) return connfd; } -gboolean process_request(GIOChannel *gio, GIOCondition condition, - gpointer unused_data) +int process_request(int listenfd) { - int listenfd; + pid_t childpid; int connfd; - (void) unused_data; - - if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) { - err("unknown condition"); - BUG(); - } - - if (condition & G_IO_IN) { - listenfd = g_io_channel_unix_get_fd(gio); - connfd = do_accept(listenfd); - if (connfd < 0) - return TRUE; - + connfd = do_accept(listenfd); + if (connfd < 0) + return -1; + childpid = fork(); + if (childpid == 0) { + close(listenfd); recv_pdu(connfd); - close(connfd); + exit(0); } - - return TRUE; + close(connfd); + return 0; } static void log_addrinfo(struct addrinfo *ai) @@ -418,10 +410,7 @@ static struct addrinfo *do_getaddrinfo(char *host, int ai_family) static void signal_handler(int i) { - dbg("received signal: code %d", i); - - if (main_loop) - g_main_loop_quit(main_loop); + dbg("received '%s' signal", strsignal(i)); } static void set_signal(void) @@ -433,14 +422,19 @@ static void set_signal(void) sigemptyset(&act.sa_mask); sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); + act.sa_handler = SIG_IGN; + sigaction(SIGCLD, &act, NULL); } -static int do_standalone_mode(gboolean daemonize) +static int do_standalone_mode(int daemonize) { struct addrinfo *ai_head; int sockfdlist[MAXSOCKFD]; int nsockfd; - int i; + int i, terminate; + struct pollfd *fds; + struct timespec timeout; + sigset_t sigmask; if (usbip_names_init(USBIDS_FILE)) err("failed to open %s", USBIDS_FILE); @@ -456,7 +450,7 @@ static int do_standalone_mode(gboolean daemonize) err("daemonizing failed: %s", strerror(errno)); return -1; } - + umask(0); usbip_use_syslog = 1; } set_signal(); @@ -472,20 +466,40 @@ static int do_standalone_mode(gboolean daemonize) err("failed to open a listening socket"); return -1; } - + fds = calloc(nsockfd, sizeof(struct pollfd)); for (i = 0; i < nsockfd; i++) { - GIOChannel *gio; - - gio = g_io_channel_unix_new(sockfdlist[i]); - g_io_add_watch(gio, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), - process_request, NULL); + fds[i].fd = sockfdlist[i]; + fds[i].events = POLLIN; + } + timeout.tv_sec = MAIN_LOOP_TIMEOUT; + timeout.tv_nsec = 0; + + sigfillset(&sigmask); + sigdelset(&sigmask, SIGTERM); + sigdelset(&sigmask, SIGINT); + + terminate = 0; + while (!terminate) { + int r; + + r = ppoll(fds, nsockfd, &timeout, &sigmask); + if (r < 0) { + dbg("%s", strerror(errno)); + terminate = 1; + } else if (r) { + for (i = 0; i < nsockfd; i++) { + if (fds[i].revents & POLLIN) { + dbg("read event on fd[%d]=%d", + i, sockfdlist[i]); + process_request(sockfdlist[i]); + } + } + } else + dbg("heartbeat timeout on ppoll()"); } - - main_loop = g_main_loop_new(FALSE, FALSE); - g_main_loop_run(main_loop); info("shutting down " PROGNAME); - + free(fds); freeaddrinfo(ai_head); usbip_host_driver_close(); usbip_names_free(); @@ -509,7 +523,7 @@ int main(int argc, char *argv[]) cmd_version } cmd; - gboolean daemonize = FALSE; + int daemonize = 0; int opt, rc = -1; usbip_use_stderr = 1; @@ -527,7 +541,7 @@ int main(int argc, char *argv[]) switch (opt) { case 'D': - daemonize = TRUE; + daemonize = 1; break; case 'd': usbip_use_debug = 1; -- cgit v0.10.2 From 107fefd4dd56748878f1ffc44c321c29f6180748 Mon Sep 17 00:00:00 2001 From: Ilija Hadzic Date: Fri, 7 Dec 2012 16:49:43 -0500 Subject: staging: usbip: userspace: add option to turn fortify on or off This comes handy when hacking with different cross compilers, some of which may or may not have _FORTIFY_SOURCE turned on by default. This patch allows us to turn _FORTIFY_SOURCE on by specifying --with-fortify option at configuration time (or to turn it off by specifying --without-fortify). If nothing is specified, default compiler behavior is assumed. Signed-off-by: Ilija Hadzic Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/userspace/configure.ac b/drivers/staging/usbip/userspace/configure.ac index 6d52841..2be4060 100644 --- a/drivers/staging/usbip/userspace/configure.ac +++ b/drivers/staging/usbip/userspace/configure.ac @@ -91,5 +91,22 @@ AC_ARG_WITH([usbids-dir], [USBIDS_DIR=$withval], [USBIDS_DIR="/usr/share/hwdata/"]) AC_SUBST([USBIDS_DIR]) +# use _FORTIFY_SOURCE +AC_MSG_CHECKING([whether to use fortify]) +AC_ARG_WITH([fortify], + [AS_HELP_STRING([--with-fortify], + [use _FORTIFY_SROUCE option when compiling)])], + dnl [ACTION-IF-GIVEN] + [if test "$withval" = "yes"; then + AC_MSG_RESULT([yes]) + CFLAGS="$CFLAGS -D_FORTIFY_SOURCE -O" + else + AC_MSG_RESULT([no]) + CFLAGS="$CFLAGS -U_FORTIFY_SOURCE" + fi + ], + dnl [ACTION-IF-NOT-GIVEN] + [AC_MSG_RESULT([default])]) + AC_CONFIG_FILES([Makefile libsrc/Makefile src/Makefile]) AC_OUTPUT -- cgit v0.10.2 From 82692d202a199553a92d3c72cdd8959b497b9b62 Mon Sep 17 00:00:00 2001 From: Ilija Hadzic Date: Fri, 7 Dec 2012 16:49:44 -0500 Subject: staging: usbip: userspace: suppress a bogus error If mkdir() of VHCI_STATE_PATH fails because the directory already exists, that's not an error. This patch fixes annoying "record connection" errors that would typically come up on attach. Signed-off-by: Ilija Hadzic Acked-by: David Chang Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c b/drivers/staging/usbip/userspace/src/usbip_attach.c index bdf61c0..2da4e44 100644 --- a/drivers/staging/usbip/userspace/src/usbip_attach.c +++ b/drivers/staging/usbip/userspace/src/usbip_attach.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "vhci_driver.h" #include "usbip_common.h" @@ -52,8 +53,18 @@ static int record_connection(char *host, char *port, char *busid, int rhport) int ret; ret = mkdir(VHCI_STATE_PATH, 0700); - if (ret < 0) - return -1; + if (ret < 0) { + /* if VHCI_STATE_PATH exists, then it better be a directory */ + if (errno == EEXIST) { + struct stat s; + ret = stat(VHCI_STATE_PATH, &s); + if (ret < 0) + return -1; + if (!(s.st_mode & S_IFDIR)) + return -1; + } else + return -1; + } snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport); -- cgit v0.10.2 From 0a6d61ec7180094a0cd6ead156a05fafa1805104 Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Thu, 29 Nov 2012 22:34:39 +0900 Subject: staging/rtl8187se: Fix spacing coding style in ieee80211/ieee80211_wx.c The following errors and warnings fixed. - ERROR: code indent should use tabs where possible - WARNING: please, no spaces at the start of a line - WARNING: please, no space before tabs Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c index c7917b2..9185a21 100644 --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c @@ -41,9 +41,9 @@ static const char *ieee80211_modes[] = { #define MAX_CUSTOM_LEN 64 static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee, - char *start, char *stop, - struct ieee80211_network *network, - struct iw_request_info *info) + char *start, char *stop, + struct ieee80211_network *network, + struct iw_request_info *info) { char custom[MAX_CUSTOM_LEN]; char *p; @@ -78,9 +78,9 @@ static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee, snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s", ieee80211_modes[network->mode]); start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN); - /* Add mode */ - iwe.cmd = SIOCGIWMODE; - if (network->capability & + /* Add mode */ + iwe.cmd = SIOCGIWMODE; + if (network->capability & (WLAN_CAPABILITY_BSS | WLAN_CAPABILITY_IBSS)) { if (network->capability & WLAN_CAPABILITY_BSS) iwe.u.mode = IW_MODE_MASTER; @@ -90,7 +90,7 @@ static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee, start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN); } - /* Add frequency/channel */ + /* Add frequency/channel */ iwe.cmd = SIOCGIWFREQ; /* iwe.u.freq.m = ieee80211_frequency(network->channel, network->mode); iwe.u.freq.e = 3; */ @@ -168,23 +168,23 @@ static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee, if (iwe.u.data.length) start = iwe_stream_add_point(info, start, stop, &iwe, custom); - memset(&iwe, 0, sizeof(iwe)); - if (network->wpa_ie_len) { + memset(&iwe, 0, sizeof(iwe)); + if (network->wpa_ie_len) { // printk("wpa_ie_len:%d\n", network->wpa_ie_len); - char buf[MAX_WPA_IE_LEN]; - memcpy(buf, network->wpa_ie, network->wpa_ie_len); - iwe.cmd = IWEVGENIE; - iwe.u.data.length = network->wpa_ie_len; - start = iwe_stream_add_point(info, start, stop, &iwe, buf); - } - - memset(&iwe, 0, sizeof(iwe)); - if (network->rsn_ie_len) { + char buf[MAX_WPA_IE_LEN]; + memcpy(buf, network->wpa_ie, network->wpa_ie_len); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = network->wpa_ie_len; + start = iwe_stream_add_point(info, start, stop, &iwe, buf); + } + + memset(&iwe, 0, sizeof(iwe)); + if (network->rsn_ie_len) { // printk("=====>rsn_ie_len:\n", network->rsn_ie_len); - char buf[MAX_WPA_IE_LEN]; - memcpy(buf, network->rsn_ie, network->rsn_ie_len); - iwe.cmd = IWEVGENIE; - iwe.u.data.length = network->rsn_ie_len; + char buf[MAX_WPA_IE_LEN]; + memcpy(buf, network->rsn_ie, network->rsn_ie_len); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = network->rsn_ie_len; start = iwe_stream_add_point(info, start, stop, &iwe, buf); } @@ -359,7 +359,7 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee, key, escape_essid(sec.keys[key], len), erq->length, len); sec.key_sizes[key] = len; - (*crypt)->ops->set_key(sec.keys[key], len, NULL, + (*crypt)->ops->set_key(sec.keys[key], len, NULL, (*crypt)->priv); sec.flags |= (1 << key); /* This ensures a key will be activated if no key is @@ -472,218 +472,218 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee, } int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) + struct iw_request_info *info, + union iwreq_data *wrqu, char *extra) { struct net_device *dev = ieee->dev; - struct iw_point *encoding = &wrqu->encoding; - struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; - int i, idx, ret = 0; - int group_key = 0; - const char *alg; - struct ieee80211_crypto_ops *ops; - struct ieee80211_crypt_data **crypt; - - struct ieee80211_security sec = { - .flags = 0, - }; + struct iw_point *encoding = &wrqu->encoding; + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; + int i, idx, ret = 0; + int group_key = 0; + const char *alg; + struct ieee80211_crypto_ops *ops; + struct ieee80211_crypt_data **crypt; + + struct ieee80211_security sec = { + .flags = 0, + }; //printk("======>encoding flag:%x,ext flag:%x, ext alg:%d\n", encoding->flags,ext->ext_flags, ext->alg); - idx = encoding->flags & IW_ENCODE_INDEX; - if (idx) { - if (idx < 1 || idx > WEP_KEYS) - return -EINVAL; - idx--; - } else - idx = ieee->tx_keyidx; - - if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { - crypt = &ieee->crypt[idx]; - group_key = 1; - } else { - /* some Cisco APs use idx>0 for unicast in dynamic WEP */ + idx = encoding->flags & IW_ENCODE_INDEX; + if (idx) { + if (idx < 1 || idx > WEP_KEYS) + return -EINVAL; + idx--; + } else + idx = ieee->tx_keyidx; + + if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { + crypt = &ieee->crypt[idx]; + group_key = 1; + } else { + /* some Cisco APs use idx>0 for unicast in dynamic WEP */ //printk("not group key, flags:%x, ext->alg:%d\n", ext->ext_flags, ext->alg); - if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP) - return -EINVAL; - if (ieee->iw_mode == IW_MODE_INFRA) - crypt = &ieee->crypt[idx]; - else - return -EINVAL; - } - - sec.flags |= SEC_ENABLED;// | SEC_ENCRYPT; - if ((encoding->flags & IW_ENCODE_DISABLED) || - ext->alg == IW_ENCODE_ALG_NONE) { - if (*crypt) - ieee80211_crypt_delayed_deinit(ieee, crypt); - - for (i = 0; i < WEP_KEYS; i++) - if (ieee->crypt[i] != NULL) - break; - - if (i == WEP_KEYS) { - sec.enabled = 0; - // sec.encrypt = 0; - sec.level = SEC_LEVEL_0; - sec.flags |= SEC_LEVEL; - } + if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP) + return -EINVAL; + if (ieee->iw_mode == IW_MODE_INFRA) + crypt = &ieee->crypt[idx]; + else + return -EINVAL; + } + + sec.flags |= SEC_ENABLED;// | SEC_ENCRYPT; + if ((encoding->flags & IW_ENCODE_DISABLED) || + ext->alg == IW_ENCODE_ALG_NONE) { + if (*crypt) + ieee80211_crypt_delayed_deinit(ieee, crypt); + + for (i = 0; i < WEP_KEYS; i++) + if (ieee->crypt[i] != NULL) + break; + + if (i == WEP_KEYS) { + sec.enabled = 0; + // sec.encrypt = 0; + sec.level = SEC_LEVEL_0; + sec.flags |= SEC_LEVEL; + } //printk("disabled: flag:%x\n", encoding->flags); - goto done; - } + goto done; + } sec.enabled = 1; // sec.encrypt = 1; - switch (ext->alg) { - case IW_ENCODE_ALG_WEP: - alg = "WEP"; - break; - case IW_ENCODE_ALG_TKIP: - alg = "TKIP"; - break; - case IW_ENCODE_ALG_CCMP: - alg = "CCMP"; - break; - default: - IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", - dev->name, ext->alg); - ret = -EINVAL; - goto done; - } + switch (ext->alg) { + case IW_ENCODE_ALG_WEP: + alg = "WEP"; + break; + case IW_ENCODE_ALG_TKIP: + alg = "TKIP"; + break; + case IW_ENCODE_ALG_CCMP: + alg = "CCMP"; + break; + default: + IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", + dev->name, ext->alg); + ret = -EINVAL; + goto done; + } // printk("8-09-08-9=====>%s, alg name:%s\n",__func__, alg); - ops = ieee80211_get_crypto_ops(alg); - if (ops == NULL) - ops = ieee80211_get_crypto_ops(alg); - if (ops == NULL) { - IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", - dev->name, ext->alg); + ops = ieee80211_get_crypto_ops(alg); + if (ops == NULL) + ops = ieee80211_get_crypto_ops(alg); + if (ops == NULL) { + IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", + dev->name, ext->alg); printk("========>unknown crypto alg %d\n", ext->alg); - ret = -EINVAL; - goto done; - } - - if (*crypt == NULL || (*crypt)->ops != ops) { - struct ieee80211_crypt_data *new_crypt; - - ieee80211_crypt_delayed_deinit(ieee, crypt); - - new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); - if (new_crypt == NULL) { - ret = -ENOMEM; - goto done; - } - new_crypt->ops = ops; - if (new_crypt->ops) - new_crypt->priv = new_crypt->ops->init(idx); - if (new_crypt->priv == NULL) { - kfree(new_crypt); - ret = -EINVAL; - goto done; - } - *crypt = new_crypt; - - } - - if (ext->key_len > 0 && (*crypt)->ops->set_key && - (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq, - (*crypt)->priv) < 0) { - IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name); + ret = -EINVAL; + goto done; + } + + if (*crypt == NULL || (*crypt)->ops != ops) { + struct ieee80211_crypt_data *new_crypt; + + ieee80211_crypt_delayed_deinit(ieee, crypt); + + new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); + if (new_crypt == NULL) { + ret = -ENOMEM; + goto done; + } + new_crypt->ops = ops; + if (new_crypt->ops) + new_crypt->priv = new_crypt->ops->init(idx); + if (new_crypt->priv == NULL) { + kfree(new_crypt); + ret = -EINVAL; + goto done; + } + *crypt = new_crypt; + + } + + if (ext->key_len > 0 && (*crypt)->ops->set_key && + (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq, + (*crypt)->priv) < 0) { + IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name); printk("key setting failed\n"); - ret = -EINVAL; - goto done; - } + ret = -EINVAL; + goto done; + } #if 1 //skip_host_crypt: //printk("skip_host_crypt:ext_flags:%x\n", ext->ext_flags); - if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { - ieee->tx_keyidx = idx; - sec.active_key = idx; - sec.flags |= SEC_ACTIVE_KEY; - } - - if (ext->alg != IW_ENCODE_ALG_NONE) { - memcpy(sec.keys[idx], ext->key, ext->key_len); - sec.key_sizes[idx] = ext->key_len; - sec.flags |= (1 << idx); - if (ext->alg == IW_ENCODE_ALG_WEP) { - // sec.encode_alg[idx] = SEC_ALG_WEP; - sec.flags |= SEC_LEVEL; - sec.level = SEC_LEVEL_1; - } else if (ext->alg == IW_ENCODE_ALG_TKIP) { - // sec.encode_alg[idx] = SEC_ALG_TKIP; - sec.flags |= SEC_LEVEL; - sec.level = SEC_LEVEL_2; - } else if (ext->alg == IW_ENCODE_ALG_CCMP) { - // sec.encode_alg[idx] = SEC_ALG_CCMP; - sec.flags |= SEC_LEVEL; - sec.level = SEC_LEVEL_3; - } - /* Don't set sec level for group keys. */ - if (group_key) - sec.flags &= ~SEC_LEVEL; - } + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { + ieee->tx_keyidx = idx; + sec.active_key = idx; + sec.flags |= SEC_ACTIVE_KEY; + } + + if (ext->alg != IW_ENCODE_ALG_NONE) { + memcpy(sec.keys[idx], ext->key, ext->key_len); + sec.key_sizes[idx] = ext->key_len; + sec.flags |= (1 << idx); + if (ext->alg == IW_ENCODE_ALG_WEP) { + // sec.encode_alg[idx] = SEC_ALG_WEP; + sec.flags |= SEC_LEVEL; + sec.level = SEC_LEVEL_1; + } else if (ext->alg == IW_ENCODE_ALG_TKIP) { + // sec.encode_alg[idx] = SEC_ALG_TKIP; + sec.flags |= SEC_LEVEL; + sec.level = SEC_LEVEL_2; + } else if (ext->alg == IW_ENCODE_ALG_CCMP) { + // sec.encode_alg[idx] = SEC_ALG_CCMP; + sec.flags |= SEC_LEVEL; + sec.level = SEC_LEVEL_3; + } + /* Don't set sec level for group keys. */ + if (group_key) + sec.flags &= ~SEC_LEVEL; + } #endif done: - if (ieee->set_security) - ieee->set_security(ieee->dev, &sec); + if (ieee->set_security) + ieee->set_security(ieee->dev, &sec); if (ieee->reset_on_keychange && - ieee->iw_mode != IW_MODE_INFRA && - ieee->reset_port && ieee->reset_port(dev)) { - IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name); - return -EINVAL; - } + ieee->iw_mode != IW_MODE_INFRA && + ieee->reset_port && ieee->reset_port(dev)) { + IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name); + return -EINVAL; + } - return ret; + return ret; } int ieee80211_wx_set_mlme(struct ieee80211_device *ieee, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) + struct iw_request_info *info, + union iwreq_data *wrqu, char *extra) { struct iw_mlme *mlme = (struct iw_mlme *) extra; // printk("\ndkgadfslkdjgalskdf===============>%s(), cmd:%x\n", __func__, mlme->cmd); #if 1 switch (mlme->cmd) { - case IW_MLME_DEAUTH: + case IW_MLME_DEAUTH: case IW_MLME_DISASSOC: // printk("disassoc now\n"); ieee80211_disassociate(ieee); break; default: - return -EOPNOTSUPP; - } + return -EOPNOTSUPP; + } #endif return 0; } int ieee80211_wx_set_auth(struct ieee80211_device *ieee, - struct iw_request_info *info, - struct iw_param *data, char *extra) + struct iw_request_info *info, + struct iw_param *data, char *extra) { /* struct ieee80211_security sec = { - .flags = SEC_AUTH_MODE, + .flags = SEC_AUTH_MODE, } */ //printk("set auth:flag:%x, data value:%x\n", data->flags, data->value); switch (data->flags & IW_AUTH_INDEX) { - case IW_AUTH_WPA_VERSION: + case IW_AUTH_WPA_VERSION: /*need to support wpa2 here*/ //printk("wpa version:%x\n", data->value); break; - case IW_AUTH_CIPHER_PAIRWISE: - case IW_AUTH_CIPHER_GROUP: - case IW_AUTH_KEY_MGMT: - /* + case IW_AUTH_CIPHER_PAIRWISE: + case IW_AUTH_CIPHER_GROUP: + case IW_AUTH_KEY_MGMT: + /* * * Host AP driver does not use these parameters and allows * * wpa_supplicant to control them internally. * */ - break; - case IW_AUTH_TKIP_COUNTERMEASURES: - ieee->tkip_countermeasures = data->value; - break; - case IW_AUTH_DROP_UNENCRYPTED: - ieee->drop_unencrypted = data->value; + break; + case IW_AUTH_TKIP_COUNTERMEASURES: + ieee->tkip_countermeasures = data->value; + break; + case IW_AUTH_DROP_UNENCRYPTED: + ieee->drop_unencrypted = data->value; break; case IW_AUTH_80211_AUTH_ALG: @@ -699,13 +699,13 @@ int ieee80211_wx_set_auth(struct ieee80211_device *ieee, #endif case IW_AUTH_RX_UNENCRYPTED_EAPOL: - ieee->ieee802_1x = data->value; + ieee->ieee802_1x = data->value; break; case IW_AUTH_PRIVACY_INVOKED: ieee->privacy_invoked = data->value; break; default: - return -EOPNOTSUPP; + return -EOPNOTSUPP; } return 0; } -- cgit v0.10.2 From 8ddbbac7f0132f05aa0277c59a19e542a0e46727 Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Thu, 29 Nov 2012 22:35:37 +0900 Subject: staging/rtl8187se: Fix spacing coding style in ieee80211/ieee80211_wx.c The following errors fixed. -ERROR: that open brace { should be on the previous line -ERROR: space required before the open parenthesis '(' -ERROR: else should follow close brace '}' -ERROR: space required before the open brace '{' Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c index 9185a21..e37555b 100644 --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c @@ -217,22 +217,18 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee, down(&ieee->wx_sem); spin_lock_irqsave(&ieee->lock, flags); - if(!ieee->bHwRadioOff) - { + if (!ieee->bHwRadioOff) { list_for_each_entry(network, &ieee->network_list, list) { i++; - if((stop-ev)<200) - { + if ((stop-ev)<200) { err = -E2BIG; break; } if (ieee->scan_age == 0 || - time_after(network->last_scanned + ieee->scan_age, jiffies)) - { + time_after(network->last_scanned + ieee->scan_age, jiffies)) { ev = rtl818x_translate_scan(ieee, ev, stop, network, info); - } - else + } else IEEE80211_DEBUG_SCAN( "Not showing network '%s (" "%pM)' due to age (%lums).\n", @@ -430,7 +426,7 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee, IEEE80211_DEBUG_WX("GET_ENCODE\n"); - if(ieee->iw_mode == IW_MODE_MONITOR) + if (ieee->iw_mode == IW_MODE_MONITOR) return -1; key = erq->flags & IW_ENCODE_INDEX; @@ -715,15 +711,13 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) { u8 *buf = NULL; - if (len>MAX_WPA_IE_LEN || (len && ie == NULL)) - { + if (len>MAX_WPA_IE_LEN || (len && ie == NULL)) { printk("return error out, len:%zu\n", len); return -EINVAL; } - if (len) - { - if (len != ie[1]+2){ + if (len) { + if (len != ie[1]+2) { printk("len:%zu, ie:%d\n", len, ie[1]); return -EINVAL; } @@ -733,8 +727,7 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) kfree(ieee->wpa_ie); ieee->wpa_ie = buf; ieee->wpa_ie_len = len; - } - else{ + } else { kfree(ieee->wpa_ie); ieee->wpa_ie = NULL; ieee->wpa_ie_len = 0; -- cgit v0.10.2 From 76e5f2f85dcf01bfd9f11475174d5496534ff75c Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Thu, 29 Nov 2012 22:35:51 +0900 Subject: staging/rtl8187se: Fix spacing coding style in ieee80211/ieee80211_wx.c The following errors fixed. -ERROR: spaces required around that '<' (ctx:VxV) -ERROR: spaces required around that '?' (ctx:VxV) -ERROR: spaces required around that ':' (ctx:VxV) -ERROR: spaces required around that '>' (ctx:VxV) Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c index e37555b..9d46087 100644 --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c @@ -221,7 +221,7 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee, list_for_each_entry(network, &ieee->network_list, list) { i++; - if ((stop-ev)<200) { + if ((stop-ev) < 200) { err = -E2BIG; break; } @@ -683,13 +683,13 @@ int ieee80211_wx_set_auth(struct ieee80211_device *ieee, break; case IW_AUTH_80211_AUTH_ALG: - ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM)?1:0; + ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM) ? 1 : 0; //printk("open_wep:%d\n", ieee->open_wep); break; #if 1 case IW_AUTH_WPA_ENABLED: - ieee->wpa_enabled = (data->value)?1:0; + ieee->wpa_enabled = (data->value) ? 1 : 0; //printk("enable wpa:%d\n", ieee->wpa_enabled); break; @@ -711,7 +711,7 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) { u8 *buf = NULL; - if (len>MAX_WPA_IE_LEN || (len && ie == NULL)) { + if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) { printk("return error out, len:%zu\n", len); return -EINVAL; } -- cgit v0.10.2 From 12f96662534cbf8578c02dfdf6657d2c430daff3 Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Thu, 29 Nov 2012 22:36:07 +0900 Subject: staging/rtl8187se: Use netdev_ printks in ieee80211/ieee80211_wx.c The following warnings fixed. -WARNING: Prefer netdev_warn(netdev, ... then dev_warn(dev, ... then pr_warn(... to printk(KERN_WARNING ... -WARNING: Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ... Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c index 9d46087..e014f7e 100644 --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c @@ -336,9 +336,8 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee, kfree(new_crypt); new_crypt = NULL; - printk(KERN_WARNING "%s: could not initialize WEP: " - "load module ieee80211_crypt_wep\n", - dev->name); + netdev_warn(ieee->dev, + "could not initialize WEP: load module ieee80211_crypt_wep\n"); return -EOPNOTSUPP; } *crypt = new_crypt; @@ -410,7 +409,7 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee, if (ieee->reset_on_keychange && ieee->iw_mode != IW_MODE_INFRA && ieee->reset_port && ieee->reset_port(dev)) { - printk(KERN_DEBUG "%s: reset_port failed\n", dev->name); + netdev_dbg(ieee->dev, "reset_port failed\n"); return -EINVAL; } return 0; -- cgit v0.10.2 From 201e7893ff2bfd315444b081569e70cd539838ee Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Fri, 30 Nov 2012 22:00:52 +0900 Subject: staging/rtl8187se: Fix spacing coding style in ieee80211/dot11d.c The following errors fixed. - ERROR: spaces required around that '=' (ctx:VxV) - ERROR: spaces required around that '<=' (ctx:VxV) - ERROR: space required after that ',' (ctx:VxV) Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/dot11d.c b/drivers/staging/rtl8187se/ieee80211/dot11d.c index 0e93eb0..247916b 100644 --- a/drivers/staging/rtl8187se/ieee80211/dot11d.c +++ b/drivers/staging/rtl8187se/ieee80211/dot11d.c @@ -39,10 +39,10 @@ Dot11d_Reset(struct ieee80211_device *ieee) memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); // Set new channel map - for (i=1; i<=11; i++) { + for (i = 1; i <= 11; i++) { (pDot11dInfo->channel_map)[i] = 1; } - for (i=12; i<=14; i++) { + for (i = 12; i <= 14; i++) { (pDot11dInfo->channel_map)[i] = 2; } @@ -116,7 +116,7 @@ Dot11d_UpdateCountryIe( #if 1 //printk("Dot11d_UpdateCountryIe(): Channel List:\n"); printk("Channel List:"); - for(i=1; i<= MAX_CHANNEL_NUMBER; i++) + for(i = 1; i <= MAX_CHANNEL_NUMBER; i++) if(pDot11dInfo->channel_map[i] > 0) printk(" %d", i); printk("\n"); @@ -125,7 +125,7 @@ Dot11d_UpdateCountryIe( UPDATE_CIE_SRC(dev, pTaddr); pDot11dInfo->CountryIeLen = CoutryIeLen; - memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe,CoutryIeLen); + memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe, CoutryIeLen); pDot11dInfo->State = DOT11D_STATE_LEARNED; } @@ -202,7 +202,7 @@ int ToLegalChannel( u8 default_chn = 0; u32 i = 0; - for (i=1; i<= MAX_CHANNEL_NUMBER; i++) + for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) { if(pDot11dInfo->channel_map[i] > 0) { -- cgit v0.10.2 From acf7537651a6d2680c0ca465ab2bfeeef31d0407 Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Fri, 30 Nov 2012 22:01:24 +0900 Subject: staging/rtl8187se: Fix spacing coding style in ieee80211/dot11d.c The following errors and warnings fixed. - WARNING: braces {} are not necessary for single statement blocks - ERROR: that open brace { should be on the previous line - ERROR: space required before the open parenthesis '(' - ERROR: space prohibited after that open parenthesis '(' Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/dot11d.c b/drivers/staging/rtl8187se/ieee80211/dot11d.c index 247916b..b61a66d 100644 --- a/drivers/staging/rtl8187se/ieee80211/dot11d.c +++ b/drivers/staging/rtl8187se/ieee80211/dot11d.c @@ -39,12 +39,11 @@ Dot11d_Reset(struct ieee80211_device *ieee) memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); // Set new channel map - for (i = 1; i <= 11; i++) { + for (i = 1; i <= 11; i++) (pDot11dInfo->channel_map)[i] = 1; - } - for (i = 12; i <= 14; i++) { + + for (i = 12; i <= 14; i++) (pDot11dInfo->channel_map)[i] = 2; - } pDot11dInfo->State = DOT11D_STATE_NONE; pDot11dInfo->CountryIeLen = 0; @@ -77,8 +76,7 @@ Dot11d_UpdateCountryIe( u8 i, j, NumTriples, MaxChnlNum; PCHNL_TXPOWER_TRIPLE pTriple; - if((CoutryIeLen - 3)%3 != 0) - { + if ((CoutryIeLen - 3)%3 != 0) { printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); Dot11d_Reset(dev); return; @@ -89,23 +87,21 @@ Dot11d_UpdateCountryIe( MaxChnlNum = 0; NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string. pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3); - for(i = 0; i < NumTriples; i++) - { - if(MaxChnlNum >= pTriple->FirstChnl) - { // It is not in a monotonically increasing order, so stop processing. + for (i = 0; i < NumTriples; i++) { + if (MaxChnlNum >= pTriple->FirstChnl) { + // It is not in a monotonically increasing order, so stop processing. printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); Dot11d_Reset(dev); return; } - if(MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls)) - { // It is not a valid set of channel id, so stop processing. + if (MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls)) { + // It is not a valid set of channel id, so stop processing. printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n"); Dot11d_Reset(dev); return; } - for(j = 0 ; j < pTriple->NumChnls; j++) - { + for (j = 0 ; j < pTriple->NumChnls; j++) { pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1; pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm; MaxChnlNum = pTriple->FirstChnl + j; @@ -116,8 +112,8 @@ Dot11d_UpdateCountryIe( #if 1 //printk("Dot11d_UpdateCountryIe(): Channel List:\n"); printk("Channel List:"); - for(i = 1; i <= MAX_CHANNEL_NUMBER; i++) - if(pDot11dInfo->channel_map[i] > 0) + for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) + if (pDot11dInfo->channel_map[i] > 0) printk(" %d", i); printk("\n"); #endif @@ -138,13 +134,11 @@ DOT11D_GetMaxTxPwrInDbm( PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); u8 MaxTxPwrInDbm = 255; - if(MAX_CHANNEL_NUMBER < Channel) - { + if (MAX_CHANNEL_NUMBER < Channel) { printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n"); return MaxTxPwrInDbm; } - if(pDot11dInfo->channel_map[Channel]) - { + if (pDot11dInfo->channel_map[Channel]) { MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel]; } @@ -159,15 +153,14 @@ DOT11D_ScanComplete( { PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); - switch(pDot11dInfo->State) - { + switch (pDot11dInfo->State) { case DOT11D_STATE_LEARNED: pDot11dInfo->State = DOT11D_STATE_DONE; break; case DOT11D_STATE_DONE: - if( GET_CIE_WATCHDOG(dev) == 0 ) - { // Reset country IE if previous one is gone. + if (GET_CIE_WATCHDOG(dev) == 0) { + // Reset country IE if previous one is gone. Dot11d_Reset(dev); } break; @@ -183,12 +176,11 @@ int IsLegalChannel( { PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); - if(MAX_CHANNEL_NUMBER < channel) - { + if (MAX_CHANNEL_NUMBER < channel) { printk("IsLegalChannel(): Invalid Channel\n"); return 0; } - if(pDot11dInfo->channel_map[channel] > 0) + if (pDot11dInfo->channel_map[channel] > 0) return 1; return 0; } @@ -202,22 +194,19 @@ int ToLegalChannel( u8 default_chn = 0; u32 i = 0; - for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) - { - if(pDot11dInfo->channel_map[i] > 0) - { + for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) { + if (pDot11dInfo->channel_map[i] > 0) { default_chn = i; break; } } - if(MAX_CHANNEL_NUMBER < channel) - { + if (MAX_CHANNEL_NUMBER < channel) { printk("IsLegalChannel(): Invalid Channel\n"); return default_chn; } - if(pDot11dInfo->channel_map[channel] > 0) + if (pDot11dInfo->channel_map[channel] > 0) return channel; return default_chn; -- cgit v0.10.2 From 14de74481f4de7e8aec3f4c6d3951efb016e83bb Mon Sep 17 00:00:00 2001 From: YAMANE Toshiaki Date: Fri, 30 Nov 2012 22:01:37 +0900 Subject: staging/rtl8187se: Fix spacing coding style in ieee80211/dot11d.c The following errors fixed. - ERROR: "foo * bar" should be "foo *bar" - ERROR: "(foo*)" should be "(foo *)" Signed-off-by: YAMANE Toshiaki Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/ieee80211/dot11d.c b/drivers/staging/rtl8187se/ieee80211/dot11d.c index b61a66d..9d2d5c5 100644 --- a/drivers/staging/rtl8187se/ieee80211/dot11d.c +++ b/drivers/staging/rtl8187se/ieee80211/dot11d.c @@ -67,9 +67,9 @@ Dot11d_Reset(struct ieee80211_device *ieee) void Dot11d_UpdateCountryIe( struct ieee80211_device *dev, - u8 * pTaddr, + u8 *pTaddr, u16 CoutryIeLen, - u8 * pCoutryIe + u8 *pCoutryIe ) { PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); @@ -107,7 +107,7 @@ Dot11d_UpdateCountryIe( MaxChnlNum = pTriple->FirstChnl + j; } - pTriple = (PCHNL_TXPOWER_TRIPLE)((u8*)pTriple + 3); + pTriple = (PCHNL_TXPOWER_TRIPLE)((u8 *)pTriple + 3); } #if 1 //printk("Dot11d_UpdateCountryIe(): Channel List:\n"); @@ -148,7 +148,7 @@ DOT11D_GetMaxTxPwrInDbm( void DOT11D_ScanComplete( - struct ieee80211_device * dev + struct ieee80211_device *dev ) { PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); @@ -170,7 +170,7 @@ DOT11D_ScanComplete( } int IsLegalChannel( - struct ieee80211_device * dev, + struct ieee80211_device *dev, u8 channel ) { @@ -186,7 +186,7 @@ int IsLegalChannel( } int ToLegalChannel( - struct ieee80211_device * dev, + struct ieee80211_device *dev, u8 channel ) { -- cgit v0.10.2 From 35997ff0cadda701711416abf6676b77358b0008 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Wed, 5 Dec 2012 21:40:18 +0100 Subject: staging/rtl8192u: cleanfile run Run cleanfile on all files inside drivers/staging/rtl819u Signed-off-by: Sebastian Hahn Signed-off-by: Jennifer Naumann Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/changes b/drivers/staging/rtl8192u/changes index 87c33fd..0485d6e 100644 --- a/drivers/staging/rtl8192u/changes +++ b/drivers/staging/rtl8192u/changes @@ -2,4 +2,3 @@ v 0.1 First version. This is based on the rtl8180-sa2400 pre-0.22-CVS code.. - diff --git a/drivers/staging/rtl8192u/ieee80211/Makefile b/drivers/staging/rtl8192u/ieee80211/Makefile index 51effd6..b5d0c2e 100644 --- a/drivers/staging/rtl8192u/ieee80211/Makefile +++ b/drivers/staging/rtl8192u/ieee80211/Makefile @@ -25,4 +25,3 @@ obj-m +=ieee80211_crypt-rsl.o obj-m +=ieee80211_crypt_wep-rsl.o obj-m +=ieee80211_crypt_tkip-rsl.o obj-m +=ieee80211_crypt_ccmp-rsl.o - diff --git a/drivers/staging/rtl8192u/ieee80211/aes.c b/drivers/staging/rtl8192u/ieee80211/aes.c index a6bb6c9..abc1023 100644 --- a/drivers/staging/rtl8192u/ieee80211/aes.c +++ b/drivers/staging/rtl8192u/ieee80211/aes.c @@ -443,7 +443,7 @@ static struct crypto_alg aes_alg = { .cipher = { .cia_min_keysize = AES_MIN_KEY_SIZE, .cia_max_keysize = AES_MAX_KEY_SIZE, - .cia_setkey = aes_set_key, + .cia_setkey = aes_set_key, .cia_encrypt = aes_encrypt, .cia_decrypt = aes_decrypt } @@ -466,4 +466,3 @@ module_exit(aes_fini); MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm"); MODULE_LICENSE("Dual BSD/GPL"); - diff --git a/drivers/staging/rtl8192u/ieee80211/arc4.c b/drivers/staging/rtl8192u/ieee80211/arc4.c index e3ad8d2..b790e9a 100644 --- a/drivers/staging/rtl8192u/ieee80211/arc4.c +++ b/drivers/staging/rtl8192u/ieee80211/arc4.c @@ -79,7 +79,7 @@ static struct crypto_alg arc4_alg = { .cra_u = { .cipher = { .cia_min_keysize = ARC4_MIN_KEY_SIZE, .cia_max_keysize = ARC4_MAX_KEY_SIZE, - .cia_setkey = arc4_set_key, + .cia_setkey = arc4_set_key, .cia_encrypt = arc4_crypt, .cia_decrypt = arc4_crypt } } }; diff --git a/drivers/staging/rtl8192u/ieee80211/crypto_compat.h b/drivers/staging/rtl8192u/ieee80211/crypto_compat.h index da48658..2ba374a 100644 --- a/drivers/staging/rtl8192u/ieee80211/crypto_compat.h +++ b/drivers/staging/rtl8192u/ieee80211/crypto_compat.h @@ -56,5 +56,3 @@ static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, } //EXPORT_SYMBOL_GPL(crypto_alloc_tfm); //EXPORT_SYMBOL_GPL(crypto_free_tfm); - - diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c index ce63fc3..f10fd5a 100644 --- a/drivers/staging/rtl8192u/ieee80211/dot11d.c +++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c @@ -218,4 +218,3 @@ EXPORT_SYMBOL(DOT11D_GetMaxTxPwrInDbm); EXPORT_SYMBOL(DOT11D_ScanComplete); EXPORT_SYMBOL(IsLegalChannel); EXPORT_SYMBOL(ToLegalChannel); - diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h index 502bfdb..bb0e4fe 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h @@ -64,7 +64,7 @@ #endif #define KEY_TYPE_NA 0x0 -#define KEY_TYPE_WEP40 0x1 +#define KEY_TYPE_WEP40 0x1 #define KEY_TYPE_TKIP 0x2 #define KEY_TYPE_CCMP 0x4 #define KEY_TYPE_WEP104 0x5 @@ -195,21 +195,21 @@ enum _ReasonCode{ auth_not_valid = 0x2, deauth_lv_ss = 0x3, inactivity = 0x4, - ap_overload = 0x5, + ap_overload = 0x5, class2_err = 0x6, class3_err = 0x7, - disas_lv_ss = 0x8, + disas_lv_ss = 0x8, asoc_not_auth = 0x9, //----MIC_CHECK - mic_failure = 0xe, + mic_failure = 0xe, //----END MIC_CHECK // Reason code defined in 802.11i D10.0 p.28. invalid_IE = 0x0d, four_way_tmout = 0x0f, two_way_tmout = 0x10, - IE_dismatch = 0x11, + IE_dismatch = 0x11, invalid_Gcipher = 0x12, invalid_Pcipher = 0x13, invalid_AKMP = 0x14, @@ -222,7 +222,7 @@ enum _ReasonCode{ QoS_unspec = 0x20, // 32 QAP_bandwidth = 0x21, // 33 poor_condition = 0x22, // 34 - no_facility = 0x23, // 35 + no_facility = 0x23, // 35 // Where is 36??? req_declined = 0x25, // 37 invalid_param = 0x26, // 38 @@ -265,7 +265,7 @@ enum _ReasonCode{ #define IEEE_WPAX_USEGROUP 0 #define IEEE_WPAX_WEP40 1 #define IEEE_WPAX_TKIP 2 -#define IEEE_WPAX_WRAP 3 +#define IEEE_WPAX_WRAP 3 #define IEEE_WPAX_CCMP 4 #define IEEE_WPAX_WEP104 5 @@ -289,12 +289,12 @@ enum _ReasonCode{ #define MAX_IE_LEN 0xff // added for kernel conflict -#define ieee80211_crypt_deinit_entries ieee80211_crypt_deinit_entries_rsl -#define ieee80211_crypt_deinit_handler ieee80211_crypt_deinit_handler_rsl -#define ieee80211_crypt_delayed_deinit ieee80211_crypt_delayed_deinit_rsl -#define ieee80211_register_crypto_ops ieee80211_register_crypto_ops_rsl +#define ieee80211_crypt_deinit_entries ieee80211_crypt_deinit_entries_rsl +#define ieee80211_crypt_deinit_handler ieee80211_crypt_deinit_handler_rsl +#define ieee80211_crypt_delayed_deinit ieee80211_crypt_delayed_deinit_rsl +#define ieee80211_register_crypto_ops ieee80211_register_crypto_ops_rsl #define ieee80211_unregister_crypto_ops ieee80211_unregister_crypto_ops_rsl -#define ieee80211_get_crypto_ops ieee80211_get_crypto_ops_rsl +#define ieee80211_get_crypto_ops ieee80211_get_crypto_ops_rsl #define ieee80211_ccmp_null ieee80211_ccmp_null_rsl @@ -302,10 +302,10 @@ enum _ReasonCode{ #define ieee80211_wep_null ieee80211_wep_null_rsl -#define free_ieee80211 free_ieee80211_rsl -#define alloc_ieee80211 alloc_ieee80211_rsl +#define free_ieee80211 free_ieee80211_rsl +#define alloc_ieee80211 alloc_ieee80211_rsl -#define ieee80211_rx ieee80211_rx_rsl +#define ieee80211_rx ieee80211_rx_rsl #define ieee80211_rx_mgt ieee80211_rx_mgt_rsl #define ieee80211_get_beacon ieee80211_get_beacon_rsl @@ -450,7 +450,7 @@ typedef struct ieee_param { /* management */ #define IEEE80211_STYPE_ASSOC_REQ 0x0000 -#define IEEE80211_STYPE_ASSOC_RESP 0x0010 +#define IEEE80211_STYPE_ASSOC_RESP 0x0010 #define IEEE80211_STYPE_REASSOC_REQ 0x0020 #define IEEE80211_STYPE_REASSOC_RESP 0x0030 #define IEEE80211_STYPE_PROBE_REQ 0x0040 @@ -536,7 +536,7 @@ do { if (ieee80211_debug_level & (level)) \ //if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA #define IEEE80211_DEBUG_DATA(level, data, datalen) \ do{ if ((ieee80211_debug_level & (level)) == (level)) \ - { \ + { \ int i; \ u8* pdata = (u8*) data; \ printk(KERN_DEBUG "ieee80211: %s()\n", __FUNCTION__); \ @@ -623,20 +623,20 @@ do { if (ieee80211_debug_level & (level)) \ #define MAX_STR_LEN 64 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. Annie, 2005-11-22.*/ #define PRINTABLE(_ch) (_ch>'!' && _ch<'~') -#define IEEE80211_PRINT_STR(_Comp, _TitleString, _Ptr, _Len) \ - if((_Comp) & level) \ +#define IEEE80211_PRINT_STR(_Comp, _TitleString, _Ptr, _Len) \ + if((_Comp) & level) \ { \ int __i; \ - u8 buffer[MAX_STR_LEN]; \ - int length = (_Len\n", _Len, buffer); \ } @@ -785,12 +785,12 @@ enum ieee80211_reasoncode { #define IEEE80211_24GHZ_BAND (1<<0) #define IEEE80211_52GHZ_BAND (1<<1) -#define IEEE80211_CCK_RATE_LEN 4 +#define IEEE80211_CCK_RATE_LEN 4 #define IEEE80211_CCK_RATE_1MB 0x02 #define IEEE80211_CCK_RATE_2MB 0x04 #define IEEE80211_CCK_RATE_5MB 0x0B #define IEEE80211_CCK_RATE_11MB 0x16 -#define IEEE80211_OFDM_RATE_LEN 8 +#define IEEE80211_OFDM_RATE_LEN 8 #define IEEE80211_OFDM_RATE_6MB 0x0C #define IEEE80211_OFDM_RATE_9MB 0x12 #define IEEE80211_OFDM_RATE_12MB 0x18 @@ -919,10 +919,10 @@ struct ieee80211_rx_stats { u16 fraglength; // FragLength should equal to PacketLength in non-fragment case u16 fragoffset; // Data offset for this fragment u16 ntotalfrag; - bool bisrxaggrsubframe; + bool bisrxaggrsubframe; bool bPacketBeacon; //cosa add for rssi bool bToSelfBA; //cosa add for rssi - char cck_adc_pwdb[4]; //cosa add for rx path selection + char cck_adc_pwdb[4]; //cosa add for rx path selection u16 Seq_Num; }; @@ -992,7 +992,7 @@ struct ieee80211_device; #define SEC_ALG_TKIP 2 #define SEC_ALG_CCMP 3 -#define WEP_KEYS 4 +#define WEP_KEYS 4 #define WEP_KEY_LEN 13 #define SCM_KEY_LEN 32 #define SCM_TEMPORAL_KEY_LENGTH 16 @@ -1205,7 +1205,7 @@ struct ieee80211_drv_agg_txb { struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT]; }__attribute__((packed)); -#define MAX_SUBFRAME_COUNT 64 +#define MAX_SUBFRAME_COUNT 64 struct ieee80211_rxb { u8 nr_subframes; struct sk_buff *subframes[MAX_SUBFRAME_COUNT]; @@ -1534,7 +1534,7 @@ struct ieee80211_network { bool bWithAironetIE; bool bCkipSupported; bool bCcxRmEnable; - u16 CcxRmState[2]; + u16 CcxRmState[2]; // CCXv4 S59, MBSSID. bool bMBssidValid; u8 MBssidMask; @@ -1726,7 +1726,7 @@ typedef struct _RT_POWER_SAVE_CONTROL bool bIPSModeBackup; bool bSwRfProcessing; RT_RF_POWER_STATE eInactivePowerState; - struct work_struct InactivePsWorkItem; + struct work_struct InactivePsWorkItem; struct timer_list InactivePsTimer; // Return point for join action @@ -1837,11 +1837,11 @@ struct ieee80211_device { u8 HTHighestOperaRate; //wb added for rate operation mode to firmware u8 bTxDisableRateFallBack; - u8 bTxUseDriverAssingedRate; + u8 bTxUseDriverAssingedRate; atomic_t atm_chnlop; atomic_t atm_swbw; // u8 HTHighestOperaRate; -// u8 HTCurrentOperaRate; +// u8 HTCurrentOperaRate; // 802.11e and WMM Traffic Stream Info (TX) struct list_head Tx_TS_Admit_List; @@ -2055,9 +2055,9 @@ struct ieee80211_device { bool bdynamic_txpower_enable; bool bCTSToSelfEnable; - u8 CTSToSelfTH; + u8 CTSToSelfTH; - u32 fsync_time_interval; + u32 fsync_time_interval; u32 fsync_rate_bitmap; u8 fsync_rssi_threshold; bool bfsync_enable; @@ -2214,7 +2214,7 @@ struct ieee80211_device { #define IEEE_A (1<<0) #define IEEE_B (1<<1) #define IEEE_G (1<<2) -#define IEEE_N_24G (1<<4) +#define IEEE_N_24G (1<<4) #define IEEE_N_5G (1<<5) #define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c index 82d4bf6..c673adc 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c @@ -233,9 +233,9 @@ static int debug = \ // IEEE80211_DL_TX | // IEEE80211_DL_RX | //IEEE80211_DL_QOS | - // IEEE80211_DL_HT | + // IEEE80211_DL_HT | // IEEE80211_DL_TS | -// IEEE80211_DL_BA | +// IEEE80211_DL_BA | // IEEE80211_DL_REORDER| // IEEE80211_DL_TRACE | //IEEE80211_DL_DATA | diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c index e3cf7a4..8e58647 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c @@ -608,7 +608,7 @@ void RxReorderIndicatePacket( struct ieee80211_device *ieee, u16 SeqNum) { PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; - PRX_REORDER_ENTRY pReorderEntry = NULL; + PRX_REORDER_ENTRY pReorderEntry = NULL; struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE]; u8 WinSize = pHTInfo->RxReorderWinSize; u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096; @@ -1043,7 +1043,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, { // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__FUNCTION__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc)); - if( (fc & (1<<11)) && + if( (fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) && (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) ) { @@ -1839,12 +1839,12 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, info_element->data[3] == 0x033){ tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); - if(tmp_htcap_len != 0){ - network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; + if(tmp_htcap_len != 0){ + network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); - } + } } if(tmp_htcap_len != 0) network->bssht.bdSupportHT = true; @@ -1856,9 +1856,9 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, if(tmp_htinfo_len == 0){ if(info_element->len >= 4 && info_element->data[0] == 0x00 && - info_element->data[1] == 0x90 && - info_element->data[2] == 0x4c && - info_element->data[3] == 0x034){ + info_element->data[1] == 0x90 && + info_element->data[2] == 0x4c && + info_element->data[3] == 0x034){ tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); if(tmp_htinfo_len != 0){ @@ -2060,7 +2060,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) || (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) ) { - network->bCkipSupported = true; + network->bCkipSupported = true; } else { @@ -2070,7 +2070,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, else { network->bWithAironetIE = false; - network->bCkipSupported = false; + network->bCkipSupported = false; } break; case MFIE_TYPE_QOS_PARAMETER: @@ -2230,8 +2230,8 @@ static inline int ieee80211_network_init( } else network->flags |= NETWORK_HAS_CCK; - network->wpa_ie_len = 0; - network->rsn_ie_len = 0; + network->wpa_ie_len = 0; + network->rsn_ie_len = 0; if (ieee80211_parse_info_param (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 7a07078..2c2bd00 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -3124,7 +3124,7 @@ inline struct sk_buff *ieee80211_disassociate_skb( void SendDisassociation( struct ieee80211_device *ieee, - u8* asSta, + u8* asSta, u8 asRsn ) { diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c index 3f5ceeb..918dee7 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c @@ -395,7 +395,7 @@ ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, cb_desc *tcb_desc) { PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; - tcb_desc->bUseShortGI = false; + tcb_desc->bUseShortGI = false; if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT) return; @@ -514,7 +514,7 @@ void ieee80211_query_protectionmode(struct ieee80211_device* ieee, cb_desc* tcb_ if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF) { tcb_desc->bCTSEnable = true; - tcb_desc->rts_rate = MGN_24M; + tcb_desc->rts_rate = MGN_24M; tcb_desc->bRTSEnable = true; break; } @@ -527,7 +527,7 @@ void ieee80211_query_protectionmode(struct ieee80211_device* ieee, cb_desc* tcb_ { tcb_desc->bCTSEnable = true; tcb_desc->rts_rate = MGN_24M; - tcb_desc->bRTSEnable = true; + tcb_desc->bRTSEnable = true; } if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE) tcb_desc->bUseShortPreamble = true; @@ -833,7 +833,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) else ieee->seq_ctrl[UP2AC(skb->priority) + 1]++; } else { - if (ieee->seq_ctrl[0] == 0xFFF) + if (ieee->seq_ctrl[0] == 0xFFF) ieee->seq_ctrl[0] = 0; else ieee->seq_ctrl[0]++; diff --git a/drivers/staging/rtl8192u/ieee80211/internal.h b/drivers/staging/rtl8192u/ieee80211/internal.h index bebe13a..6f54cfe 100644 --- a/drivers/staging/rtl8192u/ieee80211/internal.h +++ b/drivers/staging/rtl8192u/ieee80211/internal.h @@ -79,4 +79,3 @@ void crypto_exit_cipher_ops(struct crypto_tfm *tfm); void crypto_exit_compress_ops(struct crypto_tfm *tfm); #endif /* _CRYPTO_INTERNAL_H */ - diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h index 8ddc8bf9..ffd1c0c 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h @@ -1,7 +1,7 @@ #ifndef _BATYPE_H_ #define _BATYPE_H_ -#define TOTAL_TXBA_NUM 16 +#define TOTAL_TXBA_NUM 16 #define TOTAL_RXBA_NUM 16 #define BA_SETUP_TIMEOUT 200 @@ -66,4 +66,3 @@ typedef struct _BA_RECORD { } BA_RECORD, *PBA_RECORD; #endif //end _BATYPE_H_ - diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c index 1ebea3d..69735d3 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c @@ -9,8 +9,8 @@ /******************************************************************************************************************** *function: Activate BA entry. And if Time is nozero, start timer. - * input: PBA_RECORD pBA //BA entry to be enabled - * u16 Time //indicate time delay. + * input: PBA_RECORD pBA //BA entry to be enabled + * u16 Time //indicate time delay. * output: none ********************************************************************************************************************/ void ActivateBAEntry(struct ieee80211_device* ieee, PBA_RECORD pBA, u16 Time) @@ -22,7 +22,7 @@ void ActivateBAEntry(struct ieee80211_device* ieee, PBA_RECORD pBA, u16 Time) /******************************************************************************************************************** *function: deactivate BA entry, including its timer. - * input: PBA_RECORD pBA //BA entry to be disabled + * input: PBA_RECORD pBA //BA entry to be disabled * output: none ********************************************************************************************************************/ void DeActivateBAEntry( struct ieee80211_device* ieee, PBA_RECORD pBA) @@ -33,7 +33,7 @@ void DeActivateBAEntry( struct ieee80211_device* ieee, PBA_RECORD pBA) /******************************************************************************************************************** *function: deactivete BA entry in Tx Ts, and send DELBA. * input: - * PTX_TS_RECORD pTxTs //Tx Ts which is to deactivate BA entry. + * PTX_TS_RECORD pTxTs //Tx Ts which is to deactivate BA entry. * output: none * notice: As PTX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME ********************************************************************************************************************/ @@ -63,7 +63,7 @@ u8 TxTsDeleteBA( struct ieee80211_device* ieee, PTX_TS_RECORD pTxTs) /******************************************************************************************************************** *function: deactivete BA entry in Tx Ts, and send DELBA. * input: - * PRX_TS_RECORD pRxTs //Rx Ts which is to deactivate BA entry. + * PRX_TS_RECORD pRxTs //Rx Ts which is to deactivate BA entry. * output: none * notice: As PRX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME, same with above ********************************************************************************************************************/ @@ -84,7 +84,7 @@ u8 RxTsDeleteBA( struct ieee80211_device* ieee, PRX_TS_RECORD pRxTs) /******************************************************************************************************************** *function: reset BA entry * input: - * PBA_RECORD pBA //entry to be reset + * PBA_RECORD pBA //entry to be reset * output: none ********************************************************************************************************************/ void ResetBaEntry( PBA_RECORD pBA) @@ -98,12 +98,12 @@ void ResetBaEntry( PBA_RECORD pBA) //These functions need porting here or not? /******************************************************************************************************************************* *function: construct ADDBAREQ and ADDBARSP frame here together. - * input: u8* Dst //ADDBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA. - * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?) - * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ) + * input: u8* Dst //ADDBA frame's destination + * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA. + * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?) + * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ) * output: none - * return: sk_buff* skb //return constructed skb to xmit + * return: sk_buff* skb //return constructed skb to xmit *******************************************************************************************************************************/ static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, PBA_RECORD pBA, u16 StatusCode, u8 type) { @@ -126,7 +126,7 @@ static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, P return NULL; } - memset(skb->data, 0, sizeof( struct ieee80211_hdr_3addr)); //I wonder whether it's necessary. Apparently kernel will not do it when alloc a skb. + memset(skb->data, 0, sizeof( struct ieee80211_hdr_3addr)); //I wonder whether it's necessary. Apparently kernel will not do it when alloc a skb. skb_reserve(skb, ieee->tx_headroom); BAReq = ( struct ieee80211_hdr_3addr *) skb_put(skb,sizeof( struct ieee80211_hdr_3addr)); @@ -177,12 +177,12 @@ static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, P /******************************************************************************************************************** *function: construct DELBA frame - * input: u8* dst //DELBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA - * TR_SELECT TxRxSelect //TX RX direction - * u16 ReasonCode //status code. + * input: u8* dst //DELBA frame's destination + * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * TR_SELECT TxRxSelect //TX RX direction + * u16 ReasonCode //status code. * output: none - * return: sk_buff* skb //return constructed skb to xmit + * return: sk_buff* skb //return constructed skb to xmit ********************************************************************************************************************/ static struct sk_buff* ieee80211_DELBA( struct ieee80211_device* ieee, @@ -246,8 +246,8 @@ static struct sk_buff* ieee80211_DELBA( /******************************************************************************************************************** *function: send ADDBAReq frame out - * input: u8* dst //ADDBAReq frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * input: u8* dst //ADDBAReq frame's destination + * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA * output: none * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does ********************************************************************************************************************/ @@ -272,9 +272,9 @@ void ieee80211_send_ADDBAReq(struct ieee80211_device* ieee, u8* dst, PBA_RECORD /******************************************************************************************************************** *function: send ADDBARSP frame out - * input: u8* dst //DELBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA - * u16 StatusCode //RSP StatusCode + * input: u8* dst //DELBA frame's destination + * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * u16 StatusCode //RSP StatusCode * output: none * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does ********************************************************************************************************************/ @@ -297,10 +297,10 @@ void ieee80211_send_ADDBARsp(struct ieee80211_device* ieee, u8* dst, PBA_RECORD } /******************************************************************************************************************** *function: send ADDBARSP frame out - * input: u8* dst //DELBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA - * TR_SELECT TxRxSelect //TX or RX - * u16 ReasonCode //DEL ReasonCode + * input: u8* dst //DELBA frame's destination + * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * TR_SELECT TxRxSelect //TX or RX + * u16 ReasonCode //DEL ReasonCode * output: none * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does ********************************************************************************************************************/ @@ -340,7 +340,7 @@ int ieee80211_rx_ADDBAReq( struct ieee80211_device* ieee, struct sk_buff *skb) if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9) { - IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BAREQ(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9)); + IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BAREQ(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9)); return -1; } @@ -439,7 +439,7 @@ int ieee80211_rx_ADDBARsp( struct ieee80211_device* ieee, struct sk_buff *skb) if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9) { - IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BARSP(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9)); + IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BARSP(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9)); return -1; } rsp = ( struct ieee80211_hdr_3addr*)skb->data; @@ -569,7 +569,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device* ieee,struct sk_buff *skb) if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 6) { - IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in DELBA(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 6)); + IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in DELBA(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 6)); return -1; } @@ -589,7 +589,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device* ieee,struct sk_buff *skb) if(pDelBaParamSet->field.Initiator == 1) { - PRX_TS_RECORD pRxTs; + PRX_TS_RECORD pRxTs; if( !GetTs( ieee, @@ -657,7 +657,7 @@ TsInitAddBA( // BufferSize: This need to be set according to A-MPDU vector pBA->BaParamSet.field.BufferSize = 32; // BufferSize: This need to be set according to A-MPDU vector pBA->BaTimeoutValue = 0; // Timeout value: Set 0 to disable Timer - pBA->BaStartSeqCtrl.field.SeqNum = (pTS->TxCurSeq + 3) % 4096; // Block Ack will start after 3 packets later. + pBA->BaStartSeqCtrl.field.SeqNum = (pTS->TxCurSeq + 3) % 4096; // Block Ack will start after 3 packets later. ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT); @@ -734,4 +734,3 @@ void RxBaInactTimeout(unsigned long data) DELBA_REASON_TIMEOUT); return ; } - diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h index a60b39c..2b82835 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h @@ -121,7 +121,7 @@ typedef union _HT_CAPABILITY_MACPARA{ typedef enum _HT_ACTION{ ACT_RECOMMAND_WIDTH = 0, - ACT_MIMO_PWR_SAVE = 1, + ACT_MIMO_PWR_SAVE = 1, ACT_PSMP = 2, ACT_SET_PCO_PHASE = 3, ACT_MIMO_CHL_MEASURE = 4, @@ -398,9 +398,9 @@ typedef struct _BSS_HT{ typedef struct _MIMO_RSSI{ u32 EnableAntenna; u32 AntennaA; - u32 AntennaB; - u32 AntennaC; - u32 AntennaD; + u32 AntennaB; + u32 AntennaC; + u32 AntennaD; u32 Average; }MIMO_RSSI, *PMIMO_RSSI; @@ -436,11 +436,11 @@ extern u8 MCS_FILTER_1SS[16]; // MCS Bw 40 {1~7, 12~15,32} -#define RATE_ADPT_1SS_MASK 0xFF +#define RATE_ADPT_1SS_MASK 0xFF #define RATE_ADPT_2SS_MASK 0xF0 //Skip MCS8~11 because mcs7 > mcs6, 9, 10, 11. 2007.01.16 by Emily #define RATE_ADPT_MCS32_MASK 0x01 -#define IS_11N_MCS_RATE(rate) (rate&0x80) +#define IS_11N_MCS_RATE(rate) (rate&0x80) typedef enum _HT_AGGRE_SIZE{ HT_AGG_SIZE_8K = 0, @@ -478,4 +478,3 @@ typedef enum _HT_IOT_ACTION{ }HT_IOT_ACTION_E, *PHT_IOT_ACTION_E; #endif //_RTL819XU_HTTYPE_H_ - diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c index ebb5239..268b270 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c @@ -21,7 +21,7 @@ u16 MCS_DATA_RATE[2][2][77] = 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 864, 972, 1080, 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 378, 378, 432, 324, 405, 405, 486, 567, 567, 648, 270, 324, 378, 324, 378, 432, 486, 432, 486, 540, 540, - 594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891}, // Long GI, 40MHz + 594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891}, // Long GI, 40MHz {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 960, 1080, 1200, 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 420, 420, 480, 360, 450, @@ -88,7 +88,7 @@ void HTUpdateDefaultSetting(struct ieee80211_device* ieee) ieee->bTxDisableRateFallBack = 0; ieee->bTxUseDriverAssingedRate = 0; -#ifdef TO_DO_LIST +#ifdef TO_DO_LIST // 8190 only. Assign duration operation mode to firmware pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur; #endif @@ -116,7 +116,7 @@ void HTUpdateDefaultSetting(struct ieee80211_device* ieee) /******************************************************************************************************************** *function: This function print out each field on HT capability IE mainly from (Beacon/ProbeRsp/AssocReq) * input: u8* CapIE //Capability IE to be printed out - * u8* TitleString //mainly print out caller function + * u8* TitleString //mainly print out caller function * output: none * return: none * notice: Driver should not print out this message by default. @@ -125,7 +125,7 @@ void HTDebugHTCapability(u8* CapIE, u8* TitleString ) { static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily - PHT_CAPABILITY_ELE pCapELE; + PHT_CAPABILITY_ELE pCapELE; if(!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) { @@ -153,7 +153,7 @@ void HTDebugHTCapability(u8* CapIE, u8* TitleString ) /******************************************************************************************************************** *function: This function print out each field on HT Information IE mainly from (Beacon/ProbeRsp) * input: u8* InfoIE //Capability IE to be printed out - * u8* TitleString //mainly print out caller function + * u8* TitleString //mainly print out caller function * output: none * return: none * notice: Driver should not print out this message by default. @@ -217,7 +217,7 @@ void HTDebugHTInfo(u8* InfoIE, u8* TitleString) } /* -* Return: true if station in half n mode and AP supports 40 bw +* Return: true if station in half n mode and AP supports 40 bw */ bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee) { @@ -228,7 +228,7 @@ bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee) retValue = false; else if(pHTInfo->bRegBW40MHz == false) // station supports 40 bw retValue = false; - else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode + else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode retValue = false; else if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw retValue = true; @@ -245,7 +245,7 @@ bool IsHTHalfNmodeSGI(struct ieee80211_device* ieee, bool is40MHz) if(pHTInfo->bCurrentHTSupport == false ) // wireless is n mode retValue = false; - else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode + else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode retValue = false; else if(is40MHz) // ap support 40 bw { @@ -265,7 +265,7 @@ bool IsHTHalfNmodeSGI(struct ieee80211_device* ieee, bool is40MHz) return retValue; } -u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee, u8 nMcsRate) +u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee, u8 nMcsRate) { u8 is40MHz; @@ -291,8 +291,8 @@ u16 HTMcsToDataRate( struct ieee80211_device* ieee, u8 nMcsRate) /******************************************************************************************************************** *function: This function returns current datarate. - * input: struct ieee80211_device* ieee - * u8 nDataRate + * input: struct ieee80211_device* ieee + * u8 nDataRate * output: none * return: tx rate * notice: quite unsure about how to use this function //wb @@ -371,7 +371,7 @@ bool IsHTHalfNmodeAPs(struct ieee80211_device* ieee) /******************************************************************************************************************** *function: This function returns peer IOT. - * input: struct ieee80211_device* ieee + * input: struct ieee80211_device* ieee * output: none * return: * notice: @@ -408,8 +408,8 @@ void HTIOTPeerDetermine(struct ieee80211_device* ieee) /******************************************************************************************************************** *function: Check whether driver should declare received rate up to MCS13 only since some chipset is not good * at receiving MCS14~15 frame from some AP. - * input: struct ieee80211_device* ieee - * u8 * PeerMacAddr + * input: struct ieee80211_device* ieee + * u8 * PeerMacAddr * output: none * return: return 1 if driver should declare MCS13 only(otherwise return 0) * *****************************************************************************************************************/ @@ -429,7 +429,7 @@ u8 HTIOTActIsDisableMCS14(struct ieee80211_device* ieee, u8* PeerMacAddr) * PADAPTER Adapter, * * Output: None -* Return: true if driver should disable MCS15 +* Return: true if driver should disable MCS15 * 2008.04.15 Emily */ bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee) @@ -466,7 +466,7 @@ bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee) * PADAPTER Adapter, * * Output: None -* Return: true if driver should disable all two spatial stream packet +* Return: true if driver should disable all two spatial stream packet * 2008.04.21 Emily */ bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *PeerMacAddr) @@ -481,12 +481,12 @@ bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *Pee /******************************************************************************************************************** *function: Check whether driver should disable EDCA turbo mode - * input: struct ieee80211_device* ieee - * u8* PeerMacAddr + * input: struct ieee80211_device* ieee + * u8* PeerMacAddr * output: none * return: return 1 if driver should disable EDCA turbo mode(otherwise return 0) * *****************************************************************************************************************/ -u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device* ieee, u8* PeerMacAddr) +u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device* ieee, u8* PeerMacAddr) { u8 retValue = false; // default enable EDCA Turbo mode. // Set specific EDCA parameter for different AP in DM handler. @@ -539,10 +539,10 @@ void HTResetIOTSetting( /******************************************************************************************************************** *function: Construct Capablility Element in Beacon... if HTEnable is turned on - * input: struct ieee80211_device* ieee - * u8* posHTCap //pointer to store Capability Ele - * u8* len //store length of CE - * u8 IsEncrypt //whether encrypt, needed further + * input: struct ieee80211_device* ieee + * u8* posHTCap //pointer to store Capability Ele + * u8* len //store length of CE + * u8 IsEncrypt //whether encrypt, needed further * output: none * return: none * notice: posHTCap can't be null and should be initialized before. @@ -550,7 +550,7 @@ void HTResetIOTSetting( void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 IsEncrypt) { PRT_HIGH_THROUGHPUT pHT = ieee->pHTInfo; - PHT_CAPABILITY_ELE pCapELE = NULL; + PHT_CAPABILITY_ELE pCapELE = NULL; //u8 bIsDeclareMCS13; if ((posHTCap == NULL) || (pHT == NULL)) @@ -571,7 +571,7 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u //HT capability info - pCapELE->AdvCoding = 0; // This feature is not supported now!! + pCapELE->AdvCoding = 0; // This feature is not supported now!! if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) { pCapELE->ChlWidth = 0; @@ -581,18 +581,18 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0); } -// pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0); - pCapELE->MimoPwrSave = pHT->SelfMimoPs; +// pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0); + pCapELE->MimoPwrSave = pHT->SelfMimoPs; pCapELE->GreenField = 0; // This feature is not supported now!! pCapELE->ShortGI20Mhz = 1; // We can receive Short GI!! pCapELE->ShortGI40Mhz = 1; // We can receive Short GI!! //DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r", //pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz); - pCapELE->TxSTBC = 1; - pCapELE->RxSTBC = 0; + pCapELE->TxSTBC = 1; + pCapELE->RxSTBC = 0; pCapELE->DelayBA = 0; // Do not support now!! pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0; - pCapELE->DssCCk = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0); + pCapELE->DssCCk = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0); pCapELE->PSMP = 0; // Do not support now!! pCapELE->LSigTxopProtect = 0; // Do not support now!! @@ -603,13 +603,13 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u if( IsEncrypt) { - pCapELE->MPDUDensity = 7; // 8us - pCapELE->MaxRxAMPDUFactor = 2; // 2 is for 32 K and 3 is 64K + pCapELE->MPDUDensity = 7; // 8us + pCapELE->MaxRxAMPDUFactor = 2; // 2 is for 32 K and 3 is 64K } else { - pCapELE->MaxRxAMPDUFactor = 3; // 2 is for 32 K and 3 is 64K - pCapELE->MPDUDensity = 0; // no density + pCapELE->MaxRxAMPDUFactor = 3; // 2 is for 32 K and 3 is 64K + pCapELE->MPDUDensity = 0; // no density } //Supported MCS set @@ -658,10 +658,10 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u } /******************************************************************************************************************** *function: Construct Information Element in Beacon... if HTEnable is turned on - * input: struct ieee80211_device* ieee - * u8* posHTCap //pointer to store Information Ele - * u8* len //store len of - * u8 IsEncrypt //whether encrypt, needed further + * input: struct ieee80211_device* ieee + * u8* posHTCap //pointer to store Information Ele + * u8* len //store len of + * u8 IsEncrypt //whether encrypt, needed further * output: none * return: none * notice: posHTCap can't be null and be initialized before. only AP and IBSS sta should do this @@ -679,12 +679,12 @@ void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* le memset(posHTInfo, 0, *len); if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported { - pHTInfoEle->ControlChl = ieee->current_network.channel; - pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT: + pHTInfoEle->ControlChl = ieee->current_network.channel; + pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT: (ieee->current_network.channel<=6)? HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER); pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz; - pHTInfoEle->RIFS = 0; + pHTInfoEle->RIFS = 0; pHTInfoEle->PSMPAccessOnly = 0; pHTInfoEle->SrvIntGranularity = 0; pHTInfoEle->OptMode = pHT->CurrentOpMode; @@ -723,17 +723,17 @@ void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* le * Element ID Length OUI Type1 Reserved * 1 byte 1 byte 3 bytes 1 byte 1 byte * - * OUI = 0x00, 0xe0, 0x4c, - * Type = 0x02 - * Reserved = 0x00 + * OUI = 0x00, 0xe0, 0x4c, + * Type = 0x02 + * Reserved = 0x00 * * 2007.8.21 by Emily */ /******************************************************************************************************************** *function: Construct Information Element in Beacon... in RT2RT condition - * input: struct ieee80211_device* ieee - * u8* posRT2RTAgg //pointer to store Information Ele - * u8* len //store len + * input: struct ieee80211_device* ieee + * u8* posRT2RTAgg //pointer to store Information Ele + * u8* len //store len * output: none * return: none * notice: @@ -787,8 +787,8 @@ void HTConstructRT2RTAggElement(struct ieee80211_device* ieee, u8* posRT2RTAgg, /******************************************************************************************************************** *function: Pick the right Rate Adaptive table to use - * input: struct ieee80211_device* ieee - * u8* pOperateMCS //A pointer to MCS rate bitmap + * input: struct ieee80211_device* ieee + * u8* pOperateMCS //A pointer to MCS rate bitmap * return: always we return true * notice: * *****************************************************************************************************************/ @@ -840,7 +840,7 @@ u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS) * Description: * This function will get the highest speed rate in input MCS set. * -* /param Adapter Pionter to Adapter entity +* /param Adapter Pionter to Adapter entity * pMCSRateSet Pointer to MCS rate bitmap * pMCSFilter Pointer to MCS rate filter * @@ -849,9 +849,9 @@ u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS) */ /******************************************************************************************************************** *function: This function will get the highest speed rate in input MCS set. - * input: struct ieee80211_device* ieee - * u8* pMCSRateSet //Pointer to MCS rate bitmap - * u8* pMCSFilter //Pointer to MCS rate filter + * input: struct ieee80211_device* ieee + * u8* pMCSRateSet //Pointer to MCS rate bitmap + * u8* pMCSFilter //Pointer to MCS rate filter * return: Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter * notice: * *****************************************************************************************************************/ @@ -1062,7 +1062,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee) else pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity; if(ieee->pairwise_key_type != KEY_TYPE_NA ) - pHTInfo->CurrentMPDUDensity = 7; // 8us + pHTInfo->CurrentMPDUDensity = 7; // 8us // Force TX AMSDU // Lanhsin: mark for tmp to avoid deauth by ap from s3 @@ -1118,7 +1118,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee) void HTSetConnectBwModeCallback(struct ieee80211_device* ieee); /******************************************************************************************************************** *function: initialize HT info(struct PRT_HIGH_THROUGHPUT) - * input: struct ieee80211_device* ieee + * input: struct ieee80211_device* ieee * output: none * return: none * notice: This function is called when * (1) MPInitialization Phase * (2) Receiving of Deauthentication from AP @@ -1208,13 +1208,13 @@ void HTInitializeBssDesc(PBSS_HT pBssHT) } /******************************************************************************************************************** *function: initialize Bss HT structure(struct PBSS_HT) - * input: struct ieee80211_device *ieee - * struct ieee80211_network *pNetwork //usually current network we are live in + * input: struct ieee80211_device *ieee + * struct ieee80211_network *pNetwork //usually current network we are live in * output: none * return: none * notice: This function should ONLY be called before association ********************************************************************************************************************/ -void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork) +void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork) { PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; // u16 nMaxAMSDUSize; @@ -1235,7 +1235,7 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer; // Save HTCap and HTInfo information Element - if(pNetwork->bssht.bdHTCapLen > 0 && pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf)) + if(pNetwork->bssht.bdHTCapLen > 0 && pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf)) memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen); if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf)) @@ -1297,7 +1297,7 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80 } -void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork) +void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork) { PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; // PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf; @@ -1364,8 +1364,8 @@ void HTUseDefaultSetting(struct ieee80211_device* ieee) } /******************************************************************************************************************** *function: check whether HT control field exists - * input: struct ieee80211_device *ieee - * u8* pFrame //coming skb->data + * input: struct ieee80211_device *ieee + * u8* pFrame //coming skb->data * output: none * return: return true if HT control field exists(false otherwise) * notice: diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h index 9e4ced1..2625cde 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h @@ -412,14 +412,14 @@ typedef union _QOS_TCLAS{ struct _TYPE_GENERAL{ u8 Priority; - u8 ClassifierType; - u8 Mask; + u8 ClassifierType; + u8 Mask; } TYPE_GENERAL; struct _TYPE0_ETH{ u8 Priority; - u8 ClassifierType; - u8 Mask; + u8 ClassifierType; + u8 Mask; u8 SrcAddr[6]; u8 DstAddr[6]; u16 Type; @@ -427,9 +427,9 @@ typedef union _QOS_TCLAS{ struct _TYPE1_IPV4{ u8 Priority; - u8 ClassifierType; - u8 Mask; - u8 Version; + u8 ClassifierType; + u8 Mask; + u8 Version; u8 SrcIP[4]; u8 DstIP[4]; u16 SrcPort; @@ -441,9 +441,9 @@ typedef union _QOS_TCLAS{ struct _TYPE1_IPV6{ u8 Priority; - u8 ClassifierType; - u8 Mask; - u8 Version; + u8 ClassifierType; + u8 Mask; + u8 Version; u8 SrcIP[16]; u8 DstIP[16]; u16 SrcPort; @@ -453,8 +453,8 @@ typedef union _QOS_TCLAS{ struct _TYPE2_8021Q{ u8 Priority; - u8 ClassifierType; - u8 Mask; + u8 ClassifierType; + u8 Mask; u16 TagType; } TYPE2_8021Q; } QOS_TCLAS, *PQOS_TCLAS; @@ -481,7 +481,7 @@ typedef struct _QOS_TSTREAM{ // "Qos control field" and "Qos info field" //typedef struct _QOS_UAPSD{ // u8 bTriggerEnable[4]; -// u8 MaxSPLength; +// u8 MaxSPLength; // u8 HighestBufAC; //} QOS_UAPSD, *PQOS_APSD; @@ -489,7 +489,7 @@ typedef struct _QOS_TSTREAM{ // 802.11 Management frame Status Code field //---------------------------------------------------------------------------- typedef struct _OCTET_STRING{ - u8 *Octet; + u8 *Octet; u16 Length; }OCTET_STRING, *POCTET_STRING; @@ -512,7 +512,7 @@ typedef struct _STA_QOS{ AC_UAPSD Curr4acUapsd; u8 bInServicePeriod; u8 MaxSPLength; - int NumBcnBeforeTrigger; + int NumBcnBeforeTrigger; // Part 2. EDCA Parameter (perAC) u8 * pWMMInfoEle; @@ -523,7 +523,7 @@ typedef struct _STA_QOS{ //2 ToDo: remove the Qos Info Field and replace it by the above WMM Info element. // By Bruce, 2008-01-30. // Part 2. EDCA Parameter (perAC) - QOS_INFO_FIELD QosInfoField_STA; // Maintained by STA + QOS_INFO_FIELD QosInfoField_STA; // Maintained by STA QOS_INFO_FIELD QosInfoField_AP; // Retrieved from AP AC_PARAM CurAcParameters[4]; diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h index e7e26fd..7ed7243 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h @@ -28,7 +28,7 @@ typedef struct _TS_COMMON_INFO{ typedef struct _TX_TS_RECORD{ TS_COMMON_INFO TsCommonInfo; u16 TxCurSeq; - BA_RECORD TxPendingBARecord; // For BA Originator + BA_RECORD TxPendingBARecord; // For BA Originator BA_RECORD TxAdmittedBARecord; // For BA Originator // QOS_DL_RECORD DLRecord; u8 bAddBaReqInProgress; @@ -53,4 +53,3 @@ typedef struct _RX_TS_RECORD { #endif - diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c index 06a9824..0310d07 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c @@ -27,7 +27,7 @@ void RxPktPendingTimeout(unsigned long data) PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data; struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]); - PRX_REORDER_ENTRY pReorderEntry = NULL; + PRX_REORDER_ENTRY pReorderEntry = NULL; //u32 flags = 0; unsigned long flags = 0; @@ -236,8 +236,8 @@ void AdmitTS(struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 I PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect) { - //DIRECTION_VALUE dir; - u8 dir; + //DIRECTION_VALUE dir; + u8 dir; bool search_dir[4] = {0, 0, 0, 0}; struct list_head* psearch_list; //FIXME PTS_COMMON_INFO pRet = NULL; @@ -250,14 +250,14 @@ PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 } else { - search_dir[DIR_UP] = true; + search_dir[DIR_UP] = true; search_dir[DIR_BI_DIR]= true; } } else if(ieee->iw_mode == IW_MODE_ADHOC) { if(TxRxSelect == TX_DIR) - search_dir[DIR_UP] = true; + search_dir[DIR_UP] = true; else search_dir[DIR_DOWN] = true; } @@ -265,7 +265,7 @@ PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 { if(TxRxSelect == TX_DIR) { - search_dir[DIR_UP] = true; + search_dir[DIR_UP] = true; search_dir[DIR_BI_DIR]= true; search_dir[DIR_DIRECT]= true; } @@ -450,8 +450,8 @@ bool GetTs( pTSInfo->field.ucTSID = UP; // TSID pTSInfo->field.ucDirection = Dir; // Direction: if there is DirectLink, this need additional consideration. pTSInfo->field.ucAccessPolicy = 1; // Access policy - pTSInfo->field.ucAggregation = 0; // Aggregation - pTSInfo->field.ucPSB = 0; // Aggregation + pTSInfo->field.ucAggregation = 0; // Aggregation + pTSInfo->field.ucPSB = 0; // Aggregation pTSInfo->field.ucUP = UP; // User priority pTSInfo->field.ucTSInfoAckPolicy = 0; // Ack policy pTSInfo->field.ucSchedule = 0; // Schedule @@ -488,7 +488,7 @@ void RemoveTsEntry( { //#ifdef TO_DO_LIST PRX_REORDER_ENTRY pRxReorderEntry; - PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs; + PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs; if(timer_pending(&pRxTS->RxPktPendingTimer)) del_timer_sync(&pRxTS->RxPktPendingTimer); diff --git a/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h b/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h index ccf6ae7..a8df410 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h @@ -52,10 +52,10 @@ #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100 #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 -#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 -#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000 -#define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000 -#define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000 +#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 +#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000 +#define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000 +#define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000 /* * Miscellaneous stuff. @@ -396,4 +396,3 @@ void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen, #endif /* CONFIG_CRYPTO_HMAC */ #endif /* _LINUX_CRYPTO_H */ - diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c b/drivers/staging/rtl8192u/r8190_rtl8256.c index 74ff337..cf9713f 100644 --- a/drivers/staging/rtl8192u/r8190_rtl8256.c +++ b/drivers/staging/rtl8192u/r8190_rtl8256.c @@ -16,9 +16,9 @@ #include "r8190_rtl8256.h" /*-------------------------------------------------------------------------- - * Overview: set RF band width (20M or 40M) + * Overview: set RF band width (20M or 40M) * Input: struct net_device* dev - * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M + * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M * Output: NONE * Return: NONE * Note: 8226 support both 20M and 40 MHz @@ -106,16 +106,16 @@ void PHY_RF8256_Config(struct net_device* dev) *---------------------------------------------------------------------------*/ void phy_RF8256_Config_ParaFile(struct net_device* dev) { - u32 u4RegValue = 0; + u32 u4RegValue = 0; //static s1Byte szRadioAFile[] = RTL819X_PHY_RADIO_A; //static s1Byte szRadioBFile[] = RTL819X_PHY_RADIO_B; //static s1Byte szRadioCFile[] = RTL819X_PHY_RADIO_C; //static s1Byte szRadioDFile[] = RTL819X_PHY_RADIO_D; - u8 eRFPath; + u8 eRFPath; BB_REGISTER_DEFINITION_T *pPhyReg; struct r8192_priv *priv = ieee80211_priv(dev); u32 RegOffSetToBeCheck = 0x3; - u32 RegValueToBeCheck = 0x7f1; + u32 RegValueToBeCheck = 0x7f1; u32 RF3_Final_Value = 0; u8 ConstRetryTimes = 5, RetryTimes = 5; u8 ret = 0; @@ -152,7 +152,7 @@ void phy_RF8256_Config_ParaFile(struct net_device* dev) rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1); /* Set bit number of Address and Data for RF register */ - rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); // Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 + rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); // Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); // Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf); @@ -309,4 +309,3 @@ void PHY_SetRF8256OFDMTxPower(struct net_device* dev, u8 powerlevel) return; } - diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h index 57e3383..80ab937 100644 --- a/drivers/staging/rtl8192u/r8192U.h +++ b/drivers/staging/rtl8192u/r8192U.h @@ -110,7 +110,7 @@ do { if(rt_global_debug_component & component) \ #define COMP_RATE BIT12 // For Rate Adaptive mechanism, 2006.07.02, by rcnjko. #define COMP_RM BIT13 // For Radio Measurement. #define COMP_DIG BIT14 // For DIG, 2006.09.25, by rcnjko. -#define COMP_PHY BIT15 +#define COMP_PHY BIT15 #define COMP_CH BIT16 //channel setting debug #define COMP_TXAGC BIT17 // For Tx power, 060928, by rcnjko. #define COMP_HIPWR BIT18 // For High Power Mechanism, 060928, by rcnjko. @@ -209,7 +209,7 @@ do { if(rt_global_debug_component & component) \ #define IEEE80211_WATCH_DOG_TIME 2000 #define PHY_Beacon_RSSI_SLID_WIN_MAX 10 //for txpowertracking by amy -#define OFDM_Table_Length 19 +#define OFDM_Table_Length 19 #define CCK_Table_length 12 /* for rtl819x */ @@ -298,7 +298,7 @@ typedef struct _tx_desc_cmd_819x_usb { u8 Reserved4; //DOWRD 2 - u16 TxBufferSize; + u16 TxBufferSize; u16 Reserved5; //DWORD 3,4,5 @@ -391,7 +391,7 @@ typedef struct _rx_desc_819x_usb_aggr_subframe{ //DWORD 2 //u4Byte Reserved3; //DWORD 3 - //u4Byte BufferAddress; + //u4Byte BufferAddress; }rx_desc_819x_usb_aggr_subframe, *prx_desc_819x_usb_aggr_subframe; #endif @@ -424,7 +424,7 @@ typedef struct rx_drvinfo_819x_usb{ #define MAX_802_11_HEADER_LENGTH (40 + MAX_FIRMWARE_INFORMATION_SIZE) #define ENCRYPTION_MAX_OVERHEAD 128 #define USB_HWDESC_HEADER_LEN sizeof(tx_desc_819x_usb) -#define TX_PACKET_SHIFT_BYTES (USB_HWDESC_HEADER_LEN + sizeof(tx_fwinfo_819x_usb)) +#define TX_PACKET_SHIFT_BYTES (USB_HWDESC_HEADER_LEN + sizeof(tx_fwinfo_819x_usb)) #define MAX_FRAGMENT_COUNT 8 #ifdef RTL8192U #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE @@ -433,7 +433,7 @@ typedef struct rx_drvinfo_819x_usb{ #define MAX_TRANSMIT_BUFFER_SIZE 8000 #endif #else -#define MAX_TRANSMIT_BUFFER_SIZE (1600+(MAX_802_11_HEADER_LENGTH+ENCRYPTION_MAX_OVERHEAD)*MAX_FRAGMENT_COUNT) +#define MAX_TRANSMIT_BUFFER_SIZE (1600+(MAX_802_11_HEADER_LENGTH+ENCRYPTION_MAX_OVERHEAD)*MAX_FRAGMENT_COUNT) #endif #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE #define TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES (sizeof(tx_desc_819x_usb_aggr_subframe) + sizeof(tx_fwinfo_819x_usb)) @@ -711,7 +711,7 @@ typedef struct Stats //+by amy 080507 -typedef struct ChnlAccessSetting { +typedef struct ChnlAccessSetting { u16 SIFS_Timer; u16 DIFS_Timer; u16 SlotTimeTimer; @@ -721,23 +721,23 @@ typedef struct ChnlAccessSetting { }*PCHANNEL_ACCESS_SETTING,CHANNEL_ACCESS_SETTING; typedef struct _BB_REGISTER_DEFINITION{ - u32 rfintfs; // set software control: // 0x870~0x877[8 bytes] - u32 rfintfi; // readback data: // 0x8e0~0x8e7[8 bytes] - u32 rfintfo; // output data: // 0x860~0x86f [16 bytes] - u32 rfintfe; // output enable: // 0x860~0x86f [16 bytes] - u32 rf3wireOffset; // LSSI data: // 0x840~0x84f [16 bytes] - u32 rfLSSI_Select; // BB Band Select: // 0x878~0x87f [8 bytes] + u32 rfintfs; // set software control: // 0x870~0x877[8 bytes] + u32 rfintfi; // readback data: // 0x8e0~0x8e7[8 bytes] + u32 rfintfo; // output data: // 0x860~0x86f [16 bytes] + u32 rfintfe; // output enable: // 0x860~0x86f [16 bytes] + u32 rf3wireOffset; // LSSI data: // 0x840~0x84f [16 bytes] + u32 rfLSSI_Select; // BB Band Select: // 0x878~0x87f [8 bytes] u32 rfTxGainStage; // Tx gain stage: // 0x80c~0x80f [4 bytes] - u32 rfHSSIPara1; // wire parameter control1 : // 0x820~0x823,0x828~0x82b, 0x830~0x833, 0x838~0x83b [16 bytes] - u32 rfHSSIPara2; // wire parameter control2 : // 0x824~0x827,0x82c~0x82f, 0x834~0x837, 0x83c~0x83f [16 bytes] - u32 rfSwitchControl; //Tx Rx antenna control : // 0x858~0x85f [16 bytes] - u32 rfAGCControl1; //AGC parameter control1 : // 0xc50~0xc53,0xc58~0xc5b, 0xc60~0xc63, 0xc68~0xc6b [16 bytes] - u32 rfAGCControl2; //AGC parameter control2 : // 0xc54~0xc57,0xc5c~0xc5f, 0xc64~0xc67, 0xc6c~0xc6f [16 bytes] - u32 rfRxIQImbalance; //OFDM Rx IQ imbalance matrix : // 0xc14~0xc17,0xc1c~0xc1f, 0xc24~0xc27, 0xc2c~0xc2f [16 bytes] - u32 rfRxAFE; //Rx IQ DC ofset and Rx digital filter, Rx DC notch filter : // 0xc10~0xc13,0xc18~0xc1b, 0xc20~0xc23, 0xc28~0xc2b [16 bytes] - u32 rfTxIQImbalance; //OFDM Tx IQ imbalance matrix // 0xc80~0xc83,0xc88~0xc8b, 0xc90~0xc93, 0xc98~0xc9b [16 bytes] - u32 rfTxAFE; //Tx IQ DC Offset and Tx DFIR type // 0xc84~0xc87,0xc8c~0xc8f, 0xc94~0xc97, 0xc9c~0xc9f [16 bytes] - u32 rfLSSIReadBack; //LSSI RF readback data // 0x8a0~0x8af [16 bytes] + u32 rfHSSIPara1; // wire parameter control1 : // 0x820~0x823,0x828~0x82b, 0x830~0x833, 0x838~0x83b [16 bytes] + u32 rfHSSIPara2; // wire parameter control2 : // 0x824~0x827,0x82c~0x82f, 0x834~0x837, 0x83c~0x83f [16 bytes] + u32 rfSwitchControl; //Tx Rx antenna control : // 0x858~0x85f [16 bytes] + u32 rfAGCControl1; //AGC parameter control1 : // 0xc50~0xc53,0xc58~0xc5b, 0xc60~0xc63, 0xc68~0xc6b [16 bytes] + u32 rfAGCControl2; //AGC parameter control2 : // 0xc54~0xc57,0xc5c~0xc5f, 0xc64~0xc67, 0xc6c~0xc6f [16 bytes] + u32 rfRxIQImbalance; //OFDM Rx IQ imbalance matrix : // 0xc14~0xc17,0xc1c~0xc1f, 0xc24~0xc27, 0xc2c~0xc2f [16 bytes] + u32 rfRxAFE; //Rx IQ DC ofset and Rx digital filter, Rx DC notch filter : // 0xc10~0xc13,0xc18~0xc1b, 0xc20~0xc23, 0xc28~0xc2b [16 bytes] + u32 rfTxIQImbalance; //OFDM Tx IQ imbalance matrix // 0xc80~0xc83,0xc88~0xc8b, 0xc90~0xc93, 0xc98~0xc9b [16 bytes] + u32 rfTxAFE; //Tx IQ DC Offset and Tx DFIR type // 0xc84~0xc87,0xc8c~0xc8f, 0xc94~0xc97, 0xc9c~0xc9f [16 bytes] + u32 rfLSSIReadBack; //LSSI RF readback data // 0x8a0~0x8af [16 bytes] }BB_REGISTER_DEFINITION_T, *PBB_REGISTER_DEFINITION_T; typedef enum _RT_RF_TYPE_819xU{ @@ -1006,7 +1006,7 @@ typedef struct r8192_priv u8 retry_rts; u16 rts; - struct ChnlAccessSetting ChannelAccessSetting; + struct ChnlAccessSetting ChannelAccessSetting; struct work_struct reset_wq; /**********************************************************/ @@ -1014,7 +1014,7 @@ typedef struct r8192_priv u16 basic_rate; u8 short_preamble; u8 slot_time; - bool bDcut; + bool bDcut; bool bCurrentRxAggrEnable; u8 Rf_Mode; //add for Firmware RF -R/W switch prt_firmware pFirmware; @@ -1050,7 +1050,7 @@ typedef struct r8192_priv //for set channel u8 SwChnlInProgress; - u8 SwChnlStage; + u8 SwChnlStage; u8 SwChnlStep; u8 SetBWModeInProgress; HT_CHANNEL_WIDTH CurrentChannelBW; @@ -1062,8 +1062,8 @@ typedef struct r8192_priv // We save RF reg0 in this variable to reduce RF reading. // u32 RfReg0Value[4]; - u8 NumTotalRFPath; - bool brfpath_rxenable[4]; + u8 NumTotalRFPath; + bool brfpath_rxenable[4]; //RF set related bool SetRFPowerStateInProgress; //+by amy 080507 @@ -1104,7 +1104,7 @@ typedef struct r8192_priv bool btxpower_tracking; bool bcck_in_ch14; bool btxpowerdata_readfromEEPORM; - u16 TSSI_13dBm; + u16 TSSI_13dBm; //For Backup Initial Gain init_gain initgain_backup; u8 DefaultInitialGain[4]; @@ -1114,17 +1114,17 @@ typedef struct r8192_priv bool bis_cur_rdlstate; struct timer_list fsync_timer; bool bfsync_processing; // 500ms Fsync timer is active or not - u32 rate_record; - u32 rateCountDiffRecord; + u32 rate_record; + u32 rateCountDiffRecord; u32 ContinueDiffCount; bool bswitch_fsync; u8 framesync; - u32 framesyncC34; - u8 framesyncMonitor; - //Added by amy 080516 for RX related - u16 nrxAMPDU_size; - u8 nrxAMPDU_aggr_num; + u32 framesyncC34; + u8 framesyncMonitor; + //Added by amy 080516 for RX related + u16 nrxAMPDU_size; + u8 nrxAMPDU_aggr_num; //by amy for gpio bool bHwRadioOff; @@ -1204,7 +1204,7 @@ typedef enum{ #ifdef JOHN_HWSEC struct ssid_thread { struct net_device *dev; - u8 name[IW_ESSID_MAX_SIZE + 1]; + u8 name[IW_ESSID_MAX_SIZE + 1]; }; #endif diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 56367f2..1887dde 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -80,9 +80,9 @@ double __extendsfdf2(float a) {return a;} #include "dot11d.h" //set here to open your trace code. //WB u32 rt_global_debug_component = \ - // COMP_INIT | + // COMP_INIT | // COMP_DBG | - // COMP_EPROM | + // COMP_EPROM | // COMP_PHY | // COMP_RF | // COMP_FIRMWARE | @@ -159,7 +159,7 @@ static struct usb_driver rtl8192_usb_driver = { .resume = rtl8192_resume, /* PM resume fn */ #else .suspend = NULL, /* PM suspend fn */ - .resume = NULL, /* PM resume fn */ + .resume = NULL, /* PM resume fn */ #endif }; @@ -171,11 +171,11 @@ typedef struct _CHANNEL_LIST }CHANNEL_LIST, *PCHANNEL_LIST; static CHANNEL_LIST ChannelPlan[] = { - {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC - {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC - {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI + {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC + {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC + {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI. - {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI. + {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI. {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, //MKK //MKK {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel. @@ -240,7 +240,7 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv) } -#define rx_hal_is_cck_rate(_pdrvinfo)\ +#define rx_hal_is_cck_rate(_pdrvinfo)\ (_pdrvinfo->RxRate == DESC90_RATE1M ||\ _pdrvinfo->RxRate == DESC90_RATE2M ||\ _pdrvinfo->RxRate == DESC90_RATE5_5M ||\ @@ -1272,8 +1272,8 @@ struct sk_buff *DrvAggr_Aggregation(struct net_device *dev, struct ieee80211_drv { struct ieee80211_device *ieee = netdev_priv(dev); struct r8192_priv *priv = ieee80211_priv(dev); - cb_desc *tcb_desc = NULL; - u8 i; + cb_desc *tcb_desc = NULL; + u8 i; u32 TotalLength; struct sk_buff *skb; struct sk_buff *agg_skb; @@ -1444,7 +1444,7 @@ u8 DrvAggr_GetAggregatibleList(struct net_device *dev, struct sk_buff *skb, struct ieee80211_device *ieee = netdev_priv(dev); PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; u16 nMaxAggrNum = pHTInfo->UsbTxAggrNum; - cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); + cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); u8 QueueID = tcb_desc->queue_index; do { @@ -1812,7 +1812,7 @@ short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb) int status; struct urb *tx_urb; //int urb_buf_len; - unsigned int idx_pipe; + unsigned int idx_pipe; tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data; cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); u8 queue_index = tcb_desc->queue_index; @@ -2346,7 +2346,7 @@ void rtl8192_update_beacon(struct work_struct * work) { struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work); struct net_device *dev = priv->ieee80211->dev; - struct ieee80211_device* ieee = priv->ieee80211; + struct ieee80211_device* ieee = priv->ieee80211; struct ieee80211_network* net = &ieee->current_network; if (ieee->pHTInfo->bCurrentHTSupport) @@ -2717,7 +2717,7 @@ static void rtl8192_init_priv_variable(struct net_device* dev) priv->bDisableNormalResetCheck = false; priv->force_reset = false; - priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available. + priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available. priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL; priv->ieee80211->iw_mode = IW_MODE_INFRA; priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN | @@ -2778,11 +2778,11 @@ static void rtl8192_init_priv_variable(struct net_device* dev) #ifdef TO_DO_LIST if(Adapter->bInHctTest) pHalData->ReceiveConfig = pHalData->CSMethod | - RCR_AMF | RCR_ADF | //RCR_AAP | //accept management/data + RCR_AMF | RCR_ADF | //RCR_AAP | //accept management/data //guangan200710 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko. RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC - RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet + RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet ((u32)7<EarlyRxThreshold<EarlyRxThreshold == 7 ? RCR_OnlyErlPkt:0); @@ -2793,7 +2793,7 @@ static void rtl8192_init_priv_variable(struct net_device* dev) RCR_AMF | RCR_ADF | //accept management/data RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko. RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC - //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet + //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet ((u32)7<EarlyRxThreshold<EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0); @@ -3549,7 +3549,7 @@ HalTxCheckStuck819xUsb( ) { struct r8192_priv *priv = ieee80211_priv(dev); - u16 RegTxCounter = read_nic_word(dev, 0x128); + u16 RegTxCounter = read_nic_word(dev, 0x128); bool bStuck = FALSE; RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter); if(priv->TxCounter==RegTxCounter) @@ -3583,14 +3583,14 @@ TxCheckStuck(struct net_device *dev) // spin_lock_irqsave(&priv->ieee80211->lock,flags); for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++) { - if(QueueID == TXCMD_QUEUE) + if(QueueID == TXCMD_QUEUE) continue; #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0)) #else - if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0)) + if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0)) #endif - continue; + continue; bCheckFwTxCnt = true; } @@ -3611,7 +3611,7 @@ TxCheckStuck(struct net_device *dev) bool HalRxCheckStuck819xUsb(struct net_device *dev) { - u16 RegRxCounter = read_nic_word(dev, 0x130); + u16 RegRxCounter = read_nic_word(dev, 0x130); struct r8192_priv *priv = ieee80211_priv(dev); bool bStuck = FALSE; static u8 rx_chk_cnt = 0; @@ -3718,7 +3718,7 @@ rtl819x_ifcheck_resetornot(struct net_device *dev) struct r8192_priv *priv = ieee80211_priv(dev); RESET_TYPE TxResetType = RESET_TYPE_NORESET; RESET_TYPE RxResetType = RESET_TYPE_NORESET; - RT_RF_POWER_STATE rfState; + RT_RF_POWER_STATE rfState; rfState = priv->ieee80211->eRFPowerState; @@ -4006,18 +4006,18 @@ RESET_START: void CAM_read_entry( struct net_device *dev, - u32 iIndex + u32 iIndex ) { - u32 target_command=0; + u32 target_command=0; u32 target_content=0; u8 entry_i=0; u32 ulStatus; s32 i=100; // printk("=======>start read CAM\n"); - for(entry_i=0;entry_i= 3) { - ResetType = rtl819x_ifcheck_resetornot(dev); + ResetType = rtl819x_ifcheck_resetornot(dev); check_reset_cnt = 3; //DbgPrint("Start to check silent reset\n"); } @@ -4418,10 +4418,10 @@ int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) setKey( dev, ipw->u.crypt.idx, ipw->u.crypt.idx, //KeyIndex - ieee->group_key_type, //KeyType - broadcast_addr, //MacAddr + ieee->group_key_type, //KeyType + broadcast_addr, //MacAddr 0, //DefaultKey - key); //KeyContent + key); //KeyContent } } } @@ -4819,7 +4819,7 @@ rtl819x_evm_dbtopercentage( } // // Description: -// We want good-looking for signal strength/quality +// We want good-looking for signal strength/quality // 2007/7/19 01:09, by cosa. // long @@ -5203,7 +5203,7 @@ void TranslateRxSignalStuff819xUsb(struct sk_buff *skb, * Overview: Record the received data rate * * Input: -* struct net_device *dev +* struct net_device *dev * struct ieee80211_rx_stats *stats * * Output: @@ -5581,7 +5581,7 @@ rtl819xusb_process_received_packet( ) { // bool bfreerfd=false, bqueued=false; - u8* frame; + u8* frame; u16 frame_len=0; struct r8192_priv *priv = ieee80211_priv(dev); // u8 index = 0; @@ -6007,7 +6007,7 @@ void setKey( struct net_device *dev, // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo)); } else if(i==1){//MAC - TargetContent = (u32)(*(MacAddr+2)) | + TargetContent = (u32)(*(MacAddr+2)) | (u32)(*(MacAddr+3)) << 8| (u32)(*(MacAddr+4)) << 16| (u32)(*(MacAddr+5)) << 24; diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c index cd8dc85..7e2918f 100644 --- a/drivers/staging/rtl8192u/r8192U_dm.c +++ b/drivers/staging/rtl8192u/r8192U_dm.c @@ -8,7 +8,7 @@ Abstract: HW dynamic mechanism. Major Change History: - When Who What + When Who What ---------- --------------- ------------------------------- 2008-05-14 amy create version 0 porting from windows code. @@ -25,9 +25,9 @@ Major Change History: // Indicate different AP vendor for IOT issue. // static u32 edca_setting_DL[HT_IOT_PEER_MAX] = - { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5ea44f}; + { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5ea44f}; static u32 edca_setting_UL[HT_IOT_PEER_MAX] = - { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f}; + { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f}; #define RTK_UL_EDCA 0xa44f @@ -134,7 +134,7 @@ static void dm_check_pbc_gpio(struct net_device *dev); // DM --> Check current RX RF path state static void dm_check_rx_path_selection(struct net_device *dev); -static void dm_init_rxpath_selection(struct net_device *dev); +static void dm_init_rxpath_selection(struct net_device *dev); static void dm_rxpath_sel_byrssi(struct net_device *dev); @@ -259,7 +259,7 @@ extern void hal_dm_watchdog(struct net_device *dev) { //struct r8192_priv *priv = ieee80211_priv(dev); - //static u8 previous_bssid[6] ={0}; + //static u8 previous_bssid[6] ={0}; /*Add by amy 2008/05/15 ,porting from windows code.*/ dm_check_rate_adaptive(dev); @@ -315,21 +315,21 @@ extern void init_rate_adaptive(struct net_device * dev) { // 07/10/08 MH Modify for RA smooth scheme. /* 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.*/ - pra->upper_rssi_threshold_ratr = 0x8f0f0000; - pra->middle_rssi_threshold_ratr = 0x8f0ff000; - pra->low_rssi_threshold_ratr = 0x8f0ff001; - pra->low_rssi_threshold_ratr_40M = 0x8f0ff005; - pra->low_rssi_threshold_ratr_20M = 0x8f0ff001; - pra->ping_rssi_ratr = 0x0000000d;//cosa add for test + pra->upper_rssi_threshold_ratr = 0x8f0f0000; + pra->middle_rssi_threshold_ratr = 0x8f0ff000; + pra->low_rssi_threshold_ratr = 0x8f0ff001; + pra->low_rssi_threshold_ratr_40M = 0x8f0ff005; + pra->low_rssi_threshold_ratr_20M = 0x8f0ff001; + pra->ping_rssi_ratr = 0x0000000d;//cosa add for test } else if (priv->rf_type == RF_1T2R) { - pra->upper_rssi_threshold_ratr = 0x000f0000; - pra->middle_rssi_threshold_ratr = 0x000ff000; - pra->low_rssi_threshold_ratr = 0x000ff001; - pra->low_rssi_threshold_ratr_40M = 0x000ff005; - pra->low_rssi_threshold_ratr_20M = 0x000ff001; - pra->ping_rssi_ratr = 0x0000000d;//cosa add for test + pra->upper_rssi_threshold_ratr = 0x000f0000; + pra->middle_rssi_threshold_ratr = 0x000ff000; + pra->low_rssi_threshold_ratr = 0x000ff001; + pra->low_rssi_threshold_ratr_40M = 0x000ff005; + pra->low_rssi_threshold_ratr_20M = 0x000ff001; + pra->ping_rssi_ratr = 0x0000000d;//cosa add for test } } // InitRateAdaptive @@ -348,7 +348,7 @@ extern void init_rate_adaptive(struct net_device * dev) * * Revised History: * When Who Remark - * 05/26/08 amy Create version 0 porting from windows code. + * 05/26/08 amy Create version 0 porting from windows code. * *---------------------------------------------------------------------------*/ static void dm_check_rate_adaptive(struct net_device * dev) @@ -413,14 +413,14 @@ static void dm_check_rate_adaptive(struct net_device * dev) to prevent jumping frequently. */ if (pra->ratr_state == DM_RATR_STA_HIGH) { - HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra; + HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra; LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)? (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M); } else if (pra->ratr_state == DM_RATR_STA_LOW) { HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra; - LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)? + LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)? (pra->low2high_rssi_thresh_for_ra40M):(pra->low2high_rssi_thresh_for_ra20M); } else @@ -599,7 +599,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device * dev) u32 Value; u8 Pwr_Flag; u16 Avg_TSSI_Meas, TSSI_13dBm, Avg_TSSI_Meas_from_driver=0; - //RT_STATUS rtStatus = RT_STATUS_SUCCESS; + //RT_STATUS rtStatus = RT_STATUS_SUCCESS; bool rtStatus = true; u32 delta=0; @@ -954,79 +954,79 @@ static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev) struct r8192_priv *priv = ieee80211_priv(dev); //Initial the Tx BB index and mapping value - priv->txbbgain_table[0].txbb_iq_amplifygain = 12; + priv->txbbgain_table[0].txbb_iq_amplifygain = 12; priv->txbbgain_table[0].txbbgain_value=0x7f8001fe; - priv->txbbgain_table[1].txbb_iq_amplifygain = 11; + priv->txbbgain_table[1].txbb_iq_amplifygain = 11; priv->txbbgain_table[1].txbbgain_value=0x788001e2; - priv->txbbgain_table[2].txbb_iq_amplifygain = 10; + priv->txbbgain_table[2].txbb_iq_amplifygain = 10; priv->txbbgain_table[2].txbbgain_value=0x71c001c7; - priv->txbbgain_table[3].txbb_iq_amplifygain = 9; + priv->txbbgain_table[3].txbb_iq_amplifygain = 9; priv->txbbgain_table[3].txbbgain_value=0x6b8001ae; - priv->txbbgain_table[4].txbb_iq_amplifygain = 8; + priv->txbbgain_table[4].txbb_iq_amplifygain = 8; priv->txbbgain_table[4].txbbgain_value=0x65400195; - priv->txbbgain_table[5].txbb_iq_amplifygain = 7; + priv->txbbgain_table[5].txbb_iq_amplifygain = 7; priv->txbbgain_table[5].txbbgain_value=0x5fc0017f; - priv->txbbgain_table[6].txbb_iq_amplifygain = 6; + priv->txbbgain_table[6].txbb_iq_amplifygain = 6; priv->txbbgain_table[6].txbbgain_value=0x5a400169; - priv->txbbgain_table[7].txbb_iq_amplifygain = 5; + priv->txbbgain_table[7].txbb_iq_amplifygain = 5; priv->txbbgain_table[7].txbbgain_value=0x55400155; - priv->txbbgain_table[8].txbb_iq_amplifygain = 4; + priv->txbbgain_table[8].txbb_iq_amplifygain = 4; priv->txbbgain_table[8].txbbgain_value=0x50800142; - priv->txbbgain_table[9].txbb_iq_amplifygain = 3; + priv->txbbgain_table[9].txbb_iq_amplifygain = 3; priv->txbbgain_table[9].txbbgain_value=0x4c000130; - priv->txbbgain_table[10].txbb_iq_amplifygain = 2; + priv->txbbgain_table[10].txbb_iq_amplifygain = 2; priv->txbbgain_table[10].txbbgain_value=0x47c0011f; - priv->txbbgain_table[11].txbb_iq_amplifygain = 1; + priv->txbbgain_table[11].txbb_iq_amplifygain = 1; priv->txbbgain_table[11].txbbgain_value=0x43c0010f; - priv->txbbgain_table[12].txbb_iq_amplifygain = 0; + priv->txbbgain_table[12].txbb_iq_amplifygain = 0; priv->txbbgain_table[12].txbbgain_value=0x40000100; - priv->txbbgain_table[13].txbb_iq_amplifygain = -1; + priv->txbbgain_table[13].txbb_iq_amplifygain = -1; priv->txbbgain_table[13].txbbgain_value=0x3c8000f2; - priv->txbbgain_table[14].txbb_iq_amplifygain = -2; + priv->txbbgain_table[14].txbb_iq_amplifygain = -2; priv->txbbgain_table[14].txbbgain_value=0x390000e4; - priv->txbbgain_table[15].txbb_iq_amplifygain = -3; + priv->txbbgain_table[15].txbb_iq_amplifygain = -3; priv->txbbgain_table[15].txbbgain_value=0x35c000d7; - priv->txbbgain_table[16].txbb_iq_amplifygain = -4; + priv->txbbgain_table[16].txbb_iq_amplifygain = -4; priv->txbbgain_table[16].txbbgain_value=0x32c000cb; - priv->txbbgain_table[17].txbb_iq_amplifygain = -5; + priv->txbbgain_table[17].txbb_iq_amplifygain = -5; priv->txbbgain_table[17].txbbgain_value=0x300000c0; - priv->txbbgain_table[18].txbb_iq_amplifygain = -6; + priv->txbbgain_table[18].txbb_iq_amplifygain = -6; priv->txbbgain_table[18].txbbgain_value=0x2d4000b5; - priv->txbbgain_table[19].txbb_iq_amplifygain = -7; + priv->txbbgain_table[19].txbb_iq_amplifygain = -7; priv->txbbgain_table[19].txbbgain_value=0x2ac000ab; - priv->txbbgain_table[20].txbb_iq_amplifygain = -8; + priv->txbbgain_table[20].txbb_iq_amplifygain = -8; priv->txbbgain_table[20].txbbgain_value=0x288000a2; - priv->txbbgain_table[21].txbb_iq_amplifygain = -9; + priv->txbbgain_table[21].txbb_iq_amplifygain = -9; priv->txbbgain_table[21].txbbgain_value=0x26000098; - priv->txbbgain_table[22].txbb_iq_amplifygain = -10; + priv->txbbgain_table[22].txbb_iq_amplifygain = -10; priv->txbbgain_table[22].txbbgain_value=0x24000090; - priv->txbbgain_table[23].txbb_iq_amplifygain = -11; + priv->txbbgain_table[23].txbb_iq_amplifygain = -11; priv->txbbgain_table[23].txbbgain_value=0x22000088; - priv->txbbgain_table[24].txbb_iq_amplifygain = -12; + priv->txbbgain_table[24].txbb_iq_amplifygain = -12; priv->txbbgain_table[24].txbbgain_value=0x20000080; - priv->txbbgain_table[25].txbb_iq_amplifygain = -13; + priv->txbbgain_table[25].txbb_iq_amplifygain = -13; priv->txbbgain_table[25].txbbgain_value=0x1a00006c; - priv->txbbgain_table[26].txbb_iq_amplifygain = -14; + priv->txbbgain_table[26].txbb_iq_amplifygain = -14; priv->txbbgain_table[26].txbbgain_value=0x1c800072; - priv->txbbgain_table[27].txbb_iq_amplifygain = -15; + priv->txbbgain_table[27].txbb_iq_amplifygain = -15; priv->txbbgain_table[27].txbbgain_value=0x18000060; - priv->txbbgain_table[28].txbb_iq_amplifygain = -16; + priv->txbbgain_table[28].txbb_iq_amplifygain = -16; priv->txbbgain_table[28].txbbgain_value=0x19800066; - priv->txbbgain_table[29].txbb_iq_amplifygain = -17; + priv->txbbgain_table[29].txbb_iq_amplifygain = -17; priv->txbbgain_table[29].txbbgain_value=0x15800056; - priv->txbbgain_table[30].txbb_iq_amplifygain = -18; + priv->txbbgain_table[30].txbb_iq_amplifygain = -18; priv->txbbgain_table[30].txbbgain_value=0x26c0005b; - priv->txbbgain_table[31].txbb_iq_amplifygain = -19; + priv->txbbgain_table[31].txbb_iq_amplifygain = -19; priv->txbbgain_table[31].txbbgain_value=0x14400051; - priv->txbbgain_table[32].txbb_iq_amplifygain = -20; + priv->txbbgain_table[32].txbb_iq_amplifygain = -20; priv->txbbgain_table[32].txbbgain_value=0x24400051; - priv->txbbgain_table[33].txbb_iq_amplifygain = -21; + priv->txbbgain_table[33].txbb_iq_amplifygain = -21; priv->txbbgain_table[33].txbbgain_value=0x1300004c; - priv->txbbgain_table[34].txbb_iq_amplifygain = -22; + priv->txbbgain_table[34].txbb_iq_amplifygain = -22; priv->txbbgain_table[34].txbbgain_value=0x12000048; - priv->txbbgain_table[35].txbb_iq_amplifygain = -23; + priv->txbbgain_table[35].txbb_iq_amplifygain = -23; priv->txbbgain_table[35].txbbgain_value=0x11000044; - priv->txbbgain_table[36].txbb_iq_amplifygain = -24; + priv->txbbgain_table[36].txbb_iq_amplifygain = -24; priv->txbbgain_table[36].txbbgain_value=0x10000040; //ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29 @@ -1505,7 +1505,7 @@ static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev) static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u8 TM_Trigger=0; + static u8 TM_Trigger=0; //DbgPrint("dm_CheckTXPowerTracking() \n"); if(!priv->btxpower_tracking) return; @@ -1564,40 +1564,40 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14) TempVal = 0; if(!bInCH14){ //Write 0xa22 0xa23 - TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] + + TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] + (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ; rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal); //Write 0xa24 ~ 0xa27 TempVal = 0; - TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + + TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) + (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+ (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24); rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal); //Write 0xa28 0xa29 TempVal = 0; - TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + + TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ; rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal); } else { - TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] + + TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] + (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ; rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal); //Write 0xa24 ~ 0xa27 TempVal = 0; - TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + + TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) + (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+ (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24); rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal); //Write 0xa28 0xa29 TempVal = 0; - TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + + TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ; rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal); @@ -1615,14 +1615,14 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH if(!bInCH14) { //Write 0xa22 0xa23 - TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] + + TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] + (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1]<<8) ; rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_TxFilter1, TempVal); //Write 0xa24 ~ 0xa27 TempVal = 0; - TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] + + TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] + (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) + (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16 )+ (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5]<<24); @@ -1631,7 +1631,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH rCCK0_TxFilter2, TempVal); //Write 0xa28 0xa29 TempVal = 0; - TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] + + TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] + (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ; rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); @@ -1642,7 +1642,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH { // priv->CCKTxPowerAdjustCntNotCh14++; //cosa add for debug. //Write 0xa22 0xa23 - TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] + + TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] + (CCKSwingTable_Ch14[priv->CCK_index][1]<<8) ; rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); @@ -1650,7 +1650,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH rCCK0_TxFilter1, TempVal); //Write 0xa24 ~ 0xa27 TempVal = 0; - TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] + + TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] + (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) + (CCKSwingTable_Ch14[priv->CCK_index][4]<<16 )+ (CCKSwingTable_Ch14[priv->CCK_index][5]<<24); @@ -1659,7 +1659,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH rCCK0_TxFilter2, TempVal); //Write 0xa28 0xa29 TempVal = 0; - TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] + + TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] + (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ; rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); @@ -1713,7 +1713,7 @@ static void dm_txpower_reset_recovery( extern void dm_restore_dynamic_mechanism_state(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); - u32 reg_ratr = priv->rate_adaptive.last_ratr; + u32 reg_ratr = priv->rate_adaptive.last_ratr; if(!priv->up) { @@ -1934,7 +1934,7 @@ dm_change_rxpath_selection_setting( s32 DM_Value) { struct r8192_priv *priv = ieee80211_priv(dev); - prate_adaptive pRA = (prate_adaptive)&(priv->rate_adaptive); + prate_adaptive pRA = (prate_adaptive)&(priv->rate_adaptive); if(DM_Type == 0) @@ -2036,8 +2036,8 @@ static void dm_dig_init(struct net_device *dev) dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX; dm_digtable.initialgain_lowerbound_state = false; - dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW; - dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH; + dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW; + dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH; dm_digtable.rssi_high_power_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW; dm_digtable.rssi_high_power_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH; @@ -2091,7 +2091,7 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi( { struct r8192_priv *priv = ieee80211_priv(dev); u8 i; - static u8 fw_dig=0; + static u8 fw_dig=0; if (dm_digtable.dig_enable_flag == false) return; @@ -2871,7 +2871,7 @@ static void dm_check_rfctrl_gpio(struct net_device * dev) * * Revised History: * When Who Remark - * 05/28/2008 amy Create Version 0 porting from windows code. + * 05/28/2008 amy Create Version 0 porting from windows code. * *---------------------------------------------------------------------------*/ static void dm_check_pbc_gpio(struct net_device *dev) @@ -3517,8 +3517,8 @@ static void dm_EndSWFsync(struct net_device *dev) static void dm_StartSWFsync(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); - u32 rateIndex; - u32 rateBitmap; + u32 rateIndex; + u32 rateBitmap; RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__); // Initial rate record to zero, start to record. @@ -3569,7 +3569,7 @@ void dm_check_fsync(struct net_device *dev) #define RegC38_NonFsync_Other_AP 1 #define RegC38_Fsync_AP_BCM 2 struct r8192_priv *priv = ieee80211_priv(dev); - //u32 framesyncC34; + //u32 framesyncC34; static u8 reg_c38_State=RegC38_Default; static u32 reset_cnt=0; @@ -3887,4 +3887,3 @@ static void dm_send_rssi_tofw(struct net_device *dev) } /*---------------------------Define function prototype------------------------*/ - diff --git a/drivers/staging/rtl8192u/r8192U_dm.h b/drivers/staging/rtl8192u/r8192U_dm.h index 3ceb59b..8a96e9f 100644 --- a/drivers/staging/rtl8192u/r8192U_dm.h +++ b/drivers/staging/rtl8192u/r8192U_dm.h @@ -13,7 +13,7 @@ * * History: * Data Who Remark - * 10/04/2007 MHC Create initial version. + * 10/04/2007 MHC Create initial version. * *****************************************************************************/ /* Check to see if the file has been included already. */ @@ -55,12 +55,12 @@ #define TX_POWER_NEAR_FIELD_THRESH_LOW 62 //added by amy for atheros AP #define TX_POWER_ATHEROAP_THRESH_HIGH 78 -#define TX_POWER_ATHEROAP_THRESH_LOW 72 +#define TX_POWER_ATHEROAP_THRESH_LOW 72 //defined by vivi, for showing on UI -#define Current_Tx_Rate_Reg 0x1b8 -#define Initial_Tx_Rate_Reg 0x1b9 -#define Tx_Retry_Count_Reg 0x1ac +#define Current_Tx_Rate_Reg 0x1b8 +#define Initial_Tx_Rate_Reg 0x1b9 +#define Tx_Retry_Count_Reg 0x1ac #define RegC38_TH 20 /*--------------------------Define Parameters-------------------------------*/ @@ -132,8 +132,8 @@ typedef enum tag_dynamic_init_gain_operation_type_definition DIG_TYPE_PWDB_FACTOR = 8, DIG_TYPE_RX_GAIN_MIN = 9, DIG_TYPE_RX_GAIN_MAX = 10, - DIG_TYPE_ENABLE = 20, - DIG_TYPE_DISABLE = 30, + DIG_TYPE_ENABLE = 20, + DIG_TYPE_DISABLE = 30, DIG_OP_TYPE_MAX }dm_dig_op_e; @@ -251,4 +251,3 @@ extern void dm_initialize_txpower_tracking(struct net_device *dev); /* End of r8192U_dm.h */ - diff --git a/drivers/staging/rtl8192u/r8192U_hw.h b/drivers/staging/rtl8192u/r8192U_hw.h index 1bfe871..15b0423 100644 --- a/drivers/staging/rtl8192u/r8192U_hw.h +++ b/drivers/staging/rtl8192u/r8192U_hw.h @@ -122,7 +122,7 @@ enum _RTL8192Usb_HW { SIFS = 0x03E, // SIFS register TCR = 0x040, // Transmit Configuration Register -#define TCR_MXDMA_2048 7 +#define TCR_MXDMA_2048 7 #define TCR_LRL_OFFSET 0 #define TCR_SRL_OFFSET 8 #define TCR_MXDMA_OFFSET 21 @@ -379,7 +379,7 @@ enum _RTL8192Usb_HW { // IMR_POLL = 0x360, MacBlkCtrl = 0x403, // Mac block on/off control register - EPROM_CMD = 0xfe58, + EPROM_CMD = 0xfe58, #define Cmd9346CR_9356SEL (1<<4) #define EPROM_CMD_RESERVED_MASK (1<<5) #define EPROM_CMD_OPERATING_MODE_SHIFT 6 @@ -392,12 +392,12 @@ enum _RTL8192Usb_HW { #define EPROM_CK_SHIFT 2 #define EPROM_W_SHIFT 1 #define EPROM_R_SHIFT 0 - MAC0 = 0x000, - MAC1 = 0x001, - MAC2 = 0x002, - MAC3 = 0x003, - MAC4 = 0x004, - MAC5 = 0x005, + MAC0 = 0x000, + MAC1 = 0x001, + MAC2 = 0x002, + MAC3 = 0x003, + MAC4 = 0x004, + MAC5 = 0x005, }; //---------------------------------------------------------------------------- diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c index 71f2d23..6df5f75 100644 --- a/drivers/staging/rtl8192u/r8192U_wx.c +++ b/drivers/staging/rtl8192u/r8192U_wx.c @@ -1021,7 +1021,7 @@ static int dummy(struct net_device *dev, struct iw_request_info *a, static iw_handler r8192_wx_handlers[] = { NULL, /* SIOCSIWCOMMIT */ - r8192_wx_get_name, /* SIOCGIWNAME */ + r8192_wx_get_name, /* SIOCGIWNAME */ dummy, /* SIOCSIWNWID */ dummy, /* SIOCGIWNWID */ r8192_wx_set_freq, /* SIOCSIWFREQ */ @@ -1040,7 +1040,7 @@ static iw_handler r8192_wx_handlers[] = dummy, /* SIOCGIWSPY */ NULL, /* SIOCGIWTHRSPY */ NULL, /* SIOCWIWTHRSPY */ - r8192_wx_set_wap, /* SIOCSIWAP */ + r8192_wx_set_wap, /* SIOCSIWAP */ r8192_wx_get_wap, /* SIOCGIWAP */ #if (WIRELESS_EXT >= 18) r8192_wx_set_mlme, /* MLME-- */ @@ -1071,23 +1071,23 @@ static iw_handler r8192_wx_handlers[] = r8192_wx_set_power, /* SIOCSIWPOWER */ r8192_wx_get_power, /* SIOCGIWPOWER */ NULL, /*---hole---*/ - NULL, /*---hole---*/ - r8192_wx_set_gen_ie,//NULL, /* SIOCSIWGENIE */ - NULL, /* SIOCSIWGENIE */ + NULL, /*---hole---*/ + r8192_wx_set_gen_ie,//NULL, /* SIOCSIWGENIE */ + NULL, /* SIOCSIWGENIE */ #if (WIRELESS_EXT >= 18) - r8192_wx_set_auth,//NULL, /* SIOCSIWAUTH */ - NULL,//r8192_wx_get_auth,//NULL, /* SIOCSIWAUTH */ - r8192_wx_set_enc_ext, /* SIOCSIWENCODEEXT */ - NULL,//r8192_wx_get_enc_ext,//NULL, /* SIOCSIWENCODEEXT */ + r8192_wx_set_auth,//NULL, /* SIOCSIWAUTH */ + NULL,//r8192_wx_get_auth,//NULL, /* SIOCSIWAUTH */ + r8192_wx_set_enc_ext, /* SIOCSIWENCODEEXT */ + NULL,//r8192_wx_get_enc_ext,//NULL, /* SIOCSIWENCODEEXT */ #else NULL, NULL, NULL, NULL, #endif - NULL, /* SIOCSIWPMKSA */ - NULL, /*---hole---*/ + NULL, /* SIOCSIWPMKSA */ + NULL, /*---hole---*/ }; diff --git a/drivers/staging/rtl8192u/r819xU_HTGen.h b/drivers/staging/rtl8192u/r819xU_HTGen.h index f37b6d6..6a4678f 100644 --- a/drivers/staging/rtl8192u/r819xU_HTGen.h +++ b/drivers/staging/rtl8192u/r819xU_HTGen.h @@ -10,4 +10,3 @@ typedef enum _HT_IOT_ACTION{ HT_IOT_ACT_CDD_FSYNC = 0x00000020, HT_IOT_ACT_PURE_N_MODE = 0x00000040, }HT_IOT_ACTION_E, *PHT_IOT_ACTION_E; - diff --git a/drivers/staging/rtl8192u/r819xU_HTType.h b/drivers/staging/rtl8192u/r819xU_HTType.h index 6c1d05e..19a7bdd 100644 --- a/drivers/staging/rtl8192u/r819xU_HTType.h +++ b/drivers/staging/rtl8192u/r819xU_HTType.h @@ -89,7 +89,7 @@ typedef enum _CHNLOP{ typedef enum _HT_ACTION{ ACT_RECOMMAND_WIDTH = 0, - ACT_MIMO_PWR_SAVE = 1, + ACT_MIMO_PWR_SAVE = 1, ACT_PSMP = 2, ACT_SET_PCO_PHASE = 3, ACT_MIMO_CHL_MEASURE = 4, @@ -367,9 +367,9 @@ typedef struct _BSS_HT{ typedef struct _MIMO_RSSI{ u32 EnableAntenna; u32 AntennaA; - u32 AntennaB; - u32 AntennaC; - u32 AntennaD; + u32 AntennaB; + u32 AntennaC; + u32 AntennaD; u32 Average; }MIMO_RSSI, *PMIMO_RSSI; @@ -388,4 +388,3 @@ typedef struct _FALSE_ALARM_STATISTICS{ #endif //__INC_HTTYPE_H - diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.c b/drivers/staging/rtl8192u/r819xU_cmdpkt.c index a8a6dc2..b755eb4 100644 --- a/drivers/staging/rtl8192u/r819xU_cmdpkt.c +++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.c @@ -18,7 +18,7 @@ History: Data Who Remark - 05/06/2008 amy Create initial version porting from windows driver. + 05/06/2008 amy Create initial version porting from windows driver. ******************************************************************************/ #include "r8192U.h" @@ -41,7 +41,7 @@ rt_status SendTxCommandPacket( struct net_device *dev, - void* pData, + void* pData, u32 DataLen ) { @@ -106,7 +106,7 @@ SendTxCommandPacket( u32 buffer_len) { - bool rt_status = true; + bool rt_status = true; #ifdef RTL8192U return rt_status; #else @@ -188,7 +188,7 @@ SendTxCommandPacket( * * Overview: * - * Input: PADAPTER pAdapter - . + * Input: PADAPTER pAdapter - . * CMPK_TXFB_T *psTx_FB - . * * Output: NONE @@ -197,7 +197,7 @@ SendTxCommandPacket( * * Revised History: * When Who Remark - * 05/12/2008 amy Create Version 0 porting from windows code. + * 05/12/2008 amy Create Version 0 porting from windows code. * *---------------------------------------------------------------------------*/ static void @@ -289,7 +289,7 @@ cmpk_count_txstatistic( * in the command packet. * * Input: struct net_device * dev - * u8 * pmsg - Msg Ptr of the command packet. + * u8 * pmsg - Msg Ptr of the command packet. * * Output: NONE * @@ -369,7 +369,7 @@ cmdpkt_beacontimerinterrupt_819xusb( * Overview: The function is responsible for extract the message from * firmware. It will contain dedicated info in * ws-07-0063-v06-rtl819x-command-packet-specification-070315.doc. - * Please refer to chapter "Interrupt Status Element". + * Please refer to chapter "Interrupt Status Element". * * Input: struct net_device *dev, * u8* pmsg - Message Pointer of the command packet. @@ -400,8 +400,8 @@ cmpk_handle_interrupt_status( /* It seems that FW use big endian(MIPS) and DRV use little endian in windows OS. So we have to read the content byte by byte or transfer endian type before copy the message copy. */ - //rx_bcn_state.Element_ID = pMsg[0]; - //rx_bcn_state.Length = pMsg[1]; + //rx_bcn_state.Element_ID = pMsg[0]; + //rx_bcn_state.Length = pMsg[1]; rx_intr_status.length = pmsg[1]; if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2)) { @@ -478,16 +478,16 @@ cmpk_handle_query_config_rx( /* It seems that FW use big endian(MIPS) and DRV use little endian in windows OS. So we have to read the content byte by byte or transfer endian type before copy the message copy. */ - //rx_query_cfg.Element_ID = pMsg[0]; - //rx_query_cfg.Length = pMsg[1]; - rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000)>>31; - rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5; - rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3; - rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0; - rx_query_cfg.cfg_offset = pmsg[7]; - rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) | + //rx_query_cfg.Element_ID = pMsg[0]; + //rx_query_cfg.Length = pMsg[1]; + rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000)>>31; + rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5; + rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3; + rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0; + rx_query_cfg.cfg_offset = pmsg[7]; + rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) | (pmsg[10] << 8) | (pmsg[11] << 0); - rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) | + rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) | (pmsg[14] << 8) | (pmsg[15] << 0); } /* cmpk_Handle_Query_Config_Rx */ @@ -511,7 +511,7 @@ cmpk_handle_query_config_rx( * *---------------------------------------------------------------------------*/ static void cmpk_count_tx_status( struct net_device *dev, - cmpk_tx_status_t *pstx_status) + cmpk_tx_status_t *pstx_status) { struct r8192_priv *priv = ieee80211_priv(dev); diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.h b/drivers/staging/rtl8192u/r819xU_cmdpkt.h index a8855e6..fbbd270 100644 --- a/drivers/staging/rtl8192u/r819xU_cmdpkt.h +++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.h @@ -72,7 +72,7 @@ typedef struct tag_cmd_pkt_set_configuration u8 element_id; /* Command packet type. */ u8 length; /* Command packet length. */ u16 reserve1; /* */ - u8 cfg_reserve1:3; + u8 cfg_reserve1:3; u8 cfg_size:2; /* Configuration info. */ u8 cfg_type:2; /* Configuration info. */ u8 cfg_action:1; /* Configuration info. */ @@ -94,20 +94,20 @@ typedef struct tag_tx_stats_feedback // PJ quick rxcmd 09042007 // For endian transfer --> Driver will not the same as firmware structure. // DW 0 u16 reserve1; - u8 length; // Command packet length - u8 element_id; // Command packet type + u8 length; // Command packet length + u8 element_id; // Command packet type // DW 1 u16 txfail; // Tx Fail count - u16 txok; // Tx ok count + u16 txok; // Tx ok count // DW 2 - u16 txmcok; // tx multicast - u16 txretry; // Tx Retry count + u16 txmcok; // tx multicast + u16 txretry; // Tx Retry count // DW 3 u16 txucok; // tx unicast - u16 txbcok; // tx broadcast + u16 txbcok; // tx broadcast // DW 4 u16 txbcfail; // @@ -135,8 +135,8 @@ typedef struct tag_rx_debug_message_feedback // For endian transfer --> for driver // DW 0 u16 reserve1; - u8 length; // Command packet length - u8 element_id; // Command packet type + u8 length; // Command packet length + u8 element_id; // Command packet type // DW 1-?? // Variable debug message. @@ -148,15 +148,15 @@ typedef struct tag_tx_rate_history { // For endian transfer --> for driver // DW 0 - u8 element_id; // Command packet type - u8 length; // Command packet length + u8 element_id; // Command packet type + u8 length; // Command packet length u16 reserved1; // DW 1-2 CCK rate counter - u16 cck[4]; + u16 cck[4]; // DW 3-6 - u16 ofdm[8]; + u16 ofdm[8]; // DW 7-14 //UINT16 MCS_BW0_SG0[16]; diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c index b12d190..46b8043 100644 --- a/drivers/staging/rtl8192u/r819xU_firmware.c +++ b/drivers/staging/rtl8192u/r819xU_firmware.c @@ -2,7 +2,7 @@ * Procedure: Init boot code/firmware code/data session * * Description: This routine will initialize firmware. If any error occurs during the initialization - * process, the routine shall terminate immediately and return fail. + * process, the routine shall terminate immediately and return fail. * NIC driver should call NdisOpenFile only from MiniportInitialize. * * Arguments: The pointer of the adapter @@ -19,7 +19,7 @@ #include void firmware_init_param(struct net_device *dev) { - struct r8192_priv *priv = ieee80211_priv(dev); + struct r8192_priv *priv = ieee80211_priv(dev); rt_firmware *pfirmware = priv->pFirmware; pfirmware->cmdpacket_frag_thresold = GET_COMMAND_PACKET_FRAG_THRESHOLD(MAX_TRANSMIT_BUFFER_SIZE); @@ -32,7 +32,7 @@ void firmware_init_param(struct net_device *dev) bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, u32 buffer_len) { struct r8192_priv *priv = ieee80211_priv(dev); - bool rt_status = true; + bool rt_status = true; u16 frag_threshold; u16 frag_length, frag_offset = 0; //u16 total_size; @@ -241,17 +241,17 @@ CPUCheckFirmwareReady_Fail: bool init_firmware(struct net_device *dev) { - struct r8192_priv *priv = ieee80211_priv(dev); + struct r8192_priv *priv = ieee80211_priv(dev); bool rt_status = TRUE; u32 file_length = 0; u8 *mapped_file = NULL; u32 init_step = 0; opt_rst_type_e rst_opt = OPT_SYSTEM_RESET; - firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT; + firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT; rt_firmware *pfirmware = priv->pFirmware; - const struct firmware *fw_entry; + const struct firmware *fw_entry; const char *fw_name[3] = { "RTL8192U/boot.img", "RTL8192U/main.img", "RTL8192U/data.img"}; @@ -402,4 +402,3 @@ download_firmware_fail: MODULE_FIRMWARE("RTL8192U/boot.img"); MODULE_FIRMWARE("RTL8192U/main.img"); MODULE_FIRMWARE("RTL8192U/data.img"); - diff --git a/drivers/staging/rtl8192u/r819xU_firmware.h b/drivers/staging/rtl8192u/r819xU_firmware.h index a4bceeef..c48c884 100644 --- a/drivers/staging/rtl8192u/r819xU_firmware.h +++ b/drivers/staging/rtl8192u/r819xU_firmware.h @@ -24,4 +24,3 @@ typedef enum _opt_rst_type{ }opt_rst_type_e; #endif - diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c index dd1954d..2ff851f 100644 --- a/drivers/staging/rtl8192u/r819xU_phy.c +++ b/drivers/staging/rtl8192u/r819xU_phy.c @@ -124,10 +124,10 @@ static void phy_FwRFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E /****************************************************************************** *function: This function read register from RF chip * input: net_device dev - * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D + * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D * u32 Offset //target address to be read * output: none - * return: u32 readback value + * return: u32 readback value * notice: There are three types of serial operations:(1) Software serial write.(2)Hardware LSSI-Low Speed Serial Interface.(3)Hardware HSSI-High speed serial write. Driver here need to implement (1) and (2)---need more spec for this information. * ****************************************************************************/ u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset) @@ -201,7 +201,7 @@ u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, /****************************************************************************** *function: This function write data to RF register * input: net_device dev - * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D + * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D * u32 Offset //target address to be written * u32 Data //The new register data to be written * output: none @@ -283,7 +283,7 @@ void rtl8192_phy_RFSerialWrite(struct net_device* dev, RF90_RADIO_PATH_E eRFPath /****************************************************************************** *function: This function set specific bits to RF register * input: net_device dev - * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D + * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D * u32 RegAddr //target addr to be modified * u32 BitMask //taget bit pos in the addr to be modified * u32 Data //value to be write @@ -684,8 +684,8 @@ void rtl8192_InitBBRFRegDef(struct net_device* dev) /****************************************************************************** *function: This function is to write register and then readback to make sure whether BB and RF is OK * input: net_device dev - * HW90_BLOCK_E CheckBlock - * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF + * HW90_BLOCK_E CheckBlock + * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF * output: none * return: return whether BB and RF is ok(0:OK; 1:Fail) * notice: This function may be removed in the ASIC @@ -1015,7 +1015,7 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E /****************************************************************************** *function: This function set Tx Power of the channel * input: struct net_device *dev - * u8 channel + * u8 channel * output: none * return: none * Note: @@ -1052,7 +1052,7 @@ void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel) /****************************************************************************** *function: This function set RF state on or off * input: struct net_device *dev - * RT_RF_POWER_STATE eRFPowerState //Power State to set + * RT_RF_POWER_STATE eRFPowerState //Power State to set * output: none * return: none * Note: @@ -1183,10 +1183,10 @@ bool rtl8192_SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerS /**************************************************************************************** *function: This function set command table variable(struct SwChnlCmd). - * input: SwChnlCmd* CmdTable //table to be set. - * u32 CmdTableIdx //variable index in table to be set - * u32 CmdTableSz //table size. - * SwChnlCmdID CmdID //command ID to set. + * input: SwChnlCmd* CmdTable //table to be set. + * u32 CmdTableIdx //variable index in table to be set + * u32 CmdTableSz //table size. + * SwChnlCmdID CmdID //command ID to set. * u32 Para1 * u32 Para2 * u32 msDelay @@ -1229,10 +1229,10 @@ u8 rtl8192_phy_SetSwChnlCmdArray( /****************************************************************************** *function: This function set channel step by step * input: struct net_device *dev - * u8 channel - * u8* stage //3 stages - * u8* step // - * u32* delay //whether need to delay + * u8 channel + * u8* stage //3 stages + * u8* step // + * u32* delay //whether need to delay * output: store new stage, step and delay for next step(combine with function above) * return: true if finished, false otherwise * Note: Wait for simpler function to replace it //wb @@ -1386,7 +1386,7 @@ u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8* stage, u /****************************************************************************** *function: This function does actually set channel work * input: struct net_device *dev - * u8 channel + * u8 channel * output: none * return: noin * Note: We should not call this function directly @@ -1427,7 +1427,7 @@ void rtl8192_SwChnl_WorkItem(struct net_device *dev) /****************************************************************************** *function: This function scheduled actual work item to set channel * input: net_device dev - * u8 channel //channel to set + * u8 channel //channel to set * output: none * return: return code show if workitem is scheduled(1:pass, 0:fail) * Note: Delay may be required for RF configuration @@ -1501,12 +1501,12 @@ if (0) //to test current channel from RF reg 0x7. /****************************************************************************** *function: Callback routine of the work item for set bandwidth mode. * input: struct net_device *dev - * HT_CHANNEL_WIDTH Bandwidth //20M or 40M - * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care + * HT_CHANNEL_WIDTH Bandwidth //20M or 40M + * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care * output: none * return: none * Note: I doubt whether SetBWModeInProgress flag is necessary as we can - * test whether current work in the queue or not.//do I? + * test whether current work in the queue or not.//do I? * ***************************************************************************/ void rtl8192_SetBWModeWorkItem(struct net_device *dev) { @@ -1649,12 +1649,12 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev) /****************************************************************************** *function: This function schedules bandwidth switch work. * input: struct net_device *dev - * HT_CHANNEL_WIDTH Bandwidth //20M or 40M - * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care + * HT_CHANNEL_WIDTH Bandwidth //20M or 40M + * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care * output: none * return: none * Note: I doubt whether SetBWModeInProgress flag is necessary as we can - * test whether current work in the queue or not.//do I? + * test whether current work in the queue or not.//do I? * ***************************************************************************/ void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset) { @@ -1770,4 +1770,3 @@ extern void InitialGainOperateWorkItemCallBack(struct work_struct *work) break; } } - diff --git a/drivers/staging/rtl8192u/r819xU_phyreg.h b/drivers/staging/rtl8192u/r819xU_phyreg.h index cca34c0..64285d6 100644 --- a/drivers/staging/rtl8192u/r819xU_phyreg.h +++ b/drivers/staging/rtl8192u/r819xU_phyreg.h @@ -6,185 +6,185 @@ //Register //duplicate register due to connection: RF_Mode, TRxRN, NumOf L-STF //page 1 -#define rPMAC_Reset 0x100 -#define rPMAC_TxStart 0x104 -#define rPMAC_TxLegacySIG 0x108 -#define rPMAC_TxHTSIG1 0x10c -#define rPMAC_TxHTSIG2 0x110 -#define rPMAC_PHYDebug 0x114 -#define rPMAC_TxPacketNum 0x118 -#define rPMAC_TxIdle 0x11c -#define rPMAC_TxMACHeader0 0x120 -#define rPMAC_TxMACHeader1 0x124 -#define rPMAC_TxMACHeader2 0x128 -#define rPMAC_TxMACHeader3 0x12c -#define rPMAC_TxMACHeader4 0x130 -#define rPMAC_TxMACHeader5 0x134 -#define rPMAC_TxDataType 0x138 -#define rPMAC_TxRandomSeed 0x13c -#define rPMAC_CCKPLCPPreamble 0x140 -#define rPMAC_CCKPLCPHeader 0x144 -#define rPMAC_CCKCRC16 0x148 -#define rPMAC_OFDMRxCRC32OK 0x170 -#define rPMAC_OFDMRxCRC32Er 0x174 -#define rPMAC_OFDMRxParityEr 0x178 -#define rPMAC_OFDMRxCRC8Er 0x17c -#define rPMAC_CCKCRxRC16Er 0x180 -#define rPMAC_CCKCRxRC32Er 0x184 -#define rPMAC_CCKCRxRC32OK 0x188 -#define rPMAC_TxStatus 0x18c +#define rPMAC_Reset 0x100 +#define rPMAC_TxStart 0x104 +#define rPMAC_TxLegacySIG 0x108 +#define rPMAC_TxHTSIG1 0x10c +#define rPMAC_TxHTSIG2 0x110 +#define rPMAC_PHYDebug 0x114 +#define rPMAC_TxPacketNum 0x118 +#define rPMAC_TxIdle 0x11c +#define rPMAC_TxMACHeader0 0x120 +#define rPMAC_TxMACHeader1 0x124 +#define rPMAC_TxMACHeader2 0x128 +#define rPMAC_TxMACHeader3 0x12c +#define rPMAC_TxMACHeader4 0x130 +#define rPMAC_TxMACHeader5 0x134 +#define rPMAC_TxDataType 0x138 +#define rPMAC_TxRandomSeed 0x13c +#define rPMAC_CCKPLCPPreamble 0x140 +#define rPMAC_CCKPLCPHeader 0x144 +#define rPMAC_CCKCRC16 0x148 +#define rPMAC_OFDMRxCRC32OK 0x170 +#define rPMAC_OFDMRxCRC32Er 0x174 +#define rPMAC_OFDMRxParityEr 0x178 +#define rPMAC_OFDMRxCRC8Er 0x17c +#define rPMAC_CCKCRxRC16Er 0x180 +#define rPMAC_CCKCRxRC32Er 0x184 +#define rPMAC_CCKCRxRC32OK 0x188 +#define rPMAC_TxStatus 0x18c //page8 -#define rFPGA0_RFMOD 0x800 //RF mode & CCK TxSC -#define rFPGA0_TxInfo 0x804 -#define rFPGA0_PSDFunction 0x808 -#define rFPGA0_TxGainStage 0x80c -#define rFPGA0_RFTiming1 0x810 -#define rFPGA0_RFTiming2 0x814 -//#define rFPGA0_XC_RFTiming 0x818 -//#define rFPGA0_XD_RFTiming 0x81c -#define rFPGA0_XA_HSSIParameter1 0x820 -#define rFPGA0_XA_HSSIParameter2 0x824 -#define rFPGA0_XB_HSSIParameter1 0x828 -#define rFPGA0_XB_HSSIParameter2 0x82c -#define rFPGA0_XC_HSSIParameter1 0x830 -#define rFPGA0_XC_HSSIParameter2 0x834 -#define rFPGA0_XD_HSSIParameter1 0x838 -#define rFPGA0_XD_HSSIParameter2 0x83c -#define rFPGA0_XA_LSSIParameter 0x840 -#define rFPGA0_XB_LSSIParameter 0x844 -#define rFPGA0_XC_LSSIParameter 0x848 -#define rFPGA0_XD_LSSIParameter 0x84c -#define rFPGA0_RFWakeUpParameter 0x850 -#define rFPGA0_RFSleepUpParameter 0x854 -#define rFPGA0_XAB_SwitchControl 0x858 -#define rFPGA0_XCD_SwitchControl 0x85c -#define rFPGA0_XA_RFInterfaceOE 0x860 -#define rFPGA0_XB_RFInterfaceOE 0x864 -#define rFPGA0_XC_RFInterfaceOE 0x868 -#define rFPGA0_XD_RFInterfaceOE 0x86c -#define rFPGA0_XAB_RFInterfaceSW 0x870 -#define rFPGA0_XCD_RFInterfaceSW 0x874 -#define rFPGA0_XAB_RFParameter 0x878 -#define rFPGA0_XCD_RFParameter 0x87c -#define rFPGA0_AnalogParameter1 0x880 -#define rFPGA0_AnalogParameter2 0x884 -#define rFPGA0_AnalogParameter3 0x888 -#define rFPGA0_AnalogParameter4 0x88c -#define rFPGA0_XA_LSSIReadBack 0x8a0 -#define rFPGA0_XB_LSSIReadBack 0x8a4 -#define rFPGA0_XC_LSSIReadBack 0x8a8 -#define rFPGA0_XD_LSSIReadBack 0x8ac -#define rFPGA0_PSDReport 0x8b4 -#define rFPGA0_XAB_RFInterfaceRB 0x8e0 -#define rFPGA0_XCD_RFInterfaceRB 0x8e4 +#define rFPGA0_RFMOD 0x800 //RF mode & CCK TxSC +#define rFPGA0_TxInfo 0x804 +#define rFPGA0_PSDFunction 0x808 +#define rFPGA0_TxGainStage 0x80c +#define rFPGA0_RFTiming1 0x810 +#define rFPGA0_RFTiming2 0x814 +//#define rFPGA0_XC_RFTiming 0x818 +//#define rFPGA0_XD_RFTiming 0x81c +#define rFPGA0_XA_HSSIParameter1 0x820 +#define rFPGA0_XA_HSSIParameter2 0x824 +#define rFPGA0_XB_HSSIParameter1 0x828 +#define rFPGA0_XB_HSSIParameter2 0x82c +#define rFPGA0_XC_HSSIParameter1 0x830 +#define rFPGA0_XC_HSSIParameter2 0x834 +#define rFPGA0_XD_HSSIParameter1 0x838 +#define rFPGA0_XD_HSSIParameter2 0x83c +#define rFPGA0_XA_LSSIParameter 0x840 +#define rFPGA0_XB_LSSIParameter 0x844 +#define rFPGA0_XC_LSSIParameter 0x848 +#define rFPGA0_XD_LSSIParameter 0x84c +#define rFPGA0_RFWakeUpParameter 0x850 +#define rFPGA0_RFSleepUpParameter 0x854 +#define rFPGA0_XAB_SwitchControl 0x858 +#define rFPGA0_XCD_SwitchControl 0x85c +#define rFPGA0_XA_RFInterfaceOE 0x860 +#define rFPGA0_XB_RFInterfaceOE 0x864 +#define rFPGA0_XC_RFInterfaceOE 0x868 +#define rFPGA0_XD_RFInterfaceOE 0x86c +#define rFPGA0_XAB_RFInterfaceSW 0x870 +#define rFPGA0_XCD_RFInterfaceSW 0x874 +#define rFPGA0_XAB_RFParameter 0x878 +#define rFPGA0_XCD_RFParameter 0x87c +#define rFPGA0_AnalogParameter1 0x880 +#define rFPGA0_AnalogParameter2 0x884 +#define rFPGA0_AnalogParameter3 0x888 +#define rFPGA0_AnalogParameter4 0x88c +#define rFPGA0_XA_LSSIReadBack 0x8a0 +#define rFPGA0_XB_LSSIReadBack 0x8a4 +#define rFPGA0_XC_LSSIReadBack 0x8a8 +#define rFPGA0_XD_LSSIReadBack 0x8ac +#define rFPGA0_PSDReport 0x8b4 +#define rFPGA0_XAB_RFInterfaceRB 0x8e0 +#define rFPGA0_XCD_RFInterfaceRB 0x8e4 //page 9 -#define rFPGA1_RFMOD 0x900 //RF mode & OFDM TxSC -#define rFPGA1_TxBlock 0x904 -#define rFPGA1_DebugSelect 0x908 -#define rFPGA1_TxInfo 0x90c +#define rFPGA1_RFMOD 0x900 //RF mode & OFDM TxSC +#define rFPGA1_TxBlock 0x904 +#define rFPGA1_DebugSelect 0x908 +#define rFPGA1_TxInfo 0x90c //page a -#define rCCK0_System 0xa00 -#define rCCK0_AFESetting 0xa04 -#define rCCK0_CCA 0xa08 -#define rCCK0_RxAGC1 0xa0c //AGC default value, saturation level -#define rCCK0_RxAGC2 0xa10 //AGC & DAGC -#define rCCK0_RxHP 0xa14 -#define rCCK0_DSPParameter1 0xa18 //Timing recovery & Channel estimation threshold -#define rCCK0_DSPParameter2 0xa1c //SQ threshold -#define rCCK0_TxFilter1 0xa20 -#define rCCK0_TxFilter2 0xa24 -#define rCCK0_DebugPort 0xa28 //debug port and Tx filter3 -#define rCCK0_FalseAlarmReport 0xa2c //0xa2d -#define rCCK0_TRSSIReport 0xa50 -#define rCCK0_RxReport 0xa54 //0xa57 -#define rCCK0_FACounterLower 0xa5c //0xa5b -#define rCCK0_FACounterUpper 0xa58 //0xa5c +#define rCCK0_System 0xa00 +#define rCCK0_AFESetting 0xa04 +#define rCCK0_CCA 0xa08 +#define rCCK0_RxAGC1 0xa0c //AGC default value, saturation level +#define rCCK0_RxAGC2 0xa10 //AGC & DAGC +#define rCCK0_RxHP 0xa14 +#define rCCK0_DSPParameter1 0xa18 //Timing recovery & Channel estimation threshold +#define rCCK0_DSPParameter2 0xa1c //SQ threshold +#define rCCK0_TxFilter1 0xa20 +#define rCCK0_TxFilter2 0xa24 +#define rCCK0_DebugPort 0xa28 //debug port and Tx filter3 +#define rCCK0_FalseAlarmReport 0xa2c //0xa2d +#define rCCK0_TRSSIReport 0xa50 +#define rCCK0_RxReport 0xa54 //0xa57 +#define rCCK0_FACounterLower 0xa5c //0xa5b +#define rCCK0_FACounterUpper 0xa58 //0xa5c //page c -#define rOFDM0_LSTF 0xc00 -#define rOFDM0_TRxPathEnable 0xc04 -#define rOFDM0_TRMuxPar 0xc08 -#define rOFDM0_TRSWIsolation 0xc0c -#define rOFDM0_XARxAFE 0xc10 //RxIQ DC offset, Rx digital filter, DC notch filter -#define rOFDM0_XARxIQImbalance 0xc14 //RxIQ imblance matrix -#define rOFDM0_XBRxAFE 0xc18 -#define rOFDM0_XBRxIQImbalance 0xc1c -#define rOFDM0_XCRxAFE 0xc20 -#define rOFDM0_XCRxIQImbalance 0xc24 -#define rOFDM0_XDRxAFE 0xc28 -#define rOFDM0_XDRxIQImbalance 0xc2c -#define rOFDM0_RxDetector1 0xc30 //PD,BW & SBD -#define rOFDM0_RxDetector2 0xc34 //SBD & Fame Sync. -#define rOFDM0_RxDetector3 0xc38 //Frame Sync. -#define rOFDM0_RxDetector4 0xc3c //PD, SBD, Frame Sync & Short-GI -#define rOFDM0_RxDSP 0xc40 //Rx Sync Path -#define rOFDM0_CFOandDAGC 0xc44 //CFO & DAGC -#define rOFDM0_CCADropThreshold 0xc48 //CCA Drop threshold -#define rOFDM0_ECCAThreshold 0xc4c // energy CCA -#define rOFDM0_XAAGCCore1 0xc50 -#define rOFDM0_XAAGCCore2 0xc54 -#define rOFDM0_XBAGCCore1 0xc58 -#define rOFDM0_XBAGCCore2 0xc5c -#define rOFDM0_XCAGCCore1 0xc60 -#define rOFDM0_XCAGCCore2 0xc64 -#define rOFDM0_XDAGCCore1 0xc68 -#define rOFDM0_XDAGCCore2 0xc6c -#define rOFDM0_AGCParameter1 0xc70 -#define rOFDM0_AGCParameter2 0xc74 -#define rOFDM0_AGCRSSITable 0xc78 -#define rOFDM0_HTSTFAGC 0xc7c -#define rOFDM0_XATxIQImbalance 0xc80 -#define rOFDM0_XATxAFE 0xc84 -#define rOFDM0_XBTxIQImbalance 0xc88 -#define rOFDM0_XBTxAFE 0xc8c -#define rOFDM0_XCTxIQImbalance 0xc90 -#define rOFDM0_XCTxAFE 0xc94 -#define rOFDM0_XDTxIQImbalance 0xc98 -#define rOFDM0_XDTxAFE 0xc9c -#define rOFDM0_RxHPParameter 0xce0 -#define rOFDM0_TxPseudoNoiseWgt 0xce4 -#define rOFDM0_FrameSync 0xcf0 -#define rOFDM0_DFSReport 0xcf4 -#define rOFDM0_TxCoeff1 0xca4 -#define rOFDM0_TxCoeff2 0xca8 -#define rOFDM0_TxCoeff3 0xcac -#define rOFDM0_TxCoeff4 0xcb0 -#define rOFDM0_TxCoeff5 0xcb4 -#define rOFDM0_TxCoeff6 0xcb8 +#define rOFDM0_LSTF 0xc00 +#define rOFDM0_TRxPathEnable 0xc04 +#define rOFDM0_TRMuxPar 0xc08 +#define rOFDM0_TRSWIsolation 0xc0c +#define rOFDM0_XARxAFE 0xc10 //RxIQ DC offset, Rx digital filter, DC notch filter +#define rOFDM0_XARxIQImbalance 0xc14 //RxIQ imblance matrix +#define rOFDM0_XBRxAFE 0xc18 +#define rOFDM0_XBRxIQImbalance 0xc1c +#define rOFDM0_XCRxAFE 0xc20 +#define rOFDM0_XCRxIQImbalance 0xc24 +#define rOFDM0_XDRxAFE 0xc28 +#define rOFDM0_XDRxIQImbalance 0xc2c +#define rOFDM0_RxDetector1 0xc30 //PD,BW & SBD +#define rOFDM0_RxDetector2 0xc34 //SBD & Fame Sync. +#define rOFDM0_RxDetector3 0xc38 //Frame Sync. +#define rOFDM0_RxDetector4 0xc3c //PD, SBD, Frame Sync & Short-GI +#define rOFDM0_RxDSP 0xc40 //Rx Sync Path +#define rOFDM0_CFOandDAGC 0xc44 //CFO & DAGC +#define rOFDM0_CCADropThreshold 0xc48 //CCA Drop threshold +#define rOFDM0_ECCAThreshold 0xc4c // energy CCA +#define rOFDM0_XAAGCCore1 0xc50 +#define rOFDM0_XAAGCCore2 0xc54 +#define rOFDM0_XBAGCCore1 0xc58 +#define rOFDM0_XBAGCCore2 0xc5c +#define rOFDM0_XCAGCCore1 0xc60 +#define rOFDM0_XCAGCCore2 0xc64 +#define rOFDM0_XDAGCCore1 0xc68 +#define rOFDM0_XDAGCCore2 0xc6c +#define rOFDM0_AGCParameter1 0xc70 +#define rOFDM0_AGCParameter2 0xc74 +#define rOFDM0_AGCRSSITable 0xc78 +#define rOFDM0_HTSTFAGC 0xc7c +#define rOFDM0_XATxIQImbalance 0xc80 +#define rOFDM0_XATxAFE 0xc84 +#define rOFDM0_XBTxIQImbalance 0xc88 +#define rOFDM0_XBTxAFE 0xc8c +#define rOFDM0_XCTxIQImbalance 0xc90 +#define rOFDM0_XCTxAFE 0xc94 +#define rOFDM0_XDTxIQImbalance 0xc98 +#define rOFDM0_XDTxAFE 0xc9c +#define rOFDM0_RxHPParameter 0xce0 +#define rOFDM0_TxPseudoNoiseWgt 0xce4 +#define rOFDM0_FrameSync 0xcf0 +#define rOFDM0_DFSReport 0xcf4 +#define rOFDM0_TxCoeff1 0xca4 +#define rOFDM0_TxCoeff2 0xca8 +#define rOFDM0_TxCoeff3 0xcac +#define rOFDM0_TxCoeff4 0xcb0 +#define rOFDM0_TxCoeff5 0xcb4 +#define rOFDM0_TxCoeff6 0xcb8 //page d -#define rOFDM1_LSTF 0xd00 -#define rOFDM1_TRxPathEnable 0xd04 -#define rOFDM1_CFO 0xd08 -#define rOFDM1_CSI1 0xd10 -#define rOFDM1_SBD 0xd14 -#define rOFDM1_CSI2 0xd18 -#define rOFDM1_CFOTracking 0xd2c -#define rOFDM1_TRxMesaure1 0xd34 -#define rOFDM1_IntfDet 0xd3c +#define rOFDM1_LSTF 0xd00 +#define rOFDM1_TRxPathEnable 0xd04 +#define rOFDM1_CFO 0xd08 +#define rOFDM1_CSI1 0xd10 +#define rOFDM1_SBD 0xd14 +#define rOFDM1_CSI2 0xd18 +#define rOFDM1_CFOTracking 0xd2c +#define rOFDM1_TRxMesaure1 0xd34 +#define rOFDM1_IntfDet 0xd3c #define rOFDM1_PseudoNoiseStateAB 0xd50 #define rOFDM1_PseudoNoiseStateCD 0xd54 #define rOFDM1_RxPseudoNoiseWgt 0xd58 -#define rOFDM_PHYCounter1 0xda0 //cca, parity fail -#define rOFDM_PHYCounter2 0xda4 //rate illegal, crc8 fail -#define rOFDM_PHYCounter3 0xda8 //MCS not support -#define rOFDM_ShortCFOAB 0xdac -#define rOFDM_ShortCFOCD 0xdb0 -#define rOFDM_LongCFOAB 0xdb4 -#define rOFDM_LongCFOCD 0xdb8 -#define rOFDM_TailCFOAB 0xdbc -#define rOFDM_TailCFOCD 0xdc0 -#define rOFDM_PWMeasure1 0xdc4 -#define rOFDM_PWMeasure2 0xdc8 -#define rOFDM_BWReport 0xdcc -#define rOFDM_AGCReport 0xdd0 -#define rOFDM_RxSNR 0xdd4 -#define rOFDM_RxEVMCSI 0xdd8 -#define rOFDM_SIGReport 0xddc +#define rOFDM_PHYCounter1 0xda0 //cca, parity fail +#define rOFDM_PHYCounter2 0xda4 //rate illegal, crc8 fail +#define rOFDM_PHYCounter3 0xda8 //MCS not support +#define rOFDM_ShortCFOAB 0xdac +#define rOFDM_ShortCFOCD 0xdb0 +#define rOFDM_LongCFOAB 0xdb4 +#define rOFDM_LongCFOCD 0xdb8 +#define rOFDM_TailCFOAB 0xdbc +#define rOFDM_TailCFOCD 0xdc0 +#define rOFDM_PWMeasure1 0xdc4 +#define rOFDM_PWMeasure2 0xdc8 +#define rOFDM_BWReport 0xdcc +#define rOFDM_AGCReport 0xdd0 +#define rOFDM_RxSNR 0xdd4 +#define rOFDM_RxEVMCSI 0xdd8 +#define rOFDM_SIGReport 0xddc //page e #define rTxAGC_Rate18_06 0xe00 @@ -198,373 +198,373 @@ //RF //Zebra1 -#define rZebra1_HSSIEnable 0x0 -#define rZebra1_TRxEnable1 0x1 -#define rZebra1_TRxEnable2 0x2 -#define rZebra1_AGC 0x4 -#define rZebra1_ChargePump 0x5 -#define rZebra1_Channel 0x7 -#define rZebra1_TxGain 0x8 -#define rZebra1_TxLPF 0x9 -#define rZebra1_RxLPF 0xb -#define rZebra1_RxHPFCorner 0xc +#define rZebra1_HSSIEnable 0x0 +#define rZebra1_TRxEnable1 0x1 +#define rZebra1_TRxEnable2 0x2 +#define rZebra1_AGC 0x4 +#define rZebra1_ChargePump 0x5 +#define rZebra1_Channel 0x7 +#define rZebra1_TxGain 0x8 +#define rZebra1_TxLPF 0x9 +#define rZebra1_RxLPF 0xb +#define rZebra1_RxHPFCorner 0xc //Zebra4 -#define rGlobalCtrl 0 -#define rRTL8256_TxLPF 19 -#define rRTL8256_RxLPF 11 +#define rGlobalCtrl 0 +#define rRTL8256_TxLPF 19 +#define rRTL8256_RxLPF 11 //RTL8258 -#define rRTL8258_TxLPF 0x11 -#define rRTL8258_RxLPF 0x13 -#define rRTL8258_RSSILPF 0xa +#define rRTL8258_TxLPF 0x11 +#define rRTL8258_RxLPF 0x13 +#define rRTL8258_RSSILPF 0xa //Bit Mask //page-1 -#define bBBResetB 0x100 -#define bGlobalResetB 0x200 -#define bOFDMTxStart 0x4 -#define bCCKTxStart 0x8 -#define bCRC32Debug 0x100 -#define bPMACLoopback 0x10 -#define bTxLSIG 0xffffff -#define bOFDMTxRate 0xf -#define bOFDMTxReserved 0x10 -#define bOFDMTxLength 0x1ffe0 -#define bOFDMTxParity 0x20000 -#define bTxHTSIG1 0xffffff -#define bTxHTMCSRate 0x7f -#define bTxHTBW 0x80 -#define bTxHTLength 0xffff00 -#define bTxHTSIG2 0xffffff -#define bTxHTSmoothing 0x1 -#define bTxHTSounding 0x2 -#define bTxHTReserved 0x4 -#define bTxHTAggreation 0x8 -#define bTxHTSTBC 0x30 -#define bTxHTAdvanceCoding 0x40 -#define bTxHTShortGI 0x80 -#define bTxHTNumberHT_LTF 0x300 -#define bTxHTCRC8 0x3fc00 -#define bCounterReset 0x10000 -#define bNumOfOFDMTx 0xffff -#define bNumOfCCKTx 0xffff0000 -#define bTxIdleInterval 0xffff -#define bOFDMService 0xffff0000 -#define bTxMACHeader 0xffffffff -#define bTxDataInit 0xff -#define bTxHTMode 0x100 -#define bTxDataType 0x30000 -#define bTxRandomSeed 0xffffffff -#define bCCKTxPreamble 0x1 -#define bCCKTxSFD 0xffff0000 -#define bCCKTxSIG 0xff -#define bCCKTxService 0xff00 -#define bCCKLengthExt 0x8000 -#define bCCKTxLength 0xffff0000 -#define bCCKTxCRC16 0xffff -#define bCCKTxStatus 0x1 -#define bOFDMTxStatus 0x2 +#define bBBResetB 0x100 +#define bGlobalResetB 0x200 +#define bOFDMTxStart 0x4 +#define bCCKTxStart 0x8 +#define bCRC32Debug 0x100 +#define bPMACLoopback 0x10 +#define bTxLSIG 0xffffff +#define bOFDMTxRate 0xf +#define bOFDMTxReserved 0x10 +#define bOFDMTxLength 0x1ffe0 +#define bOFDMTxParity 0x20000 +#define bTxHTSIG1 0xffffff +#define bTxHTMCSRate 0x7f +#define bTxHTBW 0x80 +#define bTxHTLength 0xffff00 +#define bTxHTSIG2 0xffffff +#define bTxHTSmoothing 0x1 +#define bTxHTSounding 0x2 +#define bTxHTReserved 0x4 +#define bTxHTAggreation 0x8 +#define bTxHTSTBC 0x30 +#define bTxHTAdvanceCoding 0x40 +#define bTxHTShortGI 0x80 +#define bTxHTNumberHT_LTF 0x300 +#define bTxHTCRC8 0x3fc00 +#define bCounterReset 0x10000 +#define bNumOfOFDMTx 0xffff +#define bNumOfCCKTx 0xffff0000 +#define bTxIdleInterval 0xffff +#define bOFDMService 0xffff0000 +#define bTxMACHeader 0xffffffff +#define bTxDataInit 0xff +#define bTxHTMode 0x100 +#define bTxDataType 0x30000 +#define bTxRandomSeed 0xffffffff +#define bCCKTxPreamble 0x1 +#define bCCKTxSFD 0xffff0000 +#define bCCKTxSIG 0xff +#define bCCKTxService 0xff00 +#define bCCKLengthExt 0x8000 +#define bCCKTxLength 0xffff0000 +#define bCCKTxCRC16 0xffff +#define bCCKTxStatus 0x1 +#define bOFDMTxStatus 0x2 //page-8 -#define bRFMOD 0x1 -#define bJapanMode 0x2 -#define bCCKTxSC 0x30 -#define bCCKEn 0x1000000 -#define bOFDMEn 0x2000000 -#define bOFDMRxADCPhase 0x10000 -#define bOFDMTxDACPhase 0x40000 -#define bXATxAGC 0x3f -#define bXBTxAGC 0xf00 -#define bXCTxAGC 0xf000 -#define bXDTxAGC 0xf0000 -#define bPAStart 0xf0000000 -#define bTRStart 0x00f00000 -#define bRFStart 0x0000f000 -#define bBBStart 0x000000f0 -#define bBBCCKStart 0x0000000f -#define bPAEnd 0xf //Reg0x814 -#define bTREnd 0x0f000000 -#define bRFEnd 0x000f0000 -#define bCCAMask 0x000000f0 //T2R -#define bR2RCCAMask 0x00000f00 -#define bHSSI_R2TDelay 0xf8000000 -#define bHSSI_T2RDelay 0xf80000 -#define bContTxHSSI 0x400 //chane gain at continue Tx -#define bIGFromCCK 0x200 -#define bAGCAddress 0x3f -#define bRxHPTx 0x7000 -#define bRxHPT2R 0x38000 -#define bRxHPCCKIni 0xc0000 -#define bAGCTxCode 0xc00000 -#define bAGCRxCode 0x300000 -#define b3WireDataLength 0x800 -#define b3WireAddressLength 0x400 -#define b3WireRFPowerDown 0x1 -//#define bHWSISelect 0x8 -#define b5GPAPEPolarity 0x40000000 -#define b2GPAPEPolarity 0x80000000 -#define bRFSW_TxDefaultAnt 0x3 -#define bRFSW_TxOptionAnt 0x30 -#define bRFSW_RxDefaultAnt 0x300 -#define bRFSW_RxOptionAnt 0x3000 -#define bRFSI_3WireData 0x1 -#define bRFSI_3WireClock 0x2 -#define bRFSI_3WireLoad 0x4 -#define bRFSI_3WireRW 0x8 -#define bRFSI_3Wire 0xf //3-wire total control -#define bRFSI_RFENV 0x10 -#define bRFSI_TRSW 0x20 -#define bRFSI_TRSWB 0x40 -#define bRFSI_ANTSW 0x100 -#define bRFSI_ANTSWB 0x200 -#define bRFSI_PAPE 0x400 -#define bRFSI_PAPE5G 0x800 -#define bBandSelect 0x1 -#define bHTSIG2_GI 0x80 -#define bHTSIG2_Smoothing 0x01 -#define bHTSIG2_Sounding 0x02 -#define bHTSIG2_Aggreaton 0x08 -#define bHTSIG2_STBC 0x30 -#define bHTSIG2_AdvCoding 0x40 -#define bHTSIG2_NumOfHTLTF 0x300 -#define bHTSIG2_CRC8 0x3fc -#define bHTSIG1_MCS 0x7f -#define bHTSIG1_BandWidth 0x80 -#define bHTSIG1_HTLength 0xffff -#define bLSIG_Rate 0xf -#define bLSIG_Reserved 0x10 -#define bLSIG_Length 0x1fffe -#define bLSIG_Parity 0x20 -#define bCCKRxPhase 0x4 -#define bLSSIReadAddress 0x3f000000 //LSSI "Read" Address -#define bLSSIReadEdge 0x80000000 //LSSI "Read" edge signal -#define bLSSIReadBackData 0xfff -#define bLSSIReadOKFlag 0x1000 -#define bCCKSampleRate 0x8 //0: 44MHz, 1:88MHz - -#define bRegulator0Standby 0x1 -#define bRegulatorPLLStandby 0x2 -#define bRegulator1Standby 0x4 -#define bPLLPowerUp 0x8 -#define bDPLLPowerUp 0x10 -#define bDA10PowerUp 0x20 -#define bAD7PowerUp 0x200 -#define bDA6PowerUp 0x2000 -#define bXtalPowerUp 0x4000 -#define b40MDClkPowerUP 0x8000 -#define bDA6DebugMode 0x20000 -#define bDA6Swing 0x380000 -#define bADClkPhase 0x4000000 -#define b80MClkDelay 0x18000000 -#define bAFEWatchDogEnable 0x20000000 -#define bXtalCap 0x0f000000 -#define bIntDifClkEnable 0x400 -#define bExtSigClkEnable 0x800 -#define bBandgapMbiasPowerUp 0x10000 -#define bAD11SHGain 0xc0000 -#define bAD11InputRange 0x700000 -#define bAD11OPCurrent 0x3800000 -#define bIPathLoopback 0x4000000 -#define bQPathLoopback 0x8000000 -#define bAFELoopback 0x10000000 -#define bDA10Swing 0x7e0 -#define bDA10Reverse 0x800 -#define bDAClkSource 0x1000 -#define bAD7InputRange 0x6000 -#define bAD7Gain 0x38000 -#define bAD7OutputCMMode 0x40000 -#define bAD7InputCMMode 0x380000 -#define bAD7Current 0xc00000 -#define bRegulatorAdjust 0x7000000 -#define bAD11PowerUpAtTx 0x1 -#define bDA10PSAtTx 0x10 -#define bAD11PowerUpAtRx 0x100 -#define bDA10PSAtRx 0x1000 - -#define bCCKRxAGCFormat 0x200 - -#define bPSDFFTSamplepPoint 0xc000 -#define bPSDAverageNum 0x3000 -#define bIQPathControl 0xc00 -#define bPSDFreq 0x3ff -#define bPSDAntennaPath 0x30 -#define bPSDIQSwitch 0x40 -#define bPSDRxTrigger 0x400000 -#define bPSDTxTrigger 0x80000000 -#define bPSDSineToneScale 0x7f000000 -#define bPSDReport 0xffff +#define bRFMOD 0x1 +#define bJapanMode 0x2 +#define bCCKTxSC 0x30 +#define bCCKEn 0x1000000 +#define bOFDMEn 0x2000000 +#define bOFDMRxADCPhase 0x10000 +#define bOFDMTxDACPhase 0x40000 +#define bXATxAGC 0x3f +#define bXBTxAGC 0xf00 +#define bXCTxAGC 0xf000 +#define bXDTxAGC 0xf0000 +#define bPAStart 0xf0000000 +#define bTRStart 0x00f00000 +#define bRFStart 0x0000f000 +#define bBBStart 0x000000f0 +#define bBBCCKStart 0x0000000f +#define bPAEnd 0xf //Reg0x814 +#define bTREnd 0x0f000000 +#define bRFEnd 0x000f0000 +#define bCCAMask 0x000000f0 //T2R +#define bR2RCCAMask 0x00000f00 +#define bHSSI_R2TDelay 0xf8000000 +#define bHSSI_T2RDelay 0xf80000 +#define bContTxHSSI 0x400 //chane gain at continue Tx +#define bIGFromCCK 0x200 +#define bAGCAddress 0x3f +#define bRxHPTx 0x7000 +#define bRxHPT2R 0x38000 +#define bRxHPCCKIni 0xc0000 +#define bAGCTxCode 0xc00000 +#define bAGCRxCode 0x300000 +#define b3WireDataLength 0x800 +#define b3WireAddressLength 0x400 +#define b3WireRFPowerDown 0x1 +//#define bHWSISelect 0x8 +#define b5GPAPEPolarity 0x40000000 +#define b2GPAPEPolarity 0x80000000 +#define bRFSW_TxDefaultAnt 0x3 +#define bRFSW_TxOptionAnt 0x30 +#define bRFSW_RxDefaultAnt 0x300 +#define bRFSW_RxOptionAnt 0x3000 +#define bRFSI_3WireData 0x1 +#define bRFSI_3WireClock 0x2 +#define bRFSI_3WireLoad 0x4 +#define bRFSI_3WireRW 0x8 +#define bRFSI_3Wire 0xf //3-wire total control +#define bRFSI_RFENV 0x10 +#define bRFSI_TRSW 0x20 +#define bRFSI_TRSWB 0x40 +#define bRFSI_ANTSW 0x100 +#define bRFSI_ANTSWB 0x200 +#define bRFSI_PAPE 0x400 +#define bRFSI_PAPE5G 0x800 +#define bBandSelect 0x1 +#define bHTSIG2_GI 0x80 +#define bHTSIG2_Smoothing 0x01 +#define bHTSIG2_Sounding 0x02 +#define bHTSIG2_Aggreaton 0x08 +#define bHTSIG2_STBC 0x30 +#define bHTSIG2_AdvCoding 0x40 +#define bHTSIG2_NumOfHTLTF 0x300 +#define bHTSIG2_CRC8 0x3fc +#define bHTSIG1_MCS 0x7f +#define bHTSIG1_BandWidth 0x80 +#define bHTSIG1_HTLength 0xffff +#define bLSIG_Rate 0xf +#define bLSIG_Reserved 0x10 +#define bLSIG_Length 0x1fffe +#define bLSIG_Parity 0x20 +#define bCCKRxPhase 0x4 +#define bLSSIReadAddress 0x3f000000 //LSSI "Read" Address +#define bLSSIReadEdge 0x80000000 //LSSI "Read" edge signal +#define bLSSIReadBackData 0xfff +#define bLSSIReadOKFlag 0x1000 +#define bCCKSampleRate 0x8 //0: 44MHz, 1:88MHz + +#define bRegulator0Standby 0x1 +#define bRegulatorPLLStandby 0x2 +#define bRegulator1Standby 0x4 +#define bPLLPowerUp 0x8 +#define bDPLLPowerUp 0x10 +#define bDA10PowerUp 0x20 +#define bAD7PowerUp 0x200 +#define bDA6PowerUp 0x2000 +#define bXtalPowerUp 0x4000 +#define b40MDClkPowerUP 0x8000 +#define bDA6DebugMode 0x20000 +#define bDA6Swing 0x380000 +#define bADClkPhase 0x4000000 +#define b80MClkDelay 0x18000000 +#define bAFEWatchDogEnable 0x20000000 +#define bXtalCap 0x0f000000 +#define bIntDifClkEnable 0x400 +#define bExtSigClkEnable 0x800 +#define bBandgapMbiasPowerUp 0x10000 +#define bAD11SHGain 0xc0000 +#define bAD11InputRange 0x700000 +#define bAD11OPCurrent 0x3800000 +#define bIPathLoopback 0x4000000 +#define bQPathLoopback 0x8000000 +#define bAFELoopback 0x10000000 +#define bDA10Swing 0x7e0 +#define bDA10Reverse 0x800 +#define bDAClkSource 0x1000 +#define bAD7InputRange 0x6000 +#define bAD7Gain 0x38000 +#define bAD7OutputCMMode 0x40000 +#define bAD7InputCMMode 0x380000 +#define bAD7Current 0xc00000 +#define bRegulatorAdjust 0x7000000 +#define bAD11PowerUpAtTx 0x1 +#define bDA10PSAtTx 0x10 +#define bAD11PowerUpAtRx 0x100 +#define bDA10PSAtRx 0x1000 + +#define bCCKRxAGCFormat 0x200 + +#define bPSDFFTSamplepPoint 0xc000 +#define bPSDAverageNum 0x3000 +#define bIQPathControl 0xc00 +#define bPSDFreq 0x3ff +#define bPSDAntennaPath 0x30 +#define bPSDIQSwitch 0x40 +#define bPSDRxTrigger 0x400000 +#define bPSDTxTrigger 0x80000000 +#define bPSDSineToneScale 0x7f000000 +#define bPSDReport 0xffff //page-9 -#define bOFDMTxSC 0x30000000 -#define bCCKTxOn 0x1 -#define bOFDMTxOn 0x2 -#define bDebugPage 0xfff //reset debug page and also HWord, LWord -#define bDebugItem 0xff //reset debug page and LWord -#define bAntL 0x10 -#define bAntNonHT 0x100 -#define bAntHT1 0x1000 -#define bAntHT2 0x10000 -#define bAntHT1S1 0x100000 -#define bAntNonHTS1 0x1000000 +#define bOFDMTxSC 0x30000000 +#define bCCKTxOn 0x1 +#define bOFDMTxOn 0x2 +#define bDebugPage 0xfff //reset debug page and also HWord, LWord +#define bDebugItem 0xff //reset debug page and LWord +#define bAntL 0x10 +#define bAntNonHT 0x100 +#define bAntHT1 0x1000 +#define bAntHT2 0x10000 +#define bAntHT1S1 0x100000 +#define bAntNonHTS1 0x1000000 //page-a -#define bCCKBBMode 0x3 -#define bCCKTxPowerSaving 0x80 -#define bCCKRxPowerSaving 0x40 -#define bCCKSideBand 0x10 -#define bCCKScramble 0x8 -#define bCCKAntDiversity 0x8000 -#define bCCKCarrierRecovery 0x4000 -#define bCCKTxRate 0x3000 -#define bCCKDCCancel 0x0800 -#define bCCKISICancel 0x0400 -#define bCCKMatchFilter 0x0200 -#define bCCKEqualizer 0x0100 -#define bCCKPreambleDetect 0x800000 -#define bCCKFastFalseCCA 0x400000 -#define bCCKChEstStart 0x300000 -#define bCCKCCACount 0x080000 -#define bCCKcs_lim 0x070000 -#define bCCKBistMode 0x80000000 -#define bCCKCCAMask 0x40000000 -#define bCCKTxDACPhase 0x4 -#define bCCKRxADCPhase 0x20000000 //r_rx_clk -#define bCCKr_cp_mode0 0x0100 -#define bCCKTxDCOffset 0xf0 -#define bCCKRxDCOffset 0xf -#define bCCKCCAMode 0xc000 -#define bCCKFalseCS_lim 0x3f00 -#define bCCKCS_ratio 0xc00000 -#define bCCKCorgBit_sel 0x300000 -#define bCCKPD_lim 0x0f0000 -#define bCCKNewCCA 0x80000000 -#define bCCKRxHPofIG 0x8000 -#define bCCKRxIG 0x7f00 -#define bCCKLNAPolarity 0x800000 -#define bCCKRx1stGain 0x7f0000 -#define bCCKRFExtend 0x20000000 //CCK Rx initial gain polarity -#define bCCKRxAGCSatLevel 0x1f000000 -#define bCCKRxAGCSatCount 0xe0 -#define bCCKRxRFSettle 0x1f //AGCsamp_dly -#define bCCKFixedRxAGC 0x8000 -//#define bCCKRxAGCFormat 0x4000 //remove to HSSI register 0x824 -#define bCCKAntennaPolarity 0x2000 -#define bCCKTxFilterType 0x0c00 -#define bCCKRxAGCReportType 0x0300 -#define bCCKRxDAGCEn 0x80000000 -#define bCCKRxDAGCPeriod 0x20000000 -#define bCCKRxDAGCSatLevel 0x1f000000 -#define bCCKTimingRecovery 0x800000 -#define bCCKTxC0 0x3f0000 -#define bCCKTxC1 0x3f000000 -#define bCCKTxC2 0x3f -#define bCCKTxC3 0x3f00 -#define bCCKTxC4 0x3f0000 -#define bCCKTxC5 0x3f000000 -#define bCCKTxC6 0x3f -#define bCCKTxC7 0x3f00 -#define bCCKDebugPort 0xff0000 -#define bCCKDACDebug 0x0f000000 -#define bCCKFalseAlarmEnable 0x8000 -#define bCCKFalseAlarmRead 0x4000 -#define bCCKTRSSI 0x7f -#define bCCKRxAGCReport 0xfe -#define bCCKRxReport_AntSel 0x80000000 -#define bCCKRxReport_MFOff 0x40000000 -#define bCCKRxRxReport_SQLoss 0x20000000 -#define bCCKRxReport_Pktloss 0x10000000 -#define bCCKRxReport_Lockedbit 0x08000000 -#define bCCKRxReport_RateError 0x04000000 -#define bCCKRxReport_RxRate 0x03000000 -#define bCCKRxFACounterLower 0xff -#define bCCKRxFACounterUpper 0xff000000 -#define bCCKRxHPAGCStart 0xe000 -#define bCCKRxHPAGCFinal 0x1c00 - -#define bCCKRxFalseAlarmEnable 0x8000 -#define bCCKFACounterFreeze 0x4000 - -#define bCCKTxPathSel 0x10000000 -#define bCCKDefaultRxPath 0xc000000 -#define bCCKOptionRxPath 0x3000000 +#define bCCKBBMode 0x3 +#define bCCKTxPowerSaving 0x80 +#define bCCKRxPowerSaving 0x40 +#define bCCKSideBand 0x10 +#define bCCKScramble 0x8 +#define bCCKAntDiversity 0x8000 +#define bCCKCarrierRecovery 0x4000 +#define bCCKTxRate 0x3000 +#define bCCKDCCancel 0x0800 +#define bCCKISICancel 0x0400 +#define bCCKMatchFilter 0x0200 +#define bCCKEqualizer 0x0100 +#define bCCKPreambleDetect 0x800000 +#define bCCKFastFalseCCA 0x400000 +#define bCCKChEstStart 0x300000 +#define bCCKCCACount 0x080000 +#define bCCKcs_lim 0x070000 +#define bCCKBistMode 0x80000000 +#define bCCKCCAMask 0x40000000 +#define bCCKTxDACPhase 0x4 +#define bCCKRxADCPhase 0x20000000 //r_rx_clk +#define bCCKr_cp_mode0 0x0100 +#define bCCKTxDCOffset 0xf0 +#define bCCKRxDCOffset 0xf +#define bCCKCCAMode 0xc000 +#define bCCKFalseCS_lim 0x3f00 +#define bCCKCS_ratio 0xc00000 +#define bCCKCorgBit_sel 0x300000 +#define bCCKPD_lim 0x0f0000 +#define bCCKNewCCA 0x80000000 +#define bCCKRxHPofIG 0x8000 +#define bCCKRxIG 0x7f00 +#define bCCKLNAPolarity 0x800000 +#define bCCKRx1stGain 0x7f0000 +#define bCCKRFExtend 0x20000000 //CCK Rx initial gain polarity +#define bCCKRxAGCSatLevel 0x1f000000 +#define bCCKRxAGCSatCount 0xe0 +#define bCCKRxRFSettle 0x1f //AGCsamp_dly +#define bCCKFixedRxAGC 0x8000 +//#define bCCKRxAGCFormat 0x4000 //remove to HSSI register 0x824 +#define bCCKAntennaPolarity 0x2000 +#define bCCKTxFilterType 0x0c00 +#define bCCKRxAGCReportType 0x0300 +#define bCCKRxDAGCEn 0x80000000 +#define bCCKRxDAGCPeriod 0x20000000 +#define bCCKRxDAGCSatLevel 0x1f000000 +#define bCCKTimingRecovery 0x800000 +#define bCCKTxC0 0x3f0000 +#define bCCKTxC1 0x3f000000 +#define bCCKTxC2 0x3f +#define bCCKTxC3 0x3f00 +#define bCCKTxC4 0x3f0000 +#define bCCKTxC5 0x3f000000 +#define bCCKTxC6 0x3f +#define bCCKTxC7 0x3f00 +#define bCCKDebugPort 0xff0000 +#define bCCKDACDebug 0x0f000000 +#define bCCKFalseAlarmEnable 0x8000 +#define bCCKFalseAlarmRead 0x4000 +#define bCCKTRSSI 0x7f +#define bCCKRxAGCReport 0xfe +#define bCCKRxReport_AntSel 0x80000000 +#define bCCKRxReport_MFOff 0x40000000 +#define bCCKRxRxReport_SQLoss 0x20000000 +#define bCCKRxReport_Pktloss 0x10000000 +#define bCCKRxReport_Lockedbit 0x08000000 +#define bCCKRxReport_RateError 0x04000000 +#define bCCKRxReport_RxRate 0x03000000 +#define bCCKRxFACounterLower 0xff +#define bCCKRxFACounterUpper 0xff000000 +#define bCCKRxHPAGCStart 0xe000 +#define bCCKRxHPAGCFinal 0x1c00 + +#define bCCKRxFalseAlarmEnable 0x8000 +#define bCCKFACounterFreeze 0x4000 + +#define bCCKTxPathSel 0x10000000 +#define bCCKDefaultRxPath 0xc000000 +#define bCCKOptionRxPath 0x3000000 //page c -#define bNumOfSTF 0x3 -#define bShift_L 0xc0 -#define bGI_TH 0xc -#define bRxPathA 0x1 -#define bRxPathB 0x2 -#define bRxPathC 0x4 -#define bRxPathD 0x8 -#define bTxPathA 0x1 -#define bTxPathB 0x2 -#define bTxPathC 0x4 -#define bTxPathD 0x8 -#define bTRSSIFreq 0x200 -#define bADCBackoff 0x3000 -#define bDFIRBackoff 0xc000 -#define bTRSSILatchPhase 0x10000 -#define bRxIDCOffset 0xff -#define bRxQDCOffset 0xff00 -#define bRxDFIRMode 0x1800000 -#define bRxDCNFType 0xe000000 -#define bRXIQImb_A 0x3ff -#define bRXIQImb_B 0xfc00 -#define bRXIQImb_C 0x3f0000 -#define bRXIQImb_D 0xffc00000 -#define bDC_dc_Notch 0x60000 -#define bRxNBINotch 0x1f000000 -#define bPD_TH 0xf -#define bPD_TH_Opt2 0xc000 -#define bPWED_TH 0x700 -#define bIfMF_Win_L 0x800 -#define bPD_Option 0x1000 -#define bMF_Win_L 0xe000 -#define bBW_Search_L 0x30000 -#define bwin_enh_L 0xc0000 -#define bBW_TH 0x700000 -#define bED_TH2 0x3800000 -#define bBW_option 0x4000000 -#define bRatio_TH 0x18000000 -#define bWindow_L 0xe0000000 -#define bSBD_Option 0x1 -#define bFrame_TH 0x1c -#define bFS_Option 0x60 -#define bDC_Slope_check 0x80 -#define bFGuard_Counter_DC_L 0xe00 -#define bFrame_Weight_Short 0x7000 -#define bSub_Tune 0xe00000 -#define bFrame_DC_Length 0xe000000 -#define bSBD_start_offset 0x30000000 -#define bFrame_TH_2 0x7 -#define bFrame_GI2_TH 0x38 -#define bGI2_Sync_en 0x40 -#define bSarch_Short_Early 0x300 -#define bSarch_Short_Late 0xc00 -#define bSarch_GI2_Late 0x70000 -#define bCFOAntSum 0x1 -#define bCFOAcc 0x2 -#define bCFOStartOffset 0xc -#define bCFOLookBack 0x70 -#define bCFOSumWeight 0x80 -#define bDAGCEnable 0x10000 -#define bTXIQImb_A 0x3ff -#define bTXIQImb_B 0xfc00 -#define bTXIQImb_C 0x3f0000 -#define bTXIQImb_D 0xffc00000 -#define bTxIDCOffset 0xff -#define bTxQDCOffset 0xff00 -#define bTxDFIRMode 0x10000 -#define bTxPesudoNoiseOn 0x4000000 -#define bTxPesudoNoise_A 0xff -#define bTxPesudoNoise_B 0xff00 -#define bTxPesudoNoise_C 0xff0000 -#define bTxPesudoNoise_D 0xff000000 -#define bCCADropOption 0x20000 -#define bCCADropThres 0xfff00000 -#define bEDCCA_H 0xf -#define bEDCCA_L 0xf0 +#define bNumOfSTF 0x3 +#define bShift_L 0xc0 +#define bGI_TH 0xc +#define bRxPathA 0x1 +#define bRxPathB 0x2 +#define bRxPathC 0x4 +#define bRxPathD 0x8 +#define bTxPathA 0x1 +#define bTxPathB 0x2 +#define bTxPathC 0x4 +#define bTxPathD 0x8 +#define bTRSSIFreq 0x200 +#define bADCBackoff 0x3000 +#define bDFIRBackoff 0xc000 +#define bTRSSILatchPhase 0x10000 +#define bRxIDCOffset 0xff +#define bRxQDCOffset 0xff00 +#define bRxDFIRMode 0x1800000 +#define bRxDCNFType 0xe000000 +#define bRXIQImb_A 0x3ff +#define bRXIQImb_B 0xfc00 +#define bRXIQImb_C 0x3f0000 +#define bRXIQImb_D 0xffc00000 +#define bDC_dc_Notch 0x60000 +#define bRxNBINotch 0x1f000000 +#define bPD_TH 0xf +#define bPD_TH_Opt2 0xc000 +#define bPWED_TH 0x700 +#define bIfMF_Win_L 0x800 +#define bPD_Option 0x1000 +#define bMF_Win_L 0xe000 +#define bBW_Search_L 0x30000 +#define bwin_enh_L 0xc0000 +#define bBW_TH 0x700000 +#define bED_TH2 0x3800000 +#define bBW_option 0x4000000 +#define bRatio_TH 0x18000000 +#define bWindow_L 0xe0000000 +#define bSBD_Option 0x1 +#define bFrame_TH 0x1c +#define bFS_Option 0x60 +#define bDC_Slope_check 0x80 +#define bFGuard_Counter_DC_L 0xe00 +#define bFrame_Weight_Short 0x7000 +#define bSub_Tune 0xe00000 +#define bFrame_DC_Length 0xe000000 +#define bSBD_start_offset 0x30000000 +#define bFrame_TH_2 0x7 +#define bFrame_GI2_TH 0x38 +#define bGI2_Sync_en 0x40 +#define bSarch_Short_Early 0x300 +#define bSarch_Short_Late 0xc00 +#define bSarch_GI2_Late 0x70000 +#define bCFOAntSum 0x1 +#define bCFOAcc 0x2 +#define bCFOStartOffset 0xc +#define bCFOLookBack 0x70 +#define bCFOSumWeight 0x80 +#define bDAGCEnable 0x10000 +#define bTXIQImb_A 0x3ff +#define bTXIQImb_B 0xfc00 +#define bTXIQImb_C 0x3f0000 +#define bTXIQImb_D 0xffc00000 +#define bTxIDCOffset 0xff +#define bTxQDCOffset 0xff00 +#define bTxDFIRMode 0x10000 +#define bTxPesudoNoiseOn 0x4000000 +#define bTxPesudoNoise_A 0xff +#define bTxPesudoNoise_B 0xff00 +#define bTxPesudoNoise_C 0xff0000 +#define bTxPesudoNoise_D 0xff000000 +#define bCCADropOption 0x20000 +#define bCCADropThres 0xfff00000 +#define bEDCCA_H 0xf +#define bEDCCA_L 0xf0 #define bLambda_ED 0x300 #define bRxInitialGain 0x7f #define bRxAntDivEn 0x80 @@ -862,10 +862,10 @@ #define PathD 0x3 #define rRTL8256RxMixerPole 0xb -#define bZebraRxMixerPole 0x6 -#define rRTL8256TxBBOPBias 0x9 -#define bRTL8256TxBBOPBias 0x400 -#define rRTL8256TxBBBW 19 -#define bRTL8256TxBBBW 0x18 +#define bZebraRxMixerPole 0x6 +#define rRTL8256TxBBOPBias 0x9 +#define bRTL8256TxBBOPBias 0x400 +#define rRTL8256TxBBBW 19 +#define bRTL8256TxBBBW 0x18 #endif //__INC_HAL8190PCIPHYREG_H -- cgit v0.10.2 From 0db7a34e6c8e902c6fc58c2116278dd8e88fefb7 Mon Sep 17 00:00:00 2001 From: Jennifer Naumann Date: Wed, 5 Dec 2012 21:40:19 +0100 Subject: staging/rtl8192u: put { on same line as struct This fixes the checkpatch error "open brace '{' following struct go on the same line" in staging/rtl8192u Signed-off-by: Jennifer Naumann Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h index bb0e4fe..b85e3e3 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h @@ -1655,8 +1655,7 @@ typedef struct tx_pending_t{ struct ieee80211_txb *txb; }tx_pending_t; -typedef struct _bandwidth_autoswitch -{ +typedef struct _bandwidth_autoswitch { long threshold_20Mhzto40Mhz; long threshold_40Mhzto20Mhz; bool bforced_tx20Mhz; @@ -1668,8 +1667,7 @@ typedef struct _bandwidth_autoswitch #define REORDER_WIN_SIZE 128 #define REORDER_ENTRY_NUM 128 -typedef struct _RX_REORDER_ENTRY -{ +typedef struct _RX_REORDER_ENTRY { struct list_head List; u16 SeqNum; struct ieee80211_rxb* prxb; @@ -1709,15 +1707,13 @@ typedef struct _IbssParms{ #define MAX_NUM_RATES 264 // Max num of support rates element: 8, Max num of ext. support rate: 255. 061122, by rcnjko. // RF state. -typedef enum _RT_RF_POWER_STATE -{ +typedef enum _RT_RF_POWER_STATE { eRfOn, eRfSleep, eRfOff }RT_RF_POWER_STATE; -typedef struct _RT_POWER_SAVE_CONTROL -{ +typedef struct _RT_POWER_SAVE_CONTROL { // // Inactive Power Save(IPS) : Disable RF when disconnected diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h index ffd1c0c..2c398ca 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h @@ -28,8 +28,7 @@ struct ieee80211_ADDBA_Req{ //Is this need?I put here just to make it easier to define structure BA_RECORD //WB typedef union _SEQUENCE_CONTROL{ u16 ShortData; - struct - { + struct { u16 FragNum:4; u16 SeqNum:12; }field; diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h index 2625cde..2348ccd 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h @@ -81,8 +81,7 @@ typedef union _QOS_CTRL_FIELD{ u16 shortData; // WMM spec - struct - { + struct { u8 UP:3; u8 usRsvd1:1; u8 EOSP:1; @@ -92,8 +91,7 @@ typedef union _QOS_CTRL_FIELD{ }WMM; // 802.11e: QoS data type frame sent by non-AP QSTAs. - struct - { + struct { u8 TID:4; u8 bIsQsize:1;// 0: BIT[8:15] is TXOP Duration Requested, 1: BIT[8:15] is Queue Size. u8 AckPolicy:2; @@ -102,8 +100,7 @@ typedef union _QOS_CTRL_FIELD{ }BySta; // 802.11e: QoS data, QoS Null, and QoS Data+CF-Ack frames sent by HC. - struct - { + struct { u8 TID:4; u8 EOSP:1; u8 AckPolicy:2; @@ -112,8 +109,7 @@ typedef union _QOS_CTRL_FIELD{ }ByHc_Data; // 802.11e: QoS (+) CF-Poll frames sent by HC. - struct - { + struct { u8 TID:4; u8 EOSP:1; u8 AckPolicy:2; @@ -133,14 +129,12 @@ typedef union _QOS_CTRL_FIELD{ typedef union _QOS_INFO_FIELD{ u8 charData; - struct - { + struct { u8 ucParameterSetCount:4; u8 ucReserved:4; }WMM; - struct - { + struct { //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah u8 ucAC_VO_UAPSD:1; u8 ucAC_VI_UAPSD:1; @@ -152,16 +146,14 @@ typedef union _QOS_INFO_FIELD{ }ByWmmPsSta; - struct - { + struct { //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah u8 ucParameterSetCount:4; u8 ucReserved:3; u8 ucApUapsd:1; }ByWmmPsAp; - struct - { + struct { u8 ucAC3_UAPSD:1; u8 ucAC2_UAPSD:1; u8 ucAC1_UAPSD:1; @@ -171,8 +163,7 @@ typedef union _QOS_INFO_FIELD{ u8 ucMoreDataAck:1; } By11eSta; - struct - { + struct { u8 ucParameterSetCount:4; u8 ucQAck:1; u8 ucQueueReq:1; @@ -180,16 +171,14 @@ typedef union _QOS_INFO_FIELD{ u8 ucReserved:1; } By11eAp; - struct - { + struct { u8 ucReserved1:4; u8 ucQAck:1; u8 ucReserved2:2; u8 ucMoreDataAck:1; } ByWmmsaSta; - struct - { + struct { u8 ucReserved1:4; u8 ucQAck:1; u8 ucQueueReq:1; @@ -197,8 +186,7 @@ typedef union _QOS_INFO_FIELD{ u8 ucReserved2:1; } ByWmmsaAp; - struct - { + struct { u8 ucAC3_UAPSD:1; u8 ucAC2_UAPSD:1; u8 ucAC1_UAPSD:1; @@ -208,8 +196,7 @@ typedef union _QOS_INFO_FIELD{ u8 ucMoreDataAck:1; } ByAllSta; - struct - { + struct { u8 ucParameterSetCount:4; u8 ucQAck:1; u8 ucQueueReq:1; @@ -246,8 +233,7 @@ typedef u32 AC_CODING; typedef union _ACI_AIFSN{ u8 charData; - struct - { + struct { u8 AIFSN:4; u8 ACM:1; u8 ACI:2; @@ -261,8 +247,7 @@ typedef union _ACI_AIFSN{ // typedef union _ECW{ u8 charData; - struct - { + struct { u8 ECWmin:4; u8 ECWmax:4; }f; // Field @@ -276,8 +261,7 @@ typedef union _AC_PARAM{ u32 longData; u8 charData[4]; - struct - { + struct { ACI_AIFSN AciAifsn; ECW Ecw; u16 TXOPLimit; @@ -336,8 +320,7 @@ typedef union _QOS_TSINFO{ typedef union _TSPEC_BODY{ u8 charData[55]; - struct - { + struct { QOS_TSINFO TSInfo; //u8 TSInfo[3]; u16 NominalMSDUsize; u16 MaxMSDUsize; diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h index 80ab937..837edb6 100644 --- a/drivers/staging/rtl8192u/r8192U.h +++ b/drivers/staging/rtl8192u/r8192U.h @@ -559,8 +559,7 @@ typedef enum _WIRELESS_MODE { #define RTL_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30 -typedef struct buffer -{ +typedef struct buffer { struct buffer *next; u32 *buf; @@ -600,8 +599,7 @@ typedef struct _RT_SMOOTH_DATA_4RF { #define MAX_8192U_RX_SIZE 8192 // This maybe changed for D-cut larger aggregation size //stats seems messed up, clean it ASAP -typedef struct Stats -{ +typedef struct Stats { unsigned long txrdu; // unsigned long rxrdu; //unsigned long rxnolast; @@ -748,8 +746,7 @@ typedef enum _RT_RF_TYPE_819xU{ RF_PSEUDO_11N = 4, }RT_RF_TYPE_819xU, *PRT_RF_TYPE_819xU; -typedef struct _rate_adaptive -{ +typedef struct _rate_adaptive { u8 rate_adaptive_disabled; u8 ratr_state; u16 reserve; @@ -775,21 +772,18 @@ typedef struct _rate_adaptive #define TxBBGainTableLength 37 #define CCKTxBBGainTableLength 23 -typedef struct _txbbgain_struct -{ +typedef struct _txbbgain_struct { long txbb_iq_amplifygain; u32 txbbgain_value; } txbbgain_struct, *ptxbbgain_struct; -typedef struct _ccktxbbgain_struct -{ +typedef struct _ccktxbbgain_struct { //The Value is from a22 to a29 one Byte one time is much Safer u8 ccktxbb_valuearray[8]; } ccktxbbgain_struct,*pccktxbbgain_struct; -typedef struct _init_gain -{ +typedef struct _init_gain { u8 xaagccore1; u8 xbagccore1; u8 xcagccore1; @@ -799,8 +793,7 @@ typedef struct _init_gain } init_gain, *pinit_gain; //by amy 0606 -typedef struct _phy_ofdm_rx_status_report_819xusb -{ +typedef struct _phy_ofdm_rx_status_report_819xusb { u8 trsw_gain_X[4]; u8 pwdb_all; u8 cfosho_X[4]; @@ -816,8 +809,7 @@ typedef struct _phy_ofdm_rx_status_report_819xusb u8 rxsc_sgien_exflg; }phy_sts_ofdm_819xusb_t; -typedef struct _phy_cck_rx_status_report_819xusb -{ +typedef struct _phy_cck_rx_status_report_819xusb { /* For CCK rate descriptor. This is a unsigned 8:1 variable. LSB bit presend 0.5. And MSB 7 bts presend a signed value. Range from -64~+63.5. */ u8 adc_pwdb_X[4]; @@ -881,8 +873,7 @@ typedef enum _tag_TxCmd_Config_Index{ TXCMD_XXXX_CTRL, }DCMD_TXCMD_OP; -typedef struct r8192_priv -{ +typedef struct r8192_priv { struct usb_device *udev; //added for maintain info from eeprom short epromtype; diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 1887dde..abedae7 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -164,8 +164,7 @@ static struct usb_driver rtl8192_usb_driver = { }; -typedef struct _CHANNEL_LIST -{ +typedef struct _CHANNEL_LIST { u8 Channel[32]; u8 Len; }CHANNEL_LIST, *PCHANNEL_LIST; diff --git a/drivers/staging/rtl8192u/r8192U_dm.h b/drivers/staging/rtl8192u/r8192U_dm.h index 8a96e9f..ffb083c 100644 --- a/drivers/staging/rtl8192u/r8192U_dm.h +++ b/drivers/staging/rtl8192u/r8192U_dm.h @@ -67,8 +67,7 @@ /*------------------------------Define structure----------------------------*/ /* 2007/10/04 MH Define upper and lower threshold of DIG enable or disable. */ -typedef struct _dynamic_initial_gain_threshold_ -{ +typedef struct _dynamic_initial_gain_threshold_ { u8 dig_enable_flag; u8 dig_algorithm; u8 dbg_mode; @@ -172,8 +171,7 @@ typedef enum tag_dig_cck_cs_ratio_state_definition DIG_CS_RATIO_HIGHER = 1, DIG_CS_MAX }dm_dig_cs_ratio_e; -typedef struct _Dynamic_Rx_Path_Selection_ -{ +typedef struct _Dynamic_Rx_Path_Selection_ { u8 Enable; u8 DbgMode; u8 cck_method; @@ -203,8 +201,7 @@ typedef enum tag_DM_DbgMode_Definition DM_DBG_MAX }DM_DBG_E; -typedef struct tag_Tx_Config_Cmd_Format -{ +typedef struct tag_Tx_Config_Cmd_Format { u32 Op; /* Command packet type. */ u32 Length; /* Command packet length. */ u32 Value; diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c index 6df5f75..c1ab5cf 100644 --- a/drivers/staging/rtl8192u/r8192U_wx.c +++ b/drivers/staging/rtl8192u/r8192U_wx.c @@ -354,8 +354,7 @@ static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a, return ret; } -struct iw_range_with_scan_capa -{ +struct iw_range_with_scan_capa { /* Informative stuff (to choose between different interface) */ __u32 throughput; /* To give an idea... */ /* In theory this value should be the maximum benchmarked diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.h b/drivers/staging/rtl8192u/r819xU_cmdpkt.h index fbbd270..59caa4e 100644 --- a/drivers/staging/rtl8192u/r819xU_cmdpkt.h +++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.h @@ -19,8 +19,7 @@ /*------------------------------Define structure----------------------------*/ /* Define different command packet structure. */ /* 1. RX side: TX feedback packet. */ -typedef struct tag_cmd_pkt_tx_feedback -{ +typedef struct tag_cmd_pkt_tx_feedback { // DWORD 0 u8 element_id; /* Command packet type. */ u8 length; /* Command packet length. */ @@ -57,8 +56,7 @@ typedef struct tag_cmd_pkt_tx_feedback /* 2. RX side: Interrupt status packet. It includes Beacon State, Beacon Timer Interrupt and other useful informations in MAC ISR Reg. */ -typedef struct tag_cmd_pkt_interrupt_status -{ +typedef struct tag_cmd_pkt_interrupt_status { u8 element_id; /* Command packet type. */ u8 length; /* Command packet length. */ u16 reserve; @@ -67,8 +65,7 @@ typedef struct tag_cmd_pkt_interrupt_status /* 3. TX side: Set configuration packet. */ -typedef struct tag_cmd_pkt_set_configuration -{ +typedef struct tag_cmd_pkt_set_configuration { u8 element_id; /* Command packet type. */ u8 length; /* Command packet length. */ u16 reserve1; /* */ @@ -89,8 +86,7 @@ typedef struct tag_cmd_pkt_set_configuration #define cmpk_query_cfg_t cmpk_set_cfg_t /* 5. Multi packet feedback status. */ -typedef struct tag_tx_stats_feedback // PJ quick rxcmd 09042007 -{ +typedef struct tag_tx_stats_feedback { // PJ quick rxcmd 09042007 // For endian transfer --> Driver will not the same as firmware structure. // DW 0 u16 reserve1; @@ -130,8 +126,7 @@ typedef struct tag_tx_stats_feedback // PJ quick rxcmd 09042007 /* 6. Debug feedback message. */ /* 2007/10/23 MH Define RX debug message */ -typedef struct tag_rx_debug_message_feedback -{ +typedef struct tag_rx_debug_message_feedback { // For endian transfer --> for driver // DW 0 u16 reserve1; @@ -144,8 +139,7 @@ typedef struct tag_rx_debug_message_feedback }cmpk_rx_dbginfo_t; /* 2008/03/20 MH Define transmit rate history. For big endian format. */ -typedef struct tag_tx_rate_history -{ +typedef struct tag_tx_rate_history { // For endian transfer --> for driver // DW 0 u8 element_id; // Command packet type -- cgit v0.10.2 From fdc64a9eda15535076cc7e97fcfab3dc7d432f11 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 6 Dec 2012 12:23:03 +0100 Subject: staging/rtl8192u: indent with tabs, not spaces Converted staging/rtl8187se to use tabs instead of spaces for indentation to fix the checkpatch error "code indent should use tabs where possible". Signed-off-by: Sebastian Hahn Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h index b85e3e3..210898c 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h @@ -2088,10 +2088,10 @@ struct ieee80211_device { struct delayed_work start_ibss_wq; struct work_struct wx_sync_scan_wq; struct workqueue_struct *wq; - // Qos related. Added by Annie, 2005-11-01. - //STA_QOS StaQos; + // Qos related. Added by Annie, 2005-11-01. + //STA_QOS StaQos; - //u32 STA_EDCA_PARAM[4]; + //u32 STA_EDCA_PARAM[4]; //CHANNEL_ACCESS_SETTING ChannelAccessSetting; @@ -2107,11 +2107,11 @@ struct ieee80211_device { struct net_device *dev); int (*reset_port)(struct net_device *dev); - int (*is_queue_full) (struct net_device * dev, int pri); + int (*is_queue_full) (struct net_device * dev, int pri); - int (*handle_management) (struct net_device * dev, - struct ieee80211_network * network, u16 type); - int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb); + int (*handle_management) (struct net_device * dev, + struct ieee80211_network * network, u16 type); + int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb); /* Softmac-generated frames (management) are TXed via this * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c index 8e58647..ee7ce5f 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c @@ -52,7 +52,7 @@ static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee, u16 fc = le16_to_cpu(hdr->frame_ctl); skb->dev = ieee->dev; - skb_reset_mac_header(skb); + skb_reset_mac_header(skb); skb_pull(skb, ieee80211_get_hdrlen(fc)); skb->pkt_type = PACKET_OTHERHOST; @@ -218,16 +218,16 @@ ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb, * this is not mandatory.... but seems that the probe * response parser uses it */ - struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data; + struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data; rx_stats->len = skb->len; ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats); - //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) - if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames - { - dev_kfree_skb_any(skb); - return 0; - } + //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) + if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames + { + dev_kfree_skb_any(skb); + return 0; + } ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype); @@ -773,7 +773,7 @@ void RxReorderIndicatePacket( struct ieee80211_device *ieee, } u8 parse_subframe(struct sk_buff *skb, - struct ieee80211_rx_stats *rx_stats, + struct ieee80211_rx_stats *rx_stats, struct ieee80211_rxb *rxb,u8* src,u8* dst) { struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data; @@ -1154,8 +1154,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, type, stype, skb->len); goto rx_dropped; } - if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) - goto rx_dropped; + if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) + goto rx_dropped; /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ @@ -1402,19 +1402,19 @@ static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; * the right values */ static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element - *info_element, int sub_type) + *info_element, int sub_type) { - if (info_element->qui_subtype != sub_type) - return -1; - if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN)) - return -1; - if (info_element->qui_type != QOS_OUI_TYPE) - return -1; - if (info_element->version != QOS_VERSION_1) - return -1; + if (info_element->qui_subtype != sub_type) + return -1; + if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN)) + return -1; + if (info_element->qui_type != QOS_OUI_TYPE) + return -1; + if (info_element->version != QOS_VERSION_1) + return -1; - return 0; + return 0; } @@ -1422,56 +1422,56 @@ static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element * Parse a QoS parameter element */ static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info - *element_param, struct ieee80211_info_element - *info_element) + *element_param, struct ieee80211_info_element + *info_element) { - int ret = 0; - u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2; - - if ((info_element == NULL) || (element_param == NULL)) - return -1; - - if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) { - memcpy(element_param->info_element.qui, info_element->data, - info_element->len); - element_param->info_element.elementID = info_element->id; - element_param->info_element.length = info_element->len; - } else - ret = -1; - if (ret == 0) - ret = ieee80211_verify_qos_info(&element_param->info_element, - QOS_OUI_PARAM_SUB_TYPE); - return ret; + int ret = 0; + u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2; + + if ((info_element == NULL) || (element_param == NULL)) + return -1; + + if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) { + memcpy(element_param->info_element.qui, info_element->data, + info_element->len); + element_param->info_element.elementID = info_element->id; + element_param->info_element.length = info_element->len; + } else + ret = -1; + if (ret == 0) + ret = ieee80211_verify_qos_info(&element_param->info_element, + QOS_OUI_PARAM_SUB_TYPE); + return ret; } /* * Parse a QoS information element */ static int ieee80211_read_qos_info_element(struct - ieee80211_qos_information_element - *element_info, struct ieee80211_info_element - *info_element) + ieee80211_qos_information_element + *element_info, struct ieee80211_info_element + *info_element) { - int ret = 0; - u16 size = sizeof(struct ieee80211_qos_information_element) - 2; - - if (element_info == NULL) - return -1; - if (info_element == NULL) - return -1; - - if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) { - memcpy(element_info->qui, info_element->data, - info_element->len); - element_info->elementID = info_element->id; - element_info->length = info_element->len; - } else - ret = -1; - - if (ret == 0) - ret = ieee80211_verify_qos_info(element_info, - QOS_OUI_INFO_SUB_TYPE); - return ret; + int ret = 0; + u16 size = sizeof(struct ieee80211_qos_information_element) - 2; + + if (element_info == NULL) + return -1; + if (info_element == NULL) + return -1; + + if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) { + memcpy(element_info->qui, info_element->data, + info_element->len); + element_info->elementID = info_element->id; + element_info->length = info_element->len; + } else + ret = -1; + + if (ret == 0) + ret = ieee80211_verify_qos_info(element_info, + QOS_OUI_INFO_SUB_TYPE); + return ret; } @@ -1479,39 +1479,39 @@ static int ieee80211_read_qos_info_element(struct * Write QoS parameters from the ac parameters. */ static int ieee80211_qos_convert_ac_to_parameters(struct - ieee80211_qos_parameter_info - *param_elm, struct - ieee80211_qos_parameters - *qos_param) + ieee80211_qos_parameter_info + *param_elm, struct + ieee80211_qos_parameters + *qos_param) { - int rc = 0; - int i; - struct ieee80211_qos_ac_parameter *ac_params; + int rc = 0; + int i; + struct ieee80211_qos_ac_parameter *ac_params; u8 aci; - //u8 cw_min; - //u8 cw_max; + //u8 cw_min; + //u8 cw_max; - for (i = 0; i < QOS_QUEUE_NUM; i++) { - ac_params = &(param_elm->ac_params_record[i]); + for (i = 0; i < QOS_QUEUE_NUM; i++) { + ac_params = &(param_elm->ac_params_record[i]); aci = (ac_params->aci_aifsn & 0x60) >> 5; if(aci >= QOS_QUEUE_NUM) continue; - qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f; + qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f; /* WMM spec P.11: The minimum value for AIFSN shall be 2 */ - qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci]; + qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci]; - qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F; + qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F; - qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4; + qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4; - qos_param->flag[aci] = - (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00; - qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit); - } - return rc; + qos_param->flag[aci] = + (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00; + qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit); + } + return rc; } /* @@ -1520,38 +1520,38 @@ static int ieee80211_qos_convert_ac_to_parameters(struct * which type to read */ static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element - *info_element, - struct ieee80211_network *network) + *info_element, + struct ieee80211_network *network) { - int rc = 0; - struct ieee80211_qos_parameters *qos_param = NULL; - struct ieee80211_qos_information_element qos_info_element; - - rc = ieee80211_read_qos_info_element(&qos_info_element, info_element); - - if (rc == 0) { - network->qos_data.param_count = qos_info_element.ac_info & 0x0F; - network->flags |= NETWORK_HAS_QOS_INFORMATION; - } else { - struct ieee80211_qos_parameter_info param_element; - - rc = ieee80211_read_qos_param_element(¶m_element, - info_element); - if (rc == 0) { - qos_param = &(network->qos_data.parameters); - ieee80211_qos_convert_ac_to_parameters(¶m_element, - qos_param); - network->flags |= NETWORK_HAS_QOS_PARAMETERS; - network->qos_data.param_count = - param_element.info_element.ac_info & 0x0F; - } - } - - if (rc == 0) { - IEEE80211_DEBUG_QOS("QoS is supported\n"); - network->qos_data.supported = 1; - } - return rc; + int rc = 0; + struct ieee80211_qos_parameters *qos_param = NULL; + struct ieee80211_qos_information_element qos_info_element; + + rc = ieee80211_read_qos_info_element(&qos_info_element, info_element); + + if (rc == 0) { + network->qos_data.param_count = qos_info_element.ac_info & 0x0F; + network->flags |= NETWORK_HAS_QOS_INFORMATION; + } else { + struct ieee80211_qos_parameter_info param_element; + + rc = ieee80211_read_qos_param_element(¶m_element, + info_element); + if (rc == 0) { + qos_param = &(network->qos_data.parameters); + ieee80211_qos_convert_ac_to_parameters(¶m_element, + qos_param); + network->flags |= NETWORK_HAS_QOS_PARAMETERS; + network->qos_data.param_count = + param_element.info_element.ac_info & 0x0F; + } + } + + if (rc == 0) { + IEEE80211_DEBUG_QOS("QoS is supported\n"); + network->qos_data.supported = 1; + } + return rc; } #ifdef CONFIG_IEEE80211_DEBUG @@ -1559,37 +1559,37 @@ static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element static const char *get_info_element_string(u16 id) { - switch (id) { - MFIE_STRING(SSID); - MFIE_STRING(RATES); - MFIE_STRING(FH_SET); - MFIE_STRING(DS_SET); - MFIE_STRING(CF_SET); - MFIE_STRING(TIM); - MFIE_STRING(IBSS_SET); - MFIE_STRING(COUNTRY); - MFIE_STRING(HOP_PARAMS); - MFIE_STRING(HOP_TABLE); - MFIE_STRING(REQUEST); - MFIE_STRING(CHALLENGE); - MFIE_STRING(POWER_CONSTRAINT); - MFIE_STRING(POWER_CAPABILITY); - MFIE_STRING(TPC_REQUEST); - MFIE_STRING(TPC_REPORT); - MFIE_STRING(SUPP_CHANNELS); - MFIE_STRING(CSA); - MFIE_STRING(MEASURE_REQUEST); - MFIE_STRING(MEASURE_REPORT); - MFIE_STRING(QUIET); - MFIE_STRING(IBSS_DFS); - // MFIE_STRING(ERP_INFO); - MFIE_STRING(RSN); - MFIE_STRING(RATES_EX); - MFIE_STRING(GENERIC); - MFIE_STRING(QOS_PARAMETER); - default: - return "UNKNOWN"; - } + switch (id) { + MFIE_STRING(SSID); + MFIE_STRING(RATES); + MFIE_STRING(FH_SET); + MFIE_STRING(DS_SET); + MFIE_STRING(CF_SET); + MFIE_STRING(TIM); + MFIE_STRING(IBSS_SET); + MFIE_STRING(COUNTRY); + MFIE_STRING(HOP_PARAMS); + MFIE_STRING(HOP_TABLE); + MFIE_STRING(REQUEST); + MFIE_STRING(CHALLENGE); + MFIE_STRING(POWER_CONSTRAINT); + MFIE_STRING(POWER_CAPABILITY); + MFIE_STRING(TPC_REQUEST); + MFIE_STRING(TPC_REPORT); + MFIE_STRING(SUPP_CHANNELS); + MFIE_STRING(CSA); + MFIE_STRING(MEASURE_REQUEST); + MFIE_STRING(MEASURE_REPORT); + MFIE_STRING(QUIET); + MFIE_STRING(IBSS_DFS); + // MFIE_STRING(ERP_INFO); + MFIE_STRING(RSN); + MFIE_STRING(RATES_EX); + MFIE_STRING(GENERIC); + MFIE_STRING(QOS_PARAMETER); + default: + return "UNKNOWN"; + } } #endif @@ -1634,7 +1634,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, { u8 i; short offset; - u16 tmp_htcap_len=0; + u16 tmp_htcap_len=0; u16 tmp_htinfo_len=0; u16 ht_realtek_agg_len=0; u8 ht_realtek_agg_buf[MAX_IE_LEN]; @@ -1752,34 +1752,34 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, network->tim.tim_count = info_element->data[0]; network->tim.tim_period = info_element->data[1]; - network->dtim_period = info_element->data[1]; - if(ieee->state != IEEE80211_LINKED) - break; + network->dtim_period = info_element->data[1]; + if(ieee->state != IEEE80211_LINKED) + break; - network->last_dtim_sta_time[0] = stats->mac_time[0]; - network->last_dtim_sta_time[1] = stats->mac_time[1]; + network->last_dtim_sta_time[0] = stats->mac_time[0]; + network->last_dtim_sta_time[1] = stats->mac_time[1]; - network->dtim_data = IEEE80211_DTIM_VALID; + network->dtim_data = IEEE80211_DTIM_VALID; - if(info_element->data[0] != 0) - break; + if(info_element->data[0] != 0) + break; - if(info_element->data[2] & 1) - network->dtim_data |= IEEE80211_DTIM_MBCAST; + if(info_element->data[2] & 1) + network->dtim_data |= IEEE80211_DTIM_MBCAST; - offset = (info_element->data[2] >> 1)*2; + offset = (info_element->data[2] >> 1)*2; - //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id); + //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id); - if(ieee->assoc_id < 8*offset || - ieee->assoc_id > 8*(offset + info_element->len -3)) + if(ieee->assoc_id < 8*offset || + ieee->assoc_id > 8*(offset + info_element->len -3)) - break; + break; - offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ; + offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ; - if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) - network->dtim_data |= IEEE80211_DTIM_UCAST; + if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) + network->dtim_data |= IEEE80211_DTIM_UCAST; //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n"); break; @@ -1820,17 +1820,17 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, } #ifdef THOMAS_TURBO - if (info_element->len == 7 && - info_element->data[0] == 0x00 && - info_element->data[1] == 0xe0 && - info_element->data[2] == 0x4c && - info_element->data[3] == 0x01 && - info_element->data[4] == 0x02) { - network->Turbo_Enable = 1; - } + if (info_element->len == 7 && + info_element->data[0] == 0x00 && + info_element->data[1] == 0xe0 && + info_element->data[2] == 0x4c && + info_element->data[3] == 0x01 && + info_element->data[4] == 0x02) { + network->Turbo_Enable = 1; + } #endif - //for HTcap and HTinfo parameters + //for HTcap and HTinfo parameters if(tmp_htcap_len == 0){ if(info_element->len >= 4 && info_element->data[0] == 0x00 && @@ -2014,7 +2014,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, network->rsn_ie_len); break; - //HT related element. + //HT related element. case MFIE_TYPE_HT_CAP: IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n", info_element->len); @@ -2027,7 +2027,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT() // windows driver will update WMM parameters each beacon received once connected - // Linux driver is a bit different. + // Linux driver is a bit different. network->bssht.bdSupportHT = true; } else @@ -2189,10 +2189,10 @@ static inline int ieee80211_network_init( //char *p; #endif - network->qos_data.active = 0; - network->qos_data.supported = 0; - network->qos_data.param_count = 0; - network->qos_data.old_param_count = 0; + network->qos_data.active = 0; + network->qos_data.supported = 0; + network->qos_data.param_count = 0; + network->qos_data.old_param_count = 0; /* Pull out fixed field data */ memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); @@ -2209,9 +2209,9 @@ static inline int ieee80211_network_init( network->flags = 0; network->atim_window = 0; network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ? - 0x3 : 0x0; + 0x3 : 0x0; network->berp_info_valid = false; - network->broadcom_cap_exist = false; + network->broadcom_cap_exist = false; network->ralink_cap_exist = false; network->atheros_cap_exist = false; network->cisco_cap_exist = false; @@ -2233,9 +2233,9 @@ static inline int ieee80211_network_init( network->wpa_ie_len = 0; network->rsn_ie_len = 0; - if (ieee80211_parse_info_param - (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) - return 1; + if (ieee80211_parse_info_param + (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) + return 1; network->mode = 0; if (stats->freq == IEEE80211_52GHZ_BAND) @@ -2329,7 +2329,7 @@ static inline void update_network(struct ieee80211_network *dst, dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1]; memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters)); - dst->bssht.bdSupportHT = src->bssht.bdSupportHT; + dst->bssht.bdSupportHT = src->bssht.bdSupportHT; dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation; dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen; memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen); diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 2c2bd00..e83c310 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -2503,8 +2503,8 @@ void ieee80211_disassociate(struct ieee80211_device *ieee) } void ieee80211_associate_retry_wq(struct work_struct *work) { - struct delayed_work *dwork = container_of(work, struct delayed_work, work); - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq); + struct delayed_work *dwork = container_of(work, struct delayed_work, work); + struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq); unsigned long flags; down(&ieee->wx_sem); diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c index 918dee7..7214361 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c @@ -70,7 +70,7 @@ val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep | | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | | '-----------------------------------------------------------------------------------------' - /\ + /\ | 802.11 Data Frame | ,--------- 'ctrl' expands to >-----------' @@ -656,17 +656,17 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) memcpy(&dest, skb->data, ETH_ALEN); memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN); - /* Advance the SKB to the start of the payload */ - skb_pull(skb, sizeof(struct ethhdr)); + /* Advance the SKB to the start of the payload */ + skb_pull(skb, sizeof(struct ethhdr)); - /* Determine total amount of storage required for TXB packets */ - bytes = skb->len + SNAP_SIZE + sizeof(u16); + /* Determine total amount of storage required for TXB packets */ + bytes = skb->len + SNAP_SIZE + sizeof(u16); if (encrypt) fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_WEP; else - fc = IEEE80211_FTYPE_DATA; + fc = IEEE80211_FTYPE_DATA; //if(ieee->current_network.QoS_Enable) if(qos_actived) @@ -689,7 +689,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN); } - header.frame_ctl = cpu_to_le16(fc); + header.frame_ctl = cpu_to_le16(fc); /* Determine fragmentation size based on destination (multicast * and broadcast are not fragmented) */ diff --git a/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h b/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h index a8df410..c3c8710 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h @@ -73,7 +73,7 @@ struct cipher_alg { unsigned int cia_min_keysize; unsigned int cia_max_keysize; int (*cia_setkey)(void *ctx, const u8 *key, - unsigned int keylen, u32 *flags); + unsigned int keylen, u32 *flags); void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src); void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src); }; @@ -84,16 +84,16 @@ struct digest_alg { void (*dia_update)(void *ctx, const u8 *data, unsigned int len); void (*dia_final)(void *ctx, u8 *out); int (*dia_setkey)(void *ctx, const u8 *key, - unsigned int keylen, u32 *flags); + unsigned int keylen, u32 *flags); }; struct compress_alg { int (*coa_init)(void *ctx); void (*coa_exit)(void *ctx); int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen); + u8 *dst, unsigned int *dlen); int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen); + u8 *dst, unsigned int *dlen); }; #define cra_cipher cra_u.cipher @@ -139,15 +139,15 @@ struct cipher_tfm { unsigned int cit_ivsize; u32 cit_mode; int (*cit_setkey)(struct crypto_tfm *tfm, - const u8 *key, unsigned int keylen); + const u8 *key, unsigned int keylen); int (*cit_encrypt)(struct crypto_tfm *tfm, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes); int (*cit_encrypt_iv)(struct crypto_tfm *tfm, - struct scatterlist *dst, - struct scatterlist *src, - unsigned int nbytes, u8 *iv); + struct scatterlist *dst, + struct scatterlist *src, + unsigned int nbytes, u8 *iv); int (*cit_decrypt)(struct crypto_tfm *tfm, struct scatterlist *dst, struct scatterlist *src, @@ -162,12 +162,12 @@ struct cipher_tfm { struct digest_tfm { void (*dit_init)(struct crypto_tfm *tfm); void (*dit_update)(struct crypto_tfm *tfm, - struct scatterlist *sg, unsigned int nsg); + struct scatterlist *sg, unsigned int nsg); void (*dit_final)(struct crypto_tfm *tfm, u8 *out); void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg, - unsigned int nsg, u8 *out); + unsigned int nsg, u8 *out); int (*dit_setkey)(struct crypto_tfm *tfm, - const u8 *key, unsigned int keylen); + const u8 *key, unsigned int keylen); #ifdef CONFIG_CRYPTO_HMAC void *dit_hmac_block; #endif @@ -175,11 +175,11 @@ struct digest_tfm { struct compress_tfm { int (*cot_compress)(struct crypto_tfm *tfm, - const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen); + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen); int (*cot_decompress)(struct crypto_tfm *tfm, - const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen); + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen); }; #define crt_cipher crt_u.cipher @@ -277,8 +277,8 @@ static inline void crypto_digest_init(struct crypto_tfm *tfm) } static inline void crypto_digest_update(struct crypto_tfm *tfm, - struct scatterlist *sg, - unsigned int nsg) + struct scatterlist *sg, + unsigned int nsg) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); tfm->crt_digest.dit_update(tfm, sg, nsg); @@ -291,15 +291,15 @@ static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out) } static inline void crypto_digest_digest(struct crypto_tfm *tfm, - struct scatterlist *sg, - unsigned int nsg, u8 *out) + struct scatterlist *sg, + unsigned int nsg, u8 *out) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); tfm->crt_digest.dit_digest(tfm, sg, nsg, out); } static inline int crypto_digest_setkey(struct crypto_tfm *tfm, - const u8 *key, unsigned int keylen) + const u8 *key, unsigned int keylen) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); if (tfm->crt_digest.dit_setkey == NULL) @@ -308,25 +308,25 @@ static inline int crypto_digest_setkey(struct crypto_tfm *tfm, } static inline int crypto_cipher_setkey(struct crypto_tfm *tfm, - const u8 *key, unsigned int keylen) + const u8 *key, unsigned int keylen) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); return tfm->crt_cipher.cit_setkey(tfm, key, keylen); } static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, - struct scatterlist *dst, - struct scatterlist *src, - unsigned int nbytes) + struct scatterlist *dst, + struct scatterlist *src, + unsigned int nbytes) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); } static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, - struct scatterlist *dst, - struct scatterlist *src, - unsigned int nbytes, u8 *iv) + struct scatterlist *dst, + struct scatterlist *src, + unsigned int nbytes, u8 *iv) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); @@ -334,18 +334,18 @@ static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, } static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, - struct scatterlist *dst, - struct scatterlist *src, - unsigned int nbytes) + struct scatterlist *dst, + struct scatterlist *src, + unsigned int nbytes) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); } static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, - struct scatterlist *dst, - struct scatterlist *src, - unsigned int nbytes, u8 *iv) + struct scatterlist *dst, + struct scatterlist *src, + unsigned int nbytes, u8 *iv) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); @@ -353,30 +353,30 @@ static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, } static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, - const u8 *src, unsigned int len) + const u8 *src, unsigned int len) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); memcpy(tfm->crt_cipher.cit_iv, src, len); } static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, - u8 *dst, unsigned int len) + u8 *dst, unsigned int len) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); memcpy(dst, tfm->crt_cipher.cit_iv, len); } static inline int crypto_comp_compress(struct crypto_tfm *tfm, - const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen) + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen); } static inline int crypto_comp_decompress(struct crypto_tfm *tfm, - const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen) + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen) { BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen); @@ -388,11 +388,11 @@ static inline int crypto_comp_decompress(struct crypto_tfm *tfm, #ifdef CONFIG_CRYPTO_HMAC void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen); void crypto_hmac_update(struct crypto_tfm *tfm, - struct scatterlist *sg, unsigned int nsg); + struct scatterlist *sg, unsigned int nsg); void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key, - unsigned int *keylen, u8 *out); + unsigned int *keylen, u8 *out); void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen, - struct scatterlist *sg, unsigned int nsg, u8 *out); + struct scatterlist *sg, unsigned int nsg, u8 *out); #endif /* CONFIG_CRYPTO_HMAC */ #endif /* _LINUX_CRYPTO_H */ diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c index 3c515b7..7e49ad8 100644 --- a/drivers/staging/rtl8192u/r8180_93cx6.c +++ b/drivers/staging/rtl8192u/r8180_93cx6.c @@ -95,7 +95,7 @@ u32 eprom_read(struct net_device *dev, u32 addr) u32 ret; ret=0; - //enable EPROM programming + //enable EPROM programming write_nic_byte_E(dev, EPROM_CMD, (EPROM_CMD_PROGRAM<%s(), chan:%d\n", __FUNCTION__, priv->chan); // rtl8192_set_chan(dev, priv->chan); if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) - { - u32 reg = 0; - reg = read_nic_dword(dev, RCR); - if (priv->ieee80211->state == IEEE80211_LINKED) - priv->ReceiveConfig = reg |= RCR_CBSSID; - else - priv->ReceiveConfig = reg &= ~RCR_CBSSID; - write_nic_dword(dev, RCR, reg); - } + { + u32 reg = 0; + reg = read_nic_dword(dev, RCR); + if (priv->ieee80211->state == IEEE80211_LINKED) + priv->ReceiveConfig = reg |= RCR_CBSSID; + else + priv->ReceiveConfig = reg &= ~RCR_CBSSID; + write_nic_dword(dev, RCR, reg); + } // rtl8192_set_rxconf(dev); } static struct ieee80211_qos_parameters def_qos_parameters = { - {3,3,3,3},/* cw_min */ - {7,7,7,7},/* cw_max */ - {2,2,2,2},/* aifs */ - {0,0,0,0},/* flags */ - {0,0,0,0} /* tx_op_limit */ + {3,3,3,3},/* cw_min */ + {7,7,7,7},/* cw_max */ + {2,2,2,2},/* aifs */ + {0,0,0,0},/* flags */ + {0,0,0,0} /* tx_op_limit */ }; void rtl8192_update_beacon(struct work_struct * work) { - struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work); - struct net_device *dev = priv->ieee80211->dev; + struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work); + struct net_device *dev = priv->ieee80211->dev; struct ieee80211_device* ieee = priv->ieee80211; struct ieee80211_network* net = &ieee->current_network; @@ -3583,7 +3583,7 @@ TxCheckStuck(struct net_device *dev) for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++) { if(QueueID == TXCMD_QUEUE) - continue; + continue; #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0)) #else @@ -3591,7 +3591,7 @@ TxCheckStuck(struct net_device *dev) #endif continue; - bCheckFwTxCnt = true; + bCheckFwTxCnt = true; } // PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK); // spin_unlock_irqrestore(&priv->ieee80211->lock,flags); @@ -4110,7 +4110,7 @@ extern void rtl819x_watchdog_wqcallback(struct work_struct *work) notify_wx_assoc_event(priv->ieee80211); RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid); priv->ieee80211->link_change(dev); - queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq); + queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq); } } @@ -4807,9 +4807,9 @@ rtl819x_evm_dbtopercentage( ret_val = value; if(ret_val >= 0) - ret_val = 0; + ret_val = 0; if(ret_val <= -33) - ret_val = -33; + ret_val = -33; ret_val = 0 - ret_val; ret_val*=3; if(ret_val == 99) -- cgit v0.10.2 From c4cda304692ce6e6610b4302ea69a08a5070e4f2 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Wed, 5 Dec 2012 21:40:21 +0100 Subject: staging/rtl8192u: don't init globals to 0 or NULL Fix a couple of instances where checkpatch complained about initializing globals with 0. Signed-off-by: Sebastian Hahn Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c index c673adc..76c56e5 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c @@ -220,7 +220,7 @@ void free_ieee80211(struct net_device *dev) #ifdef CONFIG_IEEE80211_DEBUG -u32 ieee80211_debug_level = 0; +u32 ieee80211_debug_level; static int debug = \ // IEEE80211_DL_INFO | // IEEE80211_DL_WX | @@ -241,7 +241,7 @@ static int debug = \ //IEEE80211_DL_DATA | IEEE80211_DL_ERR //awayls open this flags to show error out ; -struct proc_dir_entry *ieee80211_proc = NULL; +struct proc_dir_entry *ieee80211_proc; static int show_debug_level(char *page, char **start, off_t offset, int count, int *eof, void *data) -- cgit v0.10.2 From 24fbe875256acf71ab13e869afddbc3a75d7dfbc Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Wed, 5 Dec 2012 21:40:22 +0100 Subject: staging/rtl8192u: use same indent for switch and case Fix the checkpatch error "switch and case should be at the same indent" Signed-off-by: Sebastian Hahn Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index e83c310..7062f9d 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -1948,166 +1948,166 @@ ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb, switch (WLAN_FC_GET_STYPE(header->frame_ctl)) { - case IEEE80211_STYPE_ASSOC_RESP: - case IEEE80211_STYPE_REASSOC_RESP: - - IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n", - WLAN_FC_GET_STYPE(header->frame_ctl)); - if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && - ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED && - ieee->iw_mode == IW_MODE_INFRA){ - struct ieee80211_network network_resp; - struct ieee80211_network *network = &network_resp; - - if (0 == (errcode=assoc_parse(ieee,skb, &aid))){ - ieee->state=IEEE80211_LINKED; - ieee->assoc_id = aid; - ieee->softmac_stats.rx_ass_ok++; - /* station support qos */ - /* Let the register setting defaultly with Legacy station */ - if(ieee->qos_support) { - assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data; - memset(network, 0, sizeof(*network)); - if (ieee80211_parse_info_param(ieee,assoc_resp->info_element,\ - rx_stats->len - sizeof(*assoc_resp),\ - network,rx_stats)){ - return 1; - } - else - { //filling the PeerHTCap. //maybe not necessary as we can get its info from current_network. - memcpy(ieee->pHTInfo->PeerHTCapBuf, network->bssht.bdHTCapBuf, network->bssht.bdHTCapLen); - memcpy(ieee->pHTInfo->PeerHTInfoBuf, network->bssht.bdHTInfoBuf, network->bssht.bdHTInfoLen); - } - if (ieee->handle_assoc_response != NULL) - ieee->handle_assoc_response(ieee->dev, (struct ieee80211_assoc_response_frame*)header, network); + case IEEE80211_STYPE_ASSOC_RESP: + case IEEE80211_STYPE_REASSOC_RESP: + + IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n", + WLAN_FC_GET_STYPE(header->frame_ctl)); + if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && + ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED && + ieee->iw_mode == IW_MODE_INFRA){ + struct ieee80211_network network_resp; + struct ieee80211_network *network = &network_resp; + + if (0 == (errcode=assoc_parse(ieee,skb, &aid))){ + ieee->state=IEEE80211_LINKED; + ieee->assoc_id = aid; + ieee->softmac_stats.rx_ass_ok++; + /* station support qos */ + /* Let the register setting defaultly with Legacy station */ + if(ieee->qos_support) { + assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data; + memset(network, 0, sizeof(*network)); + if (ieee80211_parse_info_param(ieee,assoc_resp->info_element,\ + rx_stats->len - sizeof(*assoc_resp),\ + network,rx_stats)){ + return 1; } - ieee80211_associate_complete(ieee); - } else { - /* aid could not been allocated */ - ieee->softmac_stats.rx_ass_err++; - printk( - "Association response status code 0x%x\n", - errcode); - IEEE80211_DEBUG_MGMT( - "Association response status code 0x%x\n", - errcode); - if(ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT) { - queue_work(ieee->wq, &ieee->associate_procedure_wq); - } else { - ieee80211_associate_abort(ieee); + else + { //filling the PeerHTCap. //maybe not necessary as we can get its info from current_network. + memcpy(ieee->pHTInfo->PeerHTCapBuf, network->bssht.bdHTCapBuf, network->bssht.bdHTCapLen); + memcpy(ieee->pHTInfo->PeerHTInfoBuf, network->bssht.bdHTInfoBuf, network->bssht.bdHTInfoLen); } + if (ieee->handle_assoc_response != NULL) + ieee->handle_assoc_response(ieee->dev, (struct ieee80211_assoc_response_frame*)header, network); + } + ieee80211_associate_complete(ieee); + } else { + /* aid could not been allocated */ + ieee->softmac_stats.rx_ass_err++; + printk( + "Association response status code 0x%x\n", + errcode); + IEEE80211_DEBUG_MGMT( + "Association response status code 0x%x\n", + errcode); + if(ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT) { + queue_work(ieee->wq, &ieee->associate_procedure_wq); + } else { + ieee80211_associate_abort(ieee); } } - break; + } + break; - case IEEE80211_STYPE_ASSOC_REQ: - case IEEE80211_STYPE_REASSOC_REQ: + case IEEE80211_STYPE_ASSOC_REQ: + case IEEE80211_STYPE_REASSOC_REQ: - if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && - ieee->iw_mode == IW_MODE_MASTER) + if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && + ieee->iw_mode == IW_MODE_MASTER) - ieee80211_rx_assoc_rq(ieee, skb); - break; + ieee80211_rx_assoc_rq(ieee, skb); + break; - case IEEE80211_STYPE_AUTH: + case IEEE80211_STYPE_AUTH: - if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){ - if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING && - ieee->iw_mode == IW_MODE_INFRA){ + if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){ + if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING && + ieee->iw_mode == IW_MODE_INFRA){ - IEEE80211_DEBUG_MGMT("Received authentication response"); + IEEE80211_DEBUG_MGMT("Received authentication response"); - if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){ - if(ieee->open_wep || !challenge){ - ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED; - ieee->softmac_stats.rx_auth_rs_ok++; - if(!(ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE)) + if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){ + if(ieee->open_wep || !challenge){ + ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED; + ieee->softmac_stats.rx_auth_rs_ok++; + if(!(ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE)) + { + if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) { - if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) + // WEP or TKIP encryption + if(IsHTHalfNmodeAPs(ieee)) { - // WEP or TKIP encryption - if(IsHTHalfNmodeAPs(ieee)) - { - bSupportNmode = true; - bHalfSupportNmode = true; - } - else - { - bSupportNmode = false; - bHalfSupportNmode = false; - } - printk("==========>to link with AP using SEC(%d, %d)", bSupportNmode, bHalfSupportNmode); + bSupportNmode = true; + bHalfSupportNmode = true; } + else + { + bSupportNmode = false; + bHalfSupportNmode = false; + } + printk("==========>to link with AP using SEC(%d, %d)", bSupportNmode, bHalfSupportNmode); } - /* Dummy wirless mode setting to avoid encryption issue */ - if(bSupportNmode) { - //N mode setting - ieee->SetWirelessMode(ieee->dev, \ - ieee->current_network.mode); - }else{ - //b/g mode setting - /*TODO*/ - ieee->SetWirelessMode(ieee->dev, IEEE_G); - } - - if (ieee->current_network.mode == IEEE_N_24G && bHalfSupportNmode == true) - { - printk("===============>entern half N mode\n"); - ieee->bHalfWirelessN24GMode = true; - } - else - ieee->bHalfWirelessN24GMode = false; - - ieee80211_associate_step2(ieee); + } + /* Dummy wirless mode setting to avoid encryption issue */ + if(bSupportNmode) { + //N mode setting + ieee->SetWirelessMode(ieee->dev, \ + ieee->current_network.mode); }else{ - ieee80211_auth_challenge(ieee, challenge, chlen); + //b/g mode setting + /*TODO*/ + ieee->SetWirelessMode(ieee->dev, IEEE_G); + } + + if (ieee->current_network.mode == IEEE_N_24G && bHalfSupportNmode == true) + { + printk("===============>entern half N mode\n"); + ieee->bHalfWirelessN24GMode = true; } + else + ieee->bHalfWirelessN24GMode = false; + + ieee80211_associate_step2(ieee); }else{ - ieee->softmac_stats.rx_auth_rs_err++; - IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode); - ieee80211_associate_abort(ieee); + ieee80211_auth_challenge(ieee, challenge, chlen); } - - }else if (ieee->iw_mode == IW_MODE_MASTER){ - ieee80211_rx_auth_rq(ieee, skb); + }else{ + ieee->softmac_stats.rx_auth_rs_err++; + IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode); + ieee80211_associate_abort(ieee); } + + }else if (ieee->iw_mode == IW_MODE_MASTER){ + ieee80211_rx_auth_rq(ieee, skb); } - break; + } + break; - case IEEE80211_STYPE_PROBE_REQ: + case IEEE80211_STYPE_PROBE_REQ: - if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) && - ((ieee->iw_mode == IW_MODE_ADHOC || - ieee->iw_mode == IW_MODE_MASTER) && - ieee->state == IEEE80211_LINKED)){ - ieee80211_rx_probe_rq(ieee, skb); - } - break; + if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) && + ((ieee->iw_mode == IW_MODE_ADHOC || + ieee->iw_mode == IW_MODE_MASTER) && + ieee->state == IEEE80211_LINKED)){ + ieee80211_rx_probe_rq(ieee, skb); + } + break; - case IEEE80211_STYPE_DISASSOC: - case IEEE80211_STYPE_DEAUTH: - /* FIXME for now repeat all the association procedure - * both for disassociation and deauthentication - */ - if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && - ieee->state == IEEE80211_LINKED && - ieee->iw_mode == IW_MODE_INFRA){ - - ieee->state = IEEE80211_ASSOCIATING; - ieee->softmac_stats.reassoc++; - - notify_wx_assoc_event(ieee); - //HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); - RemovePeerTS(ieee, header->addr2); - queue_work(ieee->wq, &ieee->associate_procedure_wq); - } - break; - case IEEE80211_STYPE_MANAGE_ACT: - ieee80211_process_action(ieee,skb); - break; - default: - return -1; - break; + case IEEE80211_STYPE_DISASSOC: + case IEEE80211_STYPE_DEAUTH: + /* FIXME for now repeat all the association procedure + * both for disassociation and deauthentication + */ + if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && + ieee->state == IEEE80211_LINKED && + ieee->iw_mode == IW_MODE_INFRA){ + + ieee->state = IEEE80211_ASSOCIATING; + ieee->softmac_stats.reassoc++; + + notify_wx_assoc_event(ieee); + //HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); + RemovePeerTS(ieee, header->addr2); + queue_work(ieee->wq, &ieee->associate_procedure_wq); + } + break; + case IEEE80211_STYPE_MANAGE_ACT: + ieee80211_process_action(ieee,skb); + break; + default: + return -1; + break; } //dev_kfree_skb_any(skb); diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c index 7214361..c39e680 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c @@ -283,22 +283,22 @@ ieee80211_classify(struct sk_buff *skb, struct ieee80211_network *network) // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); ip = ip_hdr(skb); switch (ip->tos & 0xfc) { - case 0x20: - return 2; - case 0x40: - return 1; - case 0x60: - return 3; - case 0x80: - return 4; - case 0xa0: - return 5; - case 0xc0: - return 6; - case 0xe0: - return 7; - default: - return 0; + case 0x20: + return 2; + case 0x40: + return 1; + case 0x60: + return 3; + case 0x80: + return 4; + case 0xa0: + return 5; + case 0xc0: + return 6; + case 0xe0: + return 7; + default: + return 0; } } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c index f0ba7f4..e1fe54a 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c @@ -761,7 +761,7 @@ int ieee80211_wx_set_mlme(struct ieee80211_device *ieee, case IW_MLME_DISASSOC: ieee80211_disassociate(ieee); break; - default: + default: return -EOPNOTSUPP; } return 0; diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 93fffea..f59bd92 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -1875,43 +1875,43 @@ u8 MapHwQueueToFirmwareQueue(u8 QueueID) u8 QueueSelect = 0x0; //defualt set to switch(QueueID) { - case BE_QUEUE: - QueueSelect = QSLT_BE; //or QSelect = pTcb->priority; - break; + case BE_QUEUE: + QueueSelect = QSLT_BE; //or QSelect = pTcb->priority; + break; - case BK_QUEUE: - QueueSelect = QSLT_BK; //or QSelect = pTcb->priority; - break; + case BK_QUEUE: + QueueSelect = QSLT_BK; //or QSelect = pTcb->priority; + break; - case VO_QUEUE: - QueueSelect = QSLT_VO; //or QSelect = pTcb->priority; - break; + case VO_QUEUE: + QueueSelect = QSLT_VO; //or QSelect = pTcb->priority; + break; - case VI_QUEUE: - QueueSelect = QSLT_VI; //or QSelect = pTcb->priority; - break; - case MGNT_QUEUE: - QueueSelect = QSLT_MGNT; - break; + case VI_QUEUE: + QueueSelect = QSLT_VI; //or QSelect = pTcb->priority; + break; + case MGNT_QUEUE: + QueueSelect = QSLT_MGNT; + break; - case BEACON_QUEUE: - QueueSelect = QSLT_BEACON; - break; + case BEACON_QUEUE: + QueueSelect = QSLT_BEACON; + break; - // TODO: 2006.10.30 mark other queue selection until we verify it is OK - // TODO: Remove Assertions + // TODO: 2006.10.30 mark other queue selection until we verify it is OK + // TODO: Remove Assertions //#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502) - case TXCMD_QUEUE: - QueueSelect = QSLT_CMD; - break; + case TXCMD_QUEUE: + QueueSelect = QSLT_CMD; + break; //#endif - case HIGH_QUEUE: - QueueSelect = QSLT_HIGH; - break; + case HIGH_QUEUE: + QueueSelect = QSLT_HIGH; + break; - default: - RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID); - break; + default: + RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID); + break; } return QueueSelect; } @@ -1921,39 +1921,39 @@ u8 MRateToHwRate8190Pci(u8 rate) u8 ret = DESC90_RATE1M; switch(rate) { - case MGN_1M: ret = DESC90_RATE1M; break; - case MGN_2M: ret = DESC90_RATE2M; break; - case MGN_5_5M: ret = DESC90_RATE5_5M; break; - case MGN_11M: ret = DESC90_RATE11M; break; - case MGN_6M: ret = DESC90_RATE6M; break; - case MGN_9M: ret = DESC90_RATE9M; break; - case MGN_12M: ret = DESC90_RATE12M; break; - case MGN_18M: ret = DESC90_RATE18M; break; - case MGN_24M: ret = DESC90_RATE24M; break; - case MGN_36M: ret = DESC90_RATE36M; break; - case MGN_48M: ret = DESC90_RATE48M; break; - case MGN_54M: ret = DESC90_RATE54M; break; - - // HT rate since here - case MGN_MCS0: ret = DESC90_RATEMCS0; break; - case MGN_MCS1: ret = DESC90_RATEMCS1; break; - case MGN_MCS2: ret = DESC90_RATEMCS2; break; - case MGN_MCS3: ret = DESC90_RATEMCS3; break; - case MGN_MCS4: ret = DESC90_RATEMCS4; break; - case MGN_MCS5: ret = DESC90_RATEMCS5; break; - case MGN_MCS6: ret = DESC90_RATEMCS6; break; - case MGN_MCS7: ret = DESC90_RATEMCS7; break; - case MGN_MCS8: ret = DESC90_RATEMCS8; break; - case MGN_MCS9: ret = DESC90_RATEMCS9; break; - case MGN_MCS10: ret = DESC90_RATEMCS10; break; - case MGN_MCS11: ret = DESC90_RATEMCS11; break; - case MGN_MCS12: ret = DESC90_RATEMCS12; break; - case MGN_MCS13: ret = DESC90_RATEMCS13; break; - case MGN_MCS14: ret = DESC90_RATEMCS14; break; - case MGN_MCS15: ret = DESC90_RATEMCS15; break; - case (0x80|0x20): ret = DESC90_RATEMCS32; break; - - default: break; + case MGN_1M: ret = DESC90_RATE1M; break; + case MGN_2M: ret = DESC90_RATE2M; break; + case MGN_5_5M: ret = DESC90_RATE5_5M; break; + case MGN_11M: ret = DESC90_RATE11M; break; + case MGN_6M: ret = DESC90_RATE6M; break; + case MGN_9M: ret = DESC90_RATE9M; break; + case MGN_12M: ret = DESC90_RATE12M; break; + case MGN_18M: ret = DESC90_RATE18M; break; + case MGN_24M: ret = DESC90_RATE24M; break; + case MGN_36M: ret = DESC90_RATE36M; break; + case MGN_48M: ret = DESC90_RATE48M; break; + case MGN_54M: ret = DESC90_RATE54M; break; + + // HT rate since here + case MGN_MCS0: ret = DESC90_RATEMCS0; break; + case MGN_MCS1: ret = DESC90_RATEMCS1; break; + case MGN_MCS2: ret = DESC90_RATEMCS2; break; + case MGN_MCS3: ret = DESC90_RATEMCS3; break; + case MGN_MCS4: ret = DESC90_RATEMCS4; break; + case MGN_MCS5: ret = DESC90_RATEMCS5; break; + case MGN_MCS6: ret = DESC90_RATEMCS6; break; + case MGN_MCS7: ret = DESC90_RATEMCS7; break; + case MGN_MCS8: ret = DESC90_RATEMCS8; break; + case MGN_MCS9: ret = DESC90_RATEMCS9; break; + case MGN_MCS10: ret = DESC90_RATEMCS10; break; + case MGN_MCS11: ret = DESC90_RATEMCS11; break; + case MGN_MCS12: ret = DESC90_RATEMCS12; break; + case MGN_MCS13: ret = DESC90_RATEMCS13; break; + case MGN_MCS14: ret = DESC90_RATEMCS14; break; + case MGN_MCS15: ret = DESC90_RATEMCS15; break; + case (0x80|0x20): ret = DESC90_RATEMCS32; break; + + default: break; } return ret; } @@ -4364,66 +4364,66 @@ int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) } switch (cmd) { - case RTL_IOCTL_WPA_SUPPLICANT: + case RTL_IOCTL_WPA_SUPPLICANT: //parse here for HW security - if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) + if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) + { + if (ipw->u.crypt.set_tx) { - if (ipw->u.crypt.set_tx) + if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) + ieee->pairwise_key_type = KEY_TYPE_CCMP; + else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) + ieee->pairwise_key_type = KEY_TYPE_TKIP; + else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) { - if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) - ieee->pairwise_key_type = KEY_TYPE_CCMP; - else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) - ieee->pairwise_key_type = KEY_TYPE_TKIP; - else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) - { - if (ipw->u.crypt.key_len == 13) - ieee->pairwise_key_type = KEY_TYPE_WEP104; - else if (ipw->u.crypt.key_len == 5) - ieee->pairwise_key_type = KEY_TYPE_WEP40; - } - else - ieee->pairwise_key_type = KEY_TYPE_NA; - - if (ieee->pairwise_key_type) - { - memcpy((u8*)key, ipw->u.crypt.key, 16); - EnableHWSecurityConfig8192(dev); - //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching! - //added by WB. - setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); - if (ieee->auth_mode != 2) - setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); - } + if (ipw->u.crypt.key_len == 13) + ieee->pairwise_key_type = KEY_TYPE_WEP104; + else if (ipw->u.crypt.key_len == 5) + ieee->pairwise_key_type = KEY_TYPE_WEP40; } - else //if (ipw->u.crypt.idx) //group key use idx > 0 + else + ieee->pairwise_key_type = KEY_TYPE_NA; + + if (ieee->pairwise_key_type) { memcpy((u8*)key, ipw->u.crypt.key, 16); - if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) - ieee->group_key_type= KEY_TYPE_CCMP; - else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) - ieee->group_key_type = KEY_TYPE_TKIP; - else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) - { - if (ipw->u.crypt.key_len == 13) - ieee->group_key_type = KEY_TYPE_WEP104; - else if (ipw->u.crypt.key_len == 5) - ieee->group_key_type = KEY_TYPE_WEP40; - } - else - ieee->group_key_type = KEY_TYPE_NA; + EnableHWSecurityConfig8192(dev); + //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching! + //added by WB. + setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); + if (ieee->auth_mode != 2) + setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); + } + } + else //if (ipw->u.crypt.idx) //group key use idx > 0 + { + memcpy((u8*)key, ipw->u.crypt.key, 16); + if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) + ieee->group_key_type= KEY_TYPE_CCMP; + else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) + ieee->group_key_type = KEY_TYPE_TKIP; + else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) + { + if (ipw->u.crypt.key_len == 13) + ieee->group_key_type = KEY_TYPE_WEP104; + else if (ipw->u.crypt.key_len == 5) + ieee->group_key_type = KEY_TYPE_WEP40; + } + else + ieee->group_key_type = KEY_TYPE_NA; - if (ieee->group_key_type) - { - setKey( dev, - ipw->u.crypt.idx, - ipw->u.crypt.idx, //KeyIndex - ieee->group_key_type, //KeyType - broadcast_addr, //MacAddr - 0, //DefaultKey - key); //KeyContent - } + if (ieee->group_key_type) + { + setKey( dev, + ipw->u.crypt.idx, + ipw->u.crypt.idx, //KeyIndex + ieee->group_key_type, //KeyType + broadcast_addr, //MacAddr + 0, //DefaultKey + key); //KeyContent } } + } #ifdef JOHN_HWSEC_DEBUG //john's test 0711 printk("@@ wrq->u pointer = "); @@ -4436,7 +4436,7 @@ int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data); break; - default: + default: ret = -EOPNOTSUPP; break; } @@ -4453,49 +4453,49 @@ u8 HwRateToMRate90(bool bIsHT, u8 rate) if(!bIsHT) { switch(rate) { - case DESC90_RATE1M: ret_rate = MGN_1M; break; - case DESC90_RATE2M: ret_rate = MGN_2M; break; - case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break; - case DESC90_RATE11M: ret_rate = MGN_11M; break; - case DESC90_RATE6M: ret_rate = MGN_6M; break; - case DESC90_RATE9M: ret_rate = MGN_9M; break; - case DESC90_RATE12M: ret_rate = MGN_12M; break; - case DESC90_RATE18M: ret_rate = MGN_18M; break; - case DESC90_RATE24M: ret_rate = MGN_24M; break; - case DESC90_RATE36M: ret_rate = MGN_36M; break; - case DESC90_RATE48M: ret_rate = MGN_48M; break; - case DESC90_RATE54M: ret_rate = MGN_54M; break; - - default: - ret_rate = 0xff; - RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT); - break; + case DESC90_RATE1M: ret_rate = MGN_1M; break; + case DESC90_RATE2M: ret_rate = MGN_2M; break; + case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break; + case DESC90_RATE11M: ret_rate = MGN_11M; break; + case DESC90_RATE6M: ret_rate = MGN_6M; break; + case DESC90_RATE9M: ret_rate = MGN_9M; break; + case DESC90_RATE12M: ret_rate = MGN_12M; break; + case DESC90_RATE18M: ret_rate = MGN_18M; break; + case DESC90_RATE24M: ret_rate = MGN_24M; break; + case DESC90_RATE36M: ret_rate = MGN_36M; break; + case DESC90_RATE48M: ret_rate = MGN_48M; break; + case DESC90_RATE54M: ret_rate = MGN_54M; break; + + default: + ret_rate = 0xff; + RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT); + break; } } else { switch(rate) { - case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break; - case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break; - case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break; - case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break; - case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break; - case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break; - case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break; - case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break; - case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break; - case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break; - case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break; - case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break; - case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break; - case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break; - case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break; - case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break; - case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break; - - default: - ret_rate = 0xff; - RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT); - break; + case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break; + case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break; + case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break; + case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break; + case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break; + case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break; + case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break; + case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break; + case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break; + case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break; + case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break; + case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break; + case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break; + case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break; + case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break; + case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break; + case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break; + + default: + ret_rate = 0xff; + RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT); + break; } } @@ -5696,25 +5696,25 @@ void rtl8192_irq_rx_tasklet(struct r8192_priv *priv) info = (struct rtl8192_rx_info *)skb->cb; switch (info->out_pipe) { /* Nomal packet pipe */ - case 3: - //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe); - priv->IrpPendingCount--; - rtl8192_rx_nomal(skb); - break; + case 3: + //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe); + priv->IrpPendingCount--; + rtl8192_rx_nomal(skb); + break; - /* Command packet pipe */ - case 9: - RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\ - info->out_pipe); + /* Command packet pipe */ + case 9: + RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\ + info->out_pipe); - rtl8192_rx_cmd(skb); - break; + rtl8192_rx_cmd(skb); + break; - default: /* should never get here! */ - RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\ - info->out_pipe); - dev_kfree_skb(skb); - break; + default: /* should never get here! */ + RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\ + info->out_pipe); + dev_kfree_skb(skb); + break; } } diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c index c1ab5cf..c904aa8 100644 --- a/drivers/staging/rtl8192u/r8192U_wx.c +++ b/drivers/staging/rtl8192u/r8192U_wx.c @@ -710,12 +710,12 @@ static int r8192_wx_set_enc(struct net_device *dev, #define CONF_WEP104 0x14 switch(wrqu->encoding.flags & IW_ENCODE_INDEX){ - case 0: key_idx = ieee->tx_keyidx; break; - case 1: key_idx = 0; break; - case 2: key_idx = 1; break; - case 3: key_idx = 2; break; - case 4: key_idx = 3; break; - default: break; + case 0: key_idx = ieee->tx_keyidx; break; + case 1: key_idx = 0; break; + case 2: key_idx = 1; break; + case 3: key_idx = 2; break; + case 4: key_idx = 3; break; + default: break; } if(wrqu->encoding.length==0x5){ diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c index 46b8043..573e9cd 100644 --- a/drivers/staging/rtl8192u/r819xU_firmware.c +++ b/drivers/staging/rtl8192u/r819xU_firmware.c @@ -334,56 +334,56 @@ bool init_firmware(struct net_device *dev) } switch(init_step) { - case FW_INIT_STEP0_BOOT: - /* Download boot - * initialize command descriptor. - * will set polling bit when firmware code is also configured - */ - pfirmware->firmware_status = FW_STATUS_1_MOVE_BOOT_CODE; + case FW_INIT_STEP0_BOOT: + /* Download boot + * initialize command descriptor. + * will set polling bit when firmware code is also configured + */ + pfirmware->firmware_status = FW_STATUS_1_MOVE_BOOT_CODE; #ifdef RTL8190P - // To initialize IMEM, CPU move code from 0x80000080, hence, we send 0x80 byte packet - rt_status = fwSendNullPacket(dev, RTL8190_CPU_START_OFFSET); - if(rt_status != true) - { - RT_TRACE(COMP_INIT, "fwSendNullPacket() fail ! \n"); - goto download_firmware_fail; - } + // To initialize IMEM, CPU move code from 0x80000080, hence, we send 0x80 byte packet + rt_status = fwSendNullPacket(dev, RTL8190_CPU_START_OFFSET); + if(rt_status != true) + { + RT_TRACE(COMP_INIT, "fwSendNullPacket() fail ! \n"); + goto download_firmware_fail; + } #endif - //mdelay(1000); - /* - * To initialize IMEM, CPU move code from 0x80000080, - * hence, we send 0x80 byte packet - */ - break; - - case FW_INIT_STEP1_MAIN: - /* Download firmware code. Wait until Boot Ready and Turn on CPU */ - pfirmware->firmware_status = FW_STATUS_2_MOVE_MAIN_CODE; - - /* Check Put Code OK and Turn On CPU */ - rt_status = CPUcheck_maincodeok_turnonCPU(dev); - if(rt_status != TRUE) { - RT_TRACE(COMP_ERR, "CPUcheck_maincodeok_turnonCPU fail!\n"); - goto download_firmware_fail; - } - - pfirmware->firmware_status = FW_STATUS_3_TURNON_CPU; - break; - - case FW_INIT_STEP2_DATA: - /* download initial data code */ - pfirmware->firmware_status = FW_STATUS_4_MOVE_DATA_CODE; - mdelay(1); - - rt_status = CPUcheck_firmware_ready(dev); - if(rt_status != TRUE) { - RT_TRACE(COMP_ERR, "CPUcheck_firmware_ready fail(%d)!\n",rt_status); - goto download_firmware_fail; - } - - /* wait until data code is initialized ready.*/ - pfirmware->firmware_status = FW_STATUS_5_READY; - break; + //mdelay(1000); + /* + * To initialize IMEM, CPU move code from 0x80000080, + * hence, we send 0x80 byte packet + */ + break; + + case FW_INIT_STEP1_MAIN: + /* Download firmware code. Wait until Boot Ready and Turn on CPU */ + pfirmware->firmware_status = FW_STATUS_2_MOVE_MAIN_CODE; + + /* Check Put Code OK and Turn On CPU */ + rt_status = CPUcheck_maincodeok_turnonCPU(dev); + if(rt_status != TRUE) { + RT_TRACE(COMP_ERR, "CPUcheck_maincodeok_turnonCPU fail!\n"); + goto download_firmware_fail; + } + + pfirmware->firmware_status = FW_STATUS_3_TURNON_CPU; + break; + + case FW_INIT_STEP2_DATA: + /* download initial data code */ + pfirmware->firmware_status = FW_STATUS_4_MOVE_DATA_CODE; + mdelay(1); + + rt_status = CPUcheck_firmware_ready(dev); + if(rt_status != TRUE) { + RT_TRACE(COMP_ERR, "CPUcheck_firmware_ready fail(%d)!\n",rt_status); + goto download_firmware_fail; + } + + /* wait until data code is initialized ready.*/ + pfirmware->firmware_status = FW_STATUS_5_READY; + break; } } diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c index 2ff851f..17fac41 100644 --- a/drivers/staging/rtl8192u/r819xU_phy.c +++ b/drivers/staging/rtl8192u/r819xU_phy.c @@ -957,56 +957,56 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E u8 ret = 0; switch(eRFPath){ - case RF90_PATH_A: - for(i = 0;i Date: Wed, 5 Dec 2012 21:40:23 +0100 Subject: staging/rtl8192u: do not init statics to 0 Fix the checkpatch error "do not initialize statics to 0 or NULL" Signed-off-by: Sebastian Hahn Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 7062f9d..454f889 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -498,7 +498,7 @@ void ieee80211_softmac_scan_wq(struct work_struct *work) { struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq); - static short watchdog = 0; + static short watchdog; u8 channel_map[MAX_CHANNEL_NUMBER+1]; memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); if(!ieee->ieee_up) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c index 421da8a..45422db 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c @@ -302,7 +302,7 @@ void ieee80211_wx_sync_scan_wq(struct work_struct *work) HT_EXTCHNL_OFFSET chan_offset=0; HT_CHANNEL_WIDTH bandwidth=0; int b40M = 0; - static int count = 0; + static int count; chan = ieee->current_network.channel; netif_carrier_off(ieee->dev); diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index f59bd92..01f82d3 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -3613,7 +3613,7 @@ HalRxCheckStuck819xUsb(struct net_device *dev) u16 RegRxCounter = read_nic_word(dev, 0x130); struct r8192_priv *priv = ieee80211_priv(dev); bool bStuck = FALSE; - static u8 rx_chk_cnt = 0; + static u8 rx_chk_cnt; RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter); // If rssi is small, we should check rx for long time because of bad rx. // or maybe it will continuous silent reset every 2 seconds. @@ -4071,7 +4071,7 @@ extern void rtl819x_watchdog_wqcallback(struct work_struct *work) struct net_device *dev = priv->ieee80211->dev; struct ieee80211_device* ieee = priv->ieee80211; RESET_TYPE ResetType = RESET_TYPE_NORESET; - static u8 check_reset_cnt=0; + static u8 check_reset_cnt; bool bBusyTraffic = false; if(!priv->up) @@ -4554,12 +4554,12 @@ void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee802 u8 rfpath; u32 nspatial_stream, tmp_val; //u8 i; - static u32 slide_rssi_index=0, slide_rssi_statistics=0; - static u32 slide_evm_index=0, slide_evm_statistics=0; - static u32 last_rssi=0, last_evm=0; + static u32 slide_rssi_index, slide_rssi_statistics; + static u32 slide_evm_index, slide_evm_statistics; + static u32 last_rssi, last_evm; - static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0; - static u32 last_beacon_adc_pwdb=0; + static u32 slide_beacon_adc_pwdb_index, slide_beacon_adc_pwdb_statistics; + static u32 last_beacon_adc_pwdb; struct ieee80211_hdr_3addr *hdr; u16 sc ; diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c index 7e2918f..ea46717 100644 --- a/drivers/staging/rtl8192u/r8192U_dm.c +++ b/drivers/staging/rtl8192u/r8192U_dm.c @@ -201,8 +201,8 @@ extern void deinit_hal_dm(struct net_device *dev) void dm_CheckRxAggregation(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev); PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo; - static unsigned long lastTxOkCnt = 0; - static unsigned long lastRxOkCnt = 0; + static unsigned long lastTxOkCnt; + static unsigned long lastRxOkCnt; unsigned long curTxOkCnt = 0; unsigned long curRxOkCnt = 0; @@ -359,7 +359,7 @@ static void dm_check_rate_adaptive(struct net_device * dev) u32 currentRATR, targetRATR = 0; u32 LowRSSIThreshForRA = 0, HighRSSIThreshForRA = 0; bool bshort_gi_enabled = false; - static u8 ping_rssi_state=0; + static u8 ping_rssi_state; if(!priv->up) @@ -1486,7 +1486,7 @@ void dm_initialize_txpower_tracking(struct net_device *dev) static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u32 tx_power_track_counter = 0; + static u32 tx_power_track_counter; if(!priv->btxpower_tracking) return; @@ -1505,7 +1505,7 @@ static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev) static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u8 TM_Trigger=0; + static u8 TM_Trigger; //DbgPrint("dm_CheckTXPowerTracking() \n"); if(!priv->btxpower_tracking) return; @@ -2091,7 +2091,7 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi( { struct r8192_priv *priv = ieee80211_priv(dev); u8 i; - static u8 fw_dig=0; + static u8 fw_dig; if (dm_digtable.dig_enable_flag == false) return; @@ -2131,7 +2131,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm( struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u32 reset_cnt = 0; + static u32 reset_cnt; u8 i; if (dm_digtable.dig_enable_flag == false) @@ -2319,7 +2319,7 @@ static void dm_ctrl_initgain_byrssi_highpwr( struct net_device * dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u32 reset_cnt_highpwr = 0; + static u32 reset_cnt_highpwr; // For smooth, we can not change high power DIG state in the range. if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_high_power_lowthresh) && @@ -2395,8 +2395,8 @@ static void dm_initial_gain( { struct r8192_priv *priv = ieee80211_priv(dev); u8 initial_gain=0; - static u8 initialized=0, force_write=0; - static u32 reset_cnt=0; + static u8 initialized, force_write; + static u32 reset_cnt; if(dm_digtable.dig_algorithm_switch) { @@ -2462,8 +2462,8 @@ static void dm_pd_th( struct net_device * dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u8 initialized=0, force_write=0; - static u32 reset_cnt = 0; + static u8 initialized, force_write; + static u32 reset_cnt; if(dm_digtable.dig_algorithm_switch) { @@ -2574,8 +2574,8 @@ static void dm_cs_ratio( struct net_device * dev) { struct r8192_priv *priv = ieee80211_priv(dev); - static u8 initialized=0,force_write=0; - static u32 reset_cnt = 0; + static u8 initialized,force_write; + static u32 reset_cnt; if(dm_digtable.dig_algorithm_switch) { @@ -2651,8 +2651,8 @@ static void dm_check_edca_turbo( //PSTA_QOS pStaQos = pMgntInfo->pStaQos; // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo. - static unsigned long lastTxOkCnt = 0; - static unsigned long lastRxOkCnt = 0; + static unsigned long lastTxOkCnt; + static unsigned long lastRxOkCnt; unsigned long curTxOkCnt = 0; unsigned long curRxOkCnt = 0; @@ -2785,8 +2785,8 @@ static void dm_ctstoself(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev); PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo; - static unsigned long lastTxOkCnt = 0; - static unsigned long lastRxOkCnt = 0; + static unsigned long lastTxOkCnt; + static unsigned long lastRxOkCnt; unsigned long curTxOkCnt = 0; unsigned long curRxOkCnt = 0; @@ -3044,7 +3044,7 @@ static void dm_rxpath_sel_byrssi(struct net_device * dev) u8 cck_rx_ver2_max_index=0, cck_rx_ver2_min_index=0, cck_rx_ver2_sec_index=0; u8 cur_rf_rssi; long cur_cck_pwdb; - static u8 disabled_rf_cnt=0, cck_Rx_Path_initialized=0; + static u8 disabled_rf_cnt, cck_Rx_Path_initialized; u8 update_cck_rx_path; if(priv->rf_type != RF_2T4R) @@ -3571,7 +3571,7 @@ void dm_check_fsync(struct net_device *dev) struct r8192_priv *priv = ieee80211_priv(dev); //u32 framesyncC34; static u8 reg_c38_State=RegC38_Default; - static u32 reset_cnt=0; + static u32 reset_cnt; RT_TRACE(COMP_HALDM, "RSSI %d TimeInterval %d MultipleTimeInterval %d\n", priv->ieee80211->fsync_rssi_threshold, priv->ieee80211->fsync_time_interval, priv->ieee80211->fsync_multiple_timeinterval); RT_TRACE(COMP_HALDM, "RateBitmap 0x%x FirstDiffRateThreshold %d SecondDiffRateThreshold %d\n", priv->ieee80211->fsync_rate_bitmap, priv->ieee80211->fsync_firstdiff_ratethreshold, priv->ieee80211->fsync_seconddiff_ratethreshold); -- cgit v0.10.2 From 531c336103ebbffffc3211bc9dd439ca81150323 Mon Sep 17 00:00:00 2001 From: Kurt Kanzenbach Date: Fri, 30 Nov 2012 12:18:17 +0100 Subject: staging: keucr: Replaced c99 comments Fixed a coding style issue. Replaced all c99 comments by c89 ones and deleted commented out code. Signed-off-by: Kurt Kanzenbach Acked-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/keucr/usb.c b/drivers/staging/keucr/usb.c index 55a0b82..3fea642 100644 --- a/drivers/staging/keucr/usb.c +++ b/drivers/staging/keucr/usb.c @@ -42,19 +42,12 @@ static int eucr_suspend(struct usb_interface *iface, pm_message_t message) /* Wait until no command is running */ mutex_lock(&us->dev_mutex); - //US_DEBUGP("%s\n", __func__); if (us->suspend_resume_hook) (us->suspend_resume_hook)(us, US_SUSPEND); - /* When runtime PM is working, we'll set a flag to indicate - * whether we should autoresume when a SCSI request arrives. */ - // us->Power_IsResum = true; - //us->SD_Status.Ready = 0; - mutex_unlock(&us->dev_mutex); return 0; } -//EXPORT_SYMBOL_GPL(eucr_suspend); static int eucr_resume(struct usb_interface *iface) { @@ -64,43 +57,40 @@ static int eucr_resume(struct usb_interface *iface) pr_info("--- eucr_resume---\n"); mutex_lock(&us->dev_mutex); - //US_DEBUGP("%s\n", __func__); if (us->suspend_resume_hook) (us->suspend_resume_hook)(us, US_RESUME); mutex_unlock(&us->dev_mutex); - - us->Power_IsResum = true; - // - //us->SD_Status.Ready = 0; //?? - us->SM_Status = *(PSM_STATUS)&tmp; + us->Power_IsResum = true; + + us->SM_Status = *(PSM_STATUS)&tmp; return 0; } -//EXPORT_SYMBOL_GPL(eucr_resume); + static int eucr_reset_resume(struct usb_interface *iface) { BYTE tmp = 0; struct us_data *us = usb_get_intfdata(iface); pr_info("--- eucr_reset_resume---\n"); - //US_DEBUGP("%s\n", __func__); /* Report the reset to the SCSI core */ usb_stor_report_bus_reset(us); - /* FIXME: Notify the subdrivers that they need to reinitialize - * the device */ - //ENE_InitMedia(us); + /* + * FIXME: Notify the subdrivers that they need to reinitialize + * the device + */ + us->Power_IsResum = true; - // - //us->SD_Status.Ready = 0; //?? - us->SM_Status = *(PSM_STATUS)&tmp; + + us->SM_Status = *(PSM_STATUS)&tmp; + return 0; } -//EXPORT_SYMBOL_GPL(usb_stor_reset_resume); #else @@ -110,7 +100,6 @@ static int eucr_reset_resume(struct usb_interface *iface) #endif -//----- eucr_pre_reset() --------------------- static int eucr_pre_reset(struct usb_interface *iface) { struct us_data *us = usb_get_intfdata(iface); @@ -122,7 +111,6 @@ static int eucr_pre_reset(struct usb_interface *iface) return 0; } -//----- eucr_post_reset() --------------------- static int eucr_post_reset(struct usb_interface *iface) { struct us_data *us = usb_get_intfdata(iface); @@ -136,11 +124,10 @@ static int eucr_post_reset(struct usb_interface *iface) return 0; } -//----- fill_inquiry_response() --------------------- void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int data_len) { pr_info("usb --- fill_inquiry_response\n"); - if (data_len<36) // You lose. + if (data_len < 36) /* You lose. */ return; if (data[0]&0x20) @@ -164,7 +151,6 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int usb_stor_set_xfer_buf(us, data, data_len, us->srb, TO_XFER_BUF); } -//----- usb_stor_control_thread() --------------------- static int usb_stor_control_thread(void * __us) { struct us_data *us = (struct us_data *)__us; @@ -175,7 +161,7 @@ static int usb_stor_control_thread(void * __us) { if (wait_for_completion_interruptible(&us->cmnd_ready)) break; - + /* lock the device pointers */ mutex_lock(&(us->dev_mutex)); @@ -193,7 +179,6 @@ static int usb_stor_control_thread(void * __us) { scsi_unlock(host); mutex_unlock(&us->dev_mutex); - //US_DEBUGP("-- exiting\n"); break; } @@ -273,7 +258,6 @@ SkipForAbort: return 0; } -//----- associate_dev() --------------------- static int associate_dev(struct us_data *us, struct usb_interface *intf) { pr_info("usb --- associate_dev\n"); @@ -310,7 +294,6 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf) return 0; } -//----- get_device_info() --------------------- static int get_device_info(struct us_data *us, const struct usb_device_id *id) { struct usb_device *dev = us->pusb_dev; @@ -335,7 +318,6 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) return 0; } -//----- get_transport() --------------------- static int get_transport(struct us_data *us) { pr_info("usb --- get_transport\n"); @@ -349,7 +331,6 @@ static int get_transport(struct us_data *us) default: return -EIO; } - /* pr_info("Transport: %s\n", us->transport_name); */ /* fix for single-lun devices */ if (us->fflags & US_FL_SINGLE_LUN) @@ -357,7 +338,6 @@ static int get_transport(struct us_data *us) return 0; } -//----- get_protocol() --------------------- static int get_protocol(struct us_data *us) { pr_info("usb --- get_protocol\n"); @@ -377,11 +357,9 @@ static int get_protocol(struct us_data *us) default: return -EIO; } - /* pr_info("Protocol: %s\n", us->protocol_name); */ return 0; } -//----- get_pipes() --------------------- static int get_pipes(struct us_data *us) { struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; @@ -436,7 +414,6 @@ static int get_pipes(struct us_data *us) return 0; } -//----- usb_stor_acquire_resources() --------------------- static int usb_stor_acquire_resources(struct us_data *us) { struct task_struct *th; @@ -461,7 +438,6 @@ static int usb_stor_acquire_resources(struct us_data *us) return 0; } -//----- usb_stor_release_resources() --------------------- static void usb_stor_release_resources(struct us_data *us) { pr_info("usb --- usb_stor_release_resources\n"); @@ -484,7 +460,6 @@ static void usb_stor_release_resources(struct us_data *us) usb_free_urb(us->current_urb); } -//----- dissociate_dev() --------------------- static void dissociate_dev(struct us_data *us) { pr_info("usb --- dissociate_dev\n"); @@ -501,7 +476,6 @@ static void dissociate_dev(struct us_data *us) usb_set_intfdata(us->pusb_intf, NULL); } -//----- quiesce_and_remove_host() --------------------- static void quiesce_and_remove_host(struct us_data *us) { struct Scsi_Host *host = us_to_host(us); @@ -512,19 +486,22 @@ static void quiesce_and_remove_host(struct us_data *us) if (us->pusb_dev->state == USB_STATE_NOTATTACHED) set_bit(US_FLIDX_DISCONNECTING, &us->dflags); - /* Prevent SCSI-scanning (if it hasn't started yet) + /* + * Prevent SCSI-scanning (if it hasn't started yet) * and wait for the SCSI-scanning thread to stop. */ set_bit(US_FLIDX_DONT_SCAN, &us->dflags); wake_up(&us->delay_wait); wait_for_completion(&us->scanning_done); - /* Removing the host will perform an orderly shutdown: caches + /* + * Removing the host will perform an orderly shutdown: caches * synchronized, disks spun down, etc. */ scsi_remove_host(host); - /* Prevent any new commands from being accepted and cut short + /* + * Prevent any new commands from being accepted and cut short * reset delays. */ scsi_lock(host); @@ -533,7 +510,6 @@ static void quiesce_and_remove_host(struct us_data *us) wake_up(&us->delay_wait); } -//----- release_everything() --------------------- static void release_everything(struct us_data *us) { pr_info("usb --- release_everything\n"); @@ -543,7 +519,6 @@ static void release_everything(struct us_data *us) scsi_host_put(us_to_host(us)); } -//----- usb_stor_scan_thread() --------------------- static int usb_stor_scan_thread(void * __us) { struct us_data *us = (struct us_data *)__us; @@ -575,7 +550,6 @@ static int usb_stor_scan_thread(void * __us) complete_and_exit(&us->scanning_done, 0); } -//----- eucr_probe() --------------------- static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct Scsi_Host *host; @@ -673,7 +647,6 @@ BadDevice: return result; } -//----- eucr_disconnect() --------------------- static void eucr_disconnect(struct usb_interface *intf) { struct us_data *us = usb_get_intfdata(intf); @@ -683,11 +656,7 @@ static void eucr_disconnect(struct usb_interface *intf) release_everything(us); } -/*********************************************************************** - * Initialization and registration - ***********************************************************************/ - -//----- usb_storage_driver() --------------------- +/* Initialization and registration */ static struct usb_driver usb_storage_driver = { .name = "eucr", .probe = eucr_probe, -- cgit v0.10.2 From 2c392dafa5b89c9ba88a6bbb8690b22103076bde Mon Sep 17 00:00:00 2001 From: Kurt Kanzenbach Date: Fri, 30 Nov 2012 12:18:18 +0100 Subject: staging: keucr: Removed trailing whitespaces Fixed a coding style issue. Removed trailing whitespaces in code. Signed-off-by: Kurt Kanzenbach Acked-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/keucr/usb.c b/drivers/staging/keucr/usb.c index 3fea642..71a505f 100644 --- a/drivers/staging/keucr/usb.c +++ b/drivers/staging/keucr/usb.c @@ -66,7 +66,7 @@ static int eucr_resume(struct usb_interface *iface) us->Power_IsResum = true; us->SM_Status = *(PSM_STATUS)&tmp; - + return 0; } @@ -256,7 +256,7 @@ SkipForAbort: } __set_current_state(TASK_RUNNING); return 0; -} +} static int associate_dev(struct us_data *us, struct usb_interface *intf) { -- cgit v0.10.2 From b466eb5e22acca73fe6c287646139b4d139bd26a Mon Sep 17 00:00:00 2001 From: Kurt Kanzenbach Date: Fri, 30 Nov 2012 12:18:19 +0100 Subject: staging: keucr: Fix parens/braces Fixed a coding style issue. Fixed positions of braces regarding to linux coding style. Signed-off-by: Kurt Kanzenbach Acked-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/keucr/usb.c b/drivers/staging/keucr/usb.c index 71a505f..4dec93d 100644 --- a/drivers/staging/keucr/usb.c +++ b/drivers/staging/keucr/usb.c @@ -130,12 +130,9 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int if (data_len < 36) /* You lose. */ return; - if (data[0]&0x20) - { + if (data[0]&0x20) { memset(data+8,0,28); - } - else - { + } else { u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); memcpy(data+8, us->unusual_dev->vendorName, strlen(us->unusual_dev->vendorName) > 8 ? 8 : @@ -157,8 +154,7 @@ static int usb_stor_control_thread(void * __us) struct Scsi_Host *host = us_to_host(us); pr_info("usb --- usb_stor_control_thread\n"); - for(;;) - { + for (;;) { if (wait_for_completion_interruptible(&us->cmnd_ready)) break; @@ -175,43 +171,34 @@ static int usb_stor_control_thread(void * __us) scsi_lock(host); /* When we are called with no command pending, we're done */ - if (us->srb == NULL) - { + if (us->srb == NULL) { scsi_unlock(host); mutex_unlock(&us->dev_mutex); break; } /* has the command timed out *already* ? */ - if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) - { + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { us->srb->result = DID_ABORT << 16; goto SkipForAbort; } scsi_unlock(host); - if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) - { + if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { us->srb->result = DID_ERROR << 16; - } - else if (us->srb->device->id && !(us->fflags & US_FL_SCM_MULT_TARG)) - { + } else if (us->srb->device->id + && !(us->fflags & US_FL_SCM_MULT_TARG)) { us->srb->result = DID_BAD_TARGET << 16; - } - else if (us->srb->device->lun > us->max_lun) - { + } else if (us->srb->device->lun > us->max_lun) { us->srb->result = DID_BAD_TARGET << 16; - } - else if ((us->srb->cmnd[0] == INQUIRY) && (us->fflags & US_FL_FIX_INQUIRY)) - { + } else if ((us->srb->cmnd[0] == INQUIRY) + && (us->fflags & US_FL_FIX_INQUIRY)) { unsigned char data_ptr[36] = {0x00, 0x80, 0x02, 0x02, 0x1F, 0x00, 0x00, 0x00}; fill_inquiry_response(us, data_ptr, 36); us->srb->result = SAM_STAT_GOOD; - } - else - { + } else { us->proto_handler(us->srb, us); } @@ -219,18 +206,14 @@ static int usb_stor_control_thread(void * __us) scsi_lock(host); /* indicate that the command is done */ - if (us->srb->result != DID_ABORT << 16) - { + if (us->srb->result != DID_ABORT << 16) { us->srb->scsi_done(us->srb); - } - else - { + } else { SkipForAbort: pr_info("scsi command aborted\n"); } - if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) - { + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { complete(&(us->notify)); /* Allow USB transfers to resume */ @@ -247,8 +230,7 @@ SkipForAbort: } /* for (;;) */ /* Wait until we are told to stop */ - for (;;) - { + for (;;) { set_current_state(TASK_INTERRUPTIBLE); if (kthread_should_stop()) break; @@ -272,22 +254,19 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf) /* Allocate the device-related DMA-mapped buffers */ us->cr = usb_alloc_coherent(us->pusb_dev, sizeof(*us->cr), GFP_KERNEL, &us->cr_dma); - if (!us->cr) - { + if (!us->cr) { pr_info("usb_ctrlrequest allocation failed\n"); return -ENOMEM; } us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, GFP_KERNEL, &us->iobuf_dma); - if (!us->iobuf) - { + if (!us->iobuf) { pr_info("I/O buffer allocation failed\n"); return -ENOMEM; } us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); - if (!us->sensebuf) - { + if (!us->sensebuf) { pr_info("Sense buffer allocation failed\n"); return -ENOMEM; } @@ -306,8 +285,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) us->fflags = id->driver_info; us->Power_IsResum = false; - if (us->fflags & US_FL_IGNORE_DEVICE) - { + if (us->fflags & US_FL_IGNORE_DEVICE) { pr_info("device ignored\n"); return -ENODEV; } @@ -348,7 +326,8 @@ static int get_protocol(struct us_data *us) switch (us->subclass) { case USB_SC_SCSI: us->protocol_name = "Transparent SCSI"; - if( (us->pusb_dev->descriptor.idVendor == 0x0CF2) && (us->pusb_dev->descriptor.idProduct == 0x6250) ) + if ((us->pusb_dev->descriptor.idVendor == 0x0CF2) + && (us->pusb_dev->descriptor.idProduct == 0x6250)) us->proto_handler = ENE_stor_invoke_transport; else us->proto_handler = usb_stor_invoke_transport; @@ -371,32 +350,24 @@ static int get_pipes(struct us_data *us) pr_info("usb --- get_pipes\n"); - for (i = 0; i < altsetting->desc.bNumEndpoints; i++) - { + for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { ep = &altsetting->endpoint[i].desc; - if (usb_endpoint_xfer_bulk(ep)) - { - if (usb_endpoint_dir_in(ep)) - { + if (usb_endpoint_xfer_bulk(ep)) { + if (usb_endpoint_dir_in(ep)) { if (!ep_in) ep_in = ep; - } - else - { + } else { if (!ep_out) ep_out = ep; } - } - else if (usb_endpoint_is_int_in(ep)) - { + } else if (usb_endpoint_is_int_in(ep)) { if (!ep_int) ep_int = ep; } } - if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) - { + if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) { pr_info("Endpoint sanity check failed! Rejecting dev.\n"); return -EIO; } @@ -406,8 +377,7 @@ static int get_pipes(struct us_data *us) us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); - if (ep_int) - { + if (ep_int) { us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, ep_int->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); us->ep_bInterval = ep_int->bInterval; } @@ -420,16 +390,14 @@ static int usb_stor_acquire_resources(struct us_data *us) pr_info("usb --- usb_stor_acquire_resources\n"); us->current_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!us->current_urb) - { + if (!us->current_urb) { pr_info("URB allocation failed\n"); return -ENOMEM; } /* Start up our control thread */ th = kthread_run(usb_stor_control_thread, us, "eucr-storage"); - if (IS_ERR(th)) - { + if (IS_ERR(th)) { pr_info("Unable to start control thread\n"); return PTR_ERR(th); } @@ -449,8 +417,7 @@ static void usb_stor_release_resources(struct us_data *us) kthread_stop(us->ctl_thread); /* Call the destructor routine, if it exists */ - if (us->extra_destructor) - { + if (us->extra_destructor) { pr_info("-- calling extra_destructor()\n"); us->extra_destructor(us->extra); } @@ -535,11 +502,10 @@ static int usb_stor_scan_thread(void * __us) } /* If the device is still connected, perform the scanning */ - if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) - { + if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) { /* For bulk-only devices, determine the max LUN value */ - if (us->protocol == USB_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN)) - { + if (us->protocol == USB_PR_BULK + && !(us->fflags & US_FL_SINGLE_LUN)) { mutex_lock(&us->dev_mutex); us->max_lun = usb_stor_Bulk_max_lun(us); mutex_unlock(&us->dev_mutex); @@ -561,8 +527,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id pr_info("usb --- eucr_probe\n"); host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); - if (!host) - { + if (!host) { pr_info("Unable to allocate the scsi host\n"); return -ENOMEM; } @@ -604,8 +569,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id goto BadDevice; result = scsi_add_host(host, &intf->dev); - if (result) - { + if (result) { pr_info("Unable to add the scsi host\n"); goto BadDevice; } -- cgit v0.10.2 From a37629024975714f1e2fa9851b7f77cd1bad0790 Mon Sep 17 00:00:00 2001 From: Laurent Navet Date: Fri, 30 Nov 2012 11:57:32 +0100 Subject: staging: line6: pcm.c fix checkpatch issues fix those checkpatch issues drivers/staging/line6/pcm.c:84: WARNING: simple_strtoul is obsolete, use kstrtoul instead call to obsolete simple_strtoul() replaced by kstrtoint() drivers/staging/line6/pcm.c:423: ERROR: switch and case should be at the same indent realigns comments Signed-off-by: Laurent Navet Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/pcm.c b/drivers/staging/line6/pcm.c index 6c1e313..17969c6 100644 --- a/drivers/staging/line6/pcm.c +++ b/drivers/staging/line6/pcm.c @@ -49,11 +49,11 @@ static ssize_t pcm_set_impulse_volume(struct device *dev, { struct snd_line6_pcm *line6pcm = dev2pcm(dev); int value; - int rv; + int ret; - rv = kstrtoint(buf, 10, &value); - if (rv < 0) - return rv; + ret = kstrtoint(buf, 10, &value); + if (ret < 0) + return ret; line6pcm->impulse_volume = value; @@ -81,7 +81,14 @@ static ssize_t pcm_set_impulse_period(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - dev2pcm(dev)->impulse_period = simple_strtoul(buf, NULL, 10); + int value; + int ret; + + ret = kstrtoint(buf, 10, &value); + if (ret < 0) + return ret; + + dev2pcm(dev)->impulse_period = value; return count; } @@ -455,13 +462,12 @@ int line6_init_pcm(struct usb_line6 *line6, ep_write = 0x01; break; - /* this is for interface_number == 1: - case LINE6_DEVID_TONEPORT_UX2: - case LINE6_DEVID_PODSTUDIO_UX2: - ep_read = 0x87; - ep_write = 0x00; - break; - */ + /* this is for interface_number == 1: + case LINE6_DEVID_TONEPORT_UX2: + case LINE6_DEVID_PODSTUDIO_UX2: + ep_read = 0x87; + ep_write = 0x00; + break; */ default: MISSING_CASE; -- cgit v0.10.2 From 77ecb6fe6dce7a726b374665fe1b74cc5cac30fd Mon Sep 17 00:00:00 2001 From: Laurent Navet Date: Mon, 3 Dec 2012 14:20:25 +0100 Subject: staging: line6: Use kmemdup rather than duplicating its implementation staging: line6: driver.c The semantic patch that makes this output is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Laurent Navet Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c index 1e4ce500..71c2a57 100644 --- a/drivers/staging/line6/driver.c +++ b/drivers/staging/line6/driver.c @@ -307,14 +307,13 @@ int line6_version_request_async(struct usb_line6 *line6) char *buffer; int retval; - buffer = kmalloc(sizeof(line6_request_version), GFP_ATOMIC); + buffer = kmemdup(line6_request_version, + sizeof(line6_request_version), GFP_ATOMIC); if (buffer == NULL) { dev_err(line6->ifcdev, "Out of memory"); return -ENOMEM; } - memcpy(buffer, line6_request_version, sizeof(line6_request_version)); - retval = line6_send_raw_message_async(line6, buffer, sizeof(line6_request_version)); kfree(buffer); -- cgit v0.10.2 From e02b124629dc3d9928dd1af76864d1104ea8e810 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 5 Dec 2012 21:43:16 +0300 Subject: staging: line6: delete an unused function line6_send_sysex_message_async() isn't called from anywhere. Signed-off-by: Dan Carpenter Reviewed-by: Stefan Hajnoczi Reviewed-by: Johannes Thumshirn Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c index 71c2a57..ecb461e 100644 --- a/drivers/staging/line6/driver.c +++ b/drivers/staging/line6/driver.c @@ -332,17 +332,6 @@ int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer, } /* - Send sysex message in pieces of wMaxPacketSize bytes. -*/ -int line6_send_sysex_message_async(struct usb_line6 *line6, const char *buffer, - int size) -{ - return line6_send_raw_message_async(line6, buffer, - size + SYSEX_EXTRA_SIZE) - - SYSEX_EXTRA_SIZE; -} - -/* Allocate buffer for sysex message and prepare header. @param code sysex message code @param size number of bytes between code and sysex end diff --git a/drivers/staging/line6/driver.h b/drivers/staging/line6/driver.h index f0be5a2..1dd768c2 100644 --- a/drivers/staging/line6/driver.h +++ b/drivers/staging/line6/driver.h @@ -208,8 +208,6 @@ extern int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer, int size); extern int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer, int size); -extern int line6_send_sysex_message_async(struct usb_line6 *line6, - const char *buffer, int size); extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); extern void line6_start_timer(struct timer_list *timer, unsigned int msecs, -- cgit v0.10.2 From c020a7a4ea3bfd85afc1d2b5e18414252f18fe98 Mon Sep 17 00:00:00 2001 From: Cong Ding Date: Tue, 4 Dec 2012 01:21:44 +0000 Subject: staging: echo: remove unused variable the variable j isn't used in the loop Signed-off-by: Cong Ding Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/echo/echo.c b/drivers/staging/echo/echo.c index ca87ce9..14dfd91 100644 --- a/drivers/staging/echo/echo.c +++ b/drivers/staging/echo/echo.c @@ -119,7 +119,6 @@ static inline void lms_adapt_bg(struct oslec_state *ec, int clean, int shift) { int i; - int j; int offset1; int offset2; int factor; @@ -142,7 +141,7 @@ static inline void lms_adapt_bg(struct oslec_state *ec, int clean, int shift) /* asm("st:"); */ n = ec->taps; - for (i = 0, j = offset2; i < n; i++, j++) { + for (i = 0; i < n; i++) { exp = *phist++ * factor; ec->fir_taps16[1][i] += (int16_t) ((exp + (1 << 14)) >> 15); } -- cgit v0.10.2 From 78855c7a7c3db183ddb311cd832a137ef7a5e83a Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 4 Dec 2012 21:41:07 +0100 Subject: staging: csr: remove unneeded call to memset(). In uf_send_pkt_to_encrypt(), the memory area zeroed by this call to memset() is overwritten by a call to memcpy() a few instructions later, so it is not needed. Signed-off-by: Cyril Roelandt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/csr/unifi_sme.c b/drivers/staging/csr/unifi_sme.c index 7c6c413..7669037 100644 --- a/drivers/staging/csr/unifi_sme.c +++ b/drivers/staging/csr/unifi_sme.c @@ -1196,7 +1196,6 @@ void uf_send_pkt_to_encrypt(struct work_struct *work) if (pktBulkDataLength > 0) { pktBulkData = kmalloc(pktBulkDataLength, GFP_KERNEL); - memset(pktBulkData, 0, pktBulkDataLength); } else { unifi_error(priv, "uf_send_pkt_to_encrypt() : invalid buffer\n"); return; -- cgit v0.10.2 From 0902468846460274018100bec29e2b236f70ab14 Mon Sep 17 00:00:00 2001 From: Cong Ding Date: Sat, 22 Dec 2012 17:12:26 +0100 Subject: staging: echo.c: fix memory leakage we should check the return value of calling function fir16_create(): a NULL value means the memory allocation fails. this patch also cleans up the error handling in function function oslec_create() Signed-off-by: Cong Ding Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/echo/echo.c b/drivers/staging/echo/echo.c index 14dfd91..5882139 100644 --- a/drivers/staging/echo/echo.c +++ b/drivers/staging/echo/echo.c @@ -229,6 +229,7 @@ struct oslec_state *oslec_create(int len, int adaption_mode) { struct oslec_state *ec; int i; + const int16_t *history; ec = kzalloc(sizeof(*ec), GFP_KERNEL); if (!ec) @@ -238,15 +239,22 @@ struct oslec_state *oslec_create(int len, int adaption_mode) ec->log2taps = top_bit(len); ec->curr_pos = ec->taps - 1; - for (i = 0; i < 2; i++) { - ec->fir_taps16[i] = - kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); - if (!ec->fir_taps16[i]) - goto error_oom; - } + ec->fir_taps16[0] = + kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); + if (!ec->fir_taps16[0]) + goto error_oom_0; + + ec->fir_taps16[1] = + kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); + if (!ec->fir_taps16[1]) + goto error_oom_1; - fir16_create(&ec->fir_state, ec->fir_taps16[0], ec->taps); - fir16_create(&ec->fir_state_bg, ec->fir_taps16[1], ec->taps); + history = fir16_create(&ec->fir_state, ec->fir_taps16[0], ec->taps); + if (!history) + goto error_state; + history = fir16_create(&ec->fir_state_bg, ec->fir_taps16[1], ec->taps); + if (!history) + goto error_state_bg; for (i = 0; i < 5; i++) ec->xvtx[i] = ec->yvtx[i] = ec->xvrx[i] = ec->yvrx[i] = 0; @@ -256,7 +264,7 @@ struct oslec_state *oslec_create(int len, int adaption_mode) ec->snapshot = kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); if (!ec->snapshot) - goto error_oom; + goto error_snap; ec->cond_met = 0; ec->Pstates = 0; @@ -269,10 +277,15 @@ struct oslec_state *oslec_create(int len, int adaption_mode) return ec; -error_oom: - for (i = 0; i < 2; i++) - kfree(ec->fir_taps16[i]); - +error_snap: + fir16_free(&ec->fir_state_bg); +error_state_bg: + fir16_free(&ec->fir_state); +error_state: + kfree(ec->fir_taps16[1]); +error_oom_1: + kfree(ec->fir_taps16[0]); +error_oom_0: kfree(ec); return NULL; } -- cgit v0.10.2 From 3040d05685c899c4a0be86667fa206b19dab0ab8 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Fri, 4 Jan 2013 22:25:45 +0000 Subject: staging: et131x: Replace rxdma csr register magic numbers with defines Several magic numbers were used to represent rxdma csr register bitmasks. Replace them with descriptive defines. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index 84bbcd4..b08dff9 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -577,7 +577,6 @@ static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status) return -ETIMEDOUT; } - /** * eeprom_write - Write a byte to the ET1310's EEPROM * @adapter: pointer to our private adapter structure @@ -843,29 +842,29 @@ static int et131x_init_eeprom(struct et131x_adapter *adapter) static void et131x_rx_dma_enable(struct et131x_adapter *adapter) { /* Setup the receive dma configuration register for normal operation */ - u32 csr = 0x2000; /* FBR1 enable */ + u32 csr = ET_RXDMA_CSR_FBR1_ENABLE; if (adapter->rx_ring.fbr[1]->buffsize == 4096) - csr |= 0x0800; + csr |= ET_RXDMA_CSR_FBR1_SIZE_LO; else if (adapter->rx_ring.fbr[1]->buffsize == 8192) - csr |= 0x1000; + csr |= ET_RXDMA_CSR_FBR1_SIZE_HI; else if (adapter->rx_ring.fbr[1]->buffsize == 16384) - csr |= 0x1800; + csr |= ET_RXDMA_CSR_FBR1_SIZE_LO | ET_RXDMA_CSR_FBR1_SIZE_HI; - csr |= 0x0400; /* FBR0 enable */ + csr |= ET_RXDMA_CSR_FBR0_ENABLE; if (adapter->rx_ring.fbr[0]->buffsize == 256) - csr |= 0x0100; + csr |= ET_RXDMA_CSR_FBR0_SIZE_LO; else if (adapter->rx_ring.fbr[0]->buffsize == 512) - csr |= 0x0200; + csr |= ET_RXDMA_CSR_FBR0_SIZE_HI; else if (adapter->rx_ring.fbr[0]->buffsize == 1024) - csr |= 0x0300; + csr |= ET_RXDMA_CSR_FBR0_SIZE_LO | ET_RXDMA_CSR_FBR0_SIZE_HI; writel(csr, &adapter->regs->rxdma.csr); csr = readl(&adapter->regs->rxdma.csr); - if (csr & 0x00020000) { + if (csr & ET_RXDMA_CSR_HALT_STATUS) { udelay(5); csr = readl(&adapter->regs->rxdma.csr); - if (csr & 0x00020000) { + if (csr & ET_RXDMA_CSR_HALT_STATUS) { dev_err(&adapter->pdev->dev, "RX Dma failed to exit halt state. CSR 0x%08x\n", csr); @@ -881,15 +880,16 @@ static void et131x_rx_dma_disable(struct et131x_adapter *adapter) { u32 csr; /* Setup the receive dma configuration register */ - writel(0x00002001, &adapter->regs->rxdma.csr); + writel(ET_RXDMA_CSR_HALT | ET_RXDMA_CSR_FBR1_ENABLE, + &adapter->regs->rxdma.csr); csr = readl(&adapter->regs->rxdma.csr); - if ((csr & 0x00020000) == 0) { /* Check halt status (bit 17) */ + if (!(csr & ET_RXDMA_CSR_HALT_STATUS)) { udelay(5); csr = readl(&adapter->regs->rxdma.csr); - if ((csr & 0x00020000) == 0) + if (!(csr & ET_RXDMA_CSR_HALT_STATUS)) dev_err(&adapter->pdev->dev, - "RX Dma failed to enter halt state. CSR 0x%08x\n", - csr); + "RX Dma failed to enter halt state. CSR 0x%08x\n", + csr); } } @@ -2032,7 +2032,7 @@ static void et131x_disable_interrupts(struct et131x_adapter *adapter) static void et131x_tx_dma_disable(struct et131x_adapter *adapter) { /* Setup the tramsmit dma configuration register */ - writel(ET_TXDMA_CSR_HALT|ET_TXDMA_SNGL_EPKT, + writel(ET_TXDMA_CSR_HALT | ET_TXDMA_SNGL_EPKT, &adapter->regs->txdma.csr); } diff --git a/drivers/staging/et131x/et131x.h b/drivers/staging/et131x/et131x.h index 347e63d..9fa47f9 100644 --- a/drivers/staging/et131x/et131x.h +++ b/drivers/staging/et131x/et131x.h @@ -317,6 +317,14 @@ struct txdma_regs { /* Location: */ * 18-31: unused */ +#define ET_RXDMA_CSR_HALT 0x0001 +#define ET_RXDMA_CSR_FBR0_SIZE_LO 0x0100 +#define ET_RXDMA_CSR_FBR0_SIZE_HI 0x0200 +#define ET_RXDMA_CSR_FBR0_ENABLE 0x0400 +#define ET_RXDMA_CSR_FBR1_SIZE_LO 0x0800 +#define ET_RXDMA_CSR_FBR1_SIZE_HI 0x1000 +#define ET_RXDMA_CSR_FBR1_ENABLE 0x2000 +#define ET_RXDMA_CSR_HALT_STATUS 0x00020000 /* * structure for dma writeback lo reg in rxdma address map -- cgit v0.10.2 From a129be84ba83b964dde784e87820b89d1a7d29c3 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Fri, 4 Jan 2013 22:25:46 +0000 Subject: staging: et131x: Use register defines instead of magic numbers Use register name defines instead of magic numbers where a bit of clarity would be useful. Also a small typo fix and some register prefixes added, for further clarity. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index b08dff9..e2d5555 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -344,6 +344,10 @@ struct rx_ring { * 14: UDP checksum assist */ +#define TXDESC_FLAG_LASTPKT 0x0001 +#define TXDESC_FLAG_FIRSTPKT 0x0002 +#define TXDESC_FLAG_INTPROC 0x0004 + /* struct tx_desc represents each descriptor on the ring */ struct tx_desc { u32 addr_hi; @@ -774,13 +778,12 @@ static int et131x_init_eeprom(struct et131x_adapter *adapter) /* We first need to check the EEPROM Status code located at offset * 0xB2 of config space */ - pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, - &eestatus); + pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus); /* THIS IS A WORKAROUND: * I need to call this function twice to get my card in a * LG M1 Express Dual running. I tried also a msleep before this - * function, because I thought there could be some time condidions + * function, because I thought there could be some time conditions * but it didn't work. Call the whole function twice also work. */ if (pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus)) { @@ -932,7 +935,10 @@ static void et1310_config_mac_regs1(struct et131x_adapter *adapter) /* First we need to reset everything. Write to MAC configuration * register 1 to perform reset. */ - writel(0xC00F0000, ¯egs->cfg1); + writel(ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET | + ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | + ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC, + ¯egs->cfg1); /* Next lets configure the MAC Inter-packet gap register */ ipg = 0x38005860; /* IPG1 0x38 IPG2 0x58 B2B 0x60 */ @@ -947,7 +953,7 @@ static void et1310_config_mac_regs1(struct et131x_adapter *adapter) writel(0, ¯egs->if_ctrl); /* Let's move on to setting up the mii management configuration */ - writel(0x07, ¯egs->mii_mgmt_cfg); /* Clock reset 0x7 */ + writel(ET_MAC_MIIMGMT_CLK_RST, ¯egs->mii_mgmt_cfg); /* Next lets configure the MAC Station Address register. These * values are read from the EEPROM during initialization and stored @@ -998,38 +1004,43 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) ifctrl = readl(&mac->if_ctrl); /* Set up the if mode bits */ - cfg2 &= ~0x300; + cfg2 &= ~ET_MAC_CFG2_IFMODE_MASK; if (phydev && phydev->speed == SPEED_1000) { - cfg2 |= 0x200; + cfg2 |= ET_MAC_CFG2_IFMODE_1000; /* Phy mode bit */ - ifctrl &= ~(1 << 24); + ifctrl &= ~ET_MAC_IFCTRL_PHYMODE; } else { - cfg2 |= 0x100; - ifctrl |= (1 << 24); + cfg2 |= ET_MAC_CFG2_IFMODE_100; + ifctrl |= ET_MAC_IFCTRL_PHYMODE; } /* We need to enable Rx/Tx */ - cfg1 |= CFG1_RX_ENABLE | CFG1_TX_ENABLE | CFG1_TX_FLOW; + cfg1 |= ET_MAC_CFG1_RX_ENABLE | ET_MAC_CFG1_TX_ENABLE | + ET_MAC_CFG1_TX_FLOW; /* Initialize loop back to off */ - cfg1 &= ~(CFG1_LOOPBACK | CFG1_RX_FLOW); + cfg1 &= ~(ET_MAC_CFG1_LOOPBACK | ET_MAC_CFG1_RX_FLOW); if (adapter->flowcontrol == FLOW_RXONLY || adapter->flowcontrol == FLOW_BOTH) - cfg1 |= CFG1_RX_FLOW; + cfg1 |= ET_MAC_CFG1_RX_FLOW; writel(cfg1, &mac->cfg1); /* Now we need to initialize the MAC Configuration 2 register */ /* preamble 7, check length, huge frame off, pad crc, crc enable full duplex off */ - cfg2 |= 0x7016; - cfg2 &= ~0x0021; + cfg2 |= 0x7 << ET_MAC_CFG2_PREAMBLE_SHIFT; + cfg2 |= ET_MAC_CFG2_IFMODE_LEN_CHECK; + cfg2 |= ET_MAC_CFG2_IFMODE_PAD_CRC; + cfg2 |= ET_MAC_CFG2_IFMODE_CRC_ENABLE; + cfg2 &= ~ET_MAC_CFG2_IFMODE_HUGE_FRAME; + cfg2 &= ~ET_MAC_CFG2_IFMODE_FULL_DPLX; /* Turn on duplex if needed */ if (phydev && phydev->duplex == DUPLEX_FULL) - cfg2 |= 0x01; + cfg2 |= ET_MAC_CFG2_IFMODE_FULL_DPLX; - ifctrl &= ~(1 << 26); + ifctrl &= ~ET_MAC_IFCTRL_GHDMODE; if (phydev && phydev->duplex == DUPLEX_HALF) - ifctrl |= (1<<26); /* Enable ghd */ + ifctrl |= ET_MAC_IFCTRL_GHDMODE; writel(ifctrl, &mac->if_ctrl); writel(cfg2, &mac->cfg2); @@ -1038,7 +1049,7 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) udelay(10); delay++; cfg1 = readl(&mac->cfg1); - } while ((cfg1 & CFG1_WAIT) != CFG1_WAIT && delay < 100); + } while ((cfg1 & ET_MAC_CFG1_WAIT) != ET_MAC_CFG1_WAIT && delay < 100); if (delay == 100) { dev_warn(&adapter->pdev->dev, @@ -1047,7 +1058,7 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) } /* Enable txmac */ - ctl |= 0x09; /* TX mac enable, FC disable */ + ctl |= ET_TX_CTRL_TXMAC_ENABLE | ET_TX_CTRL_FC_DISABLE; writel(ctl, &adapter->regs->txmac.ctl); /* Ready to start the RXDMA/TXDMA engine */ @@ -1139,19 +1150,19 @@ static void et1310_setup_device_for_unicast(struct et131x_adapter *adapter) * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the * MAC address for first address */ - uni_pf3 = (adapter->addr[0] << ET_UNI_PF_ADDR2_1_SHIFT) | - (adapter->addr[1] << ET_UNI_PF_ADDR2_2_SHIFT) | - (adapter->addr[0] << ET_UNI_PF_ADDR1_1_SHIFT) | + uni_pf3 = (adapter->addr[0] << ET_RX_UNI_PF_ADDR2_1_SHIFT) | + (adapter->addr[1] << ET_RX_UNI_PF_ADDR2_2_SHIFT) | + (adapter->addr[0] << ET_RX_UNI_PF_ADDR1_1_SHIFT) | adapter->addr[1]; - uni_pf2 = (adapter->addr[2] << ET_UNI_PF_ADDR2_3_SHIFT) | - (adapter->addr[3] << ET_UNI_PF_ADDR2_4_SHIFT) | - (adapter->addr[4] << ET_UNI_PF_ADDR2_5_SHIFT) | + uni_pf2 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR2_3_SHIFT) | + (adapter->addr[3] << ET_RX_UNI_PF_ADDR2_4_SHIFT) | + (adapter->addr[4] << ET_RX_UNI_PF_ADDR2_5_SHIFT) | adapter->addr[5]; - uni_pf1 = (adapter->addr[2] << ET_UNI_PF_ADDR1_3_SHIFT) | - (adapter->addr[3] << ET_UNI_PF_ADDR1_4_SHIFT) | - (adapter->addr[4] << ET_UNI_PF_ADDR1_5_SHIFT) | + uni_pf1 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR1_3_SHIFT) | + (adapter->addr[3] << ET_RX_UNI_PF_ADDR1_4_SHIFT) | + (adapter->addr[4] << ET_RX_UNI_PF_ADDR1_5_SHIFT) | adapter->addr[5]; pm_csr = readl(&adapter->regs->global.pm_csr); @@ -1208,13 +1219,13 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter) writel(0, &rxmac->mask4_word3); /* Lets setup the WOL Source Address */ - sa_lo = (adapter->addr[2] << ET_WOL_LO_SA3_SHIFT) | - (adapter->addr[3] << ET_WOL_LO_SA4_SHIFT) | - (adapter->addr[4] << ET_WOL_LO_SA5_SHIFT) | + sa_lo = (adapter->addr[2] << ET_RX_WOL_LO_SA3_SHIFT) | + (adapter->addr[3] << ET_RX_WOL_LO_SA4_SHIFT) | + (adapter->addr[4] << ET_RX_WOL_LO_SA5_SHIFT) | adapter->addr[5]; writel(sa_lo, &rxmac->sa_lo); - sa_hi = (u32) (adapter->addr[0] << ET_WOL_HI_SA1_SHIFT) | + sa_hi = (u32) (adapter->addr[0] << ET_RX_WOL_HI_SA1_SHIFT) | adapter->addr[1]; writel(sa_hi, &rxmac->sa_hi); @@ -1224,7 +1235,7 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter) /* Let's initialize the Unicast Packet filtering address */ if (adapter->packet_filter & ET131X_PACKET_TYPE_DIRECTED) { et1310_setup_device_for_unicast(adapter); - pf_ctrl |= 4; /* Unicast filter */ + pf_ctrl |= ET_RX_PFCTRL_UNICST_FILTER_ENABLE; } else { writel(0, &rxmac->uni_pf_addr1); writel(0, &rxmac->uni_pf_addr2); @@ -1233,13 +1244,13 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter) /* Let's initialize the Multicast hash */ if (!(adapter->packet_filter & ET131X_PACKET_TYPE_ALL_MULTICAST)) { - pf_ctrl |= 2; /* Multicast filter */ + pf_ctrl |= ET_RX_PFCTRL_MLTCST_FILTER_ENABLE; et1310_setup_device_for_multicast(adapter); } /* Runt packet filtering. Didn't work in version A silicon. */ - pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << 16; - pf_ctrl |= 8; /* Fragment filter */ + pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << ET_RX_PFCTRL_MIN_PKT_SZ_SHIFT; + pf_ctrl |= ET_RX_PFCTRL_FRAG_FILTER_ENABLE; if (adapter->registry_jumbo_packet > 8192) /* In order to transmit jumbo packets greater than 8k, the @@ -1290,7 +1301,7 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter) * but we still leave the packet filter on. */ writel(pf_ctrl, &rxmac->pf_ctrl); - writel(0x9, &rxmac->ctrl); + writel(ET_RX_CTRL_RXMAC_ENABLE | ET_RX_CTRL_WOL_DISABLE, &rxmac->ctrl); } static void et1310_config_txmac_regs(struct et131x_adapter *adapter) @@ -1401,7 +1412,7 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr, writel(0, &mac->mii_mgmt_cmd); /* Set up the register we need to read from on the correct PHY */ - writel(MII_ADDR(addr, reg), &mac->mii_mgmt_addr); + writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr); writel(0x1, &mac->mii_mgmt_cmd); @@ -1409,7 +1420,7 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr, udelay(50); delay++; mii_indicator = readl(&mac->mii_mgmt_indicator); - } while ((mii_indicator & MGMT_WAIT) && delay < 50); + } while ((mii_indicator & ET_MAC_MGMT_WAIT) && delay < 50); /* If we hit the max delay, we could not read the register */ if (delay == 50) { @@ -1423,7 +1434,7 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr, /* If we hit here we were able to read the register and we need to * return the value to the caller */ - *value = readl(&mac->mii_mgmt_stat) & 0xFFFF; + *value = readl(&mac->mii_mgmt_stat) & ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK; /* Stop the read operation */ writel(0, &mac->mii_mgmt_cmd); @@ -1483,7 +1494,7 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 reg, u16 value) writel(0, &mac->mii_mgmt_cmd); /* Set up the register we need to write to on the correct PHY */ - writel(MII_ADDR(addr, reg), &mac->mii_mgmt_addr); + writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr); /* Add the value to write to the registers to the mac */ writel(value, &mac->mii_mgmt_ctrl); @@ -1492,7 +1503,7 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 reg, u16 value) udelay(50); delay++; mii_indicator = readl(&mac->mii_mgmt_indicator); - } while ((mii_indicator & MGMT_BUSY) && delay < 100); + } while ((mii_indicator & ET_MAC_MGMT_BUSY) && delay < 100); /* If we hit the max delay, we could not write the register */ if (delay == 100) { @@ -1528,7 +1539,7 @@ static void et1310_phy_access_mii_bit(struct et131x_adapter *adapter, u8 *value) { u16 reg; - u16 mask = 0x0001 << bitnum; + u16 mask = 1 << bitnum; /* Read the requested register */ et131x_mii_read(adapter, regnum, ®); @@ -1839,7 +1850,7 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) writel(rx_local->psr_num_entries - 1, &rx_dma->psr_num_des); writel(0, &rx_dma->psr_full_offset); - psr_num_des = readl(&rx_dma->psr_num_des) & 0xFFF; + psr_num_des = readl(&rx_dma->psr_num_des) & ET_RXDMA_PSR_NUM_DES_MASK; writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100, &rx_dma->psr_min_des); @@ -1983,13 +1994,21 @@ static void et131x_adapter_setup(struct et131x_adapter *adapter) */ static void et131x_soft_reset(struct et131x_adapter *adapter) { - /* Disable MAC Core */ - writel(0xc00f0000, &adapter->regs->mac.cfg1); + u32 reg; - /* Set everything to a reset value */ - writel(0x7F, &adapter->regs->global.sw_reset); - writel(0x000f0000, &adapter->regs->mac.cfg1); - writel(0x00000000, &adapter->regs->mac.cfg1); + /* Disable MAC Core */ + reg = ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET | + ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | + ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC; + writel(reg, &adapter->regs->mac.cfg1); + + reg = ET_RESET_ALL; + writel(reg, &adapter->regs->global.sw_reset); + + reg = ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | + ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC; + writel(reg, &adapter->regs->mac.cfg1); + writel(0, &adapter->regs->mac.cfg1); } /** @@ -3022,23 +3041,22 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb) if (phydev && phydev->speed == SPEED_1000) { if (++adapter->tx_ring.since_irq == PARM_TX_NUM_BUFS_DEF) { /* Last element & Interrupt flag */ - desc[frag - 1].flags = 0x5; + desc[frag - 1].flags = TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; adapter->tx_ring.since_irq = 0; } else { /* Last element */ - desc[frag - 1].flags = 0x1; + desc[frag - 1].flags = TXDESC_FLAG_LASTPKT; } } else - desc[frag - 1].flags = 0x5; + desc[frag - 1].flags = TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; - desc[0].flags |= 2; /* First element flag */ + desc[0].flags |= TXDESC_FLAG_FIRSTPKT; tcb->index_start = adapter->tx_ring.send_idx; tcb->stale = 0; spin_lock_irqsave(&adapter->send_hw_lock, flags); - thiscopy = NUM_DESC_PER_RING_TX - - INDEX10(adapter->tx_ring.send_idx); + thiscopy = NUM_DESC_PER_RING_TX - INDEX10(adapter->tx_ring.send_idx); if (thiscopy >= frag) { remainder = 0; diff --git a/drivers/staging/et131x/et131x.h b/drivers/staging/et131x/et131x.h index 9fa47f9..bbe78a7 100644 --- a/drivers/staging/et131x/et131x.h +++ b/drivers/staging/et131x/et131x.h @@ -145,6 +145,8 @@ *31: selfclr_disable */ +#define ET_RESET_ALL 0x007F; + /* * SLV Timer reg at address 0x002C (low 24 bits) */ @@ -392,6 +394,8 @@ struct txdma_regs { /* Location: */ * 11-0: psr ndes */ +#define ET_RXDMA_PSR_NUM_DES_MASK 0xFFF; + /* * structure for packet status ring available offset reg in rxdma address map * located at address 0x202C @@ -567,6 +571,9 @@ struct rxdma_regs { /* Location: */ * 0: txmac_en */ +#define ET_TX_CTRL_FC_DISABLE 0x0008 +#define ET_TX_CTRL_TXMAC_ENABLE 0x0001 + /* * structure for shadow pointer reg in txmac address map * located at address 0x3004 @@ -682,6 +689,9 @@ struct txmac_regs { /* Location: */ * 0: rxmac_en */ +#define ET_RX_CTRL_WOL_DISABLE 0x0008 +#define ET_RX_CTRL_RXMAC_ENABLE 0x0001 + /* * structure for Wake On Lan Control and CRC 0 reg in rxmac address map * located at address 0x4004 @@ -723,9 +733,9 @@ struct txmac_regs { /* Location: */ * 7-0: sa6 */ -#define ET_WOL_LO_SA3_SHIFT 24 -#define ET_WOL_LO_SA4_SHIFT 16 -#define ET_WOL_LO_SA5_SHIFT 8 +#define ET_RX_WOL_LO_SA3_SHIFT 24 +#define ET_RX_WOL_LO_SA4_SHIFT 16 +#define ET_RX_WOL_LO_SA5_SHIFT 8 /* * structure for Wake On Lan Source Address Hi reg in rxmac address map @@ -736,7 +746,7 @@ struct txmac_regs { /* Location: */ * 7-0: sa2 */ -#define ET_WOL_HI_SA1_SHIFT 8 +#define ET_RX_WOL_HI_SA1_SHIFT 8 /* * structure for Wake On Lan mask reg in rxmac address map @@ -754,9 +764,9 @@ struct txmac_regs { /* Location: */ * 7-0: addr1_6 */ -#define ET_UNI_PF_ADDR1_3_SHIFT 24 -#define ET_UNI_PF_ADDR1_4_SHIFT 16 -#define ET_UNI_PF_ADDR1_5_SHIFT 8 +#define ET_RX_UNI_PF_ADDR1_3_SHIFT 24 +#define ET_RX_UNI_PF_ADDR1_4_SHIFT 16 +#define ET_RX_UNI_PF_ADDR1_5_SHIFT 8 /* * structure for Unicast Paket Filter Address 2 reg in rxmac address map @@ -768,9 +778,9 @@ struct txmac_regs { /* Location: */ * 7-0: addr2_6 */ -#define ET_UNI_PF_ADDR2_3_SHIFT 24 -#define ET_UNI_PF_ADDR2_4_SHIFT 16 -#define ET_UNI_PF_ADDR2_5_SHIFT 8 +#define ET_RX_UNI_PF_ADDR2_3_SHIFT 24 +#define ET_RX_UNI_PF_ADDR2_4_SHIFT 16 +#define ET_RX_UNI_PF_ADDR2_5_SHIFT 8 /* * structure for Unicast Paket Filter Address 1 & 2 reg in rxmac address map @@ -782,10 +792,9 @@ struct txmac_regs { /* Location: */ * 7-0: addr1_2 */ -#define ET_UNI_PF_ADDR2_1_SHIFT 24 -#define ET_UNI_PF_ADDR2_2_SHIFT 16 -#define ET_UNI_PF_ADDR1_1_SHIFT 8 - +#define ET_RX_UNI_PF_ADDR2_1_SHIFT 24 +#define ET_RX_UNI_PF_ADDR2_2_SHIFT 16 +#define ET_RX_UNI_PF_ADDR1_1_SHIFT 8 /* * structure for Multicast Hash reg in rxmac address map @@ -806,6 +815,12 @@ struct txmac_regs { /* Location: */ * 0: filter_broad_en */ +#define ET_RX_PFCTRL_MIN_PKT_SZ_SHIFT 16; +#define ET_RX_PFCTRL_FRAG_FILTER_ENABLE 0x0008; +#define ET_RX_PFCTRL_UNICST_FILTER_ENABLE 0x0004; +#define ET_RX_PFCTRL_MLTCST_FILTER_ENABLE 0x0002; +#define ET_RX_PFCTRL_BRDCST_FILTER_ENABLE 0x0001; + /* * structure for Memory Controller Interface Control Max Segment reg in rxmac * address map. Located at address 0x4088 @@ -816,6 +831,10 @@ struct txmac_regs { /* Location: */ * 0: seg_en */ +#define ET_RX_MCIF_CTRL_MAX_SEG_SIZE_SHIFT 2; +#define ET_RX_MCIF_CTRL_MAX_SEG_FC_ENABLE 0x0002; +#define ET_RX_MCIF_CTRL_MAX_SEG_ENABLE 0x0001; + /* * structure for Memory Controller Interface Water Mark reg in rxmac address * map. Located at address 0x408C @@ -915,7 +934,6 @@ struct rxmac_regs { /* Location: */ /* END OF RXMAC REGISTER ADDRESS MAP */ - /* START OF MAC REGISTER ADDRESS MAP */ /* @@ -940,12 +958,18 @@ struct rxmac_regs { /* Location: */ * 0: tx enable */ -#define CFG1_LOOPBACK 0x00000100 -#define CFG1_RX_FLOW 0x00000020 -#define CFG1_TX_FLOW 0x00000010 -#define CFG1_RX_ENABLE 0x00000004 -#define CFG1_TX_ENABLE 0x00000001 -#define CFG1_WAIT 0x0000000A /* RX & TX syncd */ +#define ET_MAC_CFG1_SOFT_RESET 0x80000000 +#define ET_MAC_CFG1_SIM_RESET 0x40000000 +#define ET_MAC_CFG1_RESET_RXMC 0x00080000 +#define ET_MAC_CFG1_RESET_TXMC 0x00040000 +#define ET_MAC_CFG1_RESET_RXFUNC 0x00020000 +#define ET_MAC_CFG1_RESET_TXFUNC 0x00010000 +#define ET_MAC_CFG1_LOOPBACK 0x00000100 +#define ET_MAC_CFG1_RX_FLOW 0x00000020 +#define ET_MAC_CFG1_TX_FLOW 0x00000010 +#define ET_MAC_CFG1_RX_ENABLE 0x00000004 +#define ET_MAC_CFG1_TX_ENABLE 0x00000001 +#define ET_MAC_CFG1_WAIT 0x0000000A /* RX & TX syncd */ /* * structure for configuration #2 reg in mac address map. @@ -963,6 +987,15 @@ struct rxmac_regs { /* Location: */ * 0: full duplex */ +#define ET_MAC_CFG2_PREAMBLE_SHIFT 12; +#define ET_MAC_CFG2_IFMODE_MASK 0x0300; +#define ET_MAC_CFG2_IFMODE_1000 0x0200; +#define ET_MAC_CFG2_IFMODE_100 0x0100; +#define ET_MAC_CFG2_IFMODE_HUGE_FRAME 0x0020; +#define ET_MAC_CFG2_IFMODE_LEN_CHECK 0x0010; +#define ET_MAC_CFG2_IFMODE_PAD_CRC 0x0004; +#define ET_MAC_CFG2_IFMODE_CRC_ENABLE 0x0002; +#define ET_MAC_CFG2_IFMODE_FULL_DPLX 0x0001; /* * structure for Interpacket gap reg in mac address map. @@ -1017,6 +1050,8 @@ struct rxmac_regs { /* Location: */ * 2-0: mgmt clock reset */ +#define ET_MAC_MIIMGMT_CLK_RST 0x0007 + /* * structure for MII Management Command reg in mac address map. * located at address 0x5024 @@ -1033,7 +1068,7 @@ struct rxmac_regs { /* Location: */ * 4-0: register */ -#define MII_ADDR(phy, reg) ((phy) << 8 | (reg)) +#define ET_MAC_MII_ADDR(phy, reg) ((phy) << 8 | (reg)) /* * structure for MII Management Control reg in mac address map. @@ -1049,6 +1084,8 @@ struct rxmac_regs { /* Location: */ * 15-0: phy control */ +#define ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK 0xFFFF; + /* * structure for MII Management Indicators reg in mac address map. * located at address 0x5034 @@ -1058,8 +1095,8 @@ struct rxmac_regs { /* Location: */ * 0: busy */ -#define MGMT_BUSY 0x00000001 /* busy */ -#define MGMT_WAIT 0x00000005 /* busy | not valid */ +#define ET_MAC_MGMT_BUSY 0x00000001 /* busy */ +#define ET_MAC_MGMT_WAIT 0x00000005 /* busy | not valid */ /* * structure for Interface Control reg in mac address map. @@ -1084,6 +1121,9 @@ struct rxmac_regs { /* Location: */ * 0: enable jabber protection */ +#define ET_MAC_IFCTRL_GHDMODE (1 << 26) +#define ET_MAC_IFCTRL_PHYMODE (1 << 24) + /* * structure for Interface Status reg in mac address map. * located at address 0x503C -- cgit v0.10.2 From ca2beaf84d9678c12b17d92623f0e90829d6ca13 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 2 Jan 2013 02:37:40 +0100 Subject: staging: speakup: Prefix externally-visible symbols This prefixes all externally-visible symbols of speakup with "spk_". Signed-off-by: Samuel Thibault Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/speakup/i18n.c b/drivers/staging/speakup/i18n.c index 7c1658b..2add1fc 100644 --- a/drivers/staging/speakup/i18n.c +++ b/drivers/staging/speakup/i18n.c @@ -390,7 +390,7 @@ static struct msg_group_t all_groups[] = { static const int num_groups = sizeof(all_groups) / sizeof(struct msg_group_t); -char *msg_get(enum msg_index_t index) +char *spk_msg_get(enum msg_index_t index) { char *ch; @@ -540,7 +540,7 @@ static int fmt_validate(char *template, char *user) * -EINVAL - Invalid format specifiers in formatted message or illegal index. * -ENOMEM - Unable to allocate memory. */ -ssize_t msg_set(enum msg_index_t index, char *text, size_t length) +ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length) { int rc = 0; char *newstr = NULL; @@ -576,7 +576,7 @@ ssize_t msg_set(enum msg_index_t index, char *text, size_t length) * Find a message group, given its name. Return a pointer to the structure * if found, or NULL otherwise. */ -struct msg_group_t *find_msg_group(const char *group_name) +struct msg_group_t *spk_find_msg_group(const char *group_name) { struct msg_group_t *group = NULL; int i; @@ -590,7 +590,7 @@ struct msg_group_t *find_msg_group(const char *group_name) return group; } -void reset_msg_group(struct msg_group_t *group) +void spk_reset_msg_group(struct msg_group_t *group) { unsigned long flags; enum msg_index_t i; @@ -606,14 +606,14 @@ void reset_msg_group(struct msg_group_t *group) } /* Called at initialization time, to establish default messages. */ -void initialize_msgs(void) +void spk_initialize_msgs(void) { memcpy(speakup_msgs, speakup_default_msgs, sizeof(speakup_default_msgs)); } /* Free user-supplied strings when module is unloaded: */ -void free_user_msgs(void) +void spk_free_user_msgs(void) { enum msg_index_t index; unsigned long flags; diff --git a/drivers/staging/speakup/i18n.h b/drivers/staging/speakup/i18n.h index 65caa80..dd338f4 100644 --- a/drivers/staging/speakup/i18n.h +++ b/drivers/staging/speakup/i18n.h @@ -218,11 +218,11 @@ struct msg_group_t { enum msg_index_t end; }; -extern char *msg_get(enum msg_index_t index); -extern ssize_t msg_set(enum msg_index_t index, char *text, size_t length); -extern struct msg_group_t *find_msg_group(const char *group_name); -extern void reset_msg_group(struct msg_group_t *group); -extern void initialize_msgs(void); -extern void free_user_msgs(void); +extern char *spk_msg_get(enum msg_index_t index); +extern ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length); +extern struct msg_group_t *spk_find_msg_group(const char *group_name); +extern void spk_reset_msg_group(struct msg_group_t *group); +extern void spk_initialize_msgs(void); +extern void spk_free_user_msgs(void); #endif diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c index 170f388..4c584ec 100644 --- a/drivers/staging/speakup/keyhelp.c +++ b/drivers/staging/speakup/keyhelp.c @@ -115,10 +115,10 @@ static void say_key(int key) key &= 0xff; for (i = 0; i < 6; i++) { if (state & masks[i]) - synth_printf(" %s", msg_get(MSG_STATES_START + i)); + synth_printf(" %s", spk_msg_get(MSG_STATES_START + i)); } if ((key > 0) && (key <= num_key_names)) - synth_printf(" %s\n", msg_get(MSG_KEYNAMES_START + (key - 1))); + synth_printf(" %s\n", spk_msg_get(MSG_KEYNAMES_START + (key - 1))); } static int help_init(void) @@ -126,9 +126,9 @@ static int help_init(void) char start = SPACE; int i; int num_funcs = MSG_FUNCNAMES_END - MSG_FUNCNAMES_START + 1; -state_tbl = our_keys[0]+SHIFT_TBL_SIZE+2; +state_tbl = spk_our_keys[0]+SHIFT_TBL_SIZE+2; for (i = 0; i < num_funcs; i++) { - char *cur_funcname = msg_get(MSG_FUNCNAMES_START + i); + char *cur_funcname = spk_msg_get(MSG_FUNCNAMES_START + i); if (start == *cur_funcname) continue; start = *cur_funcname; @@ -137,7 +137,7 @@ state_tbl = our_keys[0]+SHIFT_TBL_SIZE+2; return 0; } -int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) +int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) { int i, n; char *name; @@ -147,15 +147,15 @@ int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) help_init(); if (type == KT_LATIN) { if (ch == SPACE) { - special_handler = NULL; - synth_printf("%s\n", msg_get(MSG_LEAVING_HELP)); + spk_special_handler = NULL; + synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP)); return 1; } ch |= 32; /* lower case */ if (ch < 'a' || ch > 'z') return -1; if (letter_offsets[ch-'a'] == -1) { - synth_printf(msg_get(MSG_NO_COMMAND), ch); + synth_printf(spk_msg_get(MSG_NO_COMMAND), ch); synth_printf("\n"); return 1; } @@ -169,47 +169,47 @@ int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) cur_item--; else return -1; - } else if (type == KT_SPKUP && ch == SPEAKUP_HELP && !special_handler) { - special_handler = handle_help; - synth_printf("%s\n", msg_get(MSG_HELP_INFO)); + } else if (type == KT_SPKUP && ch == SPEAKUP_HELP && !spk_special_handler) { + spk_special_handler = spk_handle_help; + synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO)); build_key_data(); /* rebuild each time in case new mapping */ return 1; } else { name = NULL; if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) { synth_printf("%s\n", - msg_get(MSG_KEYNAMES_START + key-1)); + spk_msg_get(MSG_KEYNAMES_START + key-1)); return 1; } for (i = 0; funcvals[i] != 0 && !name; i++) { if (ch == funcvals[i]) - name = msg_get(MSG_FUNCNAMES_START + i); + name = spk_msg_get(MSG_FUNCNAMES_START + i); } if (!name) return -1; - kp = our_keys[key]+1; + kp = spk_our_keys[key]+1; for (i = 0; i < nstates; i++) { if (ch == kp[i]) break; } key += (state_tbl[i] << 8); say_key(key); - synth_printf(msg_get(MSG_KEYDESC), name); + synth_printf(spk_msg_get(MSG_KEYDESC), name); synth_printf("\n"); return 1; } - name = msg_get(MSG_FUNCNAMES_START + cur_item); + name = spk_msg_get(MSG_FUNCNAMES_START + cur_item); func = funcvals[cur_item]; synth_printf("%s", name); if (key_offsets[func] == 0) { - synth_printf(" %s\n", msg_get(MSG_IS_UNASSIGNED)); + synth_printf(" %s\n", spk_msg_get(MSG_IS_UNASSIGNED)); return 1; } p_keys = key_data + key_offsets[func]; for (n = 0; p_keys[n]; n++) { val = p_keys[n]; if (n > 0) - synth_printf("%s ", msg_get(MSG_DISJUNCTION)); + synth_printf("%s ", spk_msg_get(MSG_DISJUNCTION)); say_key(val); } return 1; diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c index 2093896..86387f4 100644 --- a/drivers/staging/speakup/kobjects.c +++ b/drivers/staging/speakup/kobjects.c @@ -41,7 +41,7 @@ static ssize_t chars_chartab_show(struct kobject *kobj, break; if (strcmp("characters", attr->attr.name) == 0) { len = scnprintf(buf_pointer, bufsize, "%d\t%s\n", - i, characters[i]); + i, spk_characters[i]); } else { /* show chartab entry */ if (IS_TYPE(i, B_CTL)) cp = "B_CTL"; @@ -185,12 +185,12 @@ static ssize_t chars_chartab_store(struct kobject *kobj, outptr[desc_length] = '\0'; if (do_characters) { - if (characters[index] != default_chars[index]) - kfree(characters[index]); - characters[index] = desc; + if (spk_characters[index] != spk_default_chars[index]) + kfree(spk_characters[index]); + spk_characters[index] = desc; used++; } else { - charclass = chartab_get_value(keyword); + charclass = spk_chartab_get_value(keyword); if (charclass == 0) { rejected++; cp = linefeed + 1; @@ -206,9 +206,9 @@ static ssize_t chars_chartab_store(struct kobject *kobj, if (reset) { if (do_characters) - reset_default_chars(); + spk_reset_default_chars(); else - reset_default_chartab(); + spk_reset_default_chartab(); } spk_unlock(flags); @@ -232,7 +232,7 @@ static ssize_t keymap_show(struct kobject *kobj, struct kobj_attribute *attr, u_char ch; unsigned long flags; spk_lock(flags); - cp1 = key_buf + SHIFT_TBL_SIZE; + cp1 = spk_key_buf + SHIFT_TBL_SIZE; num_keys = (int)(*cp1); nstates = (int)cp1[1]; cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates); @@ -271,7 +271,7 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, return -ENOMEM; } if (strchr("dDrR", *in_buff)) { - set_key_info(key_defaults, key_buf); + spk_set_key_info(spk_key_defaults, spk_key_buf); pr_info("keymap set to default values\n"); kfree(in_buff); spk_unlock(flags); @@ -282,14 +282,14 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, cp = in_buff; cp1 = (u_char *)in_buff; for (i = 0; i < 3; i++) { - cp = s2uchar(cp, cp1); + cp = spk_s2uchar(cp, cp1); cp1++; } i = (int)cp1[-2]+1; i *= (int)cp1[-1]+1; i += 2; /* 0 and last map ver */ if (cp1[-3] != KEY_MAP_VER || cp1[-1] > 10 || - i+SHIFT_TBL_SIZE+4 >= sizeof(key_buf)) { + i+SHIFT_TBL_SIZE+4 >= sizeof(spk_key_buf)) { pr_warn("i %d %d %d %d\n", i, (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]); kfree(in_buff); @@ -297,7 +297,7 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, return -EINVAL; } while (--i >= 0) { - cp = s2uchar(cp, cp1); + cp = spk_s2uchar(cp, cp1); cp1++; if (!(*cp)) break; @@ -307,8 +307,8 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, pr_warn("end %d %d %d %d\n", i, (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]); } else { - if (set_key_info(in_buff, key_buf)) { - set_key_info(key_defaults, key_buf); + if (spk_set_key_info(in_buff, spk_key_buf)) { + spk_set_key_info(spk_key_defaults, spk_key_buf); ret = -EINVAL; pr_warn("set key failed\n"); } @@ -343,7 +343,7 @@ static ssize_t silent_store(struct kobject *kobj, struct kobj_attribute *attr, spk_lock(flags); if (ch&2) { shut = 1; - do_flush(); + spk_do_flush(); } else { shut = 0; } @@ -388,7 +388,7 @@ static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr, if (new_synth_name[len - 1] == '\n') len--; new_synth_name[len] = '\0'; - strlwr(new_synth_name); + spk_strlwr(new_synth_name); if ((synth != NULL) && (!strcmp(new_synth_name, synth->name))) { pr_warn("%s already in use\n", new_synth_name); } else if (synth_init(new_synth_name) != 0) { @@ -417,7 +417,7 @@ static ssize_t synth_direct_store(struct kobject *kobj, bytes = min_t(size_t, len, 250); strncpy(tmp, ptr, bytes); tmp[bytes] = '\0'; - xlate(tmp); + spk_xlate(tmp); synth_printf("%s", tmp); ptr += bytes; len -= bytes; @@ -455,14 +455,14 @@ static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr, short mask; unsigned long flags; - p_header = var_header_by_name(attr->attr.name); + p_header = spk_var_header_by_name(attr->attr.name); if (p_header == NULL) { pr_warn("p_header is null, attr->attr.name is %s\n", attr->attr.name); return -EINVAL; } - var = get_punc_var(p_header->var_id); + var = spk_get_punc_var(p_header->var_id); if (var == NULL) { pr_warn("var is null, p_header->var_id is %i\n", p_header->var_id); @@ -470,7 +470,7 @@ static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr, } spk_lock(flags); - pb = (struct st_bits_data *) &punc_info[var->value]; + pb = (struct st_bits_data *) &spk_punc_info[var->value]; mask = pb->mask; for (i = 33; i < 128; i++) { if (!(spk_chartab[i]&mask)) @@ -497,14 +497,14 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr, if (x < 1 || x > 99) return -EINVAL; - p_header = var_header_by_name(attr->attr.name); + p_header = spk_var_header_by_name(attr->attr.name); if (p_header == NULL) { pr_warn("p_header is null, attr->attr.name is %s\n", attr->attr.name); return -EINVAL; } - var = get_punc_var(p_header->var_id); + var = spk_get_punc_var(p_header->var_id); if (var == NULL) { pr_warn("var is null, p_header->var_id is %i\n", p_header->var_id); @@ -520,9 +520,9 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr, spk_lock(flags); if (*punc_buf == 'd' || *punc_buf == 'r') - x = set_mask_bits(0, var->value, 3); + x = spk_set_mask_bits(0, var->value, 3); else - x = set_mask_bits(punc_buf, var->value, 3); + x = spk_set_mask_bits(punc_buf, var->value, 3); spk_unlock(flags); return count; @@ -542,7 +542,7 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr, char ch; unsigned long flags; - param = var_header_by_name(attr->attr.name); + param = spk_var_header_by_name(attr->attr.name); if (param == NULL) return -EINVAL; @@ -599,13 +599,13 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, int value; unsigned long flags; - param = var_header_by_name(attr->attr.name); + param = spk_var_header_by_name(attr->attr.name); if (param == NULL) return -EINVAL; if (param->data == NULL) return 0; ret = 0; - cp = xlate((char *) buf); + cp = spk_xlate((char *) buf); spk_lock(flags); switch (param->var_type) { @@ -618,7 +618,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, else len = E_SET; speakup_s2i(cp, &value); - ret = set_num_var(value, param, len); + ret = spk_set_num_var(value, param, len); if (ret == E_RANGE) { var_data = param->data; pr_warn("value for %s out of range, expect %d to %d\n", @@ -636,7 +636,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, } cp = (char *) buf; cp[len] = '\0'; - ret = set_string_var(buf, param, len); + ret = spk_set_string_var(buf, param, len); if (ret == E_TOOLONG) pr_warn("value too long for %s\n", attr->attr.name); @@ -652,19 +652,19 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, */ if (strcmp(attr->attr.name, "voice") == 0) { if (synth && synth->default_pitch) { - param = var_header_by_name("pitch"); + param = spk_var_header_by_name("pitch"); if (param) { - set_num_var(synth->default_pitch[value], param, + spk_set_num_var(synth->default_pitch[value], param, E_NEW_DEFAULT); - set_num_var(0, param, E_DEFAULT); + spk_set_num_var(0, param, E_DEFAULT); } } if (synth && synth->default_vol) { - param = var_header_by_name("vol"); + param = spk_var_header_by_name("vol"); if (param) { - set_num_var(synth->default_vol[value], param, + spk_set_num_var(synth->default_vol[value], param, E_NEW_DEFAULT); - set_num_var(0, param, E_DEFAULT); + spk_set_num_var(0, param, E_DEFAULT); } } } @@ -694,7 +694,7 @@ static ssize_t message_show_helper(char *buf, enum msg_index_t first, if (bufsize <= 1) break; printed = scnprintf(buf_pointer, bufsize, "%d\t%s\n", - index, msg_get(cursor)); + index, spk_msg_get(cursor)); buf_pointer += printed; bufsize -= printed; } @@ -788,7 +788,7 @@ static ssize_t message_store_helper(const char *buf, size_t count, continue; } - msg_stored = msg_set(curmessage, temp, desc_length); + msg_stored = spk_msg_set(curmessage, temp, desc_length); if (msg_stored < 0) { retval = msg_stored; if (msg_stored == -ENOMEM) @@ -802,7 +802,7 @@ static ssize_t message_store_helper(const char *buf, size_t count, } if (reset) - reset_msg_group(group); + spk_reset_msg_group(group); report_msg_status(reset, received, used, rejected, group->name); return retval; @@ -812,7 +812,7 @@ static ssize_t message_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { ssize_t retval = 0; - struct msg_group_t *group = find_msg_group(attr->attr.name); + struct msg_group_t *group = spk_find_msg_group(attr->attr.name); unsigned long flags; BUG_ON(!group); @@ -826,7 +826,7 @@ static ssize_t message_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { ssize_t retval = 0; - struct msg_group_t *group = find_msg_group(attr->attr.name); + struct msg_group_t *group = spk_find_msg_group(attr->attr.name); BUG_ON(!group); retval = message_store_helper(buf, count, group); diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c index 40e2488..463d125 100644 --- a/drivers/staging/speakup/main.c +++ b/drivers/staging/speakup/main.c @@ -65,23 +65,23 @@ MODULE_VERSION(SPEAKUP_VERSION); char *synth_name; module_param_named(synth, synth_name, charp, S_IRUGO); -module_param_named(quiet, quiet_boot, bool, S_IRUGO); +module_param_named(quiet, spk_quiet_boot, bool, S_IRUGO); MODULE_PARM_DESC(synth, "Synth to start if speakup is built in."); MODULE_PARM_DESC(quiet, "Do not announce when the synthesizer is found."); -special_func special_handler; +special_func spk_special_handler; -short pitch_shift, synth_flags; +short spk_pitch_shift, synth_flags; static char buf[256]; -int attrib_bleep, bleeps, bleep_time = 10; -int no_intr, spell_delay; -int key_echo, say_word_ctl; -int say_ctrl, bell_pos; -short punc_mask; -int punc_level, reading_punc; -char str_caps_start[MAXVARLEN + 1] = "\0", str_caps_stop[MAXVARLEN + 1] = "\0"; -const struct st_bits_data punc_info[] = { +int spk_attrib_bleep, spk_bleeps, spk_bleep_time = 10; +int spk_no_intr, spk_spell_delay; +int spk_key_echo, spk_say_word_ctl; +int spk_say_ctrl, spk_bell_pos; +short spk_punc_mask; +int spk_punc_level, spk_reading_punc; +char spk_str_caps_start[MAXVARLEN + 1] = "\0", spk_str_caps_stop[MAXVARLEN + 1] = "\0"; +const struct st_bits_data spk_punc_info[] = { {"none", "", 0}, {"some", "/$%&@", SOME}, {"most", "$%&#()=+*/@^<>|\\", MOST}, @@ -95,9 +95,9 @@ const struct st_bits_data punc_info[] = { static char mark_cut_flag; #define MAX_KEY 160 -u_char *our_keys[MAX_KEY], *shift_table; -u_char key_buf[600]; -const u_char key_defaults[] = { +u_char *spk_our_keys[MAX_KEY], *spk_shift_table; +u_char spk_key_buf[600]; +const u_char spk_key_defaults[] = { #include "speakupmap.h" }; @@ -129,9 +129,9 @@ static char *phonetic[] = { /* array of 256 char pointers (one for each character description) * initialized to default_chars and user selectable via * /proc/speakup/characters */ -char *characters[256]; +char *spk_characters[256]; -char *default_chars[256] = { +char *spk_default_chars[256] = { /*000*/ "null", "^a", "^b", "^c", "^d", "^e", "^f", "^g", /*008*/ "^h", "^i", "^j", "^k", "^l", "^m", "^n", "^o", /*016*/ "^p", "^q", "^r", "^s", "^t", "^u", "^v", "^w", @@ -238,7 +238,7 @@ static u_short default_chartab[256] = { }; struct task_struct *speakup_task; -struct bleep unprocessed_sound; +struct bleep spk_unprocessed_sound; static int spk_keydown; static u_char spk_lastkey, spk_close_press, keymap_flags; static u_char last_keycode, this_speakup_key; @@ -282,13 +282,13 @@ static void bleep(u_short val) 350, 370, 392, 414, 440, 466, 491, 523, 554, 587, 619, 659 }; short freq; - int time = bleep_time; + int time = spk_bleep_time; freq = vals[val % 12]; if (val > 11) freq *= (1 << (val / 12)); - unprocessed_sound.freq = freq; - unprocessed_sound.jiffies = msecs_to_jiffies(time); - unprocessed_sound.active = 1; + spk_unprocessed_sound.freq = freq; + spk_unprocessed_sound.jiffies = msecs_to_jiffies(time); + spk_unprocessed_sound.active = 1; /* We can only have 1 active sound at a time. */ } @@ -300,7 +300,7 @@ static void speakup_shut_up(struct vc_data *vc) spk_parked &= 0xfe; speakup_date(vc); if (synth != NULL) - do_flush(); + spk_do_flush(); } static void speech_kill(struct vc_data *vc) @@ -313,9 +313,9 @@ static void speech_kill(struct vc_data *vc) if (val == 2 || spk_killed) { /* dead */ spk_shut_up &= ~0x40; - synth_printf("%s\n", msg_get(MSG_IAM_ALIVE)); + synth_printf("%s\n", spk_msg_get(MSG_IAM_ALIVE)); } else { - synth_printf("%s\n", msg_get(MSG_YOU_KILLED_SPEAKUP)); + synth_printf("%s\n", spk_msg_get(MSG_YOU_KILLED_SPEAKUP)); spk_shut_up |= 0x40; } } @@ -324,10 +324,10 @@ static void speakup_off(struct vc_data *vc) { if (spk_shut_up & 0x80) { spk_shut_up &= 0x7f; - synth_printf("%s\n", msg_get(MSG_HEY_THATS_BETTER)); + synth_printf("%s\n", spk_msg_get(MSG_HEY_THATS_BETTER)); } else { spk_shut_up |= 0x80; - synth_printf("%s\n", msg_get(MSG_YOU_TURNED_ME_OFF)); + synth_printf("%s\n", spk_msg_get(MSG_YOU_TURNED_ME_OFF)); } speakup_date(vc); } @@ -336,10 +336,10 @@ static void speakup_parked(struct vc_data *vc) { if (spk_parked & 0x80) { spk_parked = 0; - synth_printf("%s\n", msg_get(MSG_UNPARKED)); + synth_printf("%s\n", spk_msg_get(MSG_UNPARKED)); } else { spk_parked |= 0x80; - synth_printf("%s\n", msg_get(MSG_PARKED)); + synth_printf("%s\n", spk_msg_get(MSG_PARKED)); } } @@ -350,16 +350,16 @@ static void speakup_cut(struct vc_data *vc) if (!mark_cut_flag) { mark_cut_flag = 1; - xs = (u_short) spk_x; - ys = (u_short) spk_y; + spk_xs = (u_short) spk_x; + spk_ys = (u_short) spk_y; spk_sel_cons = vc; - synth_printf("%s\n", msg_get(MSG_MARK)); + synth_printf("%s\n", spk_msg_get(MSG_MARK)); return; } - xe = (u_short) spk_x; - ye = (u_short) spk_y; + spk_xe = (u_short) spk_x; + spk_ye = (u_short) spk_y; mark_cut_flag = 0; - synth_printf("%s\n", msg_get(MSG_CUT)); + synth_printf("%s\n", spk_msg_get(MSG_CUT)); speakup_clear_selection(); ret = speakup_set_selection(tty); @@ -383,9 +383,9 @@ static void speakup_paste(struct vc_data *vc) { if (mark_cut_flag) { mark_cut_flag = 0; - synth_printf("%s\n", msg_get(MSG_MARK_CLEARED)); + synth_printf("%s\n", spk_msg_get(MSG_MARK_CLEARED)); } else { - synth_printf("%s\n", msg_get(MSG_PASTE)); + synth_printf("%s\n", spk_msg_get(MSG_PASTE)); speakup_paste_selection(tty); } } @@ -395,16 +395,16 @@ static void say_attributes(struct vc_data *vc) int fg = spk_attr & 0x0f; int bg = spk_attr >> 4; if (fg > 8) { - synth_printf("%s ", msg_get(MSG_BRIGHT)); + synth_printf("%s ", spk_msg_get(MSG_BRIGHT)); fg -= 8; } - synth_printf("%s", msg_get(MSG_COLORS_START + fg)); + synth_printf("%s", spk_msg_get(MSG_COLORS_START + fg)); if (bg > 7) { - synth_printf(" %s ", msg_get(MSG_ON_BLINKING)); + synth_printf(" %s ", spk_msg_get(MSG_ON_BLINKING)); bg -= 8; } else - synth_printf(" %s ", msg_get(MSG_ON)); - synth_printf("%s\n", msg_get(MSG_COLORS_START + bg)); + synth_printf(" %s ", spk_msg_get(MSG_ON)); + synth_printf("%s\n", spk_msg_get(MSG_COLORS_START + bg)); } enum { @@ -417,24 +417,24 @@ enum { static void announce_edge(struct vc_data *vc, int msg_id) { - if (bleeps & 1) + if (spk_bleeps & 1) bleep(spk_y); - if ((bleeps & 2) && (msg_id < edge_quiet)) - synth_printf("%s\n", msg_get(MSG_EDGE_MSGS_START + msg_id - 1)); + if ((spk_bleeps & 2) && (msg_id < edge_quiet)) + synth_printf("%s\n", spk_msg_get(MSG_EDGE_MSGS_START + msg_id - 1)); } static void speak_char(u_char ch) { - char *cp = characters[ch]; - struct var_t *direct = get_var(DIRECT); + char *cp = spk_characters[ch]; + struct var_t *direct = spk_get_var(DIRECT); if (direct && direct->u.n.value) { if (IS_CHAR(ch, B_CAP)) { - pitch_shift++; - synth_printf("%s", str_caps_start); + spk_pitch_shift++; + synth_printf("%s", spk_str_caps_start); } synth_printf("%c", ch); if (IS_CHAR(ch, B_CAP)) - synth_printf("%s", str_caps_stop); + synth_printf("%s", spk_str_caps_stop); return; } if (cp == NULL) { @@ -443,13 +443,13 @@ static void speak_char(u_char ch) } synth_buffer_add(SPACE); if (IS_CHAR(ch, B_CAP)) { - pitch_shift++; - synth_printf("%s", str_caps_start); + spk_pitch_shift++; + synth_printf("%s", spk_str_caps_start); synth_printf("%s", cp); - synth_printf("%s", str_caps_stop); + synth_printf("%s", spk_str_caps_stop); } else { if (*cp == '^') { - synth_printf("%s", msg_get(MSG_CTRL)); + synth_printf("%s", spk_msg_get(MSG_CTRL)); cp++; } synth_printf("%s", cp); @@ -479,9 +479,9 @@ static void say_char(struct vc_data *vc) spk_old_attr = spk_attr; ch = get_char(vc, (u_short *) spk_pos, &spk_attr); if (spk_attr != spk_old_attr) { - if (attrib_bleep & 1) + if (spk_attrib_bleep & 1) bleep(spk_y); - if (attrib_bleep & 2) + if (spk_attrib_bleep & 2) say_attributes(vc); } speak_char(ch & 0xff); @@ -497,7 +497,7 @@ static void say_phonetic_char(struct vc_data *vc) synth_printf("%s\n", phonetic[--ch]); } else { if (IS_CHAR(ch, B_NUM)) - synth_printf("%s ", msg_get(MSG_NUMBER)); + synth_printf("%s ", spk_msg_get(MSG_NUMBER)); speak_char(ch); } } @@ -527,8 +527,8 @@ static void say_next_char(struct vc_data *vc) } /* get_word - will first check to see if the character under the - * reading cursor is a space and if say_word_ctl is true it will - * return the word space. If say_word_ctl is not set it will check to + * reading cursor is a space and if spk_say_word_ctl is true it will + * return the word space. If spk_say_word_ctl is not set it will check to * see if there is a word starting on the next position to the right * and return that word if it exists. If it does not exist it will * move left to the beginning of any previous word on the line or the @@ -544,9 +544,9 @@ static u_long get_word(struct vc_data *vc) ch = (char)get_char(vc, (u_short *) tmp_pos, &temp); /* decided to take out the sayword if on a space (mis-information */ - if (say_word_ctl && ch == SPACE) { + if (spk_say_word_ctl && ch == SPACE) { *buf = '\0'; - synth_printf("%s\n", msg_get(MSG_SPACE)); + synth_printf("%s\n", spk_msg_get(MSG_SPACE)); return 0; } else if ((tmpx < vc->vc_cols - 2) && (ch == SPACE || ch == 0 || IS_WDLM(ch)) @@ -582,13 +582,13 @@ static u_long get_word(struct vc_data *vc) static void say_word(struct vc_data *vc) { u_long cnt = get_word(vc); - u_short saved_punc_mask = punc_mask; + u_short saved_punc_mask = spk_punc_mask; if (cnt == 0) return; - punc_mask = PUNC; + spk_punc_mask = PUNC; buf[cnt++] = SPACE; spkup_write(buf, cnt); - punc_mask = saved_punc_mask; + spk_punc_mask = saved_punc_mask; } static void say_prev_word(struct vc_data *vc) @@ -686,22 +686,22 @@ static void say_next_word(struct vc_data *vc) static void spell_word(struct vc_data *vc) { static char *delay_str[] = { "", ",", ".", ". .", ". . ." }; - char *cp = buf, *str_cap = str_caps_stop; - char *cp1, *last_cap = str_caps_stop; + char *cp = buf, *str_cap = spk_str_caps_stop; + char *cp1, *last_cap = spk_str_caps_stop; u_char ch; if (!get_word(vc)) return; while ((ch = (u_char) *cp)) { if (cp != buf) - synth_printf(" %s ", delay_str[spell_delay]); + synth_printf(" %s ", delay_str[spk_spell_delay]); if (IS_CHAR(ch, B_CAP)) { - str_cap = str_caps_start; - if (*str_caps_stop) - pitch_shift++; + str_cap = spk_str_caps_start; + if (*spk_str_caps_stop) + spk_pitch_shift++; else /* synth has no pitch */ - last_cap = str_caps_stop; + last_cap = spk_str_caps_stop; } else - str_cap = str_caps_stop; + str_cap = spk_str_caps_stop; if (str_cap != last_cap) { synth_printf("%s", str_cap); last_cap = str_cap; @@ -711,17 +711,17 @@ static void spell_word(struct vc_data *vc) ch &= 31; cp1 = phonetic[--ch]; } else { - cp1 = characters[ch]; + cp1 = spk_characters[ch]; if (*cp1 == '^') { - synth_printf("%s", msg_get(MSG_CTRL)); + synth_printf("%s", spk_msg_get(MSG_CTRL)); cp1++; } } synth_printf("%s", cp1); cp++; } - if (str_cap != str_caps_stop) - synth_printf("%s", str_caps_stop); + if (str_cap != spk_str_caps_stop) + synth_printf("%s", spk_str_caps_stop); } static int get_line(struct vc_data *vc) @@ -746,9 +746,9 @@ static void say_line(struct vc_data *vc) { int i = get_line(vc); char *cp; - u_short saved_punc_mask = punc_mask; + u_short saved_punc_mask = spk_punc_mask; if (i == 0) { - synth_printf("%s\n", msg_get(MSG_BLANK)); + synth_printf("%s\n", spk_msg_get(MSG_BLANK)); return; } buf[i++] = '\n'; @@ -758,9 +758,9 @@ static void say_line(struct vc_data *vc) cp++; synth_printf("%d, ", (cp - buf) + 1); } - punc_mask = punc_masks[reading_punc]; + spk_punc_mask = spk_punc_masks[spk_reading_punc]; spkup_write(buf, i); - punc_mask = saved_punc_mask; + spk_punc_mask = saved_punc_mask; } static void say_prev_line(struct vc_data *vc) @@ -792,7 +792,7 @@ static int say_from_to(struct vc_data *vc, u_long from, u_long to, { int i = 0; u_char tmp; - u_short saved_punc_mask = punc_mask; + u_short saved_punc_mask = spk_punc_mask; spk_old_attr = spk_attr; spk_attr = get_attributes((u_short *) from); while (from < to) { @@ -809,10 +809,10 @@ static int say_from_to(struct vc_data *vc, u_long from, u_long to, if (i < 1) return i; if (read_punc) - punc_mask = punc_info[reading_punc].mask; + spk_punc_mask = spk_punc_info[spk_reading_punc].mask; spkup_write(buf, i); if (read_punc) - punc_mask = saved_punc_mask; + spk_punc_mask = saved_punc_mask; return i - 1; } @@ -824,7 +824,7 @@ static void say_line_from_to(struct vc_data *vc, u_long from, u_long to, start += from * 2; if (say_from_to(vc, start, end, read_punc) <= 0) if (cursor_track != read_all_mode) - synth_printf("%s\n", msg_get(MSG_BLANK)); + synth_printf("%s\n", spk_msg_get(MSG_BLANK)); } /* Sentence Reading Commands */ @@ -924,7 +924,7 @@ static void speakup_win_say(struct vc_data *vc) { u_long start, end, from, to; if (win_start < 2) { - synth_printf("%s\n", msg_get(MSG_NO_WINDOW)); + synth_printf("%s\n", spk_msg_get(MSG_NO_WINDOW)); return; } start = vc->vc_origin + (win_top * vc->vc_size_row); @@ -975,7 +975,7 @@ static void say_first_char(struct vc_data *vc) u_char ch; spk_parked |= 0x01; if (len == 0) { - synth_printf("%s\n", msg_get(MSG_BLANK)); + synth_printf("%s\n", spk_msg_get(MSG_BLANK)); return; } for (i = 0; i < len; i++) @@ -994,7 +994,7 @@ static void say_last_char(struct vc_data *vc) u_char ch; spk_parked |= 0x01; if (len == 0) { - synth_printf("%s\n", msg_get(MSG_BLANK)); + synth_printf("%s\n", spk_msg_get(MSG_BLANK)); return; } ch = buf[--len]; @@ -1006,7 +1006,7 @@ static void say_last_char(struct vc_data *vc) static void say_position(struct vc_data *vc) { - synth_printf(msg_get(MSG_POS_INFO), spk_y + 1, spk_x + 1, + synth_printf(spk_msg_get(MSG_POS_INFO), spk_y + 1, spk_x + 1, vc->vc_num + 1); synth_printf("\n"); } @@ -1017,7 +1017,7 @@ static void say_char_num(struct vc_data *vc) u_char tmp; u_short ch = get_char(vc, (u_short *) spk_pos, &tmp); ch &= 0xff; - synth_printf(msg_get(MSG_CHAR_INFO), ch, ch); + synth_printf(spk_msg_get(MSG_CHAR_INFO), ch, ch); } /* these are stub functions to keep keyboard.c happy. */ @@ -1066,7 +1066,7 @@ static void spkup_write(const char *in_buf, int count) } else { if ((last_type & CH_RPT) && rep_count > 2) { synth_printf(" "); - synth_printf(msg_get(MSG_REPEAT_DESC), + synth_printf(spk_msg_get(MSG_REPEAT_DESC), ++rep_count); synth_printf(" "); } @@ -1074,7 +1074,7 @@ static void spkup_write(const char *in_buf, int count) } if (ch == spk_lastkey) { rep_count = 0; - if (key_echo == 1 && ch >= MINECHOCHAR) + if (spk_key_echo == 1 && ch >= MINECHOCHAR) speak_char(ch); } else if (char_type & B_ALPHA) { if ((synth_flags & SF_DEC) && (last_type & PUNC)) @@ -1083,7 +1083,7 @@ static void spkup_write(const char *in_buf, int count) } else if (char_type & B_NUM) { rep_count = 0; synth_printf("%c", ch); - } else if (char_type & punc_mask) { + } else if (char_type & spk_punc_mask) { speak_char(ch); char_type &= ~PUNC; /* for dec nospell processing */ } else if (char_type & SYNTH_OK) { @@ -1111,7 +1111,7 @@ static void spkup_write(const char *in_buf, int count) if (in_count > 2 && rep_count > 2) { if (last_type & CH_RPT) { synth_printf(" "); - synth_printf(msg_get(MSG_REPEAT_DESC2), ++rep_count); + synth_printf(spk_msg_get(MSG_REPEAT_DESC2), ++rep_count); synth_printf(" "); } rep_count = 0; @@ -1135,22 +1135,22 @@ static void do_handle_shift(struct vc_data *vc, u_char value, char up_flag) case KVAL(K_SHIFT): del_timer(&cursor_timer); spk_shut_up &= 0xfe; - do_flush(); + spk_do_flush(); read_all_doc(vc); break; case KVAL(K_CTRL): del_timer(&cursor_timer); cursor_track = prev_cursor_track; spk_shut_up &= 0xfe; - do_flush(); + spk_do_flush(); break; } } else { spk_shut_up &= 0xfe; - do_flush(); + spk_do_flush(); } - if (say_ctrl && value < NUM_CTL_LABELS) - synth_printf("%s", msg_get(MSG_CTL_START + value)); + if (spk_say_ctrl && value < NUM_CTL_LABELS) + synth_printf("%s", spk_msg_get(MSG_CTL_START + value)); spk_unlock(flags); } @@ -1171,12 +1171,12 @@ static void do_handle_latin(struct vc_data *vc, u_char value, char up_flag) spk_lastkey = value; spk_keydown++; spk_parked &= 0xfe; - if (key_echo == 2 && value >= MINECHOCHAR) + if (spk_key_echo == 2 && value >= MINECHOCHAR) speak_char(value); spk_unlock(flags); } -int set_key_info(const u_char *key_info, u_char *k_buffer) +int spk_set_key_info(const u_char *key_info, u_char *k_buffer) { int i = 0, states, key_data_len; const u_char *cp = key_info; @@ -1188,12 +1188,12 @@ int set_key_info(const u_char *key_info, u_char *k_buffer) num_keys = *cp; states = (int)cp[1]; key_data_len = (states + 1) * (num_keys + 1); - if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(key_buf)) + if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(spk_key_buf)) return -2; memset(k_buffer, 0, SHIFT_TBL_SIZE); - memset(our_keys, 0, sizeof(our_keys)); - shift_table = k_buffer; - our_keys[0] = shift_table; + memset(spk_our_keys, 0, sizeof(spk_our_keys)); + spk_shift_table = k_buffer; + spk_our_keys[0] = spk_shift_table; cp1 += SHIFT_TBL_SIZE; memcpy(cp1, cp, key_data_len + 3); /* get num_keys, states and data */ @@ -1202,13 +1202,13 @@ int set_key_info(const u_char *key_info, u_char *k_buffer) ch = *cp1++; if (ch >= SHIFT_TBL_SIZE) return -3; - shift_table[ch] = i; + spk_shift_table[ch] = i; } keymap_flags = *cp1++; while ((ch = *cp1)) { if (ch >= MAX_KEY) return -4; - our_keys[ch] = cp1; + spk_our_keys[ch] = cp1; cp1 += states + 1; } return 0; @@ -1237,24 +1237,24 @@ static void toggle_cursoring(struct vc_data *vc) cursor_track = prev_cursor_track; if (++cursor_track >= CT_Max) cursor_track = 0; - synth_printf("%s\n", msg_get(MSG_CURSOR_MSGS_START + cursor_track)); + synth_printf("%s\n", spk_msg_get(MSG_CURSOR_MSGS_START + cursor_track)); } -void reset_default_chars(void) +void spk_reset_default_chars(void) { int i; /* First, free any non-default */ for (i = 0; i < 256; i++) { - if ((characters[i] != NULL) - && (characters[i] != default_chars[i])) - kfree(characters[i]); + if ((spk_characters[i] != NULL) + && (spk_characters[i] != spk_default_chars[i])) + kfree(spk_characters[i]); } - memcpy(characters, default_chars, sizeof(default_chars)); + memcpy(spk_characters, spk_default_chars, sizeof(spk_default_chars)); } -void reset_default_chartab(void) +void spk_reset_default_chartab(void) { memcpy(spk_chartab, default_chartab, sizeof(default_chartab)); } @@ -1267,8 +1267,8 @@ static int edit_bits(struct vc_data *vc, u_char type, u_char ch, u_short key) if (type != KT_LATIN || (ch_type & B_NUM) || ch < SPACE) return -1; if (ch == SPACE) { - synth_printf("%s\n", msg_get(MSG_EDIT_DONE)); - special_handler = NULL; + synth_printf("%s\n", spk_msg_get(MSG_EDIT_DONE)); + spk_special_handler = NULL; return 1; } if (mask < PUNC && !(ch_type & PUNC)) @@ -1276,8 +1276,8 @@ static int edit_bits(struct vc_data *vc, u_char type, u_char ch, u_short key) spk_chartab[ch] ^= mask; speak_char(ch); synth_printf(" %s\n", - (spk_chartab[ch] & mask) ? msg_get(MSG_ON) : - msg_get(MSG_OFF)); + (spk_chartab[ch] & mask) ? spk_msg_get(MSG_ON) : + spk_msg_get(MSG_OFF)); return 1; } @@ -1346,7 +1346,7 @@ static void read_all_doc(struct vc_data *vc) if (cursor_track != read_all_mode) prev_cursor_track = cursor_track; cursor_track = read_all_mode; - reset_index_count(0); + spk_reset_index_count(0); if (get_sentence_buf(vc, 0) == -1) kbd_fakekey2(vc, RA_DOWN_ARROW); else { @@ -1361,7 +1361,7 @@ static void stop_read_all(struct vc_data *vc) del_timer(&cursor_timer); cursor_track = prev_cursor_track; spk_shut_up &= 0xfe; - do_flush(); + spk_do_flush(); } static void start_read_all_timer(struct vc_data *vc, int command) @@ -1370,7 +1370,7 @@ static void start_read_all_timer(struct vc_data *vc, int command) cursor_con = vc->vc_num; read_all_key = command; - cursor_timeout = get_var(CURSOR_TIME); + cursor_timeout = spk_get_var(CURSOR_TIME); mod_timer(&cursor_timer, jiffies + msecs_to_jiffies(cursor_timeout->u.n.value)); } @@ -1382,9 +1382,9 @@ static void handle_cursor_read_all(struct vc_data *vc, int command) switch (command) { case RA_NEXT_SENT: /* Get Current Sentence */ - get_index_count(&indcount, &sentcount); + spk_get_index_count(&indcount, &sentcount); /*printk("%d %d ", indcount, sentcount); */ - reset_index_count(sentcount + 1); + spk_reset_index_count(sentcount + 1); if (indcount == 1) { if (!say_sentence_num(sentcount + 1, 0)) { kbd_fakekey2(vc, RA_FIND_NEXT_SENT); @@ -1395,7 +1395,7 @@ static void handle_cursor_read_all(struct vc_data *vc, int command) sn = 0; if (!say_sentence_num(sentcount + 1, 1)) { sn = 1; - reset_index_count(sn); + spk_reset_index_count(sn); } else synth_insert_next_index(0); if (!say_sentence_num(sn, 0)) { @@ -1437,7 +1437,7 @@ static void handle_cursor_read_all(struct vc_data *vc, int command) case RA_FIND_PREV_SENT: break; case RA_TIMER: - get_index_count(&indcount, &sentcount); + spk_get_index_count(&indcount, &sentcount); if (indcount < 2) kbd_fakekey2(vc, RA_DOWN_ARROW); else @@ -1458,7 +1458,7 @@ static int pre_handle_cursor(struct vc_data *vc, u_char value, char up_flag) } del_timer(&cursor_timer); spk_shut_up &= 0xfe; - do_flush(); + spk_do_flush(); start_read_all_timer(vc, value + 1); spk_unlock(flags); return NOTIFY_STOP; @@ -1479,8 +1479,8 @@ static void do_handle_cursor(struct vc_data *vc, u_char value, char up_flag) return; } spk_shut_up &= 0xfe; - if (no_intr) - do_flush(); + if (spk_no_intr) + spk_do_flush(); /* the key press flushes if !no_inter but we want to flush on cursor * moves regardless of no_inter state */ is_cursor = value + 1; @@ -1491,7 +1491,7 @@ static void do_handle_cursor(struct vc_data *vc, u_char value, char up_flag) cursor_con = vc->vc_num; if (cursor_track == CT_Highlight) reset_highlight_buffers(vc); - cursor_timeout = get_var(CURSOR_TIME); + cursor_timeout = spk_get_var(CURSOR_TIME); mod_timer(&cursor_timer, jiffies + msecs_to_jiffies(cursor_timeout->u.n.value)); spk_unlock(flags); @@ -1603,7 +1603,7 @@ static int speak_highlight(struct vc_data *vc) if (speakup_console[vc_num]->ht.ry[hc] != vc->vc_y) return 0; spk_parked |= 0x01; - do_flush(); + spk_do_flush(); spkup_write(speakup_console[vc_num]->ht.highbuf[hc], speakup_console[vc_num]->ht.highsize[hc]); spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc]; @@ -1685,7 +1685,7 @@ static void speakup_con_write(struct vc_data *vc, const char *str, int len) if (!spk_trylock(flags)) /* Speakup output, discard */ return; - if (bell_pos && spk_keydown && (vc->vc_x == bell_pos - 1)) + if (spk_bell_pos && spk_keydown && (vc->vc_x == spk_bell_pos - 1)) bleep(3); if ((is_cursor) || (cursor_track == read_all_mode)) { if (cursor_track == CT_Highlight) @@ -1726,19 +1726,19 @@ static void do_handle_spec(struct vc_data *vc, u_char value, char up_flag) return; spk_lock(flags); spk_shut_up &= 0xfe; - if (no_intr) - do_flush(); + if (spk_no_intr) + spk_do_flush(); switch (value) { case KVAL(K_CAPS): - label = msg_get(MSG_KEYNAME_CAPSLOCK); + label = spk_msg_get(MSG_KEYNAME_CAPSLOCK); on_off = vt_get_leds(fg_console, VC_CAPSLOCK); break; case KVAL(K_NUM): - label = msg_get(MSG_KEYNAME_NUMLOCK); + label = spk_msg_get(MSG_KEYNAME_NUMLOCK); on_off = vt_get_leds(fg_console, VC_NUMLOCK); break; case KVAL(K_HOLD): - label = msg_get(MSG_KEYNAME_SCROLLLOCK); + label = spk_msg_get(MSG_KEYNAME_SCROLLLOCK); on_off = vt_get_leds(fg_console, VC_SCROLLOCK); if (speakup_console[vc->vc_num]) speakup_console[vc->vc_num]->tty_stopped = on_off; @@ -1750,7 +1750,7 @@ static void do_handle_spec(struct vc_data *vc, u_char value, char up_flag) } if (on_off < 2) synth_printf("%s %s\n", - label, msg_get(MSG_STATUS_START + on_off)); + label, spk_msg_get(MSG_STATUS_START + on_off)); spk_unlock(flags); } @@ -1764,13 +1764,13 @@ static int inc_dec_var(u_char value) int var_id = (int)value - VAR_START; int how = (var_id & 1) ? E_INC : E_DEC; var_id = var_id / 2 + FIRST_SET_VAR; - p_header = get_var_header(var_id); + p_header = spk_get_var_header(var_id); if (p_header == NULL) return -1; if (p_header->var_type != VAR_NUM) return -1; var_data = p_header->data; - if (set_num_var(1, p_header, how) != 0) + if (spk_set_num_var(1, p_header, how) != 0) return -1; if (!spk_close_press) { for (pn = p_header->name; *pn; pn++) { @@ -1790,18 +1790,18 @@ static void speakup_win_set(struct vc_data *vc) { char info[40]; if (win_start > 1) { - synth_printf("%s\n", msg_get(MSG_WINDOW_ALREADY_SET)); + synth_printf("%s\n", spk_msg_get(MSG_WINDOW_ALREADY_SET)); return; } if (spk_x < win_left || spk_y < win_top) { - synth_printf("%s\n", msg_get(MSG_END_BEFORE_START)); + synth_printf("%s\n", spk_msg_get(MSG_END_BEFORE_START)); return; } if (win_start && spk_x == win_left && spk_y == win_top) { win_left = 0; win_right = vc->vc_cols - 1; win_bottom = spk_y; - snprintf(info, sizeof(info), msg_get(MSG_WINDOW_LINE), + snprintf(info, sizeof(info), spk_msg_get(MSG_WINDOW_LINE), (int)win_top + 1); } else { if (!win_start) { @@ -1811,8 +1811,8 @@ static void speakup_win_set(struct vc_data *vc) win_bottom = spk_y; win_right = spk_x; } - snprintf(info, sizeof(info), msg_get(MSG_WINDOW_BOUNDARY), - (win_start) ? msg_get(MSG_END) : msg_get(MSG_START), + snprintf(info, sizeof(info), spk_msg_get(MSG_WINDOW_BOUNDARY), + (win_start) ? spk_msg_get(MSG_END) : spk_msg_get(MSG_START), (int)spk_y + 1, (int)spk_x + 1); } synth_printf("%s\n", info); @@ -1824,32 +1824,32 @@ static void speakup_win_clear(struct vc_data *vc) win_top = win_bottom = 0; win_left = win_right = 0; win_start = 0; - synth_printf("%s\n", msg_get(MSG_WINDOW_CLEARED)); + synth_printf("%s\n", spk_msg_get(MSG_WINDOW_CLEARED)); } static void speakup_win_enable(struct vc_data *vc) { if (win_start < 2) { - synth_printf("%s\n", msg_get(MSG_NO_WINDOW)); + synth_printf("%s\n", spk_msg_get(MSG_NO_WINDOW)); return; } win_enabled ^= 1; if (win_enabled) - synth_printf("%s\n", msg_get(MSG_WINDOW_SILENCED)); + synth_printf("%s\n", spk_msg_get(MSG_WINDOW_SILENCED)); else - synth_printf("%s\n", msg_get(MSG_WINDOW_SILENCE_DISABLED)); + synth_printf("%s\n", spk_msg_get(MSG_WINDOW_SILENCE_DISABLED)); } static void speakup_bits(struct vc_data *vc) { int val = this_speakup_key - (FIRST_EDIT_BITS - 1); - if (special_handler != NULL || val < 1 || val > 6) { - synth_printf("%s\n", msg_get(MSG_ERROR)); + if (spk_special_handler != NULL || val < 1 || val > 6) { + synth_printf("%s\n", spk_msg_get(MSG_ERROR)); return; } - pb_edit = &punc_info[val]; - synth_printf(msg_get(MSG_EDIT_PROMPT), pb_edit->name); - special_handler = edit_bits; + pb_edit = &spk_punc_info[val]; + synth_printf(spk_msg_get(MSG_EDIT_PROMPT), pb_edit->name); + spk_special_handler = edit_bits; } static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key) @@ -1887,9 +1887,9 @@ static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key) if (ch < 'x' || ch > 'y') { oops: if (!spk_killed) - synth_printf(" %s\n", msg_get(MSG_GOTO_CANCELED)); + synth_printf(" %s\n", spk_msg_get(MSG_GOTO_CANCELED)); goto_buf[num = 0] = '\0'; - special_handler = NULL; + spk_special_handler = NULL; return 1; } cp = speakup_s2i(goto_buf, &go_pos); @@ -1917,7 +1917,7 @@ oops: } goto_buf[num = 0] = '\0'; do_goto: - special_handler = NULL; + spk_special_handler = NULL; spk_parked |= 0x01; if (goto_x) { spk_pos -= spk_x * 2; @@ -1934,18 +1934,18 @@ do_goto: static void speakup_goto(struct vc_data *vc) { - if (special_handler != NULL) { - synth_printf("%s\n", msg_get(MSG_ERROR)); + if (spk_special_handler != NULL) { + synth_printf("%s\n", spk_msg_get(MSG_ERROR)); return; } - synth_printf("%s\n", msg_get(MSG_GOTO)); - special_handler = handle_goto; + synth_printf("%s\n", spk_msg_get(MSG_GOTO)); + spk_special_handler = handle_goto; return; } static void speakup_help(struct vc_data *vc) { - handle_help(vc, KT_SPKUP, SPEAKUP_HELP, 0); + spk_handle_help(vc, KT_SPKUP, SPEAKUP_HELP, 0); } static void do_nothing(struct vc_data *vc) @@ -1992,7 +1992,7 @@ static void do_spkup(struct vc_data *vc, u_char value) spk_shut_up &= 0xfe; this_speakup_key = value; if (value < SPKUP_MAX_FUNC && spkup_handler[value]) { - do_flush(); + spk_do_flush(); (*spkup_handler[value]) (vc); } else { if (inc_dec_var(value) < 0) @@ -2032,7 +2032,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym, } if (keycode >= MAX_KEY) goto no_map; - key_info = our_keys[keycode]; + key_info = spk_our_keys[keycode]; if (key_info == 0) goto no_map; /* Check valid read all mode keys */ @@ -2051,7 +2051,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym, } } shift_info = (shift_state & 0x0f) + key_speakup; - offset = shift_table[shift_info]; + offset = spk_shift_table[shift_info]; if (offset) { new_key = key_info[offset]; if (new_key) { @@ -2062,7 +2062,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym, if (up_flag || spk_killed) goto out; spk_shut_up &= 0xfe; - do_flush(); + spk_do_flush(); goto out; } if (up_flag) @@ -2070,7 +2070,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym, if (last_keycode == keycode && last_spk_jiffy + MAX_DELAY > jiffies) { spk_close_press = 1; - offset = shift_table[shift_info + 32]; + offset = spk_shift_table[shift_info + 32]; /* double press? */ if (offset && key_info[offset]) new_key = key_info[offset]; @@ -2082,7 +2082,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym, } } no_map: - if (type == KT_SPKUP && special_handler == NULL) { + if (type == KT_SPKUP && spk_special_handler == NULL) { do_spkup(vc, new_key); spk_close_press = 0; ret = 1; @@ -2096,9 +2096,9 @@ no_map: || (value == KVAL(K_LEFT)) || (value == KVAL(K_RIGHT)); if ((cursor_track != read_all_mode) || !kh) - if (!no_intr) - do_flush(); - if (special_handler) { + if (!spk_no_intr) + spk_do_flush(); + if (spk_special_handler) { if (type == KT_SPEC && value == 1) { value = '\n'; type = KT_LATIN; @@ -2106,7 +2106,7 @@ no_map: type = KT_LATIN; else if (value == 0x7f) value = 8; /* make del = backspace */ - ret = (*special_handler) (vc, type, value, keycode); + ret = (*spk_special_handler) (vc, type, value, keycode); spk_close_press = 0; if (ret < 0) bleep(9); @@ -2237,11 +2237,11 @@ static void __exit speakup_exit(void) speakup_unregister_var(i); for (i = 0; i < 256; i++) { - if (characters[i] != default_chars[i]) - kfree(characters[i]); + if (spk_characters[i] != spk_default_chars[i]) + kfree(spk_characters[i]); } - free_user_msgs(); + spk_free_user_msgs(); } /* call by: module_init() */ @@ -2254,20 +2254,20 @@ static int __init speakup_init(void) struct var_t *var; /* These first few initializations cannot fail. */ - initialize_msgs(); /* Initialize arrays for i18n. */ - reset_default_chars(); - reset_default_chartab(); - strlwr(synth_name); + spk_initialize_msgs(); /* Initialize arrays for i18n. */ + spk_reset_default_chars(); + spk_reset_default_chartab(); + spk_strlwr(synth_name); spk_vars[0].u.n.high = vc->vc_cols; for (var = spk_vars; var->var_id != MAXVARS; var++) speakup_register_var(var); for (var = synth_time_vars; (var->var_id >= 0) && (var->var_id < MAXVARS); var++) speakup_register_var(var); - for (i = 1; punc_info[i].mask != 0; i++) - set_mask_bits(0, i, 2); + for (i = 1; spk_punc_info[i].mask != 0; i++) + spk_set_mask_bits(0, i, 2); - set_key_info(key_defaults, key_buf); + spk_set_key_info(spk_key_defaults, spk_key_buf); /* From here on out, initializations can fail. */ err = speakup_add_virtual_keyboard(); @@ -2290,7 +2290,7 @@ static int __init speakup_init(void) goto error_kobjects; } - if (quiet_boot) + if (spk_quiet_boot) spk_shut_up |= 0x01; err = speakup_kobj_init(); @@ -2352,11 +2352,11 @@ error_virtkeyboard: speakup_unregister_var(i); for (i = 0; i < 256; i++) { - if (characters[i] != default_chars[i]) - kfree(characters[i]); + if (spk_characters[i] != spk_default_chars[i]) + kfree(spk_characters[i]); } - free_user_msgs(); + spk_free_user_msgs(); out: return err; diff --git a/drivers/staging/speakup/selection.c b/drivers/staging/speakup/selection.c index 0612df0..d6558fa 100644 --- a/drivers/staging/speakup/selection.c +++ b/drivers/staging/speakup/selection.c @@ -10,7 +10,7 @@ /* Don't take this from : 011-015 on the screen aren't spaces */ #define ishardspace(c) ((c) == ' ') -unsigned short xs, ys, xe, ye; /* our region points */ +unsigned short spk_xs, spk_ys, spk_xe, spk_ye; /* our region points */ /* Variables for selection control. */ /* must not be disallocated */ @@ -51,12 +51,12 @@ int speakup_set_selection(struct tty_struct *tty) int i, ps, pe; struct vc_data *vc = vc_cons[fg_console].d; - xs = limit(xs, vc->vc_cols - 1); - ys = limit(ys, vc->vc_rows - 1); - xe = limit(xe, vc->vc_cols - 1); - ye = limit(ye, vc->vc_rows - 1); - ps = ys * vc->vc_size_row + (xs << 1); - pe = ye * vc->vc_size_row + (xe << 1); + spk_xs = limit(spk_xs, vc->vc_cols - 1); + spk_ys = limit(spk_ys, vc->vc_rows - 1); + spk_xe = limit(spk_xe, vc->vc_cols - 1); + spk_ye = limit(spk_ye, vc->vc_rows - 1); + ps = spk_ys * vc->vc_size_row + (spk_xs << 1); + pe = spk_ye * vc->vc_size_row + (spk_xe << 1); if (ps > pe) { /* make sel_start <= sel_end */ diff --git a/drivers/staging/speakup/serialio.c b/drivers/staging/speakup/serialio.c index a97d3d5..e4d27aa 100644 --- a/drivers/staging/speakup/serialio.c +++ b/drivers/staging/speakup/serialio.c @@ -116,7 +116,7 @@ static void start_serial_interrupt(int irq) outb(1, speakup_info.port_tts + UART_FCR); /* Turn FIFO On */ } -void stop_serial_interrupt(void) +void spk_stop_serial_interrupt(void) { if (speakup_info.port_tts == 0) return; @@ -130,7 +130,7 @@ void stop_serial_interrupt(void) free_irq(serstate->irq, (void *) synth_readbuf_handler); } -int wait_for_xmitr(void) +int spk_wait_for_xmitr(void) { int tmout = SPK_XMITR_TIMEOUT; if ((synth->alive) && (timeouts >= NUM_DISABLE_TIMEOUTS)) { @@ -195,7 +195,7 @@ EXPORT_SYMBOL_GPL(spk_serial_in_nowait); int spk_serial_out(const char ch) { - if (synth->alive && wait_for_xmitr()) { + if (synth->alive && spk_wait_for_xmitr()) { outb_p(ch, speakup_info.port_tts); return 1; } diff --git a/drivers/staging/speakup/speakup.h b/drivers/staging/speakup/speakup.h index e66579e..22f0fbb 100644 --- a/drivers/staging/speakup/speakup.h +++ b/drivers/staging/speakup/speakup.h @@ -50,34 +50,34 @@ #define E_UNDEF -1 extern int speakup_thread(void *data); -extern void reset_default_chars(void); -extern void reset_default_chartab(void); +extern void spk_reset_default_chars(void); +extern void spk_reset_default_chartab(void); extern void synth_start(void); void synth_insert_next_index(int sent_num); -void reset_index_count(int sc); -void get_index_count(int *linecount, int *sentcount); -extern int set_key_info(const u_char *key_info, u_char *k_buffer); -extern char *strlwr(char *s); +void spk_reset_index_count(int sc); +void spk_get_index_count(int *linecount, int *sentcount); +extern int spk_set_key_info(const u_char *key_info, u_char *k_buffer); +extern char *spk_strlwr(char *s); extern char *speakup_s2i(char *start, int *dest); -extern char *s2uchar(char *start, char *dest); -extern char *xlate(char *s); +extern char *spk_s2uchar(char *start, char *dest); +extern char *spk_xlate(char *s); extern int speakup_kobj_init(void); extern void speakup_kobj_exit(void); -extern int chartab_get_value(char *keyword); +extern int spk_chartab_get_value(char *keyword); extern void speakup_register_var(struct var_t *var); extern void speakup_unregister_var(enum var_id_t var_id); -extern struct st_var_header *get_var_header(enum var_id_t var_id); -extern struct st_var_header *var_header_by_name(const char *name); -extern struct punc_var_t *get_punc_var(enum var_id_t var_id); -extern int set_num_var(int val, struct st_var_header *var, int how); -extern int set_string_var(const char *page, struct st_var_header *var, int len); -extern int set_mask_bits(const char *input, const int which, const int how); -extern special_func special_handler; -extern int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key); +extern struct st_var_header *spk_get_var_header(enum var_id_t var_id); +extern struct st_var_header *spk_var_header_by_name(const char *name); +extern struct punc_var_t *spk_get_punc_var(enum var_id_t var_id); +extern int spk_set_num_var(int val, struct st_var_header *var, int how); +extern int spk_set_string_var(const char *page, struct st_var_header *var, int len); +extern int spk_set_mask_bits(const char *input, const int which, const int how); +extern special_func spk_special_handler; +extern int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key); extern int synth_init(char *name); extern void synth_release(void); -extern void do_flush(void); +extern void spk_do_flush(void); extern void speakup_start_ttys(void); extern void synth_buffer_add(char ch); extern void synth_buffer_clear(void); @@ -90,35 +90,35 @@ extern void synth_write(const char *buf, size_t count); extern int synth_supports_indexing(void); extern struct vc_data *spk_sel_cons; -extern unsigned short xs, ys, xe, ye; /* our region points */ +extern unsigned short spk_xs, spk_ys, spk_xe, spk_ye; /* our region points */ extern wait_queue_head_t speakup_event; extern struct kobject *speakup_kobj; extern struct task_struct *speakup_task; -extern const u_char key_defaults[]; +extern const u_char spk_key_defaults[]; /* Protect speakup synthesizer list */ extern struct mutex spk_mutex; extern struct st_spk_t *speakup_console[]; extern struct spk_synth *synth; -extern char pitch_buff[]; -extern u_char *our_keys[]; -extern short punc_masks[]; -extern char str_caps_start[], str_caps_stop[]; -extern const struct st_bits_data punc_info[]; -extern u_char key_buf[600]; -extern char *characters[]; -extern char *default_chars[]; +extern char spk_pitch_buff[]; +extern u_char *spk_our_keys[]; +extern short spk_punc_masks[]; +extern char spk_str_caps_start[], spk_str_caps_stop[]; +extern const struct st_bits_data spk_punc_info[]; +extern u_char spk_key_buf[600]; +extern char *spk_characters[]; +extern char *spk_default_chars[]; extern u_short spk_chartab[]; -extern int no_intr, say_ctrl, say_word_ctl, punc_level; -extern int reading_punc, attrib_bleep, bleeps; -extern int bleep_time, bell_pos; -extern int spell_delay, key_echo; -extern short punc_mask; -extern short pitch_shift, synth_flags; -extern bool quiet_boot; +extern int spk_no_intr, spk_say_ctrl, spk_say_word_ctl, spk_punc_level; +extern int spk_reading_punc, spk_attrib_bleep, spk_bleeps; +extern int spk_bleep_time, spk_bell_pos; +extern int spk_spell_delay, spk_key_echo; +extern short spk_punc_mask; +extern short spk_pitch_shift, synth_flags; +extern bool spk_quiet_boot; extern char *synth_name; -extern struct bleep unprocessed_sound; +extern struct bleep spk_unprocessed_sound; /* Prototypes from fakekey.c. */ int speakup_add_virtual_keyboard(void); diff --git a/drivers/staging/speakup/speakup_acntpc.c b/drivers/staging/speakup/speakup_acntpc.c index bbe28b6..1c1f0d5 100644 --- a/drivers/staging/speakup/speakup_acntpc.c +++ b/drivers/staging/speakup/speakup_acntpc.c @@ -182,9 +182,9 @@ static void do_catch_up(struct spk_synth *synth) struct var_t *full_time; struct var_t *jiffy_delta; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); - full_time = get_var(FULL); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); + full_time = spk_get_var(FULL); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; diff --git a/drivers/staging/speakup/speakup_acntsa.c b/drivers/staging/speakup/speakup_acntsa.c index 590fa6b..22a8b72 100644 --- a/drivers/staging/speakup/speakup_acntsa.c +++ b/drivers/staging/speakup/speakup_acntsa.c @@ -128,7 +128,7 @@ static int synth_probe(struct spk_synth *synth) { int failed; - failed = serial_synth_probe(synth); + failed = spk_serial_synth_probe(synth); if (failed == 0) { spk_synth_immediate(synth, "\033=R\r"); mdelay(100); diff --git a/drivers/staging/speakup/speakup_apollo.c b/drivers/staging/speakup/speakup_apollo.c index 00d5ced..3e450cc 100644 --- a/drivers/staging/speakup/speakup_apollo.c +++ b/drivers/staging/speakup/speakup_apollo.c @@ -112,7 +112,7 @@ static struct spk_synth synth_apollo = { .startup = SYNTH_START, .checkval = SYNTH_CHECK, .vars = vars, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = do_catch_up, @@ -145,9 +145,9 @@ static void do_catch_up(struct spk_synth *synth) int delay_time_val = 0; int jiffy_delta_val = 0; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); - full_time = get_var(FULL); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); + full_time = spk_get_var(FULL); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; spk_unlock(flags); diff --git a/drivers/staging/speakup/speakup_audptr.c b/drivers/staging/speakup/speakup_audptr.c index 94e5099..3508aee 100644 --- a/drivers/staging/speakup/speakup_audptr.c +++ b/drivers/staging/speakup/speakup_audptr.c @@ -162,7 +162,7 @@ static int synth_probe(struct spk_synth *synth) { int failed = 0; - failed = serial_synth_probe(synth); + failed = spk_serial_synth_probe(synth); if (failed == 0) synth_version(synth); synth->alive = !failed; diff --git a/drivers/staging/speakup/speakup_bns.c b/drivers/staging/speakup/speakup_bns.c index 43e5b54..4bfe3d4 100644 --- a/drivers/staging/speakup/speakup_bns.c +++ b/drivers/staging/speakup/speakup_bns.c @@ -100,7 +100,7 @@ static struct spk_synth synth_bns = { .startup = SYNTH_START, .checkval = SYNTH_CHECK, .vars = vars, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = spk_do_catch_up, diff --git a/drivers/staging/speakup/speakup_decext.c b/drivers/staging/speakup/speakup_decext.c index b4ef915..d39a0de 100644 --- a/drivers/staging/speakup/speakup_decext.c +++ b/drivers/staging/speakup/speakup_decext.c @@ -130,7 +130,7 @@ static struct spk_synth synth_decext = { .startup = SYNTH_START, .checkval = SYNTH_CHECK, .vars = vars, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = do_catch_up, @@ -162,8 +162,8 @@ static void do_catch_up(struct spk_synth *synth) int jiffy_delta_val = 0; int delay_time_val = 0; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; diff --git a/drivers/staging/speakup/speakup_decpc.c b/drivers/staging/speakup/speakup_decpc.c index a09a0c9..6c88b55 100644 --- a/drivers/staging/speakup/speakup_decpc.c +++ b/drivers/staging/speakup/speakup_decpc.c @@ -375,8 +375,8 @@ static void do_catch_up(struct spk_synth *synth) int jiffy_delta_val; int delay_time_val; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; spk_unlock(flags); diff --git a/drivers/staging/speakup/speakup_dectlk.c b/drivers/staging/speakup/speakup_dectlk.c index daff3b9..0dd2eb9 100644 --- a/drivers/staging/speakup/speakup_dectlk.c +++ b/drivers/staging/speakup/speakup_dectlk.c @@ -134,7 +134,7 @@ static struct spk_synth synth_dectlk = { .vars = vars, .default_pitch = ap_defaults, .default_vol = g5_defaults, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = do_catch_up, @@ -214,8 +214,8 @@ static void do_catch_up(struct spk_synth *synth) int jiffy_delta_val; int delay_time_val; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; spk_unlock(flags); diff --git a/drivers/staging/speakup/speakup_dtlk.c b/drivers/staging/speakup/speakup_dtlk.c index 97bc476..a9cefbd 100644 --- a/drivers/staging/speakup/speakup_dtlk.c +++ b/drivers/staging/speakup/speakup_dtlk.c @@ -198,8 +198,8 @@ static void do_catch_up(struct spk_synth *synth) int jiffy_delta_val; int delay_time_val; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; spk_unlock(flags); diff --git a/drivers/staging/speakup/speakup_dummy.c b/drivers/staging/speakup/speakup_dummy.c index c20f411..4a24b9c 100644 --- a/drivers/staging/speakup/speakup_dummy.c +++ b/drivers/staging/speakup/speakup_dummy.c @@ -102,7 +102,7 @@ static struct spk_synth synth_dummy = { .startup = SYNTH_START, .checkval = SYNTH_CHECK, .vars = vars, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = spk_do_catch_up, diff --git a/drivers/staging/speakup/speakup_keypc.c b/drivers/staging/speakup/speakup_keypc.c index 496e014..feb5f22 100644 --- a/drivers/staging/speakup/speakup_keypc.c +++ b/drivers/staging/speakup/speakup_keypc.c @@ -184,9 +184,9 @@ static void do_catch_up(struct spk_synth *synth) int full_time_val; int jiffy_delta_val; - jiffy_delta = get_var(JIFFY); - delay_time = get_var(DELAY); - full_time = get_var(FULL); + jiffy_delta = spk_get_var(JIFFY); + delay_time = spk_get_var(DELAY); + full_time = spk_get_var(FULL); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; spk_unlock(flags); diff --git a/drivers/staging/speakup/speakup_ltlk.c b/drivers/staging/speakup/speakup_ltlk.c index 971de1a..326f94d 100644 --- a/drivers/staging/speakup/speakup_ltlk.c +++ b/drivers/staging/speakup/speakup_ltlk.c @@ -161,7 +161,7 @@ static int synth_probe(struct spk_synth *synth) { int failed = 0; - failed = serial_synth_probe(synth); + failed = spk_serial_synth_probe(synth); if (failed == 0) synth_interrogate(synth); synth->alive = !failed; diff --git a/drivers/staging/speakup/speakup_spkout.c b/drivers/staging/speakup/speakup_spkout.c index 9a3a80d..e74f856 100644 --- a/drivers/staging/speakup/speakup_spkout.c +++ b/drivers/staging/speakup/speakup_spkout.c @@ -107,7 +107,7 @@ static struct spk_synth synth_spkout = { .startup = SYNTH_START, .checkval = SYNTH_CHECK, .vars = vars, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = spk_do_catch_up, diff --git a/drivers/staging/speakup/speakup_txprt.c b/drivers/staging/speakup/speakup_txprt.c index 5d5bf7c..5a29b9f 100644 --- a/drivers/staging/speakup/speakup_txprt.c +++ b/drivers/staging/speakup/speakup_txprt.c @@ -100,7 +100,7 @@ static struct spk_synth synth_txprt = { .startup = SYNTH_START, .checkval = SYNTH_CHECK, .vars = vars, - .probe = serial_synth_probe, + .probe = spk_serial_synth_probe, .release = spk_serial_release, .synth_immediate = spk_synth_immediate, .catch_up = spk_do_catch_up, diff --git a/drivers/staging/speakup/spk_priv.h b/drivers/staging/speakup/spk_priv.h index a47c5b7..303105b 100644 --- a/drivers/staging/speakup/spk_priv.h +++ b/drivers/staging/speakup/spk_priv.h @@ -45,8 +45,8 @@ #define KT_SPKUP 15 extern const struct old_serial_port *spk_serial_init(int index); -extern void stop_serial_interrupt(void); -extern int wait_for_xmitr(void); +extern void spk_stop_serial_interrupt(void); +extern int spk_wait_for_xmitr(void); extern unsigned char spk_serial_in(void); extern unsigned char spk_serial_in_nowait(void); extern int spk_serial_out(const char ch); @@ -55,13 +55,13 @@ extern void spk_serial_release(void); extern char synth_buffer_getc(void); extern char synth_buffer_peek(void); extern int synth_buffer_empty(void); -extern struct var_t *get_var(enum var_id_t var_id); +extern struct var_t *spk_get_var(enum var_id_t var_id); extern ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); extern ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count); -extern int serial_synth_probe(struct spk_synth *synth); +extern int spk_serial_synth_probe(struct spk_synth *synth); extern const char *spk_synth_immediate(struct spk_synth *synth, const char *buff); extern void spk_do_catch_up(struct spk_synth *synth); extern void spk_synth_flush(struct spk_synth *synth); diff --git a/drivers/staging/speakup/synth.c b/drivers/staging/speakup/synth.c index df95337..59c46a4 100644 --- a/drivers/staging/speakup/synth.c +++ b/drivers/staging/speakup/synth.c @@ -20,9 +20,9 @@ #define MAXSYNTHS 16 /* Max number of synths in array. */ static struct spk_synth *synths[MAXSYNTHS]; struct spk_synth *synth; -char pitch_buff[32] = ""; +char spk_pitch_buff[32] = ""; static int module_status; -bool quiet_boot; +bool spk_quiet_boot; struct speakup_info_t speakup_info = { .spinlock = __SPIN_LOCK_UNLOCKED(speakup_info.spinlock), @@ -32,7 +32,7 @@ EXPORT_SYMBOL_GPL(speakup_info); static int do_synth_init(struct spk_synth *in_synth); -int serial_synth_probe(struct spk_synth *synth) +int spk_serial_synth_probe(struct spk_synth *synth) { const struct old_serial_port *ser; int failed = 0; @@ -59,7 +59,7 @@ int serial_synth_probe(struct spk_synth *synth) synth->alive = 1; return 0; } -EXPORT_SYMBOL_GPL(serial_synth_probe); +EXPORT_SYMBOL_GPL(spk_serial_synth_probe); /* Main loop of the progression thread: keep eating from the buffer * and push to the serial port, waiting as needed @@ -79,9 +79,9 @@ void spk_do_catch_up(struct spk_synth *synth) int delay_time_val; int full_time_val; - jiffy_delta = get_var(JIFFY); - full_time = get_var(FULL); - delay_time = get_var(DELAY); + jiffy_delta = spk_get_var(JIFFY); + full_time = spk_get_var(FULL); + delay_time = spk_get_var(DELAY); spk_lock(flags); jiffy_delta_val = jiffy_delta->u.n.value; @@ -139,7 +139,7 @@ const char *spk_synth_immediate(struct spk_synth *synth, const char *buff) while ((ch = *buff)) { if (ch == '\n') ch = synth->procspeech; - if (wait_for_xmitr()) + if (spk_wait_for_xmitr()) outb(ch, speakup_info.port_tts); else return buff; @@ -166,7 +166,7 @@ int spk_synth_is_alive_restart(struct spk_synth *synth) { if (synth->alive) return 1; - if (!synth->alive && wait_for_xmitr() > 0) { + if (!synth->alive && spk_wait_for_xmitr() > 0) { /* restart */ synth->alive = 1; synth_printf("%s", synth->init); @@ -192,20 +192,20 @@ void synth_start(void) synth_buffer_clear(); return; } - trigger_time = get_var(TRIGGER); + trigger_time = spk_get_var(TRIGGER); if (!timer_pending(&thread_timer)) mod_timer(&thread_timer, jiffies + msecs_to_jiffies(trigger_time->u.n.value)); } -void do_flush(void) +void spk_do_flush(void) { speakup_info.flushing = 1; synth_buffer_clear(); if (synth->alive) { - if (pitch_shift) { - synth_printf("%s", pitch_buff); - pitch_shift = 0; + if (spk_pitch_shift) { + synth_printf("%s", spk_pitch_buff); + spk_pitch_shift = 0; } } wake_up_interruptible_all(&speakup_event); @@ -241,7 +241,7 @@ EXPORT_SYMBOL_GPL(synth_printf); static int index_count; static int sentence_count; -void reset_index_count(int sc) +void spk_reset_index_count(int sc) { static int first = 1; if (first) @@ -277,7 +277,7 @@ void synth_insert_next_index(int sent_num) } } -void get_index_count(int *linecount, int *sentcount) +void spk_get_index_count(int *linecount, int *sentcount) { int ind = synth->get_index(); if (ind) { @@ -384,7 +384,7 @@ static int do_synth_init(struct spk_synth *in_synth) for (var = synth->vars; (var->var_id >= 0) && (var->var_id < MAXVARS); var++) speakup_register_var(var); - if (!quiet_boot) + if (!spk_quiet_boot) synth_printf("%s found\n", synth->long_name); if (synth->attributes.name && sysfs_create_group(speakup_kobj, &(synth->attributes)) < 0) @@ -412,7 +412,7 @@ void synth_release(void) sysfs_remove_group(speakup_kobj, &(synth->attributes)); for (var = synth->vars; var->var_id != MAXVARS; var++) speakup_unregister_var(var->var_id); - stop_serial_interrupt(); + spk_stop_serial_interrupt(); synth->release(); synth = NULL; } @@ -460,4 +460,4 @@ void synth_remove(struct spk_synth *in_synth) } EXPORT_SYMBOL_GPL(synth_remove); -short punc_masks[] = { 0, SOME, MOST, PUNC, PUNC|B_SYM }; +short spk_punc_masks[] = { 0, SOME, MOST, PUNC, PUNC|B_SYM }; diff --git a/drivers/staging/speakup/thread.c b/drivers/staging/speakup/thread.c index 103c5c8..42fa660 100644 --- a/drivers/staging/speakup/thread.c +++ b/drivers/staging/speakup/thread.c @@ -23,8 +23,8 @@ int speakup_thread(void *data) DEFINE_WAIT(wait); while (1) { spk_lock(flags); - our_sound = unprocessed_sound; - unprocessed_sound.active = 0; + our_sound = spk_unprocessed_sound; + spk_unprocessed_sound.active = 0; prepare_to_wait(&speakup_event, &wait, TASK_INTERRUPTIBLE); should_break = kthread_should_stop() || diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c index ab7de93..f8c1e45 100644 --- a/drivers/staging/speakup/varhandlers.c +++ b/drivers/staging/speakup/varhandlers.c @@ -16,24 +16,24 @@ static struct st_var_header var_headers[] = { { "ex_num", EXNUMBER, VAR_PROC, NULL, NULL }, { "characters", CHARS, VAR_PROC, NULL, NULL }, { "synth_direct", SYNTH_DIRECT, VAR_PROC, NULL, NULL }, - { "caps_start", CAPS_START, VAR_STRING, str_caps_start, NULL }, - { "caps_stop", CAPS_STOP, VAR_STRING, str_caps_stop, NULL }, + { "caps_start", CAPS_START, VAR_STRING, spk_str_caps_start, NULL }, + { "caps_stop", CAPS_STOP, VAR_STRING, spk_str_caps_stop, NULL }, { "delay_time", DELAY, VAR_TIME, NULL, NULL }, { "trigger_time", TRIGGER, VAR_TIME, NULL, NULL }, { "jiffy_delta", JIFFY, VAR_TIME, NULL, NULL }, { "full_time", FULL, VAR_TIME, NULL, NULL }, - { "spell_delay", SPELL_DELAY, VAR_NUM, &spell_delay, NULL }, - { "bleeps", BLEEPS, VAR_NUM, &bleeps, NULL }, - { "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &attrib_bleep, NULL }, - { "bleep_time", BLEEP_TIME, VAR_TIME, &bleep_time, NULL }, + { "spell_delay", SPELL_DELAY, VAR_NUM, &spk_spell_delay, NULL }, + { "bleeps", BLEEPS, VAR_NUM, &spk_bleeps, NULL }, + { "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &spk_attrib_bleep, NULL }, + { "bleep_time", BLEEP_TIME, VAR_TIME, &spk_bleep_time, NULL }, { "cursor_time", CURSOR_TIME, VAR_TIME, NULL, NULL }, - { "punc_level", PUNC_LEVEL, VAR_NUM, &punc_level, NULL }, - { "reading_punc", READING_PUNC, VAR_NUM, &reading_punc, NULL }, - { "say_control", SAY_CONTROL, VAR_NUM, &say_ctrl, NULL }, - { "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &say_word_ctl, NULL }, - { "no_interrupt", NO_INTERRUPT, VAR_NUM, &no_intr, NULL }, - { "key_echo", KEY_ECHO, VAR_NUM, &key_echo, NULL }, - { "bell_pos", BELL_POS, VAR_NUM, &bell_pos, NULL }, + { "punc_level", PUNC_LEVEL, VAR_NUM, &spk_punc_level, NULL }, + { "reading_punc", READING_PUNC, VAR_NUM, &spk_reading_punc, NULL }, + { "say_control", SAY_CONTROL, VAR_NUM, &spk_say_ctrl, NULL }, + { "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &spk_say_word_ctl, NULL }, + { "no_interrupt", NO_INTERRUPT, VAR_NUM, &spk_no_intr, NULL }, + { "key_echo", KEY_ECHO, VAR_NUM, &spk_key_echo, NULL }, + { "bell_pos", BELL_POS, VAR_NUM, &spk_bell_pos, NULL }, { "rate", RATE, VAR_NUM, NULL, NULL }, { "pitch", PITCH, VAR_NUM, NULL, NULL }, { "vol", VOL, VAR_NUM, NULL, NULL }, @@ -58,7 +58,7 @@ static struct punc_var_t punc_vars[] = { { -1, -1 }, }; -int chartab_get_value(char *keyword) +int spk_chartab_get_value(char *keyword) { int value = 0; @@ -103,11 +103,11 @@ void speakup_register_var(struct var_t *var) p_header->data = var; switch (p_header->var_type) { case VAR_STRING: - set_string_var(nothing, p_header, 0); + spk_set_string_var(nothing, p_header, 0); break; case VAR_NUM: case VAR_TIME: - set_num_var(0, p_header, E_DEFAULT); + spk_set_num_var(0, p_header, E_DEFAULT); break; default: break; @@ -123,7 +123,7 @@ void speakup_unregister_var(enum var_id_t var_id) p_header->data = NULL; } -struct st_var_header *get_var_header(enum var_id_t var_id) +struct st_var_header *spk_get_var_header(enum var_id_t var_id) { struct st_var_header *p_header; if (var_id < 0 || var_id >= MAXVARS) @@ -134,7 +134,7 @@ struct st_var_header *get_var_header(enum var_id_t var_id) return p_header; } -struct st_var_header *var_header_by_name(const char *name) +struct st_var_header *spk_var_header_by_name(const char *name) { int i; struct st_var_header *where = NULL; @@ -151,15 +151,15 @@ struct st_var_header *var_header_by_name(const char *name) return where; } -struct var_t *get_var(enum var_id_t var_id) +struct var_t *spk_get_var(enum var_id_t var_id) { BUG_ON(var_id < 0 || var_id >= MAXVARS); BUG_ON(!var_ptrs[var_id]); return var_ptrs[var_id]->data; } -EXPORT_SYMBOL_GPL(get_var); +EXPORT_SYMBOL_GPL(spk_get_var); -struct punc_var_t *get_punc_var(enum var_id_t var_id) +struct punc_var_t *spk_get_punc_var(enum var_id_t var_id) { struct punc_var_t *rv = NULL; struct punc_var_t *where; @@ -175,7 +175,7 @@ struct punc_var_t *get_punc_var(enum var_id_t var_id) } /* handlers for setting vars */ -int set_num_var(int input, struct st_var_header *var, int how) +int spk_set_num_var(int input, struct st_var_header *var, int how) { int val; short ret = 0; @@ -217,7 +217,7 @@ int set_num_var(int input, struct st_var_header *var, int how) if (p_val != NULL) *p_val = val; if (var->var_id == PUNC_LEVEL) { - punc_mask = punc_masks[val]; + spk_punc_mask = spk_punc_masks[val]; return ret; } if (var_data->u.n.multiplier != 0) @@ -232,7 +232,7 @@ int set_num_var(int input, struct st_var_header *var, int how) if (!var_data->u.n.synth_fmt) return ret; if (var->var_id == PITCH) - cp = pitch_buff; + cp = spk_pitch_buff; else cp = buf; if (!var_data->u.n.out_str) @@ -244,7 +244,7 @@ int set_num_var(int input, struct st_var_header *var, int how) return ret; } -int set_string_var(const char *page, struct st_var_header *var, int len) +int spk_set_string_var(const char *page, struct st_var_header *var, int len) { int ret = 0; struct var_t *var_data = var->data; @@ -267,21 +267,21 @@ int set_string_var(const char *page, struct st_var_header *var, int len) return ret; } -/* set_mask_bits sets or clears the punc/delim/repeat bits, +/* spk_set_mask_bits sets or clears the punc/delim/repeat bits, * if input is null uses the defaults. * values for how: 0 clears bits of chars supplied, * 1 clears allk, 2 sets bits for chars */ -int set_mask_bits(const char *input, const int which, const int how) +int spk_set_mask_bits(const char *input, const int which, const int how) { u_char *cp; - short mask = punc_info[which].mask; + short mask = spk_punc_info[which].mask; if (how&1) { - for (cp = (u_char *)punc_info[3].value; *cp; cp++) + for (cp = (u_char *)spk_punc_info[3].value; *cp; cp++) spk_chartab[*cp] &= ~mask; } cp = (u_char *)input; if (cp == 0) - cp = punc_info[which].value; + cp = spk_punc_info[which].value; else { for ( ; *cp; cp++) { if (*cp < SPACE) @@ -308,7 +308,7 @@ int set_mask_bits(const char *input, const int which, const int how) return 0; } -char *strlwr(char *s) +char *spk_strlwr(char *s) { char *p; if (s == NULL) @@ -341,7 +341,7 @@ char *speakup_s2i(char *start, int *dest) return start; } -char *s2uchar(char *start, char *dest) +char *spk_s2uchar(char *start, char *dest) { int val = 0; while (*start && *start <= SPACE) @@ -357,7 +357,7 @@ char *s2uchar(char *start, char *dest) return start; } -char *xlate(char *s) +char *spk_xlate(char *s) { static const char finds[] = "nrtvafe"; static const char subs[] = "\n\r\t\013\001\014\033"; -- cgit v0.10.2 From d9f5420268ca9b2bbe62f14757fac3e10eaf1ebf Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 2 Jan 2013 02:36:56 +0100 Subject: staging: speakup: Turn some symbols static Turn static some symbols which do not actually need to be externally-visible Signed-off-by: Samuel Thibault Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/speakup/fakekey.c b/drivers/staging/speakup/fakekey.c index 1b34a87..4299cf4 100644 --- a/drivers/staging/speakup/fakekey.c +++ b/drivers/staging/speakup/fakekey.c @@ -28,7 +28,7 @@ #define PRESSED 1 #define RELEASED 0 -DEFINE_PER_CPU(bool, reporting_keystroke); +static DEFINE_PER_CPU(bool, reporting_keystroke); static struct input_dev *virt_keyboard; diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c index 463d125..9916e94 100644 --- a/drivers/staging/speakup/main.c +++ b/drivers/staging/speakup/main.c @@ -251,14 +251,14 @@ DEFINE_MUTEX(spk_mutex); static int keyboard_notifier_call(struct notifier_block *, unsigned long code, void *param); -struct notifier_block keyboard_notifier_block = { +static struct notifier_block keyboard_notifier_block = { .notifier_call = keyboard_notifier_call, }; static int vt_notifier_call(struct notifier_block *, unsigned long code, void *param); -struct notifier_block vt_notifier_block = { +static struct notifier_block vt_notifier_block = { .notifier_call = vt_notifier_call, }; -- cgit v0.10.2 From 0774c2b5c1e0025cb016393d8552171c0ec55c39 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:40 +0000 Subject: staging: comedi: addi_apci_2032: interrupt safety change Put the hardware into a safe state before enabling the interrupt. In the interrupt routine, check the device has been fully configured by checking `dev->attached`. In particular, `dev->read_subdev` could be NULL early on and although the hardware's status register should indicate no interrupt has occurred (since it's been put into a safe state), it's better not to rely on it. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 8f8d3e9..3b5e1d7 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -237,6 +237,9 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) struct comedi_subdevice *s = dev->read_subdev; unsigned int val; + if (!dev->attached) + return IRQ_NONE; + /* Check if VCC OR CC interrupt has occurred */ val = inl(dev->iobase + APCI2032_STATUS_REG) & APCI2032_STATUS_IRQ; if (!val) @@ -281,6 +284,7 @@ static int apci2032_auto_attach(struct comedi_device *dev, if (ret) return ret; dev->iobase = pci_resource_start(pcidev, 1); + apci2032_reset(dev); if (pcidev->irq > 0) { ret = request_irq(pcidev->irq, apci2032_interrupt, @@ -329,7 +333,6 @@ static int apci2032_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_UNUSED; } - apci2032_reset(dev); return 0; } -- cgit v0.10.2 From b82fe57c4d059a8ff1190ead1693d66b868353b2 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:41 +0000 Subject: staging: comedi: addi_apci_2032: correct interrupt subdevice The subdevice type and flags are initialized incorrectly for the interrupt subdevice - the SDF_CMD_READ value belongs in the subdevice flags. Fix it. Also set the number of channels to 2 since there are 2 interrupt sources each with its own status bit. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 3b5e1d7..f04f59d 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -320,9 +320,9 @@ static int apci2032_auto_attach(struct comedi_device *dev, s = &dev->subdevices[2]; if (dev->irq) { dev->read_subdev = s; - s->type = COMEDI_SUBD_DI | SDF_CMD_READ; - s->subdev_flags = SDF_READABLE; - s->n_chan = 1; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_CMD_READ; + s->n_chan = 2; s->maxdata = 1; s->range_table = &range_digital; s->insn_bits = apci2032_int_insn_bits; -- cgit v0.10.2 From 6bf9a3babe630a9972b28fd3bb7d2cfcd40e6409 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:42 +0000 Subject: staging: comedi: addi_apci_2032: set COMEDI_CB_OVERFLOW If the call to `comedi_buf_put()` fails in the interrupt routine, set the `COMEDI_CB_OVERFLOW` event flag. Note that the `COMEDI_CB_ERROR` flag will have also been set by `comedi_buf_put()` in this case. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index f04f59d..aeb34db 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -248,8 +248,10 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) s->state = inl(dev->iobase + APCI2032_INT_STATUS_REG); outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); - comedi_buf_put(s->async, s->state); - s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; + if (comedi_buf_put(s->async, s->state)) + s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; + else + s->async->events |= COMEDI_CB_OVERFLOW; comedi_event(dev, s); return IRQ_HANDLED; -- cgit v0.10.2 From b652bd83a0528c43e935cb6f2f8df024b7a85c5e Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:43 +0000 Subject: staging: comedi: addi_apci_2032: make insn_bits read live data The `insn_bits` handler for the special digital input subdevice used for interrupts currently uses `s->state` for the data value, which is set to the value of the APCI2032_INT_STATUS_REG register when a valid interrupt occurs. Just read the live register contents in the `insn_bits` handler instead of relying on the interrupt service routine to read it for us. The register contains a couple of hardware error status bits. They might also be valid even when the corresponding bits have not been enabled in the APCI_INT_CTRL_REG register in which case this would be useful for checking for hardware errors without using interrupts, but this needs to be checked. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index aeb34db..4c348dd 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -159,7 +159,7 @@ static int apci2032_int_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - data[1] = s->state; + data[1] = inl(dev->iobase + APCI2032_INT_STATUS_REG) & 3; return insn->n; } @@ -245,10 +245,10 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) if (!val) return IRQ_NONE; - s->state = inl(dev->iobase + APCI2032_INT_STATUS_REG); - outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); + val = inl(dev->iobase + APCI2032_INT_STATUS_REG) & 3; + outl(0x00, dev->iobase + APCI2032_INT_CTRL_REG); - if (comedi_buf_put(s->async, s->state)) + if (comedi_buf_put(s->async, val)) s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; else s->async->events |= COMEDI_CB_OVERFLOW; -- cgit v0.10.2 From ef6543dbad12c1086f3bc3565d8266352521d8a3 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:44 +0000 Subject: staging: comedi: addi_apci_2032: only disable triggered interrupts The interrupt handler disables all interrupt sources when a valid interrupt occurs. Just disable the triggered interrupt source so we can still get interrupts for the other interrupt source. Also add a comment indicating why the triggered interrupt source is disabled. The interrupt sources are level-sensitive and indicate hardware errors that are likely to be persistent, so if we reenabled them they would just keep triggering repeatedly. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 4c348dd..98691fd 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -246,7 +246,13 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) return IRQ_NONE; val = inl(dev->iobase + APCI2032_INT_STATUS_REG) & 3; - outl(0x00, dev->iobase + APCI2032_INT_CTRL_REG); + /* Disable triggered interrupt sources. */ + outl(~val & 3, dev->iobase + APCI2032_INT_CTRL_REG); + /* + * Note: We don't reenable the triggered interrupt sources because they + * are level-sensitive, hardware error status interrupt sources and + * they'd keep triggering interrupts repeatedly. + */ if (comedi_buf_put(s->async, val)) s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; -- cgit v0.10.2 From 5c2d4cba9586ddc3505f51bddf935ddc65a0e0bb Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:45 +0000 Subject: staging: comedi: addi_apci_2032: use channel list When setting up asynchronous commands for the special interrupt subdevice, use the channel list to decide which interrupt sources to enable. Set the maximum length of the channel list to be the same as the number of channels (2). Normally, the channel list would include channel 0, channel 1 or both. When reading the scan data in the interrupt routine, the readings from each channel in the channel list will be packed into a single unsigned short data value. Make each bit in this value correspond to an index in the channel list. Since all the channels in the channel list are read at the same time, insist that the scan end argument is the length of the channel list and that the conversion source is `TRIG_NOW`. Allocate some private data for the special interrupt subdevice to hold a spin-lock, the channels to be enabled and an indication of whether the command is still active. Stop the command if a buffer overflow occurs. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 98691fd..dd81ddc 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -58,6 +58,12 @@ struct apci2032_private { unsigned int wdog_ctrl; }; +struct apci2032_int_private { + spinlock_t spinlock; + bool active; + unsigned char enabled_isns; +}; + static int apci2032_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -163,6 +169,16 @@ static int apci2032_int_insn_bits(struct comedi_device *dev, return insn->n; } +static void apci2032_int_stop(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct apci2032_int_private *subpriv = s->private; + + subpriv->active = false; + subpriv->enabled_isns = 0; + outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); +} + static int apci2032_int_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) @@ -172,8 +188,8 @@ static int apci2032_int_cmdtest(struct comedi_device *dev, /* Step 1 : check if triggers are trivially valid */ err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW); - err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_OTHER); - err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW); + err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT); + err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW); err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE); @@ -189,17 +205,9 @@ static int apci2032_int_cmdtest(struct comedi_device *dev, /* Step 3: check if arguments are trivially valid */ err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); - - /* - * 0 == no trigger - * 1 == trigger on VCC interrupt - * 2 == trigger on CC interrupt - * 3 == trigger on either VCC or CC interrupt - */ - err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg, 3); - + err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0); - err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, 1); + err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); if (err) @@ -217,8 +225,20 @@ static int apci2032_int_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { struct comedi_cmd *cmd = &s->async->cmd; + struct apci2032_int_private *subpriv = s->private; + unsigned char enabled_isns; + unsigned int n; + unsigned long flags; + + enabled_isns = 0; + for (n = 0; n < cmd->chanlist_len; n++) + enabled_isns |= 1 << CR_CHAN(cmd->chanlist[n]); - outl(cmd->scan_begin_arg, dev->iobase + APCI2032_INT_CTRL_REG); + spin_lock_irqsave(&subpriv->spinlock, flags); + subpriv->enabled_isns = enabled_isns; + subpriv->active = true; + outl(subpriv->enabled_isns, dev->iobase + APCI2032_INT_CTRL_REG); + spin_unlock_irqrestore(&subpriv->spinlock, flags); return 0; } @@ -226,7 +246,13 @@ static int apci2032_int_cmd(struct comedi_device *dev, static int apci2032_int_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { - outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); + struct apci2032_int_private *subpriv = s->private; + unsigned long flags; + + spin_lock_irqsave(&subpriv->spinlock, flags); + if (subpriv->active) + apci2032_int_stop(dev, s); + spin_unlock_irqrestore(&subpriv->spinlock, flags); return 0; } @@ -235,7 +261,9 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) { struct comedi_device *dev = d; struct comedi_subdevice *s = dev->read_subdev; + struct apci2032_int_private *subpriv; unsigned int val; + bool do_event = false; if (!dev->attached) return IRQ_NONE; @@ -245,6 +273,9 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) if (!val) return IRQ_NONE; + subpriv = s->private; + spin_lock(&subpriv->spinlock); + val = inl(dev->iobase + APCI2032_INT_STATUS_REG) & 3; /* Disable triggered interrupt sources. */ outl(~val & 3, dev->iobase + APCI2032_INT_CTRL_REG); @@ -254,11 +285,31 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) * they'd keep triggering interrupts repeatedly. */ - if (comedi_buf_put(s->async, val)) - s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; - else - s->async->events |= COMEDI_CB_OVERFLOW; - comedi_event(dev, s); + if (subpriv->active && (val & subpriv->enabled_isns) != 0) { + unsigned short bits; + unsigned int n, len; + unsigned int *chanlist; + + /* Bits in scan data correspond to indices in channel list. */ + bits = 0; + len = s->async->cmd.chanlist_len; + chanlist = &s->async->cmd.chanlist[0]; + for (n = 0; n < len; n++) + if ((val & (1U << CR_CHAN(chanlist[n]))) != 0) + bits |= 1U << n; + + if (comedi_buf_put(s->async, bits)) { + s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; + } else { + apci2032_int_stop(dev, s); + s->async->events |= COMEDI_CB_OVERFLOW; + } + do_event = true; + } + + spin_unlock(&subpriv->spinlock); + if (do_event) + comedi_event(dev, s); return IRQ_HANDLED; } @@ -327,10 +378,18 @@ static int apci2032_auto_attach(struct comedi_device *dev, /* Initialize the interrupt subdevice */ s = &dev->subdevices[2]; if (dev->irq) { + struct apci2032_int_private *subpriv; + dev->read_subdev = s; + subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); + if (!subpriv) + return -ENOMEM; + spin_lock_init(&subpriv->spinlock); + s->private = subpriv; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; s->n_chan = 2; + s->len_chanlist = 2; s->maxdata = 1; s->range_table = &range_digital; s->insn_bits = apci2032_int_insn_bits; @@ -352,6 +411,8 @@ static void apci2032_detach(struct comedi_device *dev) apci2032_reset(dev); if (dev->irq) free_irq(dev->irq, dev); + if (dev->read_subdev) + kfree(dev->read_subdev->private); if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); -- cgit v0.10.2 From 5f6c2a954d17544c68ce83d016ea456207cadeac Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:46 +0000 Subject: staging: comedi: addi_apci_2032: always initialize interrupt subdevice Initialize the special interrupt subdevice as a digital input subdevice even if the interrupt handler cannot be registered. It's `insn_bits` handler will still read the interrupt status register. This hardware status bits in this register might be valid even if they haven't been enabled in the interrupt control register, but this needs to be checked. In any case, initializing the subdevice as a digital input subdevice is harmless. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index dd81ddc..c302bf9 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -377,6 +377,12 @@ static int apci2032_auto_attach(struct comedi_device *dev, /* Initialize the interrupt subdevice */ s = &dev->subdevices[2]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 2; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci2032_int_insn_bits; if (dev->irq) { struct apci2032_int_private *subpriv; @@ -386,18 +392,11 @@ static int apci2032_auto_attach(struct comedi_device *dev, return -ENOMEM; spin_lock_init(&subpriv->spinlock); s->private = subpriv; - s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; - s->n_chan = 2; s->len_chanlist = 2; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = apci2032_int_insn_bits; s->do_cmdtest = apci2032_int_cmdtest; s->do_cmd = apci2032_int_cmd; s->cancel = apci2032_int_cancel; - } else { - s->type = COMEDI_SUBD_UNUSED; } return 0; -- cgit v0.10.2 From 215caceb3dac9eb7d431c9da21394c6ccb778b15 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 3 Dec 2012 18:15:47 +0000 Subject: staging: comedi: addi_apci_2032: support stop_src == TRIG_COUNT When setting up asynchronous commands on the special interrupt subdevice, support the `TRIG_COUNT` stop source to allow the command to stop automatically after a specified number of scans. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index c302bf9..31e1259 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -60,6 +60,7 @@ struct apci2032_private { struct apci2032_int_private { spinlock_t spinlock; + unsigned int stop_count; bool active; unsigned char enabled_isns; }; @@ -179,6 +180,30 @@ static void apci2032_int_stop(struct comedi_device *dev, outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); } +static bool apci2032_int_start(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned char enabled_isns) +{ + struct apci2032_int_private *subpriv = s->private; + struct comedi_cmd *cmd = &s->async->cmd; + bool do_event; + + subpriv->enabled_isns = enabled_isns; + subpriv->stop_count = cmd->stop_arg; + if (cmd->stop_src == TRIG_COUNT && subpriv->stop_count == 0) { + /* An empty acquisition! */ + s->async->events |= COMEDI_CB_EOA; + subpriv->active = false; + do_event = true; + } else { + subpriv->active = true; + outl(enabled_isns, dev->iobase + APCI2032_INT_CTRL_REG); + do_event = false; + } + + return do_event; +} + static int apci2032_int_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) @@ -191,12 +216,14 @@ static int apci2032_int_cmdtest(struct comedi_device *dev, err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT); err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW); err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); - err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE); + err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); if (err) return 1; /* Step 2a : make sure trigger sources are unique */ + err |= cfc_check_trigger_is_unique(cmd->stop_src); + /* Step 2b : and mutually compatible */ if (err) @@ -208,7 +235,8 @@ static int apci2032_int_cmdtest(struct comedi_device *dev, err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0); err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); - err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); + if (cmd->stop_src == TRIG_NONE) + err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); if (err) return 3; @@ -229,17 +257,19 @@ static int apci2032_int_cmd(struct comedi_device *dev, unsigned char enabled_isns; unsigned int n; unsigned long flags; + bool do_event; enabled_isns = 0; for (n = 0; n < cmd->chanlist_len; n++) enabled_isns |= 1 << CR_CHAN(cmd->chanlist[n]); spin_lock_irqsave(&subpriv->spinlock, flags); - subpriv->enabled_isns = enabled_isns; - subpriv->active = true; - outl(subpriv->enabled_isns, dev->iobase + APCI2032_INT_CTRL_REG); + do_event = apci2032_int_start(dev, s, enabled_isns); spin_unlock_irqrestore(&subpriv->spinlock, flags); + if (do_event) + comedi_event(dev, s); + return 0; } @@ -300,6 +330,15 @@ static irqreturn_t apci2032_interrupt(int irq, void *d) if (comedi_buf_put(s->async, bits)) { s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; + if (s->async->cmd.stop_src == TRIG_COUNT && + subpriv->stop_count > 0) { + subpriv->stop_count--; + if (subpriv->stop_count == 0) { + /* end of acquisition */ + s->async->events |= COMEDI_CB_EOA; + apci2032_int_stop(dev, s); + } + } } else { apci2032_int_stop(dev, s); s->async->events |= COMEDI_CB_OVERFLOW; -- cgit v0.10.2 From f95d45d114e1fd024bdee67beb80fce9b9c96126 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 4 Dec 2012 15:47:14 -0700 Subject: staging: comedi: pcm_common: remove module This module is built whenever CONFIG_COMEDI is enabled but it is only used by the pcmmio and pcmuio drivers. The pcm_common module consists of one exported function. Put a local copy of the function in the pcmmio and pcmuio drivers. This removes the need for the pcm_common module and the now unused pcm_common.[ch] files can be deleted and removed from the Makefile. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index 0de4d2e..3a04e30 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -2,7 +2,6 @@ # # Comedi "helper" modules -obj-$(CONFIG_COMEDI) += pcm_common.o # Comedi misc drivers obj-$(CONFIG_COMEDI_BOND) += comedi_bond.o diff --git a/drivers/staging/comedi/drivers/pcm_common.c b/drivers/staging/comedi/drivers/pcm_common.c deleted file mode 100644 index 8a718ae..0000000 --- a/drivers/staging/comedi/drivers/pcm_common.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "../comedidev.h" - -#include "comedi_fc.h" -#include "pcm_common.h" - -int comedi_pcm_cmdtest(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_cmd *cmd) -{ - int err = 0; - - /* Step 1 : check if triggers are trivially valid */ - - err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); - err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT); - err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW); - err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); - err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); - - if (err) - return 1; - - /* Step 2a : make sure trigger sources are unique */ - - err |= cfc_check_trigger_is_unique(cmd->start_src); - err |= cfc_check_trigger_is_unique(cmd->stop_src); - - /* Step 2b : and mutually compatible */ - - if (err) - return 2; - - /* Step 3: check if arguments are trivially valid */ - - err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); - err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); - err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0); - err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); - - switch (cmd->stop_src) { - case TRIG_COUNT: - /* any count allowed */ - break; - case TRIG_NONE: - err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); - break; - default: - break; - } - - if (err) - return 3; - - /* step 4: fix up any arguments */ - - /* if (err) return 4; */ - - return 0; -} -EXPORT_SYMBOL(comedi_pcm_cmdtest); - -MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/pcm_common.h b/drivers/staging/comedi/drivers/pcm_common.h deleted file mode 100644 index cd4840c..0000000 --- a/drivers/staging/comedi/drivers/pcm_common.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _comedi_common_H -#define _comedi_common_H - -extern int comedi_pcm_cmdtest(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_cmd *cmd); - -#endif diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c index 7522bfb..045f442 100644 --- a/drivers/staging/comedi/drivers/pcmmio.c +++ b/drivers/staging/comedi/drivers/pcmmio.c @@ -78,9 +78,10 @@ Configuration Options: #include #include +#include + #include "../comedidev.h" -#include "pcm_common.h" -#include /* for PCI devices */ +#include "comedi_fc.h" /* This stuff is all from pcmuio.c -- it refers to the DIO subdevices only */ #define CHANS_PER_PORT 8 @@ -802,11 +803,59 @@ static int pcmmio_cmd(struct comedi_device *dev, struct comedi_subdevice *s) return 0; } -static int -pcmmio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_cmd *cmd) +static int pcmmio_cmdtest(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) { - return comedi_pcm_cmdtest(dev, s, cmd); + int err = 0; + + /* Step 1 : check if triggers are trivially valid */ + + err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); + err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT); + err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW); + err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); + err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); + + if (err) + return 1; + + /* Step 2a : make sure trigger sources are unique */ + + err |= cfc_check_trigger_is_unique(cmd->start_src); + err |= cfc_check_trigger_is_unique(cmd->stop_src); + + /* Step 2b : and mutually compatible */ + + if (err) + return 2; + + /* Step 3: check if arguments are trivially valid */ + + err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); + + switch (cmd->stop_src) { + case TRIG_COUNT: + /* any count allowed */ + break; + case TRIG_NONE: + err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); + break; + default: + break; + } + + if (err) + return 3; + + /* step 4: fix up any arguments */ + + /* if (err) return 4; */ + + return 0; } static int adc_wait_ready(unsigned long iobase) diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index 31ea20c..c61cc64 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c @@ -77,10 +77,10 @@ Configuration Options: #include #include -#include "../comedidev.h" -#include "pcm_common.h" +#include -#include /* for PCI devices */ +#include "../comedidev.h" +#include "comedi_fc.h" #define CHANS_PER_PORT 8 #define PORTS_PER_ASIC 6 @@ -740,11 +740,59 @@ static int pcmuio_cmd(struct comedi_device *dev, struct comedi_subdevice *s) return 0; } -static int -pcmuio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_cmd *cmd) +static int pcmuio_cmdtest(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) { - return comedi_pcm_cmdtest(dev, s, cmd); + int err = 0; + + /* Step 1 : check if triggers are trivially valid */ + + err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); + err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT); + err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW); + err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); + err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); + + if (err) + return 1; + + /* Step 2a : make sure trigger sources are unique */ + + err |= cfc_check_trigger_is_unique(cmd->start_src); + err |= cfc_check_trigger_is_unique(cmd->stop_src); + + /* Step 2b : and mutually compatible */ + + if (err) + return 2; + + /* Step 3: check if arguments are trivially valid */ + + err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); + + switch (cmd->stop_src) { + case TRIG_COUNT: + /* any count allowed */ + break; + case TRIG_NONE: + err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); + break; + default: + break; + } + + if (err) + return 3; + + /* step 4: fix up any arguments */ + + /* if (err) return 4; */ + + return 0; } static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) -- cgit v0.10.2 From 2aae0076c9676a6e56793e25df95eab4bdadc94e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:31:57 -0700 Subject: staging: comedi: comedi_fops: remove forward declarations Move a couple of the functions to remove the need for the forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index b7bba17..91b9e93 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -90,14 +90,6 @@ static DEFINE_SPINLOCK(comedi_file_info_table_lock); static struct comedi_device_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; -static void do_become_nonbusy(struct comedi_device *dev, - struct comedi_subdevice *s); -static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s); - -static int comedi_fasync(int fd, struct file *file, int on); - -static int is_device_busy(struct comedi_device *dev); - static int resize_async_buffer(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_async *async, unsigned new_size) @@ -317,6 +309,70 @@ static struct device_attribute comedi_dev_attrs[] = { __ATTR_NULL }; +static void comedi_set_subdevice_runflags(struct comedi_subdevice *s, + unsigned mask, unsigned bits) +{ + unsigned long flags; + + spin_lock_irqsave(&s->spin_lock, flags); + s->runflags &= ~mask; + s->runflags |= (bits & mask); + spin_unlock_irqrestore(&s->spin_lock, flags); +} + +/* + This function restores a subdevice to an idle state. + */ +static void do_become_nonbusy(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct comedi_async *async = s->async; + + comedi_set_subdevice_runflags(s, SRF_RUNNING, 0); + if (async) { + comedi_reset_async_buf(async); + async->inttrig = NULL; + kfree(async->cmd.chanlist); + async->cmd.chanlist = NULL; + } else { + dev_err(dev->class_dev, + "BUG: (?) do_become_nonbusy called with async=NULL\n"); + } + + s->busy = NULL; +} + +static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s) +{ + int ret = 0; + + if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) && s->cancel) + ret = s->cancel(dev, s); + + do_become_nonbusy(dev, s); + + return ret; +} + +static int is_device_busy(struct comedi_device *dev) +{ + struct comedi_subdevice *s; + int i; + + if (!dev->attached) + return 0; + + for (i = 0; i < dev->n_subdevices; i++) { + s = &dev->subdevices[i]; + if (s->busy) + return 1; + if (s->async && s->async->mmap_count) + return 1; + } + + return 0; +} + /* COMEDI_DEVCONFIG device config ioctl @@ -1123,17 +1179,6 @@ error: return ret; } -static void comedi_set_subdevice_runflags(struct comedi_subdevice *s, - unsigned mask, unsigned bits) -{ - unsigned long flags; - - spin_lock_irqsave(&s->spin_lock, flags); - s->runflags &= ~mask; - s->runflags |= (bits & mask); - spin_unlock_irqrestore(&s->spin_lock, flags); -} - static int do_cmd_ioctl(struct comedi_device *dev, struct comedi_cmd __user *arg, void *file) { @@ -1621,19 +1666,6 @@ done: return rc; } -static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s) -{ - int ret = 0; - - if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) && s->cancel) - ret = s->cancel(dev, s); - - do_become_nonbusy(dev, s); - - return ret; -} - - static void comedi_vm_open(struct vm_area_struct *area) { struct comedi_async *async; @@ -2023,28 +2055,6 @@ done: return count ? count : retval; } -/* - This function restores a subdevice to an idle state. - */ -static void do_become_nonbusy(struct comedi_device *dev, - struct comedi_subdevice *s) -{ - struct comedi_async *async = s->async; - - comedi_set_subdevice_runflags(s, SRF_RUNNING, 0); - if (async) { - comedi_reset_async_buf(async); - async->inttrig = NULL; - kfree(async->cmd.chanlist); - async->cmd.chanlist = NULL; - } else { - dev_err(dev->class_dev, - "BUG: (?) do_become_nonbusy called with async=NULL\n"); - } - - s->busy = NULL; -} - static int comedi_open(struct inode *inode, struct file *file) { const unsigned minor = iminor(inode); @@ -2125,6 +2135,22 @@ ok: return 0; } +static int comedi_fasync(int fd, struct file *file, int on) +{ + const unsigned minor = iminor(file->f_dentry->d_inode); + struct comedi_device_file_info *dev_file_info; + struct comedi_device *dev; + dev_file_info = comedi_get_device_file_info(minor); + + if (dev_file_info == NULL) + return -ENODEV; + dev = dev_file_info->device; + if (dev == NULL) + return -ENODEV; + + return fasync_helper(fd, file, on, &dev->async_queue); +} + static int comedi_close(struct inode *inode, struct file *file) { const unsigned minor = iminor(inode); @@ -2169,22 +2195,6 @@ static int comedi_close(struct inode *inode, struct file *file) return 0; } -static int comedi_fasync(int fd, struct file *file, int on) -{ - const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device_file_info *dev_file_info; - struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); - - if (dev_file_info == NULL) - return -ENODEV; - dev = dev_file_info->device; - if (dev == NULL) - return -ENODEV; - - return fasync_helper(fd, file, on, &dev->async_queue); -} - static const struct file_operations comedi_fops = { .owner = THIS_MODULE, .unlocked_ioctl = comedi_unlocked_ioctl, @@ -2356,25 +2366,6 @@ unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) } EXPORT_SYMBOL(comedi_get_subdevice_runflags); -static int is_device_busy(struct comedi_device *dev) -{ - struct comedi_subdevice *s; - int i; - - if (!dev->attached) - return 0; - - for (i = 0; i < dev->n_subdevices; i++) { - s = &dev->subdevices[i]; - if (s->busy) - return 1; - if (s->async && s->async->mmap_count) - return 1; - } - - return 0; -} - static void comedi_device_init(struct comedi_device *dev) { memset(dev, 0, sizeof(struct comedi_device)); -- cgit v0.10.2 From 43bd33f22444868cbc9d4cbec7a3efb0a7c2cb25 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:33:29 -0700 Subject: staging: comedi: don't expose comedi_get_{read, write}_subdevice These two inline helper function in comedidev.h are only used in comedi_fops.c. They return information that should only be used by the comedi core. Move both functions to comedi_fops.c so they aren't exposed to the comedi drivers. Also, remove the inline tag and let the compiler figure it out. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 91b9e93..38de7f7 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -90,6 +90,26 @@ static DEFINE_SPINLOCK(comedi_file_info_table_lock); static struct comedi_device_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; +static struct comedi_subdevice * +comedi_get_read_subdevice(const struct comedi_device_file_info *info) +{ + if (info->read_subdevice) + return info->read_subdevice; + if (info->device == NULL) + return NULL; + return info->device->read_subdev; +} + +static struct comedi_subdevice * +comedi_get_write_subdevice(const struct comedi_device_file_info *info) +{ + if (info->write_subdevice) + return info->write_subdevice; + if (info->device == NULL) + return NULL; + return info->device->write_subdev; +} + static int resize_async_buffer(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_async *async, unsigned new_size) diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 692e1e6..a2123ae 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -282,26 +282,6 @@ static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor); -static inline struct comedi_subdevice *comedi_get_read_subdevice( - const struct comedi_device_file_info *info) -{ - if (info->read_subdevice) - return info->read_subdevice; - if (info->device == NULL) - return NULL; - return info->device->read_subdev; -} - -static inline struct comedi_subdevice *comedi_get_write_subdevice( - const struct comedi_device_file_info *info) -{ - if (info->write_subdevice) - return info->write_subdevice; - if (info->device == NULL) - return NULL; - return info->device->write_subdev; -} - int comedi_alloc_subdevices(struct comedi_device *, int); void comedi_device_detach(struct comedi_device *dev); -- cgit v0.10.2 From 85104e9b409013c78624b367dec02e6ccc996635 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:34:40 -0700 Subject: staging: comedi: comedi_fops: introduce comedi_dev_from_minor() A number of functions have to call comedi_get_device_file_info() to get the comedi_device_file_info pointer for a given minor. That pointer is only used to get the actual comedi_device pointer for the minor. Introduce a new helper function, comedi_dev_from_minor(), to simplify this operation. This will also allow us to make the comedi_device_file_info struct private. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 38de7f7..647c7f3 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -90,6 +90,16 @@ static DEFINE_SPINLOCK(comedi_file_info_table_lock); static struct comedi_device_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; +struct comedi_device *comedi_dev_from_minor(unsigned minor) +{ + struct comedi_device_file_info *info; + + info = comedi_get_device_file_info(minor); + + return info ? info->device : NULL; +} +EXPORT_SYMBOL_GPL(comedi_dev_from_minor); + static struct comedi_subdevice * comedi_get_read_subdevice(const struct comedi_device_file_info *info) { diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index a2123ae..fc2c179 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -282,6 +282,8 @@ static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor); +struct comedi_device *comedi_dev_from_minor(unsigned minor); + int comedi_alloc_subdevices(struct comedi_device *, int); void comedi_device_detach(struct comedi_device *dev); -- cgit v0.10.2 From 4da5fa9a439fda3019585aecab44462fd641b6f8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:35:23 -0700 Subject: staging: comedi: use comedi_dev_from_minor() Remove the need to export comedi_get_device_file_info() by using the new helper comedi_dev_from_minor(). This will also allow us to make the comedi_device_file_info struct private. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 647c7f3..3945b5f 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1608,14 +1608,11 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device_file_info *dev_file_info = - comedi_get_device_file_info(minor); - struct comedi_device *dev; + struct comedi_device *dev = comedi_dev_from_minor(minor); int rc; - if (dev_file_info == NULL || dev_file_info->device == NULL) + if (!dev) return -ENODEV; - dev = dev_file_info->device; mutex_lock(&dev->mutex); @@ -2088,12 +2085,9 @@ done: static int comedi_open(struct inode *inode, struct file *file) { const unsigned minor = iminor(inode); - struct comedi_device_file_info *dev_file_info = - comedi_get_device_file_info(minor); - struct comedi_device *dev = - dev_file_info ? dev_file_info->device : NULL; + struct comedi_device *dev = comedi_dev_from_minor(minor); - if (dev == NULL) { + if (!dev) { DPRINTK("invalid minor number\n"); return -ENODEV; } @@ -2168,14 +2162,9 @@ ok: static int comedi_fasync(int fd, struct file *file, int on) { const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device_file_info *dev_file_info; - struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); + struct comedi_device *dev = comedi_dev_from_minor(minor); - if (dev_file_info == NULL) - return -ENODEV; - dev = dev_file_info->device; - if (dev == NULL) + if (!dev) return -ENODEV; return fasync_helper(fd, file, on, &dev->async_queue); @@ -2184,16 +2173,11 @@ static int comedi_fasync(int fd, struct file *file, int on) static int comedi_close(struct inode *inode, struct file *file) { const unsigned minor = iminor(inode); + struct comedi_device *dev = comedi_dev_from_minor(minor); struct comedi_subdevice *s = NULL; int i; - struct comedi_device_file_info *dev_file_info; - struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); - if (dev_file_info == NULL) - return -ENODEV; - dev = dev_file_info->device; - if (dev == NULL) + if (!dev) return -ENODEV; mutex_lock(&dev->mutex); diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 50cf498..c0adc16 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -213,13 +213,10 @@ int comedi_driver_unregister(struct comedi_driver *driver) /* check for devices using this driver */ for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { - struct comedi_device_file_info *dev_file_info = - comedi_get_device_file_info(i); - struct comedi_device *dev; + struct comedi_device *dev = comedi_dev_from_minor(i); - if (dev_file_info == NULL) + if (!dev) continue; - dev = dev_file_info->device; mutex_lock(&dev->mutex); if (dev->attached && dev->driver == driver) { @@ -834,7 +831,6 @@ int comedi_auto_config(struct device *hardware_device, struct comedi_driver *driver, unsigned long context) { int minor; - struct comedi_device_file_info *dev_file_info; struct comedi_device *comedi_dev; int ret; @@ -852,8 +848,7 @@ int comedi_auto_config(struct device *hardware_device, if (minor < 0) return minor; - dev_file_info = comedi_get_device_file_info(minor); - comedi_dev = dev_file_info->device; + comedi_dev = comedi_dev_from_minor(minor); mutex_lock(&comedi_dev->mutex); if (comedi_dev->attached) diff --git a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c index 4dc09a2..8932a51 100644 --- a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c +++ b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c @@ -42,7 +42,6 @@ MODULE_LICENSE("GPL"); struct comedi_device *comedi_open(const char *filename) { - struct comedi_device_file_info *dev_file_info; struct comedi_device *dev; unsigned int minor; @@ -54,12 +53,9 @@ struct comedi_device *comedi_open(const char *filename) if (minor >= COMEDI_NUM_BOARD_MINORS) return NULL; - dev_file_info = comedi_get_device_file_info(minor); - if (dev_file_info == NULL) - return NULL; - dev = dev_file_info->device; + dev = comedi_dev_from_minor(minor); - if (dev == NULL || !dev->attached) + if (!dev || !dev->attached) return NULL; if (!try_module_get(dev->driver->module)) diff --git a/drivers/staging/comedi/proc.c b/drivers/staging/comedi/proc.c index 01acbe9..732134f 100644 --- a/drivers/staging/comedi/proc.c +++ b/drivers/staging/comedi/proc.c @@ -49,13 +49,10 @@ static int comedi_read(char *buf, char **start, off_t offset, int len, "driver_name, board_name, n_subdevices"); for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { - struct comedi_device_file_info *dev_file_info = - comedi_get_device_file_info(i); - struct comedi_device *dev; + struct comedi_device *dev = comedi_dev_from_minor(i); - if (dev_file_info == NULL) + if (!dev) continue; - dev = dev_file_info->device; if (dev->attached) { devices_q = 1; -- cgit v0.10.2 From 87b1ad7a80d0a297448893e06f37c775951119d0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:36:00 -0700 Subject: staging: comedi: comedi_fops: don't export comedi_get_device_file_info() This function is now only used in comedi_fops.c and does not need to be exported. Make it static and move it to avoid forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 3945b5f..1950f1e 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -90,6 +90,18 @@ static DEFINE_SPINLOCK(comedi_file_info_table_lock); static struct comedi_device_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; +static struct comedi_device_file_info * +comedi_get_device_file_info(unsigned minor) +{ + struct comedi_device_file_info *info; + + BUG_ON(minor >= COMEDI_NUM_MINORS); + spin_lock(&comedi_file_info_table_lock); + info = comedi_file_info_table[minor]; + spin_unlock(&comedi_file_info_table_lock); + return info; +} + struct comedi_device *comedi_dev_from_minor(unsigned minor) { struct comedi_device_file_info *info; @@ -2540,15 +2552,3 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s) } kfree(info); } - -struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor) -{ - struct comedi_device_file_info *info; - - BUG_ON(minor >= COMEDI_NUM_MINORS); - spin_lock(&comedi_file_info_table_lock); - info = comedi_file_info_table[minor]; - spin_unlock(&comedi_file_info_table_lock); - return info; -} -EXPORT_SYMBOL_GPL(comedi_get_device_file_info); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index fc2c179..3e1fd84 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -280,8 +280,6 @@ enum comedi_minor_bits { static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; -struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor); - struct comedi_device *comedi_dev_from_minor(unsigned minor); int comedi_alloc_subdevices(struct comedi_device *, int); -- cgit v0.10.2 From e79c8d21000eb484c54b2fa2f42e6b55775ef144 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:36:42 -0700 Subject: staging: comedi: don't expose struct comedi_device_file_info This structure is only used in comedi_fops.c as part of handling the file operations and sysfs files. Remove it's defenition from comedidev.h so it's not exposed to the comedi drivers. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 1950f1e..e66464b 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -86,6 +86,13 @@ MODULE_PARM_DESC(comedi_default_buf_maxsize_kb, "default maximum size of asynchronous buffer in KiB (default " __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB) ")"); +struct comedi_device_file_info { + struct comedi_device *device; + struct comedi_subdevice *read_subdevice; + struct comedi_subdevice *write_subdevice; + struct device *hardware_device; +}; + static DEFINE_SPINLOCK(comedi_file_info_table_lock); static struct comedi_device_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 3e1fd84..2bbb7c9 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -250,13 +250,6 @@ static inline const void *comedi_board(const struct comedi_device *dev) return dev->board_ptr; } -struct comedi_device_file_info { - struct comedi_device *device; - struct comedi_subdevice *read_subdevice; - struct comedi_subdevice *write_subdevice; - struct device *hardware_device; -}; - #ifdef CONFIG_COMEDI_DEBUG extern int comedi_debug; #else -- cgit v0.10.2 From cd6b7636e961b621b54f6f132db81c3ea7c2ca5e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:38:02 -0700 Subject: staging: comedi: comedi_fops: rename struct comedi_device_file_info For aesthetic reasons, rename this struct to comedi_file_info. It's a bit shorter and allows fixing some of the ugly line breaks used to keep the lines < 80 chars. Also, consistently use the local variable name 'info' instead of the longer 'dev_file_info' to also fix some ugly line breaks. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index e66464b..cc6f32d 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -86,7 +86,7 @@ MODULE_PARM_DESC(comedi_default_buf_maxsize_kb, "default maximum size of asynchronous buffer in KiB (default " __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB) ")"); -struct comedi_device_file_info { +struct comedi_file_info { struct comedi_device *device; struct comedi_subdevice *read_subdevice; struct comedi_subdevice *write_subdevice; @@ -94,13 +94,11 @@ struct comedi_device_file_info { }; static DEFINE_SPINLOCK(comedi_file_info_table_lock); -static struct comedi_device_file_info -*comedi_file_info_table[COMEDI_NUM_MINORS]; +static struct comedi_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; -static struct comedi_device_file_info * -comedi_get_device_file_info(unsigned minor) +static struct comedi_file_info *comedi_get_device_file_info(unsigned minor) { - struct comedi_device_file_info *info; + struct comedi_file_info *info; BUG_ON(minor >= COMEDI_NUM_MINORS); spin_lock(&comedi_file_info_table_lock); @@ -111,7 +109,7 @@ comedi_get_device_file_info(unsigned minor) struct comedi_device *comedi_dev_from_minor(unsigned minor) { - struct comedi_device_file_info *info; + struct comedi_file_info *info; info = comedi_get_device_file_info(minor); @@ -120,7 +118,7 @@ struct comedi_device *comedi_dev_from_minor(unsigned minor) EXPORT_SYMBOL_GPL(comedi_dev_from_minor); static struct comedi_subdevice * -comedi_get_read_subdevice(const struct comedi_device_file_info *info) +comedi_get_read_subdevice(const struct comedi_file_info *info) { if (info->read_subdevice) return info->read_subdevice; @@ -130,7 +128,7 @@ comedi_get_read_subdevice(const struct comedi_device_file_info *info) } static struct comedi_subdevice * -comedi_get_write_subdevice(const struct comedi_device_file_info *info) +comedi_get_write_subdevice(const struct comedi_file_info *info) { if (info->write_subdevice) return info->write_subdevice; @@ -184,7 +182,7 @@ static int resize_async_buffer(struct comedi_device *dev, static ssize_t show_max_read_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_read_subdevice(info); unsigned int size = 0; @@ -200,7 +198,7 @@ static ssize_t store_max_read_buffer_kb(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_read_subdevice(info); unsigned int size; int err; @@ -225,7 +223,7 @@ static ssize_t store_max_read_buffer_kb(struct device *dev, static ssize_t show_read_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_read_subdevice(info); unsigned int size = 0; @@ -241,7 +239,7 @@ static ssize_t store_read_buffer_kb(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_read_subdevice(info); unsigned int size; int err; @@ -267,7 +265,7 @@ static ssize_t show_max_write_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_write_subdevice(info); unsigned int size = 0; @@ -283,7 +281,7 @@ static ssize_t store_max_write_buffer_kb(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_write_subdevice(info); unsigned int size; int err; @@ -308,7 +306,7 @@ static ssize_t store_max_write_buffer_kb(struct device *dev, static ssize_t show_write_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_write_subdevice(info); unsigned int size = 0; @@ -324,7 +322,7 @@ static ssize_t store_write_buffer_kb(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct comedi_device_file_info *info = dev_get_drvdata(dev); + struct comedi_file_info *info = dev_get_drvdata(dev); struct comedi_subdevice *s = comedi_get_write_subdevice(info); unsigned int size; int err; @@ -584,12 +582,11 @@ static int do_devinfo_ioctl(struct comedi_device *dev, { struct comedi_devinfo devinfo; const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device_file_info *dev_file_info = - comedi_get_device_file_info(minor); + struct comedi_file_info *info = comedi_get_device_file_info(minor); struct comedi_subdevice *read_subdev = - comedi_get_read_subdevice(dev_file_info); + comedi_get_read_subdevice(info); struct comedi_subdevice *write_subdev = - comedi_get_write_subdevice(dev_file_info); + comedi_get_write_subdevice(info); memset(&devinfo, 0, sizeof(devinfo)); @@ -1753,13 +1750,12 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma) int i; int retval; struct comedi_subdevice *s; - struct comedi_device_file_info *dev_file_info; + struct comedi_file_info *info = comedi_get_device_file_info(minor); struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); - if (dev_file_info == NULL) + if (info == NULL) return -ENODEV; - dev = dev_file_info->device; + dev = info->device; if (dev == NULL) return -ENODEV; @@ -1770,9 +1766,9 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma) goto done; } if (vma->vm_flags & VM_WRITE) - s = comedi_get_write_subdevice(dev_file_info); + s = comedi_get_write_subdevice(info); else - s = comedi_get_read_subdevice(dev_file_info); + s = comedi_get_read_subdevice(info); if (s == NULL) { retval = -EINVAL; @@ -1830,13 +1826,12 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_subdevice *read_subdev; struct comedi_subdevice *write_subdev; - struct comedi_device_file_info *dev_file_info; + struct comedi_file_info *info = comedi_get_device_file_info(minor); struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); - if (dev_file_info == NULL) + if (info == NULL) return -ENODEV; - dev = dev_file_info->device; + dev = info->device; if (dev == NULL) return -ENODEV; @@ -1848,7 +1843,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) } mask = 0; - read_subdev = comedi_get_read_subdevice(dev_file_info); + read_subdev = comedi_get_read_subdevice(info); if (read_subdev) { poll_wait(file, &read_subdev->async->wait_head, wait); if (!read_subdev->busy @@ -1858,7 +1853,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) mask |= POLLIN | POLLRDNORM; } } - write_subdev = comedi_get_write_subdevice(dev_file_info); + write_subdev = comedi_get_write_subdevice(info); if (write_subdev) { poll_wait(file, &write_subdev->async->wait_head, wait); comedi_buf_write_alloc(write_subdev->async, @@ -1884,13 +1879,12 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, int n, m, count = 0, retval = 0; DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device_file_info *dev_file_info; + struct comedi_file_info *info = comedi_get_device_file_info(minor); struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); - if (dev_file_info == NULL) + if (info == NULL) return -ENODEV; - dev = dev_file_info->device; + dev = info->device; if (dev == NULL) return -ENODEV; @@ -1900,7 +1894,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, goto done; } - s = comedi_get_write_subdevice(dev_file_info); + s = comedi_get_write_subdevice(info); if (s == NULL) { retval = -EIO; goto done; @@ -1995,13 +1989,12 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, int n, m, count = 0, retval = 0; DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device_file_info *dev_file_info; + struct comedi_file_info *info = comedi_get_device_file_info(minor); struct comedi_device *dev; - dev_file_info = comedi_get_device_file_info(minor); - if (dev_file_info == NULL) + if (info == NULL) return -ENODEV; - dev = dev_file_info->device; + dev = info->device; if (dev == NULL) return -ENODEV; @@ -2011,7 +2004,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, goto done; } - s = comedi_get_read_subdevice(dev_file_info); + s = comedi_get_read_subdevice(info); if (s == NULL) { retval = -EIO; goto done; @@ -2276,7 +2269,7 @@ static int __init comedi_init(void) comedi_num_legacy_minors = 16; memset(comedi_file_info_table, 0, - sizeof(struct comedi_device_file_info *) * COMEDI_NUM_MINORS); + sizeof(struct comedi_file_info *) * COMEDI_NUM_MINORS); retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS, "comedi"); @@ -2419,11 +2412,11 @@ static void comedi_device_cleanup(struct comedi_device *dev) int comedi_alloc_board_minor(struct device *hardware_device) { - struct comedi_device_file_info *info; + struct comedi_file_info *info; struct device *csdev; unsigned i; - info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); + info = kzalloc(sizeof(struct comedi_file_info), GFP_KERNEL); if (info == NULL) return -ENOMEM; info->device = kzalloc(sizeof(struct comedi_device), GFP_KERNEL); @@ -2460,7 +2453,7 @@ int comedi_alloc_board_minor(struct device *hardware_device) void comedi_free_board_minor(unsigned minor) { - struct comedi_device_file_info *info; + struct comedi_file_info *info; BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS); spin_lock(&comedi_file_info_table_lock); @@ -2485,7 +2478,7 @@ void comedi_free_board_minor(unsigned minor) int comedi_find_board_minor(struct device *hardware_device) { int minor; - struct comedi_device_file_info *info; + struct comedi_file_info *info; for (minor = 0; minor < COMEDI_NUM_BOARD_MINORS; minor++) { spin_lock(&comedi_file_info_table_lock); @@ -2502,11 +2495,11 @@ int comedi_find_board_minor(struct device *hardware_device) int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct comedi_subdevice *s) { - struct comedi_device_file_info *info; + struct comedi_file_info *info; struct device *csdev; unsigned i; - info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); + info = kmalloc(sizeof(struct comedi_file_info), GFP_KERNEL); if (info == NULL) return -ENOMEM; info->device = dev; @@ -2538,7 +2531,7 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, void comedi_free_subdevice_minor(struct comedi_subdevice *s) { - struct comedi_device_file_info *info; + struct comedi_file_info *info; if (s == NULL) return; -- cgit v0.10.2 From ed69335c727b7a499ac8499d943c6c879c937d69 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:38:30 -0700 Subject: staging: comedi: comedi_fops: rename comedi_get_device_file_info() The 'get' usually implies increasing a reference count of an object. This function returns a pointer but does not do any reference counting. For aesthetic reasons, rename the function to better represent what its doing. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index cc6f32d..0920dcc 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -96,7 +96,7 @@ struct comedi_file_info { static DEFINE_SPINLOCK(comedi_file_info_table_lock); static struct comedi_file_info *comedi_file_info_table[COMEDI_NUM_MINORS]; -static struct comedi_file_info *comedi_get_device_file_info(unsigned minor) +static struct comedi_file_info *comedi_file_info_from_minor(unsigned minor) { struct comedi_file_info *info; @@ -111,7 +111,7 @@ struct comedi_device *comedi_dev_from_minor(unsigned minor) { struct comedi_file_info *info; - info = comedi_get_device_file_info(minor); + info = comedi_file_info_from_minor(minor); return info ? info->device : NULL; } @@ -582,7 +582,7 @@ static int do_devinfo_ioctl(struct comedi_device *dev, { struct comedi_devinfo devinfo; const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_file_info *info = comedi_get_device_file_info(minor); + struct comedi_file_info *info = comedi_file_info_from_minor(minor); struct comedi_subdevice *read_subdev = comedi_get_read_subdevice(info); struct comedi_subdevice *write_subdev = @@ -1750,7 +1750,7 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma) int i; int retval; struct comedi_subdevice *s; - struct comedi_file_info *info = comedi_get_device_file_info(minor); + struct comedi_file_info *info = comedi_file_info_from_minor(minor); struct comedi_device *dev; if (info == NULL) @@ -1826,7 +1826,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_subdevice *read_subdev; struct comedi_subdevice *write_subdev; - struct comedi_file_info *info = comedi_get_device_file_info(minor); + struct comedi_file_info *info = comedi_file_info_from_minor(minor); struct comedi_device *dev; if (info == NULL) @@ -1879,7 +1879,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, int n, m, count = 0, retval = 0; DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_file_info *info = comedi_get_device_file_info(minor); + struct comedi_file_info *info = comedi_file_info_from_minor(minor); struct comedi_device *dev; if (info == NULL) @@ -1989,7 +1989,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, int n, m, count = 0, retval = 0; DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_file_info *info = comedi_get_device_file_info(minor); + struct comedi_file_info *info = comedi_file_info_from_minor(minor); struct comedi_device *dev; if (info == NULL) -- cgit v0.10.2 From 7d8a25674f8358e09daf4f1ed4e7dd93416f7b5b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:38:53 -0700 Subject: staging: comedi: comedi_fops: rename comedi_{read,write}_subdevice() The 'get' usually implies increasing a reference count of an object. These function return a pointer but do not do any reference counting. For aesthetic reasons, rename the functions to better represent what they do. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 0920dcc..a480b6e 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -118,7 +118,7 @@ struct comedi_device *comedi_dev_from_minor(unsigned minor) EXPORT_SYMBOL_GPL(comedi_dev_from_minor); static struct comedi_subdevice * -comedi_get_read_subdevice(const struct comedi_file_info *info) +comedi_read_subdevice(const struct comedi_file_info *info) { if (info->read_subdevice) return info->read_subdevice; @@ -128,7 +128,7 @@ comedi_get_read_subdevice(const struct comedi_file_info *info) } static struct comedi_subdevice * -comedi_get_write_subdevice(const struct comedi_file_info *info) +comedi_write_subdevice(const struct comedi_file_info *info) { if (info->write_subdevice) return info->write_subdevice; @@ -183,7 +183,7 @@ static ssize_t show_max_read_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_read_subdevice(info); + struct comedi_subdevice *s = comedi_read_subdevice(info); unsigned int size = 0; mutex_lock(&info->device->mutex); @@ -199,7 +199,7 @@ static ssize_t store_max_read_buffer_kb(struct device *dev, const char *buf, size_t count) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_read_subdevice(info); + struct comedi_subdevice *s = comedi_read_subdevice(info); unsigned int size; int err; @@ -224,7 +224,7 @@ static ssize_t show_read_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_read_subdevice(info); + struct comedi_subdevice *s = comedi_read_subdevice(info); unsigned int size = 0; mutex_lock(&info->device->mutex); @@ -240,7 +240,7 @@ static ssize_t store_read_buffer_kb(struct device *dev, const char *buf, size_t count) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_read_subdevice(info); + struct comedi_subdevice *s = comedi_read_subdevice(info); unsigned int size; int err; @@ -266,7 +266,7 @@ static ssize_t show_max_write_buffer_kb(struct device *dev, char *buf) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_write_subdevice(info); + struct comedi_subdevice *s = comedi_write_subdevice(info); unsigned int size = 0; mutex_lock(&info->device->mutex); @@ -282,7 +282,7 @@ static ssize_t store_max_write_buffer_kb(struct device *dev, const char *buf, size_t count) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_write_subdevice(info); + struct comedi_subdevice *s = comedi_write_subdevice(info); unsigned int size; int err; @@ -307,7 +307,7 @@ static ssize_t show_write_buffer_kb(struct device *dev, struct device_attribute *attr, char *buf) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_write_subdevice(info); + struct comedi_subdevice *s = comedi_write_subdevice(info); unsigned int size = 0; mutex_lock(&info->device->mutex); @@ -323,7 +323,7 @@ static ssize_t store_write_buffer_kb(struct device *dev, const char *buf, size_t count) { struct comedi_file_info *info = dev_get_drvdata(dev); - struct comedi_subdevice *s = comedi_get_write_subdevice(info); + struct comedi_subdevice *s = comedi_write_subdevice(info); unsigned int size; int err; @@ -583,10 +583,8 @@ static int do_devinfo_ioctl(struct comedi_device *dev, struct comedi_devinfo devinfo; const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_subdevice *read_subdev = - comedi_get_read_subdevice(info); - struct comedi_subdevice *write_subdev = - comedi_get_write_subdevice(info); + struct comedi_subdevice *read_subdev = comedi_read_subdevice(info); + struct comedi_subdevice *write_subdev = comedi_write_subdevice(info); memset(&devinfo, 0, sizeof(devinfo)); @@ -1766,9 +1764,9 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma) goto done; } if (vma->vm_flags & VM_WRITE) - s = comedi_get_write_subdevice(info); + s = comedi_write_subdevice(info); else - s = comedi_get_read_subdevice(info); + s = comedi_read_subdevice(info); if (s == NULL) { retval = -EINVAL; @@ -1843,7 +1841,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) } mask = 0; - read_subdev = comedi_get_read_subdevice(info); + read_subdev = comedi_read_subdevice(info); if (read_subdev) { poll_wait(file, &read_subdev->async->wait_head, wait); if (!read_subdev->busy @@ -1853,7 +1851,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) mask |= POLLIN | POLLRDNORM; } } - write_subdev = comedi_get_write_subdevice(info); + write_subdev = comedi_write_subdevice(info); if (write_subdev) { poll_wait(file, &write_subdev->async->wait_head, wait); comedi_buf_write_alloc(write_subdev->async, @@ -1894,7 +1892,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, goto done; } - s = comedi_get_write_subdevice(info); + s = comedi_write_subdevice(info); if (s == NULL) { retval = -EIO; goto done; @@ -2004,7 +2002,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, goto done; } - s = comedi_get_read_subdevice(info); + s = comedi_read_subdevice(info); if (s == NULL) { retval = -EIO; goto done; -- cgit v0.10.2 From 0e700923bf63b4afb7bb213f140d5a6e28c32aa6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:39:18 -0700 Subject: staging: comedi: comedi_fops: cleanup do_devinfo_ioctl() Consolidate the local variables 'read_subdev' and 'write_subdev' into a single local variable 's'. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index a480b6e..f67b12a 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -580,11 +580,10 @@ static int do_devinfo_ioctl(struct comedi_device *dev, struct comedi_devinfo __user *arg, struct file *file) { - struct comedi_devinfo devinfo; const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_subdevice *read_subdev = comedi_read_subdevice(info); - struct comedi_subdevice *write_subdev = comedi_write_subdevice(info); + struct comedi_subdevice *s; + struct comedi_devinfo devinfo; memset(&devinfo, 0, sizeof(devinfo)); @@ -594,13 +593,15 @@ static int do_devinfo_ioctl(struct comedi_device *dev, strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN); strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN); - if (read_subdev) - devinfo.read_subdevice = read_subdev - dev->subdevices; + s = comedi_read_subdevice(info); + if (s) + devinfo.read_subdevice = s - dev->subdevices; else devinfo.read_subdevice = -1; - if (write_subdev) - devinfo.write_subdevice = write_subdev - dev->subdevices; + s = comedi_write_subdevice(info); + if (s) + devinfo.write_subdevice = s - dev->subdevices; else devinfo.write_subdevice = -1; -- cgit v0.10.2 From ca081b1d7e2f355b54a6fa1e63f84b8ceb9597de Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:39:44 -0700 Subject: staging: comedi: comedi_fops: cleanup comedi_poll() Consolidate the local variables 'read_subdev' and 'write_subdev' into a single local variable 's'. Use comedi_dev_from_minor() to simplify the return -ENODEV tests. Use a goto in the !dev->attached test so that the mutex_unlock() call is in a common place. Cleanup the formating of the || in the read and write subdevice poll code. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index f67b12a..093f403 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1823,49 +1823,40 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) { unsigned int mask = 0; const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_subdevice *read_subdev; - struct comedi_subdevice *write_subdev; struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev; + struct comedi_device *dev = comedi_dev_from_minor(minor); + struct comedi_subdevice *s; - if (info == NULL) - return -ENODEV; - dev = info->device; - if (dev == NULL) + if (!dev) return -ENODEV; mutex_lock(&dev->mutex); + if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); - mutex_unlock(&dev->mutex); - return 0; + goto done; } - mask = 0; - read_subdev = comedi_read_subdevice(info); - if (read_subdev) { - poll_wait(file, &read_subdev->async->wait_head, wait); - if (!read_subdev->busy - || comedi_buf_read_n_available(read_subdev->async) > 0 - || !(comedi_get_subdevice_runflags(read_subdev) & - SRF_RUNNING)) { + s = comedi_read_subdevice(info); + if (s) { + poll_wait(file, &s->async->wait_head, wait); + if (!s->busy || !(comedi_get_subdevice_runflags(s) & SRF_RUNNING) || + comedi_buf_read_n_available(s->async) > 0) mask |= POLLIN | POLLRDNORM; - } } - write_subdev = comedi_write_subdevice(info); - if (write_subdev) { - poll_wait(file, &write_subdev->async->wait_head, wait); - comedi_buf_write_alloc(write_subdev->async, - write_subdev->async->prealloc_bufsz); - if (!write_subdev->busy - || !(comedi_get_subdevice_runflags(write_subdev) & - SRF_RUNNING) - || comedi_buf_write_n_allocated(write_subdev->async) >= - bytes_per_sample(write_subdev->async->subdevice)) { + + s = comedi_write_subdevice(info); + if (s) { + unsigned int bps = bytes_per_sample(s->async->subdevice); + + poll_wait(file, &s->async->wait_head, wait); + comedi_buf_write_alloc(s->async, s->async->prealloc_bufsz); + if (!s->busy || !(comedi_get_subdevice_runflags(s) & SRF_RUNNING) || + comedi_buf_write_n_allocated(s->async) >= bps) mask |= POLLOUT | POLLWRNORM; - } } +done: mutex_unlock(&dev->mutex); return mask; } -- cgit v0.10.2 From 5c87fef53cb338a919a18349facaf172c1f0cf75 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:40:08 -0700 Subject: staging: comedi: comedi_fops: remove the goto's in comedi_read() Use comedi_dev_from_minor() to simplify the return -ENODEV tests. Cleanup the sanity checking a bit and remove the need for the goto's when returning an initial error condition. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 093f403..cf1410d 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1980,38 +1980,25 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev; + struct comedi_device *dev = comedi_dev_from_minor(minor); - if (info == NULL) - return -ENODEV; - dev = info->device; - if (dev == NULL) + if (!dev) return -ENODEV; if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); - retval = -ENODEV; - goto done; + return -ENODEV; } s = comedi_read_subdevice(info); - if (s == NULL) { - retval = -EIO; - goto done; - } + if (!s) + return -EIO; + async = s->async; - if (!nbytes) { - retval = 0; - goto done; - } - if (!s->busy) { - retval = 0; - goto done; - } - if (s->busy != file) { - retval = -EACCES; - goto done; - } + if (!s->busy || !nbytes) + return 0; + if (s->busy != file) + return -EACCES; add_wait_queue(&async->wait_head, &wait); while (nbytes > 0 && !retval) { @@ -2080,7 +2067,6 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, set_current_state(TASK_RUNNING); remove_wait_queue(&async->wait_head, &wait); -done: return count ? count : retval; } -- cgit v0.10.2 From 2714b019fd570309e9a4cab2b988cbb7a36bbecd Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:40:34 -0700 Subject: staging: comedi: comedi_fops: remove the goto's in comedi_write() Use comedi_dev_from_minor() to simplify the return -ENODEV tests. Cleanup the sanity checking a bit and remove the need for the goto's when returning an initial error condition. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index cf1410d..0e9b522 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1870,39 +1870,27 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev; + struct comedi_device *dev = comedi_dev_from_minor(minor); - if (info == NULL) - return -ENODEV; - dev = info->device; - if (dev == NULL) + if (!dev) return -ENODEV; if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); - retval = -ENODEV; - goto done; + return -ENODEV; } s = comedi_write_subdevice(info); - if (s == NULL) { - retval = -EIO; - goto done; - } + if (!s) + return -EIO; + async = s->async; - if (!nbytes) { - retval = 0; - goto done; - } - if (!s->busy) { - retval = 0; - goto done; - } - if (s->busy != file) { - retval = -EACCES; - goto done; - } + if (!s->busy || !nbytes) + return 0; + if (s->busy != file) + return -EACCES; + add_wait_queue(&async->wait_head, &wait); while (nbytes > 0 && !retval) { set_current_state(TASK_INTERRUPTIBLE); @@ -1967,7 +1955,6 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, set_current_state(TASK_RUNNING); remove_wait_queue(&async->wait_head, &wait); -done: return count ? count : retval; } -- cgit v0.10.2 From a5787824c08f553a5f283fb754b2473a6ad19857 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:40:59 -0700 Subject: staging: comedi: comedi_fops: move the MODULE_* information to EOF For aesthetic reasons, move the MODULE_* information to the end of the file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 0e9b522..a066187 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -49,10 +49,6 @@ #include "comedi_internal.h" -MODULE_AUTHOR("http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi core module"); -MODULE_LICENSE("GPL"); - #ifdef CONFIG_COMEDI_DEBUG int comedi_debug; EXPORT_SYMBOL(comedi_debug); @@ -2515,3 +2511,7 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s) } kfree(info); } + +MODULE_AUTHOR("http://www.comedi.org"); +MODULE_DESCRIPTION("Comedi core module"); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 91fa0b0c96eb46444c9bc0d2994626fc371dd6db Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:41:19 -0700 Subject: staging: comedi: comedi_fops: move the module_{init, exit} functions to EOF For aesthetic reasons, move the module_{init,exit} functions to the end of the file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index a066187..805a503 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2205,91 +2205,6 @@ static void comedi_cleanup_legacy_minors(void) comedi_free_board_minor(i); } -static int __init comedi_init(void) -{ - int i; - int retval; - - pr_info("comedi: version " COMEDI_RELEASE " - http://www.comedi.org\n"); - - if (comedi_num_legacy_minors < 0 || - comedi_num_legacy_minors > COMEDI_NUM_BOARD_MINORS) { - pr_err("comedi: error: invalid value for module parameter \"comedi_num_legacy_minors\". Valid values are 0 through %i.\n", - COMEDI_NUM_BOARD_MINORS); - return -EINVAL; - } - - /* - * comedi is unusable if both comedi_autoconfig and - * comedi_num_legacy_minors are zero, so we might as well adjust the - * defaults in that case - */ - if (comedi_autoconfig == 0 && comedi_num_legacy_minors == 0) - comedi_num_legacy_minors = 16; - - memset(comedi_file_info_table, 0, - sizeof(struct comedi_file_info *) * COMEDI_NUM_MINORS); - - retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), - COMEDI_NUM_MINORS, "comedi"); - if (retval) - return -EIO; - cdev_init(&comedi_cdev, &comedi_fops); - comedi_cdev.owner = THIS_MODULE; - kobject_set_name(&comedi_cdev.kobj, "comedi"); - if (cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) { - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), - COMEDI_NUM_MINORS); - return -EIO; - } - comedi_class = class_create(THIS_MODULE, "comedi"); - if (IS_ERR(comedi_class)) { - pr_err("comedi: failed to create class\n"); - cdev_del(&comedi_cdev); - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), - COMEDI_NUM_MINORS); - return PTR_ERR(comedi_class); - } - - comedi_class->dev_attrs = comedi_dev_attrs; - - /* XXX requires /proc interface */ - comedi_proc_init(); - - /* create devices files for legacy/manual use */ - for (i = 0; i < comedi_num_legacy_minors; i++) { - int minor; - minor = comedi_alloc_board_minor(NULL); - if (minor < 0) { - comedi_cleanup_legacy_minors(); - cdev_del(&comedi_cdev); - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), - COMEDI_NUM_MINORS); - return minor; - } - } - - return 0; -} - -static void __exit comedi_cleanup(void) -{ - int i; - - comedi_cleanup_legacy_minors(); - for (i = 0; i < COMEDI_NUM_MINORS; ++i) - BUG_ON(comedi_file_info_table[i]); - - class_destroy(comedi_class); - cdev_del(&comedi_cdev); - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); - - comedi_proc_cleanup(); -} - -module_init(comedi_init); -module_exit(comedi_cleanup); - void comedi_error(const struct comedi_device *dev, const char *s) { dev_err(dev->class_dev, "%s: %s\n", dev->driver->driver_name, s); @@ -2512,6 +2427,90 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s) kfree(info); } +static int __init comedi_init(void) +{ + int i; + int retval; + + pr_info("comedi: version " COMEDI_RELEASE " - http://www.comedi.org\n"); + + if (comedi_num_legacy_minors < 0 || + comedi_num_legacy_minors > COMEDI_NUM_BOARD_MINORS) { + pr_err("comedi: error: invalid value for module parameter \"comedi_num_legacy_minors\". Valid values are 0 through %i.\n", + COMEDI_NUM_BOARD_MINORS); + return -EINVAL; + } + + /* + * comedi is unusable if both comedi_autoconfig and + * comedi_num_legacy_minors are zero, so we might as well adjust the + * defaults in that case + */ + if (comedi_autoconfig == 0 && comedi_num_legacy_minors == 0) + comedi_num_legacy_minors = 16; + + memset(comedi_file_info_table, 0, + sizeof(struct comedi_file_info *) * COMEDI_NUM_MINORS); + + retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS, "comedi"); + if (retval) + return -EIO; + cdev_init(&comedi_cdev, &comedi_fops); + comedi_cdev.owner = THIS_MODULE; + kobject_set_name(&comedi_cdev.kobj, "comedi"); + if (cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) { + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS); + return -EIO; + } + comedi_class = class_create(THIS_MODULE, "comedi"); + if (IS_ERR(comedi_class)) { + pr_err("comedi: failed to create class\n"); + cdev_del(&comedi_cdev); + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS); + return PTR_ERR(comedi_class); + } + + comedi_class->dev_attrs = comedi_dev_attrs; + + /* XXX requires /proc interface */ + comedi_proc_init(); + + /* create devices files for legacy/manual use */ + for (i = 0; i < comedi_num_legacy_minors; i++) { + int minor; + minor = comedi_alloc_board_minor(NULL); + if (minor < 0) { + comedi_cleanup_legacy_minors(); + cdev_del(&comedi_cdev); + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS); + return minor; + } + } + + return 0; +} +module_init(comedi_init); + +static void __exit comedi_cleanup(void) +{ + int i; + + comedi_cleanup_legacy_minors(); + for (i = 0; i < COMEDI_NUM_MINORS; ++i) + BUG_ON(comedi_file_info_table[i]); + + class_destroy(comedi_class); + cdev_del(&comedi_cdev); + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); + + comedi_proc_cleanup(); +} +module_exit(comedi_cleanup); + MODULE_AUTHOR("http://www.comedi.org"); MODULE_DESCRIPTION("Comedi core module"); MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 76cca89f4b032abad514c0821be35d999c9707ce Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:41:42 -0700 Subject: staging: comedi: comedi_fops: move comedi_cleanup_legacy_minors() This function is only called by the module_{init,exit} functions. For aesthetic reasons, move it near them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 805a503..a7bec57 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2197,14 +2197,6 @@ static const struct file_operations comedi_fops = { static struct class *comedi_class; static struct cdev comedi_cdev; -static void comedi_cleanup_legacy_minors(void) -{ - unsigned i; - - for (i = 0; i < comedi_num_legacy_minors; i++) - comedi_free_board_minor(i); -} - void comedi_error(const struct comedi_device *dev, const char *s) { dev_err(dev->class_dev, "%s: %s\n", dev->driver->driver_name, s); @@ -2427,6 +2419,14 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s) kfree(info); } +static void comedi_cleanup_legacy_minors(void) +{ + unsigned i; + + for (i = 0; i < comedi_num_legacy_minors; i++) + comedi_free_board_minor(i); +} + static int __init comedi_init(void) { int i; -- cgit v0.10.2 From bc252fd12c9430a011497d3726fad47683d58dc0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:42:02 -0700 Subject: staging: comedi: comedi_fops: fix a number of sizeof(struct foo) forms As mentioned in CodingStyle, the prefered form is: p = kmalloc(sizeof(*p), ...); Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index a7bec57..bc45c12 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -451,7 +451,7 @@ static int do_devconfig_ioctl(struct comedi_device *dev, return 0; } - if (copy_from_user(&it, arg, sizeof(struct comedi_devconfig))) + if (copy_from_user(&it, arg, sizeof(it))) return -EFAULT; it.board_name[COMEDI_NAMELEN - 1] = 0; @@ -519,7 +519,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev, struct comedi_subdevice *s; int retval = 0; - if (copy_from_user(&bc, arg, sizeof(struct comedi_bufconfig))) + if (copy_from_user(&bc, arg, sizeof(bc))) return -EFAULT; if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0) @@ -552,7 +552,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev, bc.maximum_size = async->max_bufsize; copyback: - if (copy_to_user(arg, &bc, sizeof(struct comedi_bufconfig))) + if (copy_to_user(arg, &bc, sizeof(bc))) return -EFAULT; return 0; @@ -601,7 +601,7 @@ static int do_devinfo_ioctl(struct comedi_device *dev, else devinfo.write_subdevice = -1; - if (copy_to_user(arg, &devinfo, sizeof(struct comedi_devinfo))) + if (copy_to_user(arg, &devinfo, sizeof(devinfo))) return -EFAULT; return 0; @@ -628,9 +628,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, struct comedi_subdinfo *tmp, *us; struct comedi_subdevice *s; - tmp = - kcalloc(dev->n_subdevices, sizeof(struct comedi_subdinfo), - GFP_KERNEL); + tmp = kcalloc(dev->n_subdevices, sizeof(*tmp), GFP_KERNEL); if (!tmp) return -ENOMEM; @@ -681,8 +679,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, us->settling_time_0 = s->settling_time_0; } - ret = copy_to_user(arg, tmp, - dev->n_subdevices * sizeof(struct comedi_subdinfo)); + ret = copy_to_user(arg, tmp, dev->n_subdevices * sizeof(*tmp)); kfree(tmp); @@ -709,7 +706,7 @@ static int do_chaninfo_ioctl(struct comedi_device *dev, struct comedi_subdevice *s; struct comedi_chaninfo it; - if (copy_from_user(&it, arg, sizeof(struct comedi_chaninfo))) + if (copy_from_user(&it, arg, sizeof(it))) return -EFAULT; if (it.subdev >= dev->n_subdevices) @@ -776,7 +773,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, struct comedi_subdevice *s; struct comedi_async *async; - if (copy_from_user(&bi, arg, sizeof(struct comedi_bufinfo))) + if (copy_from_user(&bi, arg, sizeof(bi))) return -EFAULT; if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0) @@ -831,7 +828,7 @@ copyback_position: bi.buf_read_ptr = async->buf_read_ptr; copyback: - if (copy_to_user(arg, &bi, sizeof(struct comedi_bufinfo))) + if (copy_to_user(arg, &bi, sizeof(bi))) return -EFAULT; return 0; @@ -865,7 +862,7 @@ static int do_insnlist_ioctl(struct comedi_device *dev, int i = 0; int ret = 0; - if (copy_from_user(&insnlist, arg, sizeof(struct comedi_insnlist))) + if (copy_from_user(&insnlist, arg, sizeof(insnlist))) return -EFAULT; data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL); @@ -875,8 +872,7 @@ static int do_insnlist_ioctl(struct comedi_device *dev, goto error; } - insns = - kcalloc(insnlist.n_insns, sizeof(struct comedi_insn), GFP_KERNEL); + insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL); if (!insns) { DPRINTK("kmalloc failed\n"); ret = -ENOMEM; @@ -884,7 +880,7 @@ static int do_insnlist_ioctl(struct comedi_device *dev, } if (copy_from_user(insns, insnlist.insns, - sizeof(struct comedi_insn) * insnlist.n_insns)) { + sizeof(*insns) * insnlist.n_insns)) { DPRINTK("copy_from_user failed\n"); ret = -EFAULT; goto error; @@ -1185,7 +1181,7 @@ static int do_insn_ioctl(struct comedi_device *dev, goto error; } - if (copy_from_user(&insn, arg, sizeof(struct comedi_insn))) { + if (copy_from_user(&insn, arg, sizeof(insn))) { ret = -EFAULT; goto error; } @@ -1229,7 +1225,7 @@ static int do_cmd_ioctl(struct comedi_device *dev, int ret = 0; unsigned int __user *user_chanlist; - if (copy_from_user(&cmd, arg, sizeof(struct comedi_cmd))) { + if (copy_from_user(&cmd, arg, sizeof(cmd))) { DPRINTK("bad cmd address\n"); return -EFAULT; } @@ -1319,7 +1315,7 @@ static int do_cmd_ioctl(struct comedi_device *dev, /* restore chanlist pointer before copying back */ cmd.chanlist = (unsigned int __force *)user_chanlist; cmd.data = NULL; - if (copy_to_user(arg, &cmd, sizeof(struct comedi_cmd))) { + if (copy_to_user(arg, &cmd, sizeof(cmd))) { DPRINTK("fault writing cmd\n"); ret = -EFAULT; goto cleanup; @@ -1378,7 +1374,7 @@ static int do_cmdtest_ioctl(struct comedi_device *dev, unsigned int *chanlist = NULL; unsigned int __user *user_chanlist; - if (copy_from_user(&cmd, arg, sizeof(struct comedi_cmd))) { + if (copy_from_user(&cmd, arg, sizeof(cmd))) { DPRINTK("bad cmd address\n"); return -EFAULT; } @@ -1442,7 +1438,7 @@ static int do_cmdtest_ioctl(struct comedi_device *dev, /* restore chanlist pointer before copying back */ cmd.chanlist = (unsigned int __force *)user_chanlist; - if (copy_to_user(arg, &cmd, sizeof(struct comedi_cmd))) { + if (copy_to_user(arg, &cmd, sizeof(cmd))) { DPRINTK("bad cmd address\n"); ret = -EFAULT; goto cleanup; @@ -2260,7 +2256,7 @@ EXPORT_SYMBOL(comedi_get_subdevice_runflags); static void comedi_device_init(struct comedi_device *dev) { - memset(dev, 0, sizeof(struct comedi_device)); + memset(dev, 0, sizeof(*dev)); spin_lock_init(&dev->spinlock); mutex_init(&dev->mutex); dev->minor = -1; @@ -2282,7 +2278,7 @@ int comedi_alloc_board_minor(struct device *hardware_device) struct device *csdev; unsigned i; - info = kzalloc(sizeof(struct comedi_file_info), GFP_KERNEL); + info = kzalloc(sizeof(*info), GFP_KERNEL); if (info == NULL) return -ENOMEM; info->device = kzalloc(sizeof(struct comedi_device), GFP_KERNEL); @@ -2365,7 +2361,7 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct device *csdev; unsigned i; - info = kmalloc(sizeof(struct comedi_file_info), GFP_KERNEL); + info = kmalloc(sizeof(*info), GFP_KERNEL); if (info == NULL) return -ENOMEM; info->device = dev; -- cgit v0.10.2 From 74120719a70c984e04c16afe53dbdea868bed6da Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:42:26 -0700 Subject: staging: comedi: comedi_fops: move comedi_get_subdevice_runflags() For aesthetic reasons, move this function so its near comedi_set_subdevice_runflags(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index bc45c12..0161f94 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -363,6 +363,18 @@ static void comedi_set_subdevice_runflags(struct comedi_subdevice *s, spin_unlock_irqrestore(&s->spin_lock, flags); } +unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) +{ + unsigned long flags; + unsigned runflags; + + spin_lock_irqsave(&s->spin_lock, flags); + runflags = s->runflags; + spin_unlock_irqrestore(&s->spin_lock, flags); + return runflags; +} +EXPORT_SYMBOL(comedi_get_subdevice_runflags); + /* This function restores a subdevice to an idle state. */ @@ -2242,18 +2254,6 @@ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s) } EXPORT_SYMBOL(comedi_event); -unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) -{ - unsigned long flags; - unsigned runflags; - - spin_lock_irqsave(&s->spin_lock, flags); - runflags = s->runflags; - spin_unlock_irqrestore(&s->spin_lock, flags); - return runflags; -} -EXPORT_SYMBOL(comedi_get_subdevice_runflags); - static void comedi_device_init(struct comedi_device *dev) { memset(dev, 0, sizeof(*dev)); -- cgit v0.10.2 From e0dac318ee2807d5ec1b09c1a608fdc25ef2ac7b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:42:47 -0700 Subject: staging: comedi: comedi_fops: introduce comedi_is_subdevice_running() Introduce a helper function that checks the subdevice runflags to see if the subdevice is running a command. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 0161f94..368dbc9 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -375,6 +375,14 @@ unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) } EXPORT_SYMBOL(comedi_get_subdevice_runflags); +bool comedi_is_subdevice_running(struct comedi_subdevice *s) +{ + unsigned runflags = comedi_get_subdevice_runflags(s); + + return (runflags & SRF_RUNNING) ? true : false; +} +EXPORT_SYMBOL_GPL(comedi_is_subdevice_running); + /* This function restores a subdevice to an idle state. */ diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 2bbb7c9..791030d 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -362,6 +362,8 @@ enum subdevice_runflags { SRF_RUNNING = 0x08000000 }; +bool comedi_is_subdevice_running(struct comedi_subdevice *s); + int comedi_check_chanlist(struct comedi_subdevice *s, int n, unsigned int *chanlist); -- cgit v0.10.2 From f012463068dbe0be2680aca6c607f7c6f5f0cdf3 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:43:18 -0700 Subject: staging: comedi: use comedi_is_subdevice_running() Use the helper function comedi_is_subdevice_running() instead of getting the subdevice runflags and then masking the result. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 368dbc9..b67fb0d 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -409,7 +409,7 @@ static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { int ret = 0; - if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) && s->cancel) + if (comedi_is_subdevice_running(s) && s->cancel) ret = s->cancel(dev, s); do_become_nonbusy(dev, s); @@ -660,7 +660,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, us->type = s->type; us->n_chan = s->n_chan; us->subd_flags = s->subdev_flags; - if (comedi_get_subdevice_runflags(s) & SRF_RUNNING) + if (comedi_is_subdevice_running(s)) us->subd_flags |= SDF_RUNNING; #define TIMER_nanosec 5 /* backwards compatibility */ us->timer_type = TIMER_nanosec; @@ -1852,7 +1852,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) s = comedi_read_subdevice(info); if (s) { poll_wait(file, &s->async->wait_head, wait); - if (!s->busy || !(comedi_get_subdevice_runflags(s) & SRF_RUNNING) || + if (!s->busy || !comedi_is_subdevice_running(s) || comedi_buf_read_n_available(s->async) > 0) mask |= POLLIN | POLLRDNORM; } @@ -1863,7 +1863,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) poll_wait(file, &s->async->wait_head, wait); comedi_buf_write_alloc(s->async, s->async->prealloc_bufsz); - if (!s->busy || !(comedi_get_subdevice_runflags(s) & SRF_RUNNING) || + if (!s->busy || !comedi_is_subdevice_running(s) || comedi_buf_write_n_allocated(s->async) >= bps) mask |= POLLOUT | POLLWRNORM; } @@ -1907,7 +1907,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, while (nbytes > 0 && !retval) { set_current_state(TASK_INTERRUPTIBLE); - if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { + if (!comedi_is_subdevice_running(s)) { if (count == 0) { if (comedi_get_subdevice_runflags(s) & SRF_ERROR) { @@ -2014,7 +2014,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, n = m; if (n == 0) { - if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { + if (!comedi_is_subdevice_running(s)) { do_become_nonbusy(dev, s); if (comedi_get_subdevice_runflags(s) & SRF_ERROR) { @@ -2227,7 +2227,7 @@ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s) /* DPRINTK("comedi_event 0x%x\n",mask); */ - if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) == 0) + if (!comedi_is_subdevice_running(s)) return; if (s-> diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 56dc599..81d7350 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -1086,7 +1086,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status, ("ni_mio_common: a_status=0xffff. Card removed?\n"); /* we probably aren't even running a command now, * so it's a good idea to be careful. */ - if (comedi_get_subdevice_runflags(s) & SRF_RUNNING) { + if (comedi_is_subdevice_running(s)) { s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; ni_event(dev, s); -- cgit v0.10.2 From ade1764ff5f03bea4bc848de5e6d3db0758ff15a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:43:40 -0700 Subject: staging: comedi: comedi_fops: don't export comedi_get_subdevice_runflags() The subdevice runflags are protected with a spin_lock. Only the comedi core should be accessing them directly. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index b67fb0d..7d85f57 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -363,7 +363,7 @@ static void comedi_set_subdevice_runflags(struct comedi_subdevice *s, spin_unlock_irqrestore(&s->spin_lock, flags); } -unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) +static unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) { unsigned long flags; unsigned runflags; @@ -373,7 +373,6 @@ unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s) spin_unlock_irqrestore(&s->spin_lock, flags); return runflags; } -EXPORT_SYMBOL(comedi_get_subdevice_runflags); bool comedi_is_subdevice_running(struct comedi_subdevice *s) { diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 791030d..5127dc2 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -367,7 +367,6 @@ bool comedi_is_subdevice_running(struct comedi_subdevice *s); int comedi_check_chanlist(struct comedi_subdevice *s, int n, unsigned int *chanlist); -unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s); /* range stuff */ -- cgit v0.10.2 From c098c21a9d32f1cd828f23e617cb55909c75e7e2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:44:02 -0700 Subject: staging: comedi: comedi_fops: introduce comedi_is_subdevice_in_error() Introduce, and use, a helper to check the subdevice runflags to see if the SRF_ERROR flag is set. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 7d85f57..eb96217 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -382,6 +382,13 @@ bool comedi_is_subdevice_running(struct comedi_subdevice *s) } EXPORT_SYMBOL_GPL(comedi_is_subdevice_running); +static bool comedi_is_subdevice_in_error(struct comedi_subdevice *s) +{ + unsigned runflags = comedi_get_subdevice_runflags(s); + + return (runflags & SRF_ERROR) ? true : false; +} + /* This function restores a subdevice to an idle state. */ @@ -1908,12 +1915,10 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, if (!comedi_is_subdevice_running(s)) { if (count == 0) { - if (comedi_get_subdevice_runflags(s) & - SRF_ERROR) { + if (comedi_is_subdevice_in_error(s)) retval = -EPIPE; - } else { + else retval = 0; - } do_become_nonbusy(dev, s); } break; @@ -2015,12 +2020,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, if (n == 0) { if (!comedi_is_subdevice_running(s)) { do_become_nonbusy(dev, s); - if (comedi_get_subdevice_runflags(s) & - SRF_ERROR) { + if (comedi_is_subdevice_in_error(s)) retval = -EPIPE; - } else { + else retval = 0; - } break; } if (file->f_flags & O_NONBLOCK) { -- cgit v0.10.2 From 9682e28c49f85d4a3c5d2cab401d03ae266f6dde Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:44:24 -0700 Subject: staging: comedi: comedi_fops: introduce comedi_is_subdevice_idle() Introduce, and use, a helper to check the subdevice runflags to see if it is not in error and not running. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index eb96217..33f5187 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -389,6 +389,13 @@ static bool comedi_is_subdevice_in_error(struct comedi_subdevice *s) return (runflags & SRF_ERROR) ? true : false; } +static bool comedi_is_subdevice_idle(struct comedi_subdevice *s) +{ + unsigned runflags = comedi_get_subdevice_runflags(s); + + return (runflags & (SRF_ERROR | SRF_RUNNING)) ? false : true; +} + /* This function restores a subdevice to an idle state. */ @@ -834,9 +841,8 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, bi.bytes_read = comedi_buf_read_alloc(async, bi.bytes_read); comedi_buf_read_free(async, bi.bytes_read); - if (!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | - SRF_RUNNING)) - && async->buf_write_count == async->buf_read_count) { + if (comedi_is_subdevice_idle(s) && + async->buf_write_count == async->buf_read_count) { do_become_nonbusy(dev, s); } } @@ -2061,7 +2067,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, buf += n; break; /* makes device work like a pipe */ } - if (!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | SRF_RUNNING)) && + if (comedi_is_subdevice_idle(s) && async->buf_read_count - async->buf_write_count == 0) { do_become_nonbusy(dev, s); } -- cgit v0.10.2 From 401d99de5c0b70f7d64a410ed01d19032698656c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:44:46 -0700 Subject: staging: comedi: comedi_fops: cleanup comedi_{read, write}_subdevice() Flip the info->device tests so than the return NULL occurs last. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 33f5187..8d407cc 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -118,9 +118,9 @@ comedi_read_subdevice(const struct comedi_file_info *info) { if (info->read_subdevice) return info->read_subdevice; - if (info->device == NULL) - return NULL; - return info->device->read_subdev; + if (info->device) + return info->device->read_subdev; + return NULL; } static struct comedi_subdevice * @@ -128,9 +128,9 @@ comedi_write_subdevice(const struct comedi_file_info *info) { if (info->write_subdevice) return info->write_subdevice; - if (info->device == NULL) - return NULL; - return info->device->write_subdev; + if (info->device) + return info->device->write_subdev; + return NULL; } static int resize_async_buffer(struct comedi_device *dev, -- cgit v0.10.2 From a52840a98bbb50a7ed881b6cc361957c58c2731d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:45:12 -0700 Subject: staging: comedi: comedi_fops: cleanup comedi_mmap() Use comedi_dev_from_minor() to simplify the return -ENODEV tests. Change the (foo == NULL) tests to simply (!foo). Use a local variable to hold a pointer to the async->buf_page_list[] when doing the remap_pfn_range(). This cleans up the ugly line breaks for the page_to_pfn(virt_to_page(...) operation. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 8d407cc..2826a29 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1766,39 +1766,38 @@ static struct vm_operations_struct comedi_vm_ops = { static int comedi_mmap(struct file *file, struct vm_area_struct *vma) { const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_async *async = NULL; + struct comedi_file_info *info = comedi_file_info_from_minor(minor); + struct comedi_device *dev = comedi_dev_from_minor(minor); + struct comedi_subdevice *s; + struct comedi_async *async; unsigned long start = vma->vm_start; unsigned long size; int n_pages; int i; int retval; - struct comedi_subdevice *s; - struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev; - if (info == NULL) - return -ENODEV; - dev = info->device; - if (dev == NULL) + if (!dev) return -ENODEV; mutex_lock(&dev->mutex); + if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); retval = -ENODEV; goto done; } + if (vma->vm_flags & VM_WRITE) s = comedi_write_subdevice(info); else s = comedi_read_subdevice(info); - - if (s == NULL) { + if (!s) { retval = -EINVAL; goto done; } + async = s->async; - if (async == NULL) { + if (!async) { retval = -EINVAL; goto done; } @@ -1821,11 +1820,11 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma) n_pages = size >> PAGE_SHIFT; for (i = 0; i < n_pages; ++i) { + struct comedi_buf_page *buf = &async->buf_page_list[i]; + if (remap_pfn_range(vma, start, - page_to_pfn(virt_to_page - (async->buf_page_list - [i].virt_addr)), PAGE_SIZE, - PAGE_SHARED)) { + page_to_pfn(virt_to_page(buf->virt_addr)), + PAGE_SIZE, PAGE_SHARED)) { retval = -EAGAIN; goto done; } -- cgit v0.10.2 From 71cf6d3ee9351d668e9374d4026bf3337540eb22 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 15:45:34 -0700 Subject: staging: comedi: comedi_fops: use kzalloc in comedi_alloc_subdevice_minor() The hardware_device member of comedi_file_info is not set in this function. Use kzalloc to make sure this pointer does not contain invalid data. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 2826a29..dda47b1 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2376,8 +2376,8 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct device *csdev; unsigned i; - info = kmalloc(sizeof(*info), GFP_KERNEL); - if (info == NULL) + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) return -ENOMEM; info->device = dev; info->read_subdevice = s; -- cgit v0.10.2 From 90a35c15c5d7d5c6254772d2752975dda185710c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 17:27:02 -0700 Subject: staging: comedi: store the 'index' for each subdevice Store the 'index' for each comedi_subdevice when they are initially allocated by comedi_alloc_subdevice(). This allows removing the pointer math in comedi_fops.c which is used to figure out the index that user space uses to access the individual subdevices. Fix the ni_mio_common driver so it also uses the 'index' instead of doing the pointer math. Also, remove a couple unused macros in the pcmda12, pcmmio, and pcmuio drivers which also do the pointer math to figure out the index. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index dda47b1..2fd577f 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -169,7 +169,7 @@ static int resize_async_buffer(struct comedi_device *dev, } DPRINTK("comedi%i subd %d buffer resized to %i bytes\n", - dev->minor, (int)(s - dev->subdevices), async->prealloc_bufsz); + dev->minor, s->index, async->prealloc_bufsz); return 0; } @@ -624,13 +624,13 @@ static int do_devinfo_ioctl(struct comedi_device *dev, s = comedi_read_subdevice(info); if (s) - devinfo.read_subdevice = s - dev->subdevices; + devinfo.read_subdevice = s->index; else devinfo.read_subdevice = -1; s = comedi_write_subdevice(info); if (s) - devinfo.write_subdevice = s - dev->subdevices; + devinfo.write_subdevice = s->index; else devinfo.write_subdevice = -1; @@ -2398,7 +2398,7 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, s->minor = i; csdev = device_create(comedi_class, dev->class_dev, MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i_subd%i", - dev->minor, (int)(s - dev->subdevices)); + dev->minor, s->index); if (!IS_ERR(csdev)) s->class_dev = csdev; dev_set_drvdata(csdev, info); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 5127dc2..2599964 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -77,6 +77,7 @@ struct comedi_subdevice { struct comedi_device *device; + int index; int type; int n_chan; int subdev_flags; diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index c0adc16..b67a0c9 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -70,6 +70,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) for (i = 0; i < num_subdevices; ++i) { s = &dev->subdevices[i]; s->device = dev; + s->index = i; s->async_dma_dir = DMA_NONE; spin_lock_init(&s->spin_lock); s->minor = -1; diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 81d7350..b740359 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -986,7 +986,7 @@ static void ni_event(struct comedi_device *dev, struct comedi_subdevice *s) if (s-> async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW | COMEDI_CB_EOA)) { - switch (s - dev->subdevices) { + switch (s->index) { case NI_AI_SUBDEV: ni_ai_reset(dev, s); break; diff --git a/drivers/staging/comedi/drivers/pcmda12.c b/drivers/staging/comedi/drivers/pcmda12.c index 0882daf..48b049b 100644 --- a/drivers/staging/comedi/drivers/pcmda12.c +++ b/drivers/staging/comedi/drivers/pcmda12.c @@ -55,7 +55,6 @@ Configuration Options: #include /* for PCI devices */ -#define SDEV_NO ((int)(s - dev->subdevices)) #define CHANS 8 #define IOSIZE 16 #define LSB(x) ((unsigned char)((x) & 0xff)) diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c index 045f442..d6d3d95 100644 --- a/drivers/staging/comedi/drivers/pcmmio.c +++ b/drivers/staging/comedi/drivers/pcmmio.c @@ -94,7 +94,6 @@ Configuration Options: #define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) #define MAX_DIO_CHANS (PORTS_PER_ASIC*1*CHANS_PER_PORT) #define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) -#define SDEV_NO ((int)(s - dev->subdevices)) #define CALC_N_DIO_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) /* IO Memory sizes */ #define ASIC_IOSIZE (0x0B) diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index c61cc64..b74431f 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c @@ -92,7 +92,6 @@ Configuration Options: #define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) #define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT) #define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) -#define SDEV_NO ((int)(s - dev->subdevices)) #define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) /* IO Memory sizes */ #define ASIC_IOSIZE (0x10) -- cgit v0.10.2 From 21f181f16cea4a4cbaea25409ddb044a4ad5cd34 Mon Sep 17 00:00:00 2001 From: Lijo Antony Date: Tue, 1 Jan 2013 22:41:06 +0400 Subject: Staging: comedi: comedidev.h: fixed a camel case Fixed a camel case issue. Signed-off-by: Lijo Antony Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 2599964..34a85d3 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -464,7 +464,7 @@ static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) static inline void *comedi_aux_data(int options[], int n) { unsigned long address; - unsigned long addressLow; + unsigned long address_low; int bit_shift; if (sizeof(int) >= sizeof(void *)) address = options[COMEDI_DEVCONF_AUX_DATA_LO]; @@ -472,9 +472,9 @@ static inline void *comedi_aux_data(int options[], int n) address = options[COMEDI_DEVCONF_AUX_DATA_HI]; bit_shift = sizeof(int) * 8; address <<= bit_shift; - addressLow = options[COMEDI_DEVCONF_AUX_DATA_LO]; - addressLow &= (1UL << bit_shift) - 1; - address |= addressLow; + address_low = options[COMEDI_DEVCONF_AUX_DATA_LO]; + address_low &= (1UL << bit_shift) - 1; + address |= address_low; } if (n >= 1) address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; -- cgit v0.10.2 From 0653bed67922d757a750adcb16edf8f56e4abcde Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 4 Jan 2013 11:33:21 +0000 Subject: staging: comedi: comedi_test: fix race when cancelling command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Éric Piel reported a kernel oops in the "comedi_test" module. It was a NULL pointer dereference within `waveform_ai_interrupt()` (actually a timer function) that sometimes occurred when a running asynchronous command is cancelled (either by the `COMEDI_CANCEL` ioctl or by closing the device file). This seems to be a race between the caller of `waveform_ai_cancel()` which on return from that function goes and tears down the running command, and the timer function which uses the command. In particular, `async->cmd.chanlist` gets freed (and the pointer set to NULL) by `do_become_nonbusy()` in "comedi_fops.c" but a previously scheduled `waveform_ai_interrupt()` timer function will dereference that pointer regardless, leading to the oops. Fix it by replacing the `del_timer()` call in `waveform_ai_cancel()` with `del_timer_sync()`. Signed-off-by: Ian Abbott Reported-by: Éric Piel Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index fb3d093..01de996 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -345,7 +345,7 @@ static int waveform_ai_cancel(struct comedi_device *dev, struct waveform_private *devpriv = dev->private; devpriv->timer_running = 0; - del_timer(&devpriv->timer); + del_timer_sync(&devpriv->timer); return 0; } -- cgit v0.10.2 From 594dc67c239afd2f33b40c826bba887b38adf270 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 4 Jan 2013 11:33:22 +0000 Subject: staging: comedi: comedi_test: remove unnecessary del_timer() call In the "comedi_test" module, the timer function `waveform_ai_interrupt()` doesn't need to remove the timer from the timer queue as the caller has already removed it from the queue. Remove the call to `del_timer()` in this function. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index 01de996..c401f67 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -218,8 +218,6 @@ static void waveform_ai_interrupt(unsigned long arg) if ((async->events & COMEDI_CB_EOA) == 0 && devpriv->timer_running) mod_timer(&devpriv->timer, jiffies + 1); - else - del_timer(&devpriv->timer); comedi_event(dev, dev->read_subdev); } -- cgit v0.10.2 From ea4f72b27985e21c846ffbff1a27871db4f8708e Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 4 Jan 2013 11:33:23 +0000 Subject: staging: comedi: comedi_test: change end-of-acquisition test In the "comedi_test" module's acquisition timer function `waveform_ai_interrupt()`, move the code for ending the acquisition outside the scan loop. Determine if the number of scans to be done is sufficient to end the acquisition before entering the scan loop. On leaving the scan loop, set the `COMEDI_CB_EOA` event if the acquisition is ending. Only reschedule the timer if the acquisition is not ending. Remove the somewhat useless `timer_running` flag from the private data. This was intended to stop the timer function adding the timer back on the timer queue periodically, but the flag setting wasn't synchronized with the timer and we already use `del_timer_sync()` to synchronize removal from the queue. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index c401f67..48255b3 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -70,7 +70,6 @@ struct waveform_private { unsigned long ai_count; /* number of conversions remaining */ unsigned int scan_period; /* scan period in usec */ unsigned int convert_period; /* conversion period in usec */ - unsigned timer_running:1; unsigned int ao_loopbacks[N_CHANS]; }; @@ -176,6 +175,7 @@ static void waveform_ai_interrupt(unsigned long arg) unsigned long elapsed_time; unsigned int num_scans; struct timeval now; + bool stopping = false; do_gettimeofday(&now); @@ -189,6 +189,15 @@ static void waveform_ai_interrupt(unsigned long arg) (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period; async->events = 0; + if (cmd->stop_src == TRIG_COUNT) { + unsigned int remaining = cmd->stop_arg - devpriv->ai_count; + if (num_scans >= remaining) { + /* about to finish */ + num_scans = remaining; + stopping = true; + } + } + for (i = 0; i < num_scans; i++) { for (j = 0; j < cmd->chanlist_len; j++) { cfc_write_to_buffer(dev->read_subdev, @@ -205,18 +214,15 @@ static void waveform_ai_interrupt(unsigned long arg) devpriv-> convert_period)); } - devpriv->ai_count++; - if (cmd->stop_src == TRIG_COUNT - && devpriv->ai_count >= cmd->stop_arg) { - async->events |= COMEDI_CB_EOA; - break; - } } + devpriv->ai_count += i; devpriv->usec_current += elapsed_time; devpriv->usec_current %= devpriv->usec_period; - if ((async->events & COMEDI_CB_EOA) == 0 && devpriv->timer_running) + if (stopping) + async->events |= COMEDI_CB_EOA; + else mod_timer(&devpriv->timer, jiffies + 1); comedi_event(dev, dev->read_subdev); @@ -315,7 +321,6 @@ static int waveform_ai_cmd(struct comedi_device *dev, return -1; } - devpriv->timer_running = 1; devpriv->ai_count = 0; devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro; @@ -342,7 +347,6 @@ static int waveform_ai_cancel(struct comedi_device *dev, { struct waveform_private *devpriv = dev->private; - devpriv->timer_running = 0; del_timer_sync(&devpriv->timer); return 0; } -- cgit v0.10.2 From 8bd48c9ef1f1af96dc699e67a8dc985046e6f22b Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 4 Jan 2013 11:33:24 +0000 Subject: staging: comedi: comedi_test: make samples unsigned Represent the fake samples as unsigned shorts instead of signed shorts, as this is the usual Comedi convention. There is no change to the actual binary representation, although the `cfc_write_to_buffer()` call currently expects a signed short for some bizarre reason. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index 48255b3..ce13fbc 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -85,8 +85,9 @@ static const struct comedi_lrange waveform_ai_ranges = { } }; -static short fake_sawtooth(struct comedi_device *dev, unsigned int range_index, - unsigned long current_time) +static unsigned short fake_sawtooth(struct comedi_device *dev, + unsigned int range_index, + unsigned long current_time) { struct waveform_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; @@ -109,9 +110,9 @@ static short fake_sawtooth(struct comedi_device *dev, unsigned int range_index, return offset + value; } -static short fake_squarewave(struct comedi_device *dev, - unsigned int range_index, - unsigned long current_time) +static unsigned short fake_squarewave(struct comedi_device *dev, + unsigned int range_index, + unsigned long current_time) { struct waveform_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; @@ -131,15 +132,17 @@ static short fake_squarewave(struct comedi_device *dev, return offset + value; } -static short fake_flatline(struct comedi_device *dev, unsigned int range_index, - unsigned long current_time) +static unsigned short fake_flatline(struct comedi_device *dev, + unsigned int range_index, + unsigned long current_time) { return dev->read_subdev->maxdata / 2; } /* generates a different waveform depending on what channel is read */ -static short fake_waveform(struct comedi_device *dev, unsigned int channel, - unsigned int range, unsigned long current_time) +static unsigned short fake_waveform(struct comedi_device *dev, + unsigned int channel, unsigned int range, + unsigned long current_time) { enum { SAWTOOTH_CHAN, -- cgit v0.10.2 From 0642c94bcb2f3f61a3f68e98684a2b2f13f0411d Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 4 Jan 2013 11:33:25 +0000 Subject: staging: comedi: comedi_test: tidy up waveform_ai_interrupt() Use a local variable to reduce the indentation in `waveform_ai_interrupt()`. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index ce13fbc..a8e40ca 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -203,19 +203,13 @@ static void waveform_ai_interrupt(unsigned long arg) for (i = 0; i < num_scans; i++) { for (j = 0; j < cmd->chanlist_len; j++) { - cfc_write_to_buffer(dev->read_subdev, - fake_waveform(dev, - CR_CHAN(cmd-> - chanlist[j]), - CR_RANGE(cmd-> - chanlist[j]), - devpriv-> - usec_current + - i * - devpriv->scan_period + - j * - devpriv-> - convert_period)); + unsigned short sample; + sample = fake_waveform(dev, CR_CHAN(cmd->chanlist[j]), + CR_RANGE(cmd->chanlist[j]), + devpriv->usec_current + + i * devpriv->scan_period + + j * devpriv->convert_period); + cfc_write_to_buffer(dev->read_subdev, sample); } } -- cgit v0.10.2 From ae6eee39aed3244f07bc9ddefbc4f947e572aceb Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 4 Jan 2013 11:33:26 +0000 Subject: staging: comedi: comedi_test: whitespace fixes Fix lines over 80 characters and line up nearby comments. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index a8e40ca..270fea5 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -62,12 +62,12 @@ zero volts). /* Data unique to this driver */ struct waveform_private { struct timer_list timer; - struct timeval last; /* time at which last timer interrupt occurred */ + struct timeval last; /* time last timer interrupt occurred */ unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */ unsigned long usec_period; /* waveform period in microseconds */ - unsigned long usec_current; /* current time (modulo waveform period) */ - unsigned long usec_remainder; /* usec since last scan; */ - unsigned long ai_count; /* number of conversions remaining */ + unsigned long usec_current; /* current time (mod waveform period) */ + unsigned long usec_remainder; /* usec since last scan */ + unsigned long ai_count; /* number of conversions remaining */ unsigned int scan_period; /* scan period in usec */ unsigned int convert_period; /* conversion period in usec */ unsigned int ao_loopbacks[N_CHANS]; -- cgit v0.10.2 From 5eaf711b53cb9977f7f54f6889c9a63d045c0ed2 Mon Sep 17 00:00:00 2001 From: Lijo Antony Date: Sat, 5 Jan 2013 18:12:54 +0400 Subject: Staging: comedi: addi_common.c: checkpatch.pl fixes checkpatch.pl style fixes: - Broken license text into 80 char lines - fixed two space before tab issues - Removed unnecessary braces from if-else Signed-off-by: Lijo Antony Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c index 90cc432..1051fa5 100644 --- a/drivers/staging/comedi/drivers/addi-data/addi_common.c +++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c @@ -11,13 +11,21 @@ Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. http://www.addi-data.com info@addi-data.com -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. -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. +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. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -You should also find the complete GPL in the COPYING file accompanying this source code. +You should also find the complete GPL in the COPYING file accompanying this +source code. @endverbatim */ @@ -29,10 +37,10 @@ You should also find the complete GPL in the COPYING file accompanying this sour | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | +-----------------------------------------------------------------------+ - | Project : ADDI DATA | Compiler : GCC | + | Project : ADDI DATA | Compiler : GCC | | Modulname : addi_common.c | Version : 2.96 | +-------------------------------+---------------------------------------+ - | Author : | Date : | + | Author : | Date : | +-----------------------------------------------------------------------+ | Description : ADDI COMMON Main Module | +-----------------------------------------------------------------------+ @@ -167,11 +175,11 @@ static int addi_auto_attach(struct comedi_device *dev, if (this_board->i_PCIEeprom) { if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { /* Set 3 wait stait */ - if (!(strcmp(dev->board_name, "apci035"))) { + if (!(strcmp(dev->board_name, "apci035"))) outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); - } else { + else outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); - } + /* Enable the interrupt for the controller */ dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); -- cgit v0.10.2 From fd958f7eb4d0959f65377aaab4a63ba33cc53f06 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Dec 2012 17:49:24 -0700 Subject: staging: comedi: Makefile: conditionally compile multi-file core module Instead of using the #ifdef'ery in the comedi_compat32.c and proc.c files to include/exclude them from the comedi core, modify the Makefile to include those files automatically when enabled in the .config. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index 8dbd306..f895c0c 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,11 +1,8 @@ -obj-$(CONFIG_COMEDI) += comedi.o +comedi-y := comedi_fops.o range.o drivers.o +comedi-$(CONFIG_PROC_FS) += proc.o +comedi-$(CONFIG_COMPAT) += comedi_compat32.o -obj-$(CONFIG_COMEDI) += kcomedilib/ -obj-$(CONFIG_COMEDI) += drivers/ +obj-$(CONFIG_COMEDI) += comedi.o -comedi-y := \ - comedi_fops.o \ - proc.o \ - range.o \ - drivers.o \ - comedi_compat32.o \ +obj-$(CONFIG_COMEDI) += kcomedilib/ +obj-$(CONFIG_COMEDI) += drivers/ diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c index 4b7cbfa..ad208cd 100644 --- a/drivers/staging/comedi/comedi_compat32.c +++ b/drivers/staging/comedi/comedi_compat32.c @@ -30,8 +30,6 @@ #include "comedi.h" #include "comedi_compat32.h" -#ifdef CONFIG_COMPAT - #define COMEDI32_CHANINFO _IOR(CIO, 3, struct comedi32_chaninfo_struct) #define COMEDI32_RANGEINFO _IOR(CIO, 8, struct comedi32_rangeinfo_struct) /* N.B. COMEDI32_CMD and COMEDI_CMD ought to use _IOWR, not _IOR. @@ -460,5 +458,3 @@ long comedi_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return raw_ioctl(file, cmd, arg); } - -#endif /* CONFIG_COMPAT */ diff --git a/drivers/staging/comedi/proc.c b/drivers/staging/comedi/proc.c index 732134f..362c214 100644 --- a/drivers/staging/comedi/proc.c +++ b/drivers/staging/comedi/proc.c @@ -33,7 +33,6 @@ #include #include -#ifdef CONFIG_PROC_FS static int comedi_read(char *buf, char **start, off_t offset, int len, int *eof, void *data) { @@ -92,4 +91,3 @@ void comedi_proc_cleanup(void) { remove_proc_entry("comedi", NULL); } -#endif -- cgit v0.10.2 From ac6a98d452baa4f9acae7c2238f6626bae8283ff Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Wed, 12 Dec 2012 01:24:50 +0100 Subject: staging: omap-thermal: fix error check in omap_thermal_expose_sensor() and in omap_thermal_register_cpu_cooling(). The omap_bandgap_get_sensor_data() function returns ERR_PTR(), so we need to use IS_ERR() rather than a NULL check. Signed-off-by: Cyril Roelandt Acked-by: Eduardo Valentin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/omap-thermal/omap-thermal-common.c b/drivers/staging/omap-thermal/omap-thermal-common.c index 61f1070..79a55aa 100644 --- a/drivers/staging/omap-thermal/omap-thermal-common.c +++ b/drivers/staging/omap-thermal/omap-thermal-common.c @@ -260,7 +260,7 @@ int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id, data = omap_bandgap_get_sensor_data(bg_ptr, id); - if (!data) + if (IS_ERR(data)) data = omap_thermal_build_data(bg_ptr, id); if (!data) @@ -309,7 +309,7 @@ int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id) struct omap_thermal_data *data; data = omap_bandgap_get_sensor_data(bg_ptr, id); - if (!data) + if (IS_ERR(data)) data = omap_thermal_build_data(bg_ptr, id); if (!data) -- cgit v0.10.2 From 2df29e7bf2e99bfb085370753291083ae745b057 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 11 Dec 2012 01:20:48 +0100 Subject: staging: rtl8712: avoid a useless call to memset(). In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset(). Signed-off-by: Cyril Roelandt Acked-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c index 3a64790..72c51b3 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c @@ -1131,11 +1131,11 @@ static int r8711_wx_get_wap(struct net_device *dev, struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; wrqu->ap_addr.sa_family = ARPHRD_ETHER; - memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); - if (check_fwstate(pmlmepriv, _FW_LINKED | - WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE)) { + if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE | + WIFI_AP_STATE)) memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN); - } + else + memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); return 0; } -- cgit v0.10.2 From 2cc1dd939c381db7a6f5d025cf4688eb3de9746b Mon Sep 17 00:00:00 2001 From: Masanari Iida Date: Mon, 7 Jan 2013 23:38:35 +0900 Subject: staging: vme: Fix URL in Kconfig The URL vmelinux.org is not accessible. Change it to www.vmelinux.org. Signed-off-by: Masanari Iida Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vme/devices/Kconfig b/drivers/staging/vme/devices/Kconfig index d0cab17..8e8bbb1 100644 --- a/drivers/staging/vme/devices/Kconfig +++ b/drivers/staging/vme/devices/Kconfig @@ -6,7 +6,7 @@ config VME_USER help If you say Y here you want to be able to access a limited number of VME windows in a manner at least semi-compatible with the interface - provided with the original driver at http://vmelinux.org/. + provided with the original driver at . config VME_PIO2 tristate "GE PIO2 VME" -- cgit v0.10.2 From dbc320f7490933eb6a073d82aceac75d5e7ce82b Mon Sep 17 00:00:00 2001 From: Masanari Iida Date: Mon, 7 Jan 2013 23:28:10 +0900 Subject: staging: Add angle bracket before and after the URL Add missing angle bracket before and after the URL. Signed-off-by: Masanari Iida Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/speakup/Kconfig b/drivers/staging/speakup/Kconfig index d288cf0..b416ace 100644 --- a/drivers/staging/speakup/Kconfig +++ b/drivers/staging/speakup/Kconfig @@ -8,7 +8,7 @@ config SPEAKUP video console for blind people. If built in to the kernel, it can speak everything on the text console from boot up to shutdown. For more information on Speakup, - point your browser at http://www.linux-speakup.org/. + point your browser at . There is also a mailing list at the above url that you can subscribe to. diff --git a/drivers/staging/usbip/Kconfig b/drivers/staging/usbip/Kconfig index 199b1d4..8860009 100644 --- a/drivers/staging/usbip/Kconfig +++ b/drivers/staging/usbip/Kconfig @@ -8,7 +8,7 @@ config USBIP_CORE USB/IP core that is required by both drivers. For more details, and to get the userspace utility - programs, please see http://usbip.sourceforge.net/. + programs, please see . To compile this as a module, choose M here: the module will be called usbip-core. diff --git a/drivers/staging/winbond/Kconfig b/drivers/staging/winbond/Kconfig index a29f608..db5b053 100644 --- a/drivers/staging/winbond/Kconfig +++ b/drivers/staging/winbond/Kconfig @@ -8,4 +8,4 @@ config W35UND Hardware is present in some Kohjinsha subnotebooks, and in some stand-alone USB modules. Chipset name seems to be w89c35d. - Check http://code.google.com/p/winbondport/ for new version. + Check for new version. diff --git a/drivers/staging/zram/Kconfig b/drivers/staging/zram/Kconfig index be5abe8..983314c 100644 --- a/drivers/staging/zram/Kconfig +++ b/drivers/staging/zram/Kconfig @@ -14,7 +14,7 @@ config ZRAM disks and maybe many more. See zram.txt for more information. - Project home: http://compcache.googlecode.com/ + Project home: config ZRAM_DEBUG bool "Compressed RAM block device debug support" -- cgit v0.10.2 From 94b84e4510f5b625d74e410103d49dfce826a41d Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 7 Jan 2013 23:09:53 +0100 Subject: staging/csr: Fix dereference before check Smatch complains about some pointers that are dereferenced before being checked: drivers/staging/csr/sme_sys.c:285 CsrWifiRouterCtrlHipReqHandler() warn: variable dereferenced before check 'priv' (see line 283) drivers/staging/csr/sme_sys.c:1503 CsrWifiRouterMaPacketReqHandler() warn: variable dereferenced before check 'priv' (see line 1501) drivers/staging/csr/sme_sys.c:2062 CsrWifiRouterCtrlPeerDelReqHandler() warn: variable dereferenced before check 'priv' (see line 2059) drivers/staging/csr/sme_sys.c:2477 CsrWifiRouterCtrlPeerAddReqHandler() warn: variable dereferenced before check 'priv' (see line 2474) drivers/staging/csr/sme_sys.c:3045 CsrWifiRouterCtrlWapiRxPktReqHandler() warn: variable dereferenced before check 'priv' (see line 3039) We put the check before the dereferencing and prevent an oops and fix the warning. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/csr/sme_sys.c b/drivers/staging/csr/sme_sys.c index 2b06819..b1151a2 100644 --- a/drivers/staging/csr/sme_sys.c +++ b/drivers/staging/csr/sme_sys.c @@ -280,7 +280,7 @@ void CsrWifiRouterCtrlHipReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) CSR_SIGNAL *signal; u16 interfaceTag = 0; CSR_MA_PACKET_REQUEST *req; - netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; + netInterface_priv_t *interfacePriv; if (priv == NULL) { return; @@ -294,6 +294,8 @@ void CsrWifiRouterCtrlHipReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) return; } + interfacePriv = priv->interfacePriv[interfaceTag]; + /* Initialize bulkdata to avoid os_net_buf is garbage */ memset(&bulkdata, 0, sizeof(bulk_data_param_t)); @@ -1498,7 +1500,7 @@ void CsrWifiRouterMaPacketReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) u8 *daddr, *saddr; u16 interfaceTag = mareq->interfaceTag & 0x00ff; int queue; - netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; + netInterface_priv_t *interfacePriv; if (!mareq->frame || !priv || !priv->smepriv) { @@ -1510,6 +1512,8 @@ void CsrWifiRouterMaPacketReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) unifi_error(priv, "CsrWifiRouterMaPacketReqHandler: interfaceID >= CSR_WIFI_NUM_INTERFACES.\n"); return; } + + interfacePriv = priv->interfacePriv[interfaceTag]; /* get a pointer to dest & source Mac address */ daddr = mareq->frame; saddr = (mareq->frame + ETH_ALEN); @@ -2056,9 +2060,9 @@ void CsrWifiRouterCtrlPeerDelReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) CsrWifiRouterCtrlPeerDelReq* req = (CsrWifiRouterCtrlPeerDelReq*)msg; CsrResult status = CSR_RESULT_SUCCESS; unifi_priv_t *priv = (unifi_priv_t*)drvpriv; - netInterface_priv_t *interfacePriv = priv->interfacePriv[req->interfaceTag]; + netInterface_priv_t *interfacePriv; - unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerDelReqHandler \n"); + unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerDelReqHandler\n"); if (priv == NULL) { unifi_error(priv, "CsrWifiRouterCtrlPeerDelReqHandler: invalid smepriv\n"); @@ -2071,6 +2075,8 @@ void CsrWifiRouterCtrlPeerDelReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) return; } + interfacePriv = priv->interfacePriv[req->interfaceTag]; + switch(interfacePriv->interfaceMode) { case CSR_WIFI_ROUTER_CTRL_MODE_AP: @@ -2471,7 +2477,7 @@ void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) CsrResult status = CSR_RESULT_SUCCESS; unifi_priv_t *priv = (unifi_priv_t*)drvpriv; u32 handle = 0; - netInterface_priv_t *interfacePriv = priv->interfacePriv[req->interfaceTag]; + netInterface_priv_t *interfacePriv; unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerAddReqHandler \n"); if (priv == NULL) @@ -2486,6 +2492,8 @@ void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) return; } + interfacePriv = priv->interfacePriv[req->interfaceTag]; + switch(interfacePriv->interfaceMode) { case CSR_WIFI_ROUTER_CTRL_MODE_AP: @@ -3036,21 +3044,24 @@ void CsrWifiRouterCtrlWapiRxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) ul_client_t *client; CSR_SIGNAL signal; CSR_MA_PACKET_INDICATION *pkt_ind; - netInterface_priv_t *interfacePriv = priv->interfacePriv[req->interfaceTag]; + netInterface_priv_t *interfacePriv; + + if (priv == NULL) { + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid priv\n", __func__); + return; + } + + if (priv->smepriv == NULL) { + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid sme priv\n", __func__); + return; + } + + interfacePriv = priv->interfacePriv[req->interfaceTag]; if (CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) { unifi_trace(priv, UDBG6, ">>%s\n", __FUNCTION__); - if (priv == NULL) { - unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid priv\n",__FUNCTION__); - return; - } - - if (priv->smepriv == NULL) { - unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid sme priv\n",__FUNCTION__); - return; - } if (req->dataLength == 0 || req->data == NULL) { unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: invalid request\n",__FUNCTION__); -- cgit v0.10.2 From 0f5afdd2389d983d38030ff95d2a07373a5550fc Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Sat, 22 Dec 2012 09:00:44 +1000 Subject: staging: android: Avoid using camelcase in binder.h This changes the following: 1: BinderDriverReturnProtocol -> binder_driver_return_protocol 2: BinderDriverCommandProtocol -> binder_driver_return_protocol These enums are not currently used, but still generate noise in checkpatch. Well, did. They don't now :) Signed-off-by: Cruz Julian Bishop Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/android/binder.h b/drivers/staging/android/binder.h index 2f7d195..76ead8d 100644 --- a/drivers/staging/android/binder.h +++ b/drivers/staging/android/binder.h @@ -163,7 +163,7 @@ struct binder_pri_ptr_cookie { void *cookie; }; -enum BinderDriverReturnProtocol { +enum binder_driver_return_protocol { BR_ERROR = _IOR('r', 0, int), /* * int: error code @@ -251,7 +251,7 @@ enum BinderDriverReturnProtocol { */ }; -enum BinderDriverCommandProtocol { +enum binder_driver_command_protocol { BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), BC_REPLY = _IOW('c', 1, struct binder_transaction_data), /* -- cgit v0.10.2 From 167bccbd80b3625af5e7ec04ad4810321c1f300a Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Sat, 22 Dec 2012 09:00:45 +1000 Subject: staging: android: Fix two checkpatch issues in binder.c This fixes two instances of "static const char * array should probably be static const char * const" I have seen other commits doing this in other files, so I am assuming it should be done here as well. Please tell me if this is wrong :) Signed-off-by: Cruz Julian Bishop Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c index 2d12e8a..538ebe2 100644 --- a/drivers/staging/android/binder.c +++ b/drivers/staging/android/binder.c @@ -3227,7 +3227,7 @@ static void print_binder_proc(struct seq_file *m, m->count = start_pos; } -static const char *binder_return_strings[] = { +static const char * const binder_return_strings[] = { "BR_ERROR", "BR_OK", "BR_TRANSACTION", @@ -3248,7 +3248,7 @@ static const char *binder_return_strings[] = { "BR_FAILED_REPLY" }; -static const char *binder_command_strings[] = { +static const char * const binder_command_strings[] = { "BC_TRANSACTION", "BC_REPLY", "BC_ACQUIRE_RESULT", @@ -3268,7 +3268,7 @@ static const char *binder_command_strings[] = { "BC_DEAD_BINDER_DONE" }; -static const char *binder_objstat_strings[] = { +static const char * const binder_objstat_strings[] = { "proc", "thread", "node", -- cgit v0.10.2 From d7f9729f6e06c9613a88a18c4e1fbbdf2f6146fd Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Sat, 22 Dec 2012 09:00:46 +1000 Subject: staging: android: Add some Kconfig help entries This commit adds Kconfig entries for the following: 1: ANDROID_BINDER_IPC 2: ASHMEM (additional text) 3: ANDROID_LOGGER It also changes "Register" to "Registers" in ANDROID_LOW_MEMORY_KILLER Finally, all "help" instances are changed to "---help---", as recommended by kconfig-language.txt in order to visually aid developers. Signed-off-by: Cruz Julian Bishop Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig index 0ce50d1..465a28c 100644 --- a/drivers/staging/android/Kconfig +++ b/drivers/staging/android/Kconfig @@ -11,19 +11,42 @@ if ANDROID config ANDROID_BINDER_IPC bool "Android Binder IPC Driver" default n + ---help--- + Binder is used in Android for both communication between processes, + and remote method invocation. + + This means one Android process can call a method/routine in another + Android process, using Binder to identify, invoke and pass arguments + between said processes. config ASHMEM bool "Enable the Anonymous Shared Memory Subsystem" default n depends on SHMEM || TINY_SHMEM - help + ---help--- The ashmem subsystem is a new shared memory allocator, similar to POSIX SHM but with different behavior and sporting a simpler file-based API. + It is, in theory, a good memory allocator for low-memory devices, + because it can discard shared memory units when under memory pressure. + config ANDROID_LOGGER tristate "Android log driver" default n + ---help--- + This adds support for system-wide logging using four log buffers. + + These are: + + 1: main + 2: events + 3: radio + 4: system + + Log reading and writing is performed via normal Linux reads and + optimized writes. This optimization avoids logging having too + much overhead in the system. config ANDROID_TIMED_OUTPUT bool "Timed output class driver" @@ -38,13 +61,13 @@ config ANDROID_LOW_MEMORY_KILLER bool "Android Low Memory Killer" default N ---help--- - Register processes to be killed when memory is low + Registers processes to be killed when memory is low config ANDROID_INTF_ALARM_DEV bool "Android alarm driver" depends on RTC_CLASS default n - help + ---help--- Provides non-wakeup and rtc backed wakeup alarms based on rtc or elapsed realtime, and a non-wakeup alarm on the monotonic clock. Also exports the alarm interface to user-space. -- cgit v0.10.2 From 0fb3321321254b9239108285db65046e127f6627 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Sun, 2 Dec 2012 03:40:21 +0100 Subject: rtl8712: remove useless calls to memset(). These calls are followed by calls to memcpy() on the same memory area, so they can be safely removed. Signed-off-by: Cyril Roelandt Acked-by: Larry Finger Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/mlme_linux.c b/drivers/staging/rtl8712/mlme_linux.c index 7279854..f569a70 100644 --- a/drivers/staging/rtl8712/mlme_linux.c +++ b/drivers/staging/rtl8712/mlme_linux.c @@ -106,8 +106,6 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter) * disconnect with AP for 60 seconds. */ - memset(&backupPMKIDList[0], 0x00, sizeof( - struct RT_PMKID_LIST) * NUM_PMKID_CACHE); memcpy(&backupPMKIDList[0], &adapter->securitypriv. PMKIDList[0], sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE); diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c index 31f31dbf..f16307f 100644 --- a/drivers/staging/rtl8712/rtl871x_cmd.c +++ b/drivers/staging/rtl8712/rtl871x_cmd.c @@ -525,7 +525,6 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork) kfree(pcmd); return _FAIL; } - memset(psecnetwork, 0, t_len); memcpy(psecnetwork, &pnetwork->network, t_len); auth = &psecuritypriv->authenticator_ie[0]; psecuritypriv->authenticator_ie[0] = (unsigned char) diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c index d3ab24e..53a7c8c 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c @@ -97,8 +97,6 @@ static u8 do_join(struct _adapter *padapter) pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE; pibss = padapter->registrypriv.dev_network. MacAddress; - memset(&pdev_network->Ssid, 0, - sizeof(struct ndis_802_11_ssid)); memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c index c51ad9e..e52f04d 100644 --- a/drivers/staging/rtl8712/rtl871x_mlme.c +++ b/drivers/staging/rtl8712/rtl871x_mlme.c @@ -604,9 +604,6 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf) adapter->registrypriv. dev_network.MacAddress; pmlmepriv->fw_state ^= _FW_UNDER_SURVEY; - memset(&pdev_network->Ssid, 0, - sizeof(struct - ndis_802_11_ssid)); memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct @@ -1006,8 +1003,6 @@ void r8712_stadel_event_callback(struct _adapter *adapter, u8 *pbuf) memcpy(pdev_network, &tgt_network->network, r8712_get_ndis_wlan_bssid_ex_sz(&tgt_network-> network)); - memset(&pdev_network->Ssid, 0, - sizeof(struct ndis_802_11_ssid)); memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); -- cgit v0.10.2 From f00c493b519d42fb2ba26d1bc697974dc58b0a2a Mon Sep 17 00:00:00 2001 From: Patrik Karlin Date: Wed, 9 Jan 2013 09:39:44 +0100 Subject: staging: rtl8192u: fixed some coding style issues in r8192U_core.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes some coding style issues. in r8192U_core.c No logic is changed. Signed-off-by: Patrik KÃ¥rlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 01f82d3..c54f0a7 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -189,53 +189,47 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv) struct ieee80211_device* ieee = priv->ieee80211; switch (channel_plan) { - case COUNTRY_CODE_FCC: - case COUNTRY_CODE_IC: - case COUNTRY_CODE_ETSI: - case COUNTRY_CODE_SPAIN: - case COUNTRY_CODE_FRANCE: - case COUNTRY_CODE_MKK: - case COUNTRY_CODE_MKK1: - case COUNTRY_CODE_ISRAEL: - case COUNTRY_CODE_TELEC: - case COUNTRY_CODE_MIC: - { - Dot11d_Init(ieee); - ieee->bGlobalDomain = false; - //actually 8225 & 8256 rf chips only support B,G,24N mode - if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) - { - min_chan = 1; - max_chan = 14; - } - else - { - RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__); - } - if (ChannelPlan[channel_plan].Len != 0){ - // Clear old channel map - memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); - // Set new channel map - for (i=0;i max_chan) + case COUNTRY_CODE_FCC: + case COUNTRY_CODE_IC: + case COUNTRY_CODE_ETSI: + case COUNTRY_CODE_SPAIN: + case COUNTRY_CODE_FRANCE: + case COUNTRY_CODE_MKK: + case COUNTRY_CODE_MKK1: + case COUNTRY_CODE_ISRAEL: + case COUNTRY_CODE_TELEC: + case COUNTRY_CODE_MIC: + Dot11d_Init(ieee); + ieee->bGlobalDomain = false; + //actually 8225 & 8256 rf chips only support B,G,24N mode + if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) { + min_chan = 1; + max_chan = 14; + } + else { + RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__); + } + if (ChannelPlan[channel_plan].Len != 0) { + // Clear old channel map + memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); + // Set new channel map + for (i=0;i max_chan) break; - GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1; - } + GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1; } - break; } - case COUNTRY_CODE_GLOBAL_DOMAIN: - { - GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings. - Dot11d_Reset(ieee); - ieee->bGlobalDomain = true; - break; - } - default: - break; + break; + + case COUNTRY_CODE_GLOBAL_DOMAIN: + GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings. + Dot11d_Reset(ieee); + ieee->bGlobalDomain = true; + break; + + default: + break; } - return; } -- cgit v0.10.2 From 29b48ae391c9bff7e8c0c2286940d9278cc522ec Mon Sep 17 00:00:00 2001 From: Patrik Karlin Date: Wed, 9 Jan 2013 09:40:23 +0100 Subject: staging: rtl8192u: removed some non used else's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch removes some else blocks that has no function in the code Signed-off-by: Patrik KÃ¥rlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index c54f0a7..beafab1 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -2175,7 +2175,7 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff* skb) dev->trans_start = jiffies; atomic_inc(&priv->tx_pending[tcb_desc->queue_index]); return 0; - }else{ + } else { RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status); return -1; @@ -4571,11 +4571,8 @@ void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee802 { // if previous packet is not aggregated packet bcheck = true; - }else - { } - if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) { slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX; @@ -5675,10 +5672,6 @@ void rtl8192_rx_cmd(struct sk_buff *skb) dev_kfree_skb_any(skb); } - else - ; - - } void rtl8192_irq_rx_tasklet(struct r8192_priv *priv) -- cgit v0.10.2 From 666b3bf2f1f731a94e1dbb3d9d28a3e4207b84d1 Mon Sep 17 00:00:00 2001 From: Patrik Karlin Date: Wed, 9 Jan 2013 09:40:56 +0100 Subject: staging: rtl8192u: fixed coding style issues in r8192U_core.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes some coding style issuses in r8192U_core.c No logic is changed Signed-off-by: Patrik KÃ¥rlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index beafab1..f7de2f6 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -509,55 +509,50 @@ static int proc_get_registers(char *page, char **start, int max=0xff; /* This dump the current register page */ -len += snprintf(page + len, count - len, + len += snprintf(page + len, count - len, "\n####################page 0##################\n "); - for(n=0;n<=max;) - { + for (n=0;n<=max;) { //printk( "\nD: %2x> ", n); len += snprintf(page + len, count - len, "\nD: %2x > ",n); - for(i=0;i<16 && n<=max;i++,n++) - len += snprintf(page + len, count - len, - "%2x ",read_nic_byte(dev,0x000|n)); + for (i=0;i<16 && n<=max;i++,n++) + len += snprintf(page + len, count - len, + "%2x ",read_nic_byte(dev,0x000|n)); // printk("%2x ",read_nic_byte(dev,n)); } -len += snprintf(page + len, count - len, + len += snprintf(page + len, count - len, "\n####################page 1##################\n "); - for(n=0;n<=max;) - { + for (n=0;n<=max;) { //printk( "\nD: %2x> ", n); len += snprintf(page + len, count - len, - "\nD: %2x > ",n); + "\nD: %2x > ",n); - for(i=0;i<16 && n<=max;i++,n++) - len += snprintf(page + len, count - len, - "%2x ",read_nic_byte(dev,0x100|n)); + for (i=0;i<16 && n<=max;i++,n++) + len += snprintf(page + len, count - len, + "%2x ",read_nic_byte(dev,0x100|n)); // printk("%2x ",read_nic_byte(dev,n)); } -len += snprintf(page + len, count - len, + len += snprintf(page + len, count - len, "\n####################page 3##################\n "); - for(n=0;n<=max;) - { + for (n=0;n<=max;) { //printk( "\nD: %2x> ", n); len += snprintf(page + len, count - len, "\nD: %2x > ",n); for(i=0;i<16 && n<=max;i++,n++) - len += snprintf(page + len, count - len, - "%2x ",read_nic_byte(dev,0x300|n)); + len += snprintf(page + len, count - len, + "%2x ",read_nic_byte(dev,0x300|n)); // printk("%2x ",read_nic_byte(dev,n)); } - len += snprintf(page + len, count - len,"\n"); *eof = 1; return len; - } -- cgit v0.10.2 From c07f972105a19104f56e82fab6c65c364d9f33b8 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:19 +0000 Subject: rtl8712: code clean up Clean some trivial formating problems in rtl8712 from staging tree. This patch also changes the way preprocessor macros are defined to keep checkpatch.pl quiet. Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h index 21515c3..da4000e 100644 --- a/drivers/staging/rtl8712/ieee80211.h +++ b/drivers/staging/rtl8712/ieee80211.h @@ -777,7 +777,7 @@ extern inline int ieee80211_get_hdrlen(u16 fc) struct registry_priv; u8 *r8712_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen); -u8 *r8712_get_ie(u8*pbuf, sint index, sint *len, sint limit); +u8 *r8712_get_ie(u8 *pbuf, sint index, sint *len, sint limit); unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *rsn_ie_len, int limit); unsigned char *r8712_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit); diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h index 9d93189..0ce79b1 100644 --- a/drivers/staging/rtl8712/rtl871x_cmd.h +++ b/drivers/staging/rtl8712/rtl871x_cmd.h @@ -749,7 +749,7 @@ u8 r8712_setopmode_cmd(struct _adapter *padapter, u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset); u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan); u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset); -u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 * pval); +u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval); u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode); u8 r8712_setrfreg_cmd(struct _adapter *padapter, u8 offset, u32 val); u8 r8712_setrttbl_cmd(struct _adapter *padapter, diff --git a/drivers/staging/rtl8712/rtl871x_security.h b/drivers/staging/rtl8712/rtl871x_security.h index a13395f..c732aea 100644 --- a/drivers/staging/rtl8712/rtl871x_security.h +++ b/drivers/staging/rtl8712/rtl871x_security.h @@ -207,9 +207,9 @@ void seccalctkipmic( u8 *Miccode, u8 priority); -void r8712_secmicsetkey(struct mic_data *pmicdata, u8 * key); -void r8712_secmicappend(struct mic_data *pmicdata, u8 * src, u32 nBytes); -void r8712_secgetmic(struct mic_data *pmicdata, u8 * dst); +void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key); +void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes); +void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst); u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe); u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe); void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe); diff --git a/drivers/staging/rtl8712/sta_info.h b/drivers/staging/rtl8712/sta_info.h index f8016e9..c4e0ef2 100644 --- a/drivers/staging/rtl8712/sta_info.h +++ b/drivers/staging/rtl8712/sta_info.h @@ -140,7 +140,7 @@ void r8712_free_all_stainfo(struct _adapter *padapter); struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr); void r8712_init_bcmc_stainfo(struct _adapter *padapter); struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter); -u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 * mac_addr); +u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 *mac_addr); #endif /* _STA_INFO_H_ */ diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h index 793443e..c08ed2a 100644 --- a/drivers/staging/rtl8712/wifi.h +++ b/drivers/staging/rtl8712/wifi.h @@ -159,99 +159,85 @@ enum WIFI_REG_DOMAIN { #define _PRIVACY_ BIT(14) #define _ORDER_ BIT(15) -#define SetToDs(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_TO_DS_); \ - } while (0) +#define SetToDs(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_TO_DS_); \ +}) #define GetToDs(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_TO_DS_)) != 0) -#define ClearToDs(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \ - } while (0) +#define ClearToDs(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \ +}) -#define SetFrDs(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_FROM_DS_); \ - } while (0) +#define SetFrDs(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_FROM_DS_); \ +}) #define GetFrDs(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_FROM_DS_)) != 0) -#define ClearFrDs(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \ - } while (0) +#define ClearFrDs(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \ +}) #define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe)) -#define SetMFrag(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \ - } while (0) +#define SetMFrag(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \ +}) #define GetMFrag(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_MORE_FRAG_)) != 0) -#define ClearMFrag(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \ - } while (0) +#define ClearMFrag(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \ +}) -#define SetRetry(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_RETRY_); \ - } while (0) +#define SetRetry(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_RETRY_); \ +}) #define GetRetry(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_RETRY_)) != 0) -#define ClearRetry(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \ - } while (0) +#define ClearRetry(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \ +}) -#define SetPwrMgt(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_PWRMGT_); \ - } while (0) +#define SetPwrMgt(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_PWRMGT_); \ +}) #define GetPwrMgt(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_PWRMGT_)) != 0) -#define ClearPwrMgt(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \ - } while (0) +#define ClearPwrMgt(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \ +}) -#define SetMData(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \ - } while (0) +#define SetMData(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \ +}) #define GetMData(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_MORE_DATA_)) != 0) -#define ClearMData(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \ - } while (0) +#define ClearMData(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \ +}) -#define SetPrivacy(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_PRIVACY_); \ - } while (0) +#define SetPrivacy(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_PRIVACY_); \ +}) #define GetPrivacy(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_PRIVACY_)) != 0) -#define ClearPrivacy(pbuf) \ - do { \ - *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PRIVACY_)); \ - } while (0) +#define ClearPrivacy(pbuf) ({ \ + *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PRIVACY_)); \ +}) #define GetOrder(pbuf) (((*(unsigned short *)(pbuf)) & \ @@ -287,48 +273,42 @@ enum WIFI_REG_DOMAIN { #define GetTupleCache(pbuf) (cpu_to_le16(*(unsigned short *)\ ((addr_t)(pbuf) + 22))) -#define SetFragNum(pbuf, num) \ - do { \ - *(unsigned short *)((addr_t)(pbuf) + 22) = \ - ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ - le16_to_cpu(~(0x000f))) | \ - cpu_to_le16(0x0f & (num)); \ - } while (0) - -#define SetSeqNum(pbuf, num) \ - do { \ - *(unsigned short *)((addr_t)(pbuf) + 22) = \ - ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ - le16_to_cpu((unsigned short)0x000f)) | \ - le16_to_cpu((unsigned short)(0xfff0 & (num << 4))); \ - } while (0) - -#define SetDuration(pbuf, dur) \ - do { \ - *(unsigned short *)((addr_t)(pbuf) + 2) |= \ - cpu_to_le16(0xffff & (dur)); \ - } while (0) - -#define SetPriority(pbuf, tid) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(tid & 0xf); \ - } while (0) +#define SetFragNum(pbuf, num) ({ \ + *(unsigned short *)((addr_t)(pbuf) + 22) = \ + ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ + le16_to_cpu(~(0x000f))) | \ + cpu_to_le16(0x0f & (num)); \ +}) + +#define SetSeqNum(pbuf, num) ({ \ + *(unsigned short *)((addr_t)(pbuf) + 22) = \ + ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ + le16_to_cpu((unsigned short)0x000f)) | \ + le16_to_cpu((unsigned short)(0xfff0 & (num << 4))); \ +}) + +#define SetDuration(pbuf, dur) ({ \ + *(unsigned short *)((addr_t)(pbuf) + 2) |= \ + cpu_to_le16(0xffff & (dur)); \ +}) + +#define SetPriority(pbuf, tid) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(tid & 0xf); \ +}) #define GetPriority(pbuf) ((le16_to_cpu(*(unsigned short *)(pbuf))) & 0xf) -#define SetAckpolicy(pbuf, ack) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \ - } while (0) +#define SetAckpolicy(pbuf, ack) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \ +}) #define GetAckpolicy(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 5) & 0x3) #define GetAMsdu(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 7) & 0x1) -#define SetAMsdu(pbuf, amsdu) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16((amsdu & 1) << 7); \ - } while (0) +#define SetAMsdu(pbuf, amsdu) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16((amsdu & 1) << 7); \ +}) #define GetAid(pbuf) (cpu_to_le16(*(unsigned short *)((addr_t)(pbuf) + 2)) \ & 0x3fff) @@ -526,10 +506,9 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe) #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800 -#define SetOrderBit(pbuf) \ - do { \ - *(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \ - } while (0) +#define SetOrderBit(pbuf) ({ \ + *(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \ +}) #define GetOrderBit(pbuf) (((*(unsigned short *)(pbuf)) & \ le16_to_cpu(_ORDER_)) != 0) -- cgit v0.10.2 From 94973b63e1bdcd3e712d9199329c9a2141eb9139 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:20 +0000 Subject: rtl8712: remove unused macros from rtl8712/wifi.h Those definitions are not used anywhere in the kernel. If you know any reason why they should stay in the code please speak up! Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h index c08ed2a..73d7cd2 100644 --- a/drivers/staging/rtl8712/wifi.h +++ b/drivers/staging/rtl8712/wifi.h @@ -437,11 +437,7 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe) #define _SSID_IE_ 0 #define _SUPPORTEDRATES_IE_ 1 #define _DSSET_IE_ 3 -#define _TIM_IE_ 5 #define _IBSS_PARA_IE_ 6 -#define _CHLGETXT_IE_ 16 -#define _RSN_IE_2_ 48` -#define _SSN_IE_1_ 221 #define _ERPINFO_IE_ 42 #define _EXT_SUPPORTEDRATES_IE_ 50 -- cgit v0.10.2 From 87a573ada017b40facab87b149fcbb3344eab9e8 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:21 +0000 Subject: rtl8712: replace printk with better solutions Replace printk with netdev_printk helpers, dev_printk helpers or pr_err/warn/info if there is no device info available. Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c index cb9d4cf..d801c5a 100644 --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -49,7 +49,7 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context) if (!firmware) { struct usb_device *udev = padapter->dvobjpriv.pusbdev; struct usb_interface *pusb_intf = padapter->pusb_intf; - printk(KERN_ERR "r8712u: Firmware request failed\n"); + dev_err(&udev->dev, "r8712u: Firmware request failed\n"); padapter->fw_found = false; usb_put_dev(udev); usb_set_intfdata(pusb_intf, NULL); @@ -69,12 +69,11 @@ int rtl871x_load_fw(struct _adapter *padapter) int rc; init_completion(&padapter->rtl8712_fw_ready); - printk(KERN_INFO "r8712u: Loading firmware from \"%s\"\n", - firmware_file); + dev_info(dev, "r8712u: Loading firmware from \"%s\"\n", firmware_file); rc = request_firmware_nowait(THIS_MODULE, 1, firmware_file, dev, GFP_KERNEL, padapter, rtl871x_load_fw_cb); if (rc) - printk(KERN_ERR "r8712u: Firmware request error %d\n", rc); + dev_err(dev, "r8712u: Firmware request error %d\n", rc); return rc; } MODULE_FIRMWARE("rtlwifi/rtl8712u.bin"); @@ -84,8 +83,8 @@ static u32 rtl871x_open_fw(struct _adapter *padapter, const u8 **ppmappedfw) const struct firmware **praw = &padapter->fw; if (padapter->fw->size > 200000) { - printk(KERN_ERR "r8172u: Badfw->size of %d\n", - (int)padapter->fw->size); + dev_err(&padapter->pnetdev->dev, "r8172u: Badfw->size of %d\n", + (int)padapter->fw->size); return 0; } *ppmappedfw = (u8 *)((*praw)->data); @@ -334,11 +333,13 @@ uint rtl8712_hal_init(struct _adapter *padapter) if (rtl8712_dl_fw(padapter) != _SUCCESS) return _FAIL; - printk(KERN_INFO "r8712u: 1 RCR=0x%x\n", r8712_read32(padapter, RCR)); + netdev_info(padapter->pnetdev, "1 RCR=0x%x\n", + r8712_read32(padapter, RCR)); val32 = r8712_read32(padapter, RCR); r8712_write32(padapter, RCR, (val32 | BIT(26))); /* Enable RX TCP Checksum offload */ - printk(KERN_INFO "r8712u: 2 RCR=0x%x\n", r8712_read32(padapter, RCR)); + netdev_info(padapter->pnetdev, "2 RCR=0x%x\n", + r8712_read32(padapter, RCR)); val32 = r8712_read32(padapter, RCR); r8712_write32(padapter, RCR, (val32|BIT(25))); /* Append PHY status */ val32 = 0; diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c index e00f791..b65bf5e 100644 --- a/drivers/staging/rtl8712/os_intfs.c +++ b/drivers/staging/rtl8712/os_intfs.c @@ -224,8 +224,7 @@ struct net_device *r8712_init_netdev(void) } padapter = (struct _adapter *) netdev_priv(pnetdev); padapter->pnetdev = pnetdev; - printk(KERN_INFO "r8712u: register rtl8712_netdev_ops to" - " netdev_ops\n"); + pr_info("r8712u: register rtl8712_netdev_ops to netdev_ops\n"); pnetdev->netdev_ops = &rtl8712_netdev_ops; pnetdev->watchdog_timeo = HZ; /* 1 second timeout */ pnetdev->wireless_handlers = (struct iw_handler_def *) diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c index c76732c..d59a74a 100644 --- a/drivers/staging/rtl8712/rtl8712_recv.c +++ b/drivers/staging/rtl8712/rtl8712_recv.c @@ -115,11 +115,11 @@ void r8712_free_recv_priv(struct recv_priv *precvpriv) kfree(precvpriv->pallocated_recv_buf); skb_queue_purge(&precvpriv->rx_skb_queue); if (skb_queue_len(&precvpriv->rx_skb_queue)) - printk(KERN_WARNING "r8712u: rx_skb_queue not empty\n"); + netdev_warn(padapter->pnetdev, "r8712u: rx_skb_queue not empty\n"); skb_queue_purge(&precvpriv->free_recv_skb_queue); if (skb_queue_len(&precvpriv->free_recv_skb_queue)) - printk(KERN_WARNING "r8712u: free_recv_skb_queue not empty " - "%d\n", skb_queue_len(&precvpriv->free_recv_skb_queue)); + netdev_warn(padapter->pnetdev, "r8712u: free_recv_skb_queue not empty %d\n", + skb_queue_len(&precvpriv->free_recv_skb_queue)); } int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf) @@ -364,9 +364,8 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe) nSubframe_Length = (nSubframe_Length >> 8) + (nSubframe_Length << 8); if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) { - printk(KERN_WARNING "r8712u: nRemain_Length is %d and" - " nSubframe_Length is: %d\n", - a_len, nSubframe_Length); + netdev_warn(padapter->pnetdev, "r8712u: nRemain_Length is %d and nSubframe_Length is: %d\n", + a_len, nSubframe_Length); goto exit; } /* move the data point to data content */ @@ -381,8 +380,7 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe) memcpy(data_ptr, pdata, nSubframe_Length); subframes[nr_subframes++] = sub_skb; if (nr_subframes >= MAX_SUBFRAME_COUNT) { - printk(KERN_WARNING "r8712u: ParseSubframe(): Too" - " many Subframes! Packets dropped!\n"); + netdev_warn(padapter->pnetdev, "r8712u: ParseSubframe(): Too many Subframes! Packets dropped!\n"); break; } pdata += nSubframe_Length; diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c index 72c51b3..43de44a 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c @@ -415,8 +415,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, } else return -EINVAL; if (strcmp(param->u.crypt.alg, "WEP") == 0) { - printk(KERN_INFO "r8712u: wpa_set_encryption, crypt.alg =" - " WEP\n"); + netdev_info(dev, "r8712u: %s: crypt.alg = WEP\n", __func__); padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; padapter->securitypriv.PrivacyAlgrthm = _WEP40_; @@ -608,8 +607,7 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie, if ((eid == _VENDOR_SPECIFIC_IE_) && (!memcmp(&buf[cnt+2], wps_oui, 4))) { - printk(KERN_INFO "r8712u: " - "SET WPS_IE\n"); + netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE\n"); padapter->securitypriv.wps_ie_len = ((buf[cnt+1] + 2) < (MAX_WPA_IE_LEN << 2)) ? @@ -620,8 +618,7 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie, padapter->securitypriv.wps_ie_len); padapter->securitypriv.wps_phase = true; - printk(KERN_INFO "r8712u: SET WPS_IE," - " wps_phase==true\n"); + netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE, wps_phase==true\n"); cnt += buf[cnt+1]+2; break; } else @@ -829,8 +826,8 @@ static int r871x_wx_set_pmkid(struct net_device *dev, strIssueBssid, ETH_ALEN)) { /* BSSID is matched, the same AP => rewrite * with new PMKID. */ - printk(KERN_INFO "r8712u: r871x_wx_set_pmkid:" - " BSSID exists in the PMKList.\n"); + netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n", + __func__); memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN); psecuritypriv->PMKIDList[j].bUsed = true; @@ -841,9 +838,8 @@ static int r871x_wx_set_pmkid(struct net_device *dev, } if (!blInserted) { /* Find a new entry */ - printk(KERN_INFO "r8712u: r871x_wx_set_pmkid: Use the" - " new entry index = %d for this PMKID.\n", - psecuritypriv->PMKIDIndex); + netdev_info(dev, "r8712u: %s: Use the new entry index = %d for this PMKID.\n", + __func__, psecuritypriv->PMKIDIndex); memcpy(psecuritypriv->PMKIDList[psecuritypriv-> PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN); memcpy(psecuritypriv->PMKIDList[psecuritypriv-> @@ -876,8 +872,7 @@ static int r871x_wx_set_pmkid(struct net_device *dev, intReturn = true; break; default: - printk(KERN_INFO "r8712u: r871x_wx_set_pmkid: " - "unknown Command\n"); + netdev_info(dev, "r8712u: %s: unknown Command\n", __func__); intReturn = false; break; } @@ -1045,8 +1040,8 @@ static int r871x_wx_set_priv(struct net_device *dev, ); sprintf(ext, "OK"); } else { - printk(KERN_INFO "r8712u: r871x_wx_set_priv: unknown Command" - " %s.\n", ext); + netdev_info(dev, "r8712u: %s: unknown Command %s.\n", + __func__, ext); goto FREE_EXT; } if (copy_to_user(dwrq->pointer, ext, @@ -1183,8 +1178,8 @@ static int r8711_wx_set_scan(struct net_device *dev, u8 status = true; if (padapter->bDriverStopped == true) { - printk(KERN_WARNING "r8712u: in r8711_wx_set_scan: " - "bDriverStopped=%d\n", padapter->bDriverStopped); + netdev_info(dev, "In %s: bDriverStopped=%d\n", + __func__, padapter->bDriverStopped); return -1; } if (padapter->bup == false) @@ -1556,8 +1551,7 @@ static int r8711_wx_set_enc(struct net_device *dev, key = erq->flags & IW_ENCODE_INDEX; memset(&wep, 0, sizeof(struct NDIS_802_11_WEP)); if (erq->flags & IW_ENCODE_DISABLED) { - printk(KERN_INFO "r8712u: r8711_wx_set_enc: " - "EncryptionDisabled\n"); + netdev_info(dev, "r8712u: %s: EncryptionDisabled\n", __func__); padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_; @@ -1578,8 +1572,7 @@ static int r8711_wx_set_enc(struct net_device *dev, } /* set authentication mode */ if (erq->flags & IW_ENCODE_OPEN) { - printk(KERN_INFO "r8712u: r8711_wx_set_enc: " - "IW_ENCODE_OPEN\n"); + netdev_info(dev, "r8712u: %s: IW_ENCODE_OPEN\n", __func__); padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; padapter->securitypriv.AuthAlgrthm = 0; /* open system */ @@ -1588,8 +1581,7 @@ static int r8711_wx_set_enc(struct net_device *dev, authmode = Ndis802_11AuthModeOpen; padapter->securitypriv.ndisauthtype = authmode; } else if (erq->flags & IW_ENCODE_RESTRICTED) { - printk(KERN_INFO "r8712u: r8711_wx_set_enc: " - "IW_ENCODE_RESTRICTED\n"); + netdev_info(dev, "r8712u: %s: IW_ENCODE_RESTRICTED\n", __func__); padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; padapter->securitypriv.AuthAlgrthm = 1; /* shared system */ @@ -1977,9 +1969,9 @@ static int r871x_mp_ioctl_hdl(struct net_device *dev, status = phandler->handler(&oid_par); /* todo:check status, BytesNeeded, etc. */ } else { - printk(KERN_INFO "r8712u: r871x_mp_ioctl_hdl(): err!," - " subcode=%d, oid=%d, handler=%p\n", - poidparam->subcode, phandler->oid, phandler->handler); + netdev_info(dev, "r8712u: %s: err!, subcode=%d, oid=%d, handler=%p\n", + __func__, poidparam->subcode, phandler->oid, + phandler->handler); ret = -EFAULT; goto _r871x_mp_ioctl_hdl_exit; } @@ -2034,13 +2026,13 @@ static int r871x_get_ap_info(struct net_device *dev, break; pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list); if (hwaddr_aton_i(data, bssid)) { - printk(KERN_INFO "r8712u: Invalid BSSID '%s'.\n", - (u8 *)data); + netdev_info(dev, "r8712u: Invalid BSSID '%s'.\n", + (u8 *)data); spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock), - irqL); + irqL); return -EINVAL; } - printk(KERN_INFO "r8712u: BSSID:%pM\n", bssid); + netdev_info(dev, "r8712u: BSSID:%pM\n", bssid); if (!memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN)) { /* BSSID match, then check if supporting wpa/wpa2 */ pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12], diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c index e52f04d..6596154 100644 --- a/drivers/staging/rtl8712/rtl871x_mlme.c +++ b/drivers/staging/rtl8712/rtl871x_mlme.c @@ -1043,8 +1043,8 @@ void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf) struct sta_priv *pstapriv = &adapter->stapriv; struct recv_reorder_ctrl *precvreorder_ctrl = NULL; - printk(KERN_INFO "r8712u: [%s] mac = %pM, seq = %d, tid = %d\n", - __func__, pAddbareq_pram->MacAddress, + netdev_info(adapter->pnetdev, "%s: mac = %pM, seq = %d, tid = %d\n", + __func__, pAddbareq_pram->MacAddress, pAddbareq_pram->StartSeqNum, pAddbareq_pram->tid); psta = r8712_get_stainfo(pstapriv, pAddbareq_pram->MacAddress); if (psta) { diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c index a96cd06..c812d6c7 100644 --- a/drivers/staging/rtl8712/usb_intf.c +++ b/drivers/staging/rtl8712/usb_intf.c @@ -205,9 +205,9 @@ static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state) { struct net_device *pnetdev = usb_get_intfdata(pusb_intf); - printk(KERN_INFO "r8712: suspending...\n"); + netdev_info(pnetdev, "Suspending...\n"); if (!pnetdev || !netif_running(pnetdev)) { - printk(KERN_INFO "r8712: unable to suspend\n"); + netdev_info(pnetdev, "Unable to suspend\n"); return 0; } if (pnetdev->netdev_ops->ndo_stop) @@ -221,9 +221,9 @@ static int r871x_resume(struct usb_interface *pusb_intf) { struct net_device *pnetdev = usb_get_intfdata(pusb_intf); - printk(KERN_INFO "r8712: resuming...\n"); + netdev_info(pnetdev, "Resuming...\n"); if (!pnetdev || !netif_running(pnetdev)) { - printk(KERN_INFO "r8712: unable to resume\n"); + netdev_info(pnetdev, "Unable to resume\n"); return 0; } netif_device_attach(pnetdev); @@ -273,12 +273,12 @@ static uint r8712_usb_dvobj_init(struct _adapter *padapter) pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints; if (pusbd->speed == USB_SPEED_HIGH) { pdvobjpriv->ishighspeed = true; - printk(KERN_INFO "r8712u: USB_SPEED_HIGH with %d endpoints\n", - pdvobjpriv->nr_endpoint); + dev_info(&pusbd->dev, "r8712u: USB_SPEED_HIGH with %d endpoints\n", + pdvobjpriv->nr_endpoint); } else { pdvobjpriv->ishighspeed = false; - printk(KERN_INFO "r8712u: USB_SPEED_LOW with %d endpoints\n", - pdvobjpriv->nr_endpoint); + dev_info(&pusbd->dev, "r8712u: USB_SPEED_LOW with %d endpoints\n", + pdvobjpriv->nr_endpoint); } if ((r8712_alloc_io_queue(padapter)) == _FAIL) status = _FAIL; @@ -423,9 +423,9 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf, tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/ /* To check system boot selection.*/ - printk(KERN_INFO "r8712u: Boot from %s: Autoload %s\n", - (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE", - (tmpU1b & _EEPROM_EN) ? "OK" : "Failed"); + dev_info(&udev->dev, "r8712u: Boot from %s: Autoload %s\n", + (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE", + (tmpU1b & _EEPROM_EN) ? "OK" : "Failed"); /* To check autoload success or not.*/ if (tmpU1b & _EEPROM_EN) { @@ -533,8 +533,8 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf, RT_CID_DEFAULT; break; } - printk(KERN_INFO "r8712u: CustomerID = 0x%.4x\n", - padapter->eeprompriv.CustomerID); + dev_info(&udev->dev, "r8712u: CustomerID = 0x%.4x\n", + padapter->eeprompriv.CustomerID); /* Led mode */ switch (padapter->eeprompriv.CustomerID) { case RT_CID_DEFAULT: @@ -590,11 +590,9 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf, * address by setting bit 1 of first octet. */ mac[0] &= 0xFE; - printk(KERN_INFO "r8712u: MAC Address from user = " - "%pM\n", mac); + dev_info(&udev->dev, "r8712u: MAC Address from user = %pM\n", mac); } else - printk(KERN_INFO "r8712u: MAC Address from efuse = " - "%pM\n", mac); + dev_info(&udev->dev, "r8712u: MAC Address from efuse = %pM\n", mac); memcpy(pnetdev->dev_addr, mac, ETH_ALEN); } /* step 6. Load the firmware asynchronously */ @@ -661,7 +659,6 @@ static void __exit r8712u_drv_halt(void) { drvpriv.drv_registered = false; usb_deregister(&drvpriv.r871xu_drv); - printk(KERN_INFO "r8712u: Driver unloaded\n"); } module_init(r8712u_drv_entry); diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c index 24e1ec5..9e28ef0 100644 --- a/drivers/staging/rtl8712/usb_ops_linux.c +++ b/drivers/staging/rtl8712/usb_ops_linux.c @@ -243,8 +243,7 @@ static void r8712_usb_read_port_complete(struct urb *purb) (unsigned char *)precvbuf); break; case -EINPROGRESS: - printk(KERN_ERR "r8712u: ERROR: URB IS IN" - " PROGRESS!/n"); + netdev_err(padapter->pnetdev, "ERROR: URB IS IN PROGRESS!\n"); break; default: break; @@ -336,8 +335,7 @@ void r8712_xmit_bh(void *priv) if ((padapter->bDriverStopped == true) || (padapter->bSurpriseRemoved == true)) { - printk(KERN_ERR "r8712u: xmit_bh => bDriverStopped" - " or bSurpriseRemoved\n"); + netdev_err(padapter->pnetdev, "xmit_bh => bDriverStopped or bSurpriseRemoved\n"); return; } ret = r8712_xmitframe_complete(padapter, pxmitpriv, NULL); @@ -387,7 +385,7 @@ static void usb_write_port_complete(struct urb *purb) case 0: break; default: - printk(KERN_WARNING "r8712u: pipe error: (%d)\n", purb->status); + netdev_warn(padapter->pnetdev, "r8712u: pipe error: (%d)\n", purb->status); break; } /* not to consider tx fragment */ @@ -502,8 +500,8 @@ int r8712_usbctrl_vendorreq(struct intf_priv *pintfpriv, u8 request, u16 value, palloc_buf = _malloc((u32) len + 16); if (palloc_buf == NULL) { - printk(KERN_ERR "r8712u: [%s] Can't alloc memory for vendor" - " request\n", __func__); + dev_err(&udev->dev, "%s: Can't alloc memory for vendor request\n", + __func__); return -1; } pIo_buf = palloc_buf + 16 - ((addr_t)(palloc_buf) & 0x0f); diff --git a/drivers/staging/rtl8712/xmit_linux.c b/drivers/staging/rtl8712/xmit_linux.c index 65542cb..4d22bb7 100644 --- a/drivers/staging/rtl8712/xmit_linux.c +++ b/drivers/staging/rtl8712/xmit_linux.c @@ -134,8 +134,7 @@ int r8712_xmit_resource_alloc(struct _adapter *padapter, for (i = 0; i < 8; i++) { pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL); if (pxmitbuf->pxmit_urb[i] == NULL) { - printk(KERN_ERR "r8712u: pxmitbuf->pxmit_urb[i]" - " == NULL"); + netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n"); return _FAIL; } } -- cgit v0.10.2 From 0024a1e73404b06a302f39eb3ceb15d9d741c552 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:22 +0000 Subject: rtl8712: replace min with min_t I've changed the ugly casting here and used min_t() instead. I also changed the u16 to a u32 because ->network.Ssid.SsidLength is 32 bits. It doesn't make a difference, but truncating the upper bits away is sloppy. Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c index 43de44a..f034567 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c @@ -188,8 +188,7 @@ static inline char *translate_scan(struct _adapter *padapter, /* Add the ESSID */ iwe.cmd = SIOCGIWESSID; iwe.u.data.flags = 1; - iwe.u.data.length = (u16)min((u16)pnetwork->network.Ssid.SsidLength, - (u16)32); + iwe.u.data.length = min_t(u32, pnetwork->network.Ssid.SsidLength, 32); start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid); /* parsing HT_CAP_IE */ @@ -1194,8 +1193,7 @@ static int r8711_wx_set_scan(struct net_device *dev, if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { struct ndis_802_11_ssid ssid; unsigned long irqL; - u32 len = (u32) min((u8)req->essid_len, - (u8)IW_ESSID_MAX_SIZE); + u32 len = min_t(u8, req->essid_len, IW_ESSID_MAX_SIZE); memset((unsigned char *)&ssid, 0, sizeof(struct ndis_802_11_ssid)); memcpy(ssid.Ssid, req->essid, len); -- cgit v0.10.2 From fc6556e8442dfe275becf7e7349c5e8916d2a1cc Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:23 +0000 Subject: rtl8712: remove unused macros Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c index 9e28ef0..dca398a 100644 --- a/drivers/staging/rtl8712/usb_ops_linux.c +++ b/drivers/staging/rtl8712/usb_ops_linux.c @@ -45,9 +45,6 @@ struct zero_bulkout_context { void *padapter; }; -#define usb_write_cmd r8712_usb_write_mem -#define usb_write_cmd_complete usb_write_mem_complete - uint r8712_usb_init_intf_priv(struct intf_priv *pintfpriv) { pintfpriv->piorw_urb = usb_alloc_urb(0, GFP_ATOMIC); -- cgit v0.10.2 From 9e01b9f3137b89328561efd70509af6051d903f6 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:24 +0000 Subject: rtl8712: remove all NDIS_* definitions and use rndis.h instead Remove duplicate code.The definitions are already in include/linux/rndis.h Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c index 9a33eae..5d6d55e 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c @@ -28,6 +28,7 @@ #define _RTL871X_IOCTL_RTL_C_ +#include #include "osdep_service.h" #include "drv_types.h" #include "wlan_bssdef.h" @@ -42,8 +43,8 @@ uint oid_rt_get_signal_quality_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv) @@ -52,14 +53,14 @@ uint oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(u32 *)poid_par_priv->information_buf = padapter->recvpriv.rx_smallpacket_crcerr; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv) @@ -68,14 +69,14 @@ uint oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(u32 *)poid_par_priv->information_buf = padapter->recvpriv.rx_middlepacket_crcerr; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv) @@ -84,29 +85,29 @@ uint oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(u32 *)poid_par_priv->information_buf = padapter->recvpriv.rx_largepacket_crcerr; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_tx_retry_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_rx_retry_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv) @@ -115,29 +116,29 @@ uint oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(u32 *)poid_par_priv->information_buf = padapter->recvpriv.rx_pkts + padapter->recvpriv.rx_drop; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_tx_beacon_ok_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_tx_beacon_err_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv) @@ -146,22 +147,22 @@ uint oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(uint *)poid_par_priv->information_buf = padapter->recvpriv.rx_icv_err; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH ; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH ; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_set_encryption_algorithm_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv) @@ -171,7 +172,7 @@ uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv) u32 preamblemode = 0 ; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { if (padapter->registrypriv.preamble == PREAMBLE_LONG) preamblemode = 0; @@ -182,15 +183,15 @@ uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv) *(u32 *)poid_par_priv->information_buf = preamblemode; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_ap_ip_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_channelplan_hdl(struct oid_par_priv *poid_par_priv) @@ -200,10 +201,10 @@ uint oid_rt_get_channelplan_hdl(struct oid_par_priv *poid_par_priv) struct eeprom_priv *peeprompriv = &padapter->eeprompriv; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; *(u16 *)poid_par_priv->information_buf = peeprompriv->channel_plan; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_set_channelplan_hdl(struct oid_par_priv @@ -214,9 +215,9 @@ uint oid_rt_set_channelplan_hdl(struct oid_par_priv struct eeprom_priv *peeprompriv = &padapter->eeprompriv; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; peeprompriv->channel_plan = *(u16 *)poid_par_priv->information_buf; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv @@ -227,7 +228,7 @@ uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv u32 preamblemode = 0; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { preamblemode = *(u32 *)poid_par_priv->information_buf; if (preamblemode == 0) @@ -239,21 +240,21 @@ uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv *(u32 *)poid_par_priv->information_buf = preamblemode; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_set_bcn_intvl_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_dedicate_probe_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv @@ -263,14 +264,14 @@ uint oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(u32 *)poid_par_priv->information_buf = padapter->xmitpriv.tx_bytes; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv @@ -280,37 +281,37 @@ uint oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { *(u32 *)poid_par_priv->information_buf = padapter->recvpriv.rx_bytes; *poid_par_priv->bytes_rw = poid_par_priv-> information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_current_tx_power_level_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_enc_key_mismatch_count_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_enc_key_match_count_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv) @@ -322,7 +323,7 @@ uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv) u32 channelnum; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) || (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) pnic_Config = &pmlmepriv->cur_network.network.Configuration; @@ -332,22 +333,22 @@ uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv) channelnum = pnic_Config->DSConfig; *(u32 *)poid_par_priv->information_buf = channelnum; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_hardware_radio_off_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_key_mismatch_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv @@ -356,7 +357,7 @@ uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv u32 ulInfo = 0; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len >= sizeof(u32)) { ulInfo |= 0x0100; /* WIRELESS_MODE_B */ ulInfo |= 0x0200; /* WIRELESS_MODE_G */ @@ -364,108 +365,108 @@ uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv *(u32 *) poid_par_priv->information_buf = ulInfo; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - return NDIS_STATUS_INVALID_LENGTH; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_channel_list_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_scan_in_progress_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_forced_data_rate_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_wireless_mode_for_scan_list_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_bss_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_scan_with_magic_packet_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_ap_get_associated_station_list_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_ap_switch_into_ap_mode_hdl(struct oid_par_priv* poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_ap_supported_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_ap_set_passphrase_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_rf_write_registry_hdl(struct oid_par_priv* poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */ - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len == (sizeof(unsigned long) * 3)) { if (!r8712_setrfreg_cmd(Adapter, *(unsigned char *)poid_par_priv->information_buf, (unsigned long)(*((unsigned long *) poid_par_priv->information_buf + 2)))) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; return status; } uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */ - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len == (sizeof(unsigned long)*3)) { if (Adapter->mppriv.act_in_progress == true) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; else { /* init workparam */ Adapter->mppriv.act_in_progress = true; @@ -486,10 +487,10 @@ uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv) *(unsigned char *)poid_par_priv->information_buf, (unsigned char *)&Adapter->mppriv.workparam. io_value)) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; } } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; return status; } @@ -508,7 +509,7 @@ uint oid_rt_get_connect_state_hdl(struct oid_par_priv *poid_par_priv) u32 ulInfo; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; /* nStatus==0 CheckingStatus * nStatus==1 Associated * nStatus==2 AdHocMode @@ -524,12 +525,12 @@ uint oid_rt_get_connect_state_hdl(struct oid_par_priv *poid_par_priv) ulInfo = NOTASSOCIATED ; *(u32 *)poid_par_priv->information_buf = ulInfo; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_set_default_key_id_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } diff --git a/drivers/staging/rtl8712/rtl871x_mp.h b/drivers/staging/rtl8712/rtl871x_mp.h index 255dc94..51395d1 100644 --- a/drivers/staging/rtl8712/rtl871x_mp.h +++ b/drivers/staging/rtl8712/rtl871x_mp.h @@ -26,62 +26,6 @@ #ifndef __RTL871X_MP_H_ #define __RTL871X_MP_H_ -/* 00 - Success */ -/* 11 - Error */ -#define STATUS_SUCCESS (0x00000000L) -#define STATUS_PENDING (0x00000103L) -#define STATUS_UNSUCCESSFUL (0xC0000001L) -#define STATUS_INSUFFICIENT_RESOURCES (0xC000009AL) -#define STATUS_NOT_SUPPORTED (0xC00000BBL) -#define NDIS_STATUS_SUCCESS ((uint)STATUS_SUCCESS) -#define NDIS_STATUS_PENDING ((uint) STATUS_PENDING) -#define NDIS_STATUS_NOT_RECOGNIZED ((uint)0x00010001L) -#define NDIS_STATUS_NOT_COPIED ((uint)0x00010002L) -#define NDIS_STATUS_NOT_ACCEPTED ((uint)0x00010003L) -#define NDIS_STATUS_CALL_ACTIVE ((uint)0x00010007L) -#define NDIS_STATUS_FAILURE ((uint) STATUS_UNSUCCESSFUL) -#define NDIS_STATUS_RESOURCES ((uint)\ - STATUS_INSUFFICIENT_RESOURCES) -#define NDIS_STATUS_CLOSING ((uint)0xC0010002L) -#define NDIS_STATUS_BAD_VERSION ((uint)0xC0010004L) -#define NDIS_STATUS_BAD_CHARACTERISTICS ((uint)0xC0010005L) -#define NDIS_STATUS_ADAPTER_NOT_FOUND ((uint)0xC0010006L) -#define NDIS_STATUS_OPEN_FAILED ((uint)0xC0010007L) -#define NDIS_STATUS_DEVICE_FAILED ((uint)0xC0010008L) -#define NDIS_STATUS_MULTICAST_FULL ((uint)0xC0010009L) -#define NDIS_STATUS_MULTICAST_EXISTS ((uint)0xC001000AL) -#define NDIS_STATUS_MULTICAST_NOT_FOUND ((uint)0xC001000BL) -#define NDIS_STATUS_REQUEST_ABORTED ((uint)0xC001000CL) -#define NDIS_STATUS_RESET_IN_PROGRESS ((uint)0xC001000DL) -#define NDIS_STATUS_CLOSING_INDICATING ((uint)0xC001000EL) -#define NDIS_STATUS_NOT_SUPPORTED ((uint)STATUS_NOT_SUPPORTED) -#define NDIS_STATUS_INVALID_PACKET ((uint)0xC001000FL) -#define NDIS_STATUS_OPEN_LIST_FULL ((uint)0xC0010010L) -#define NDIS_STATUS_ADAPTER_NOT_READY ((uint)0xC0010011L) -#define NDIS_STATUS_ADAPTER_NOT_OPEN ((uint)0xC0010012L) -#define NDIS_STATUS_NOT_INDICATING ((uint)0xC0010013L) -#define NDIS_STATUS_INVALID_LENGTH ((uint)0xC0010014L) -#define NDIS_STATUS_INVALID_DATA ((uint)0xC0010015L) -#define NDIS_STATUS_BUFFER_TOO_SHORT ((uint)0xC0010016L) -#define NDIS_STATUS_INVALID_OID ((uint)0xC0010017L) -#define NDIS_STATUS_ADAPTER_REMOVED ((uint)0xC0010018L) -#define NDIS_STATUS_UNSUPPORTED_MEDIA ((uint)0xC0010019L) -#define NDIS_STATUS_GROUP_ADDRESS_IN_USE ((uint)0xC001001AL) -#define NDIS_STATUS_FILE_NOT_FOUND ((uint)0xC001001BL) -#define NDIS_STATUS_ERROR_READING_FILE ((uint)0xC001001CL) -#define NDIS_STATUS_ALREADY_MAPPED ((uint)0xC001001DL) -#define NDIS_STATUS_RESOURCE_CONFLICT ((uint)0xC001001EL) -#define NDIS_STATUS_NO_CABLE ((uint)0xC001001FL) -#define NDIS_STATUS_INVALID_SAP ((uint)0xC0010020L) -#define NDIS_STATUS_SAP_IN_USE ((uint)0xC0010021L) -#define NDIS_STATUS_INVALID_ADDRESS ((uint)0xC0010022L) -#define NDIS_STATUS_VC_NOT_ACTIVATED ((uint)0xC0010023L) -#define NDIS_STATUS_DEST_OUT_OF_ORDER ((uint)0xC0010024L) /* cause 27*/ -#define NDIS_STATUS_VC_NOT_AVAILABLE ((uint)0xC0010025L) /* 35,45*/ -#define NDIS_STATUS_CELLRATE_NOT_AVAILABLE ((uint)0xC0010026L) /* 37*/ -#define NDIS_STATUS_INCOMPATABLE_QOS ((uint)0xC0010027L) /* 49*/ -#define NDIS_STATUS_AAL_PARAMS_UNSUPPORTED ((uint)0xC0010028L) /* 93*/ -#define NDIS_STATUS_NO_ROUTE_TO_DESTINATION ((uint)0xC0010029L) /* 3*/ #define MPT_NOOP 0 #define MPT_READ_MAC_1BYTE 1 #define MPT_READ_MAC_2BYTE 2 diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c index 5eb461b..5bd4296 100644 --- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c +++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c @@ -26,6 +26,7 @@ * ******************************************************************************/ +#include #include "osdep_service.h" #include "drv_types.h" #include "mlme_osdep.h" @@ -34,12 +35,12 @@ uint oid_null_function(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); @@ -48,7 +49,7 @@ uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) Adapter->registrypriv.wireless_mode = *(u8 *)poid_par_priv->information_buf; else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; } else if (poid_par_priv->type_of_oid == QUERY_OID) { if (poid_par_priv->information_buf_len >= sizeof(u8)) { *(u8 *)poid_par_priv->information_buf = @@ -56,16 +57,16 @@ uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; } else { - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; } return status; } uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); struct bb_reg_param *pbbreg; @@ -73,9 +74,9 @@ uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv) u32 value; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/ if (offset < BB_REG_BASE_ADDR) @@ -87,7 +88,7 @@ uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv) uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); struct bb_reg_param *pbbreg; @@ -95,9 +96,9 @@ uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv) u32 value; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/ if (offset < BB_REG_BASE_ADDR) @@ -110,7 +111,7 @@ uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv) uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); struct rf_reg_param *pbbreg; @@ -119,13 +120,13 @@ uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv) u32 value; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); path = (u8)pbbreg->path; if (path > RF_PATH_B) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; offset = (u8)pbbreg->offset; value = pbbreg->value; r8712_rf_reg_write(Adapter, path, offset, value); @@ -136,20 +137,20 @@ uint oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct rf_reg_param *pbbreg; u8 path; u8 offset; u32 value; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); path = (u8)pbbreg->path; if (path > RF_PATH_B) /* 1T2R path_a /path_b */ - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; offset = (u8)pbbreg->offset; value = r8712_rf_reg_read(Adapter, path, offset); pbbreg->value = value; @@ -265,16 +266,16 @@ uint oid_rt_pro_set_data_rate_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 ratevalue; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; ratevalue = *((u32 *)poid_par_priv->information_buf); if (ratevalue >= MPT_RATE_LAST) - return NDIS_STATUS_INVALID_DATA; + return RNDIS_STATUS_INVALID_DATA; Adapter->mppriv.curr_rateidx = ratevalue; r8712_SetDataRate(Adapter); return status; @@ -284,16 +285,16 @@ uint oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 mode; u8 val8; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; mode = *((u32 *)poid_par_priv->information_buf); Adapter->mppriv.mode = mode;/* 1 for loopback*/ if (mp_start_test(Adapter) == _FAIL) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; r8712_write8(Adapter, MSR, 1); /* Link in ad hoc network, 0x1025004C */ r8712_write8(Adapter, RCR, 0); /* RCR : disable all pkt, 0x10250048 */ /* RCR disable Check BSSID, 0x1025004a */ @@ -313,12 +314,12 @@ uint oid_rt_pro_stop_test_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (mp_stop_test(Adapter) == _FAIL) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } @@ -327,16 +328,16 @@ uint oid_rt_pro_set_channel_direct_call_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 Channel; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; Channel = *((u32 *)poid_par_priv->information_buf); if (Channel > 14) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.curr_ch = Channel; r8712_SetChannel(Adapter); return status; @@ -346,13 +347,13 @@ uint oid_rt_pro_set_antenna_bb_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 antenna; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; antenna = *((u32 *)poid_par_priv->information_buf); Adapter->mppriv.antenna_tx = (u16)((antenna & 0xFFFF0000) >> 16); Adapter->mppriv.antenna_rx = (u16)(antenna & 0x0000FFFF); @@ -365,16 +366,16 @@ uint oid_rt_pro_set_tx_power_control_hdl( { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 tx_pwr_idx; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; tx_pwr_idx = *((u32 *)poid_par_priv->information_buf); if (tx_pwr_idx > MAX_TX_PWR_INDEX_N_MODE) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.curr_txpoweridx = (u8)tx_pwr_idx; r8712_SetTxPower(Adapter); return status; @@ -383,12 +384,12 @@ uint oid_rt_pro_set_tx_power_control_hdl( uint oid_rt_pro_query_tx_packet_sent_hdl( struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } if (poid_par_priv->information_buf_len == sizeof(u32)) { @@ -396,19 +397,19 @@ uint oid_rt_pro_query_tx_packet_sent_hdl( Adapter->mppriv.tx_pktcount; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; return status; } uint oid_rt_pro_query_rx_packet_received_hdl( struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } if (poid_par_priv->information_buf_len == sizeof(u32)) { @@ -416,19 +417,19 @@ uint oid_rt_pro_query_rx_packet_received_hdl( Adapter->mppriv.rx_pktcount; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; return status; } uint oid_rt_pro_query_rx_packet_crc32_error_hdl( struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } if (poid_par_priv->information_buf_len == sizeof(u32)) { @@ -436,7 +437,7 @@ uint oid_rt_pro_query_rx_packet_crc32_error_hdl( Adapter->mppriv.rx_crcerrpktcount; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; return status; } @@ -447,25 +448,25 @@ uint oid_rt_pro_reset_tx_packet_sent_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.tx_pktcount = 0; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len == sizeof(u32)) { Adapter->mppriv.rx_pktcount = 0; Adapter->mppriv.rx_crcerrpktcount = 0; } else - status = NDIS_STATUS_INVALID_LENGTH; + status = RNDIS_STATUS_INVALID_LENGTH; return status; } @@ -476,9 +477,9 @@ uint oid_rt_reset_phy_rx_packet_count_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; r8712_ResetPhyRxPktCount(Adapter); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv @@ -488,13 +489,13 @@ uint oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; *(u32 *)poid_par_priv->information_buf = r8712_GetPhyRxPktReceived(Adapter); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv @@ -504,13 +505,13 @@ uint oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; *(u32 *)poid_par_priv->information_buf = r8712_GetPhyRxPktCRC32Error(Adapter); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv @@ -520,10 +521,10 @@ uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.curr_modem = *((u8 *)poid_par_priv->information_buf); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv @@ -534,10 +535,10 @@ uint oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv u32 bStartTest; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32 *)poid_par_priv->information_buf); r8712_SetContinuousTx(Adapter, (u8)bStartTest); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv @@ -548,10 +549,10 @@ uint oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv u32 bStartTest; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32 *)poid_par_priv->information_buf); r8712_SetSingleCarrierTx(Adapter, (u8)bStartTest); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv @@ -562,10 +563,10 @@ uint oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv u32 bStartTest; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32 *)poid_par_priv->information_buf); r8712_SetCarrierSuppressionTx(Adapter, (u8)bStartTest); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv @@ -576,28 +577,28 @@ uint oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv u32 bStartTest; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32 *)poid_par_priv->information_buf); r8712_SetSingleToneTx(Adapter, (u8)bStartTest); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro8711_join_bss_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct ndis_802_11_ssid *pssid; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = (u32)sizeof(struct ndis_802_11_ssid); *poid_par_priv->bytes_rw = 0; if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pssid = (struct ndis_802_11_ssid *)poid_par_priv->information_buf; if (mp_start_joinbss(Adapter, pssid) == _FAIL) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_rw = sizeof(struct ndis_802_11_ssid); return status; } @@ -607,12 +608,12 @@ uint oid_rt_pro_read_register_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct mp_rw_reg *RegRWStruct; u16 offset; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf; if ((RegRWStruct->offset >= 0x10250800) && (RegRWStruct->offset <= 0x10250FFF)) { @@ -635,7 +636,7 @@ uint oid_rt_pro_read_register_hdl(struct oid_par_priv RegRWStruct->offset); break; default: - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; break; } } @@ -647,14 +648,14 @@ uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct mp_rw_reg *RegRWStruct; u16 offset; u32 value; u32 oldValue = 0; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf; if ((RegRWStruct->offset >= 0x10250800) && (RegRWStruct->offset <= 0x10250FFF)) { @@ -691,11 +692,11 @@ uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv) (unsigned int)RegRWStruct->value); break; default: - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; break; } - if ((status == NDIS_STATUS_SUCCESS) && + if ((status == RNDIS_STATUS_SUCCESS) && (RegRWStruct->offset == HIMR) && (RegRWStruct->width == 4)) Adapter->ImrContent = RegRWStruct->value; @@ -711,12 +712,12 @@ uint oid_rt_pro_burst_read_register_hdl(struct oid_par_priv struct burst_rw_reg *pBstRwReg; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; pBstRwReg = (struct burst_rw_reg *)poid_par_priv->information_buf; r8712_read_mem(Adapter, pBstRwReg->offset, (u32)pBstRwReg->len, pBstRwReg->Data); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_burst_write_register_hdl(struct oid_par_priv @@ -727,16 +728,16 @@ uint oid_rt_pro_burst_write_register_hdl(struct oid_par_priv struct burst_rw_reg *pBstRwReg; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; pBstRwReg = (struct burst_rw_reg *)poid_par_priv->information_buf; r8712_write_mem(Adapter, pBstRwReg->offset, (u32)pBstRwReg->len, pBstRwReg->Data); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_write_txcmd_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv) @@ -746,12 +747,12 @@ uint oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv) struct eeprom_rw_param *pEEPROM; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; pEEPROM = (struct eeprom_rw_param *)poid_par_priv->information_buf; pEEPROM->value = r8712_eeprom_read16(Adapter, (u16)(pEEPROM->offset >> 1)); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_write16_eeprom_hdl(struct oid_par_priv *poid_par_priv) @@ -761,12 +762,12 @@ uint oid_rt_pro_write16_eeprom_hdl(struct oid_par_priv *poid_par_priv) struct eeprom_rw_param *pEEPROM; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; pEEPROM = (struct eeprom_rw_param *)poid_par_priv->information_buf; r8712_eeprom_write16(Adapter, (u16)(pEEPROM->offset >> 1), pEEPROM->value); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv) @@ -776,17 +777,17 @@ uint oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv) struct mp_wiparam *pwi_param; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct mp_wiparam)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; if (Adapter->mppriv.workparam.bcompleted == false) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; pwi_param = (struct mp_wiparam *)poid_par_priv->information_buf; memcpy(pwi_param, &Adapter->mppriv.workparam, sizeof(struct mp_wiparam)); Adapter->mppriv.act_in_progress = false; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv) @@ -795,42 +796,42 @@ uint oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(uint) * 2) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; if (*(uint *)poid_par_priv->information_buf == 1) Adapter->mppriv.rx_pktloss = 0; *((uint *)poid_par_priv->information_buf+1) = Adapter->mppriv.rx_pktloss; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_rd_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_wr_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_rf_intfs_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (r8712_setrfintfs_cmd(Adapter, *(unsigned char *) poid_par_priv->information_buf) == _FAIL) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } @@ -838,10 +839,10 @@ uint oid_rt_poll_rx_status_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; memcpy(poid_par_priv->information_buf, (unsigned char *)&Adapter->mppriv.rxstat, sizeof(struct recv_stat)); @@ -852,7 +853,7 @@ uint oid_rt_poll_rx_status_hdl(struct oid_par_priv *poid_par_priv) uint oid_rt_pro_cfg_debug_message_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv @@ -860,13 +861,13 @@ uint oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (r8712_setdatarate_cmd(Adapter, poid_par_priv->information_buf) != _SUCCESS) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } @@ -874,16 +875,16 @@ uint oid_rt_get_thermal_meter_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (Adapter->mppriv.act_in_progress == true) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u8)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; /*init workparam*/ Adapter->mppriv.act_in_progress = true; Adapter->mppriv.workparam.bcompleted = false; @@ -904,14 +905,14 @@ uint oid_rt_pro_set_power_tracking_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u8)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; if (!r8712_setptm_cmd(Adapter, *((u8 *)poid_par_priv->information_buf))) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } @@ -920,13 +921,13 @@ uint oid_rt_pro_set_basic_rate_hdl(struct oid_par_priv *poid_par_priv) struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff}; - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 ratevalue; u8 datarates[NumRates]; int i; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; ratevalue = *((u32 *)poid_par_priv->information_buf); for (i = 0; i < NumRates; i++) { if (ratevalue == mpdatarate[i]) @@ -935,7 +936,7 @@ uint oid_rt_pro_set_basic_rate_hdl(struct oid_par_priv *poid_par_priv) datarates[i] = 0xff; } if (r8712_setbasicrate_cmd(Adapter, datarates) != _SUCCESS) - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } @@ -945,14 +946,14 @@ uint oid_rt_pro_qry_pwrstate_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < 8) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; *poid_par_priv->bytes_rw = 8; memcpy(poid_par_priv->information_buf, &(Adapter->pwrctrlpriv.pwr_mode), 8); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv) @@ -962,18 +963,18 @@ uint oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv) uint pwr_mode, smart_ps; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_rw = 0; *poid_par_priv->bytes_needed = 8; if (poid_par_priv->information_buf_len < 8) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pwr_mode = *(uint *)(poid_par_priv->information_buf); smart_ps = *(uint *)((addr_t)poid_par_priv->information_buf + 4); if (pwr_mode != Adapter->pwrctrlpriv.pwr_mode || smart_ps != Adapter->pwrctrlpriv.smart_ps) r8712_set_ps_mode(Adapter, pwr_mode, smart_ps); *poid_par_priv->bytes_rw = 8; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv @@ -981,20 +982,20 @@ uint oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct setratable_parm *prate_table; u8 res; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = sizeof(struct setratable_parm); if (poid_par_priv->information_buf_len < sizeof(struct setratable_parm)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; prate_table = (struct setratable_parm *)poid_par_priv->information_buf; res = r8712_setrttbl_cmd(Adapter, prate_table); if (res == _FAIL) - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; return status; } @@ -1002,8 +1003,8 @@ uint oid_rt_pro_h2c_get_rate_table_hdl(struct oid_par_priv *poid_par_priv) { if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv @@ -1016,7 +1017,7 @@ uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv *poid_par_priv->bytes_needed = sizeof(u8); if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; if (poid_par_priv->type_of_oid == SET_OID) { encry_mode = *((u8 *)poid_par_priv->information_buf); @@ -1054,7 +1055,7 @@ uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv *(u8 *)poid_par_priv->information_buf = encry_mode; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } /*----------------------------------------------------------------------*/ uint oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv) @@ -1062,24 +1063,24 @@ uint oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv) struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct sta_info *psta = NULL; u8 *macaddr; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = ETH_ALEN; if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; macaddr = (u8 *) poid_par_priv->information_buf; psta = r8712_get_stainfo(&Adapter->stapriv, macaddr); if (psta == NULL) { /* the sta in sta_info_queue => do nothing*/ psta = r8712_alloc_stainfo(&Adapter->stapriv, macaddr); if (psta == NULL) - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; } return status; } @@ -1090,18 +1091,18 @@ uint oid_rt_pro_dele_sta_info_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); unsigned long irqL; - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct sta_info *psta = NULL; u8 *macaddr; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = ETH_ALEN; if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; macaddr = (u8 *)poid_par_priv->information_buf; @@ -1125,15 +1126,15 @@ uint oid_rt_pro_query_dr_variable_hdl(struct oid_par_priv *poid_par_priv) struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct DR_VARIABLE_STRUCT *pdrv_var; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = sizeof(struct DR_VARIABLE_STRUCT); if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pdrv_var = (struct DR_VARIABLE_STRUCT *)poid_par_priv->information_buf; pdrv_var->variable = mp_query_drv_var(Adapter, pdrv_var->offset, pdrv_var->variable); @@ -1144,7 +1145,7 @@ uint oid_rt_pro_query_dr_variable_hdl(struct oid_par_priv *poid_par_priv) /*--------------------------------------------------------------------------*/ uint oid_rt_pro_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv) { - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } /*------------------------------------------------------------------------*/ uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv) @@ -1152,17 +1153,17 @@ uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv) struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct EFUSE_ACCESS_STRUCT *pefuse; u8 *data; u16 addr = 0, cnts = 0; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct EFUSE_ACCESS_STRUCT)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf; addr = pefuse->start_addr; cnts = pefuse->cnts; @@ -1170,9 +1171,9 @@ uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv) memset(data, 0xFF, cnts); if ((addr > 511) || (cnts < 1) || (cnts > 512) || (addr + cnts) > EFUSE_MAX_SIZE) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (r8712_efuse_access(Adapter, true, addr, cnts, data) == false) - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; return status; } @@ -1182,14 +1183,14 @@ uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv) struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct EFUSE_ACCESS_STRUCT *pefuse; u8 *data; u16 addr = 0, cnts = 0; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf; addr = pefuse->start_addr; @@ -1198,9 +1199,9 @@ uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv) if ((addr > 511) || (cnts < 1) || (cnts > 512) || (addr + cnts) > r8712_efuse_get_max_size(Adapter)) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (r8712_efuse_access(Adapter, false, addr, cnts, data) == false) - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; return status; } /*----------------------------------------------------------------------*/ @@ -1208,12 +1209,12 @@ uint oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct PGPKT_STRUCT *ppgpkt; *poid_par_priv->bytes_rw = 0; if (poid_par_priv->information_buf_len < sizeof(struct PGPKT_STRUCT)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; ppgpkt = (struct PGPKT_STRUCT *)poid_par_priv->information_buf; if (poid_par_priv->type_of_oid == QUERY_OID) { if (r8712_efuse_pg_packet_read(Adapter, ppgpkt->offset, @@ -1221,7 +1222,7 @@ uint oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv) *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; else - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; } else { if (r8712_efuse_reg_init(Adapter) == true) { if (r8712_efuse_pg_packet_write(Adapter, ppgpkt->offset, @@ -1229,10 +1230,10 @@ uint oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv) *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; else - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; r8712_efuse_reg_uninit(Adapter); } else - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; } return status; } @@ -1242,12 +1243,12 @@ uint oid_rt_get_efuse_current_size_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(int)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; r8712_efuse_reg_init(Adapter); *(int *)poid_par_priv->information_buf = r8712_efuse_get_current_size(Adapter); @@ -1260,12 +1261,12 @@ uint oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; *(int *)poid_par_priv->information_buf = r8712_efuse_get_max_size(Adapter); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; @@ -1274,7 +1275,7 @@ uint oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv) uint oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv) { - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; if (poid_par_priv->type_of_oid == QUERY_OID) status = oid_rt_pro_read_efuse_hdl(poid_par_priv); @@ -1287,18 +1288,18 @@ uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u8 *data; *poid_par_priv->bytes_rw = 0; if (poid_par_priv->information_buf_len < EFUSE_MAP_MAX_SIZE) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; data = (u8 *)poid_par_priv->information_buf; if (poid_par_priv->type_of_oid == QUERY_OID) { if (r8712_efuse_map_read(Adapter, 0, EFUSE_MAP_MAX_SIZE, data)) *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE; else - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; } else { /* SET_OID */ if (r8712_efuse_reg_init(Adapter) == true) { @@ -1306,10 +1307,10 @@ uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv) EFUSE_MAP_MAX_SIZE, data)) *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE; else - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; r8712_efuse_reg_uninit(Adapter); } else { - status = NDIS_STATUS_FAILURE; + status = RNDIS_STATUS_FAILURE; } } return status; @@ -1319,13 +1320,13 @@ uint oid_rt_set_bandwidth_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 bandwidth; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; bandwidth = *((u32 *)poid_par_priv->information_buf);/*4*/ if (bandwidth != HT_CHANNEL_WIDTH_20) bandwidth = HT_CHANNEL_WIDTH_40; @@ -1338,16 +1339,16 @@ uint oid_rt_set_crystal_cap_hdl(struct oid_par_priv *poid_par_priv) { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; u32 crystal_cap = 0; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; crystal_cap = *((u32 *)poid_par_priv->information_buf);/*4*/ if (crystal_cap > 0xf) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.curr_crystalcap = crystal_cap; r8712_SetCrystalCap(Adapter); return status; @@ -1362,9 +1363,9 @@ uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv u32 rcr_val32; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u8)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; rx_pkt_type = *((u8 *)poid_par_priv->information_buf);/*4*/ rcr_val32 = r8712_read32(Adapter, RCR);/*RCR = 0x10250048*/ rcr_val32 &= ~(RCR_CBSSID | RCR_AB | RCR_AM | RCR_APM | RCR_AAP); @@ -1391,7 +1392,7 @@ uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv else Adapter->mppriv.check_mp_pkt = 0; r8712_write32(Adapter, RCR, rcr_val32); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv @@ -1402,12 +1403,12 @@ uint oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv u32 txagc; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; txagc = *(u32 *)poid_par_priv->information_buf; r8712_SetTxAGCOffset(Adapter, txagc); - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv @@ -1415,16 +1416,16 @@ uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv { struct _adapter *Adapter = (struct _adapter *) (poid_par_priv->adapter_context); - uint status = NDIS_STATUS_SUCCESS; + uint status = RNDIS_STATUS_SUCCESS; struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; struct mp_priv *pmppriv = &Adapter->mppriv; u32 type; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; type = *(u32 *)poid_par_priv->information_buf; @@ -1435,7 +1436,7 @@ uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv pmppriv->mode = type; _clr_fwstate_(pmlmepriv, WIFI_MP_LPBK_STATE); } else - status = NDIS_STATUS_NOT_ACCEPTED; + status = RNDIS_STATUS_NOT_ACCEPTED; return status; } /*--------------------------------------------------------------------------*/ @@ -1450,10 +1451,10 @@ uint oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv) u8 bpwrup; if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; bpwrup = *(u8 *)poid_par_priv->information_buf; /*CALL the power_down function*/ - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } /*-------------------------------------------------------------------------- */ @@ -1463,11 +1464,11 @@ uint oid_rt_get_power_mode_hdl(struct oid_par_priv *poid_par_priv) (poid_par_priv->adapter_context); if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; + return RNDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; + return RNDIS_STATUS_INVALID_LENGTH; *(int *)poid_par_priv->information_buf = Adapter->registrypriv.low_power ? POWER_LOW : POWER_NORMAL; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return NDIS_STATUS_SUCCESS; + return RNDIS_STATUS_SUCCESS; } -- cgit v0.10.2 From 7414e8252c115f7630e348cda64e4c4a5b69c511 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 10 Dec 2012 23:21:25 +0000 Subject: rtl8712: remove unused definitions from ethernet.h Signed-off-by: Przemo Firszt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8712/ethernet.h b/drivers/staging/rtl8712/ethernet.h index 9095420..fad173f 100644 --- a/drivers/staging/rtl8712/ethernet.h +++ b/drivers/staging/rtl8712/ethernet.h @@ -26,15 +26,8 @@ #ifndef __INC_ETHERNET_H #define __INC_ETHERNET_H -#define ETHERNET_ADDRESS_LENGTH 6 /*!< Ethernet Address Length*/ #define ETHERNET_HEADER_SIZE 14 /*!< Ethernet Header Length*/ #define LLC_HEADER_SIZE 6 /*!< LLC Header Length*/ -#define TYPE_LENGTH_FIELD_SIZE 2 /*!< Type/Length Size*/ -#define MINIMUM_ETHERNET_PACKET_SIZE 60 /*!< Min Ethernet Packet Size*/ -#define MAXIMUM_ETHERNET_PACKET_SIZE 1514 /*!< Max Ethernet Packet Size*/ - -/*!< Is Multicast Address? */ -#define RT_ETH_IS_MULTICAST(_pAddr) ((((u8 *)(_pAddr))[0]&0x01) != 0) #endif /* #ifndef __INC_ETHERNET_H */ -- cgit v0.10.2 From 709b2fae7cbadd2582f425aa6c102390d5aa9683 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Fri, 11 Jan 2013 23:08:13 +0100 Subject: staging: line6: drop ToneportSourceInfo CamelCase name Fix the following checkpatch.pl warning: WARNING: Avoid CamelCase: #5383: FILE: staging/line6/toneport.c:90: +struct ToneportSourceInfo { Since the struct is only used to define the global toneport_source_info[] table, I have chosen to make the struct anonymous and part of the table definition. Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c index a529dd3..2f44d56 100644 --- a/drivers/staging/line6/toneport.c +++ b/drivers/staging/line6/toneport.c @@ -87,12 +87,10 @@ static struct line6_pcm_properties toneport_pcm_properties = { static int led_red = 0x00; static int led_green = 0x26; -struct ToneportSourceInfo { +static const struct { const char *name; int code; -}; - -static const struct ToneportSourceInfo toneport_source_info[] = { +} toneport_source_info[] = { {"Microphone", 0x0a01}, {"Line", 0x0801}, {"Instrument", 0x0b01}, -- cgit v0.10.2 From 0a1eb4e847b8a4919a909f96c08f66b0e5cd145b Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Fri, 11 Jan 2013 23:08:12 +0100 Subject: staging: line6: wrap lines to 80 chars in pod.c Fix the following checkpatch.pl warnings: WARNING: line over 80 characters #4508: FILE: staging/line6/pod.c:37: + /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */ WARNING: line over 80 characters #4630: FILE: staging/line6/pod.c:159: + if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) { Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/pod.c b/drivers/staging/line6/pod.c index e542540..1a11906 100644 --- a/drivers/staging/line6/pod.c +++ b/drivers/staging/line6/pod.c @@ -34,7 +34,9 @@ enum { POD_SYSEX_DUMPMEM = 0x73, POD_SYSEX_DUMP = 0x74, POD_SYSEX_DUMPREQ = 0x75 - /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */ + + /* dumps entire internal memory of PODxt Pro */ + /* POD_SYSEX_DUMPMEM2 = 0x76 */ }; enum { @@ -156,7 +158,8 @@ void line6_pod_process_message(struct usb_line6_pod *pod) case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE: case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN: - if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) { + if (memcmp(buf + 1, line6_midi_id, + sizeof(line6_midi_id)) == 0) { switch (buf[5]) { case POD_SYSEX_DUMP: break; -- cgit v0.10.2 From bc776f2758684e641a501a9abc7a7c1b237d210d Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Fri, 11 Jan 2013 23:08:10 +0100 Subject: staging: line6: wrap comment to 80 chars in driver.c Fix the following checkpatch.pl warning: WARNING: line over 80 characters #1107: FILE: staging/line6/driver.c:523: + /* Wait for data length. We'll get a couple of 0xff until length arrives. */ Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c index ecb461e..a065674 100644 --- a/drivers/staging/line6/driver.c +++ b/drivers/staging/line6/driver.c @@ -520,7 +520,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data, return ret; } - /* Wait for data length. We'll get a couple of 0xff until length arrives. */ + /* Wait for data length. We'll get 0xff until length arrives. */ do { ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | -- cgit v0.10.2 From 4d3f50e4e5b423058f9eb47077837f975162ac24 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Fri, 11 Jan 2013 23:08:11 +0100 Subject: staging: line6: use pr_err() instead of printk(KERN_ERR, ...) Fix the following checkpatch.pl warning: WARNING: Prefer netdev_err(netdev, ... then dev_err(dev, ... then pr_err(... to printk(KERN_ERR ... #1861: FILE: staging/line6/driver.h:56: + printk(KERN_ERR "line6usb driver bug: missing case in %s:%d\n", \ Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/driver.h b/drivers/staging/line6/driver.h index 1dd768c2..2e0f134 100644 --- a/drivers/staging/line6/driver.h +++ b/drivers/staging/line6/driver.h @@ -53,7 +53,7 @@ #define LINE6_CHANNEL_MASK 0x0f #define MISSING_CASE \ - printk(KERN_ERR "line6usb driver bug: missing case in %s:%d\n", \ + pr_err("line6usb driver bug: missing case in %s:%d\n", \ __FILE__, __LINE__) #define CHECK_RETURN(x) \ -- cgit v0.10.2 From 269edc8ee93c59820b2b54c2d010ab09c5e45cfe Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Fri, 11 Jan 2013 23:08:09 +0100 Subject: staging: line6: rename MidiBuffer to avoid CamelCase Fix checkpatch.pl warnings related to MidiBuffer: WARNING: Avoid CamelCase: #947: FILE: staging/line6/driver.c:363: + struct MidiBuffer *mb = &line6->line6midi->midibuf_in; Rename MidiBuffer to midi_buffer. Note that "midibuf" would be another good name but sound/oss/midibuf.c already uses it for a different concept. Avoid possible confusion by using "midi_buffer" instead. Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c index a065674..1b05633 100644 --- a/drivers/staging/line6/driver.c +++ b/drivers/staging/line6/driver.c @@ -360,7 +360,7 @@ char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2, static void line6_data_received(struct urb *urb) { struct usb_line6 *line6 = (struct usb_line6 *)urb->context; - struct MidiBuffer *mb = &line6->line6midi->midibuf_in; + struct midi_buffer *mb = &line6->line6midi->midibuf_in; int done; if (urb->status == -ESHUTDOWN) diff --git a/drivers/staging/line6/midi.c b/drivers/staging/line6/midi.c index 6982eca..e3f9a53 100644 --- a/drivers/staging/line6/midi.c +++ b/drivers/staging/line6/midi.c @@ -45,7 +45,7 @@ static void line6_midi_transmit(struct snd_rawmidi_substream *substream) struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; struct snd_line6_midi *line6midi = line6->line6midi; - struct MidiBuffer *mb = &line6midi->midibuf_out; + struct midi_buffer *mb = &line6midi->midibuf_out; unsigned long flags; unsigned char chunk[line6->max_packet_size]; int req, done; diff --git a/drivers/staging/line6/midi.h b/drivers/staging/line6/midi.h index 19dabd5..78f903f 100644 --- a/drivers/staging/line6/midi.h +++ b/drivers/staging/line6/midi.h @@ -57,12 +57,12 @@ struct snd_line6_midi { /** Buffer for incoming MIDI stream. */ - struct MidiBuffer midibuf_in; + struct midi_buffer midibuf_in; /** Buffer for outgoing MIDI stream. */ - struct MidiBuffer midibuf_out; + struct midi_buffer midibuf_out; }; extern int line6_init_midi(struct usb_line6 *line6); diff --git a/drivers/staging/line6/midibuf.c b/drivers/staging/line6/midibuf.c index 968e0de..f0adb7b 100644 --- a/drivers/staging/line6/midibuf.c +++ b/drivers/staging/line6/midibuf.c @@ -33,23 +33,23 @@ static int midibuf_message_length(unsigned char code) } } -static int midibuf_is_empty(struct MidiBuffer *this) +static int midibuf_is_empty(struct midi_buffer *this) { return (this->pos_read == this->pos_write) && !this->full; } -static int midibuf_is_full(struct MidiBuffer *this) +static int midibuf_is_full(struct midi_buffer *this) { return this->full; } -void line6_midibuf_reset(struct MidiBuffer *this) +void line6_midibuf_reset(struct midi_buffer *this) { this->pos_read = this->pos_write = this->full = 0; this->command_prev = -1; } -int line6_midibuf_init(struct MidiBuffer *this, int size, int split) +int line6_midibuf_init(struct midi_buffer *this, int size, int split) { this->buf = kmalloc(size, GFP_KERNEL); @@ -62,14 +62,14 @@ int line6_midibuf_init(struct MidiBuffer *this, int size, int split) return 0; } -void line6_midibuf_status(struct MidiBuffer *this) +void line6_midibuf_status(struct midi_buffer *this) { pr_debug("midibuf size=%d split=%d pos_read=%d pos_write=%d full=%d command_prev=%02x\n", this->size, this->split, this->pos_read, this->pos_write, this->full, this->command_prev); } -int line6_midibuf_bytes_free(struct MidiBuffer *this) +int line6_midibuf_bytes_free(struct midi_buffer *this) { return midibuf_is_full(this) ? @@ -78,7 +78,7 @@ int line6_midibuf_bytes_free(struct MidiBuffer *this) 1; } -int line6_midibuf_bytes_used(struct MidiBuffer *this) +int line6_midibuf_bytes_used(struct midi_buffer *this) { return midibuf_is_empty(this) ? @@ -87,7 +87,7 @@ int line6_midibuf_bytes_used(struct MidiBuffer *this) 1; } -int line6_midibuf_write(struct MidiBuffer *this, unsigned char *data, +int line6_midibuf_write(struct midi_buffer *this, unsigned char *data, int length) { int bytes_free; @@ -130,7 +130,8 @@ int line6_midibuf_write(struct MidiBuffer *this, unsigned char *data, return length + skip_active_sense; } -int line6_midibuf_read(struct MidiBuffer *this, unsigned char *data, int length) +int line6_midibuf_read(struct midi_buffer *this, unsigned char *data, + int length) { int bytes_used; int length1, length2; @@ -234,7 +235,7 @@ int line6_midibuf_read(struct MidiBuffer *this, unsigned char *data, int length) return length + repeat; } -int line6_midibuf_ignore(struct MidiBuffer *this, int length) +int line6_midibuf_ignore(struct midi_buffer *this, int length) { int bytes_used = line6_midibuf_bytes_used(this); @@ -246,7 +247,7 @@ int line6_midibuf_ignore(struct MidiBuffer *this, int length) return length; } -int line6_midibuf_skip_message(struct MidiBuffer *this, unsigned short mask) +int line6_midibuf_skip_message(struct midi_buffer *this, unsigned short mask) { int cmd = this->command_prev; @@ -257,7 +258,7 @@ int line6_midibuf_skip_message(struct MidiBuffer *this, unsigned short mask) return 0; } -void line6_midibuf_destroy(struct MidiBuffer *this) +void line6_midibuf_destroy(struct midi_buffer *this) { kfree(this->buf); this->buf = NULL; diff --git a/drivers/staging/line6/midibuf.h b/drivers/staging/line6/midibuf.h index 444cb3a..707482b 100644 --- a/drivers/staging/line6/midibuf.h +++ b/drivers/staging/line6/midibuf.h @@ -12,7 +12,7 @@ #ifndef MIDIBUF_H #define MIDIBUF_H -struct MidiBuffer { +struct midi_buffer { unsigned char *buf; int size; int split; @@ -21,18 +21,18 @@ struct MidiBuffer { int command_prev; }; -extern int line6_midibuf_bytes_used(struct MidiBuffer *mb); -extern int line6_midibuf_bytes_free(struct MidiBuffer *mb); -extern void line6_midibuf_destroy(struct MidiBuffer *mb); -extern int line6_midibuf_ignore(struct MidiBuffer *mb, int length); -extern int line6_midibuf_init(struct MidiBuffer *mb, int size, int split); -extern int line6_midibuf_read(struct MidiBuffer *mb, unsigned char *data, +extern int line6_midibuf_bytes_used(struct midi_buffer *mb); +extern int line6_midibuf_bytes_free(struct midi_buffer *mb); +extern void line6_midibuf_destroy(struct midi_buffer *mb); +extern int line6_midibuf_ignore(struct midi_buffer *mb, int length); +extern int line6_midibuf_init(struct midi_buffer *mb, int size, int split); +extern int line6_midibuf_read(struct midi_buffer *mb, unsigned char *data, int length); -extern void line6_midibuf_reset(struct MidiBuffer *mb); -extern int line6_midibuf_skip_message(struct MidiBuffer *mb, +extern void line6_midibuf_reset(struct midi_buffer *mb); +extern int line6_midibuf_skip_message(struct midi_buffer *mb, unsigned short mask); -extern void line6_midibuf_status(struct MidiBuffer *mb); -extern int line6_midibuf_write(struct MidiBuffer *mb, unsigned char *data, +extern void line6_midibuf_status(struct midi_buffer *mb); +extern int line6_midibuf_write(struct midi_buffer *mb, unsigned char *data, int length); #endif -- cgit v0.10.2 From 7936095f945f62faf0da510f8305b6536b8f2c1b Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Fri, 11 Jan 2013 23:08:14 +0100 Subject: staging: line6: avoid CamelCase POD_* enums in pod.c Fix the following checkpatch.pl warnings: WARNING: Avoid CamelCase: #4512: FILE: staging/line6/pod.c:41: + POD_monitor_level = 0x04, WARNING: Avoid CamelCase: #4513: FILE: staging/line6/pod.c:42: + POD_system_invalid = 0x10000 Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/pod.c b/drivers/staging/line6/pod.c index 1a11906..ba6fed4 100644 --- a/drivers/staging/line6/pod.c +++ b/drivers/staging/line6/pod.c @@ -40,8 +40,8 @@ enum { }; enum { - POD_monitor_level = 0x04, - POD_system_invalid = 0x10000 + POD_MONITOR_LEVEL = 0x04, + POD_SYSTEM_INVALID = 0x10000 }; /* *INDENT-ON* */ @@ -170,7 +170,7 @@ void line6_pod_process_message(struct usb_line6_pod *pod) << 8) | ((int)buf[9] << 4) | (int)buf[10]; - if (buf[6] == POD_monitor_level) + if (buf[6] == POD_MONITOR_LEVEL) pod->monitor_level = value; break; } @@ -372,7 +372,7 @@ static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol, pod->monitor_level = ucontrol->value.integer.value[0]; pod_set_system_param_int(pod, ucontrol->value.integer.value[0], - POD_monitor_level); + POD_MONITOR_LEVEL); return 1; } @@ -463,7 +463,7 @@ static int pod_try_init(struct usb_interface *interface, */ if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) { - pod->monitor_level = POD_system_invalid; + pod->monitor_level = POD_SYSTEM_INVALID; /* initiate startup procedure: */ pod_startup1(pod); -- cgit v0.10.2 From ccbdccd4a7981c150a882123a577c11b2e808051 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 10 Jan 2013 22:55:18 -0800 Subject: Staging: bcm: add a missing break statement My static checker complains that there is a missing break statement here. From the context, it does look like a break statement was intended. Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 4283753..e6152f4 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -2810,6 +2810,7 @@ int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x case CONTROL_SECTION: /* Not Clear So Putting failure. confirm and fix it. */ SectEndOffset = STATUS_FAILURE; + break; case ISO_IMAGE1_PART2: if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End != UNINIT_PTR_IN_CS) SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End); -- cgit v0.10.2 From 955e7da82d8cc917a2c604c782b525dec3466921 Mon Sep 17 00:00:00 2001 From: Alexey Khoroshilov Date: Fri, 11 Jan 2013 13:01:39 +0400 Subject: staging: ced1401: fix GFP_KERNEL in spinlock context Allowi() calls usb_submit_urb(pdx->pUrbCharIn, bInCallback ? GFP_ATOMIC : GFP_KERNEL) under spin_lock_irqsave(&pdx->charInLock, flags). That means it should use GFP_ATOMIC anyway. As soon as it is the only usage of bInCallback argument, the patch removes it at all. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ced1401/ced_ioc.c b/drivers/staging/ced1401/ced_ioc.c index d043471..82a333f 100644 --- a/drivers/staging/ced1401/ced_ioc.c +++ b/drivers/staging/ced1401/ced_ioc.c @@ -123,7 +123,7 @@ int SendString(DEVICE_EXTENSION * pdx, const char __user * pData, iReturn = PutChars(pdx, buffer, n); } - Allowi(pdx, false); // make sure we have input int + Allowi(pdx); // make sure we have input int mutex_unlock(&pdx->io_mutex); return iReturn; @@ -140,7 +140,7 @@ int SendChar(DEVICE_EXTENSION * pdx, char c) mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o iReturn = PutChars(pdx, &c, 1); dev_dbg(&pdx->interface->dev, "SendChar >%c< (0x%02x)", c, c); - Allowi(pdx, false); // Make sure char reads are running + Allowi(pdx); // Make sure char reads are running mutex_unlock(&pdx->io_mutex); return iReturn; } @@ -433,8 +433,8 @@ int GetChar(DEVICE_EXTENSION * pdx) dev_dbg(&pdx->interface->dev, "GetChar"); - Allowi(pdx, false); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars + Allowi(pdx); // Make sure char reads are running + SendChars(pdx); // and send any buffered chars spin_lock_irq(&pdx->charInLock); if (pdx->dwNumInput > 0) // worth looking @@ -447,7 +447,7 @@ int GetChar(DEVICE_EXTENSION * pdx) iReturn = U14ERR_NOIN; // no input data to read spin_unlock_irq(&pdx->charInLock); - Allowi(pdx, false); // Make sure char reads are running + Allowi(pdx); // Make sure char reads are running mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o return iReturn; @@ -472,7 +472,7 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) return -ENOMEM; mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx, false); // Make sure char reads are running + Allowi(pdx); // Make sure char reads are running SendChars(pdx); // and send any buffered chars spin_lock_irq(&pdx->charInLock); @@ -518,7 +518,7 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) } else spin_unlock_irq(&pdx->charInLock); - Allowi(pdx, false); // Make sure char reads are running + Allowi(pdx); // Make sure char reads are running mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o return iReturn; @@ -531,7 +531,7 @@ int Stat1401(DEVICE_EXTENSION * pdx) { int iReturn; mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx, false); // make sure we allow pending chars + Allowi(pdx); // make sure we allow pending chars SendChars(pdx); // in both directions iReturn = pdx->dwNumInput; // no lock as single read mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o @@ -550,7 +550,7 @@ int LineCount(DEVICE_EXTENSION * pdx) int iReturn = 0; // will be count of line ends mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx, false); // Make sure char reads are running + Allowi(pdx); // Make sure char reads are running SendChars(pdx); // and send any buffered chars spin_lock_irq(&pdx->charInLock); // Get protection diff --git a/drivers/staging/ced1401/usb1401.c b/drivers/staging/ced1401/usb1401.c index a27043a..60bed3e 100644 --- a/drivers/staging/ced1401/usb1401.c +++ b/drivers/staging/ced1401/usb1401.c @@ -697,7 +697,7 @@ static void staged_callback(struct urb *pUrb) // in Allowi as if it were protected by the char lock. In any case, most systems will // not be upset by char input during DMA... sigh. Needs sorting out. if (bRestartCharInput) // may be out of date, but... - Allowi(pdx, true); // ...Allowi tests a lock too. + Allowi(pdx); // ...Allowi tests a lock too. dev_dbg(&pdx->interface->dev, "%s done", __func__); } @@ -1172,7 +1172,7 @@ static void ced_readchar_callback(struct urb *pUrb) pdx->bReadCharsPending = false; // No longer have a pending read spin_unlock(&pdx->charInLock); // already at irq level - Allowi(pdx, true); // see if we can do the next one + Allowi(pdx); // see if we can do the next one } /**************************************************************************** @@ -1182,7 +1182,7 @@ static void ced_readchar_callback(struct urb *pUrb) ** we can pick up any inward transfers. This can be called in multiple contexts ** so we use the irqsave version of the spinlock. ****************************************************************************/ -int Allowi(DEVICE_EXTENSION * pdx, bool bInCallback) +int Allowi(DEVICE_EXTENSION * pdx) { int iReturn = U14ERR_NOERROR; unsigned long flags; @@ -1211,9 +1211,7 @@ int Allowi(DEVICE_EXTENSION * pdx, bool bInCallback) pdx, pdx->bInterval); pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // short xfers are OK by default usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); // in case we need to kill it - iReturn = - usb_submit_urb(pdx->pUrbCharIn, - bInCallback ? GFP_ATOMIC : GFP_KERNEL); + iReturn = usb_submit_urb(pdx->pUrbCharIn, GFP_ATOMIC); if (iReturn) { usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later diff --git a/drivers/staging/ced1401/usb1401.h b/drivers/staging/ced1401/usb1401.h index adb5fa4..8fc6958 100644 --- a/drivers/staging/ced1401/usb1401.h +++ b/drivers/staging/ced1401/usb1401.h @@ -204,7 +204,7 @@ typedef struct _DEVICE_EXTENSION /// Definitions of routimes used between compilation object files // in usb1401.c -extern int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback); +extern int Allowi(DEVICE_EXTENSION* pdx); extern int SendChars(DEVICE_EXTENSION* pdx); extern void ced_draw_down(DEVICE_EXTENSION *pdx); extern int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, -- cgit v0.10.2 From ca3d70bd68455133eabcb8a0ae1b40254d87188b Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Tue, 1 Jan 2013 21:24:13 -0800 Subject: staging: zram: simplify num_devices paramater Simplify dealing with num_devices when initializing zram. Also cleanup some of the output messages. Signed-off-by: Davidlohr Bueso Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index fb4a7c9..8115be9 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -40,7 +40,7 @@ static int zram_major; struct zram *zram_devices; /* Module params (documentation at end) */ -static unsigned int num_devices; +static unsigned int num_devices = 1; static void zram_stat_inc(u32 *v) { @@ -715,13 +715,7 @@ static int __init zram_init(void) goto out; } - if (!num_devices) { - pr_info("num_devices not specified. Using default: 1\n"); - num_devices = 1; - } - /* Allocate the device array and initialize each one */ - pr_info("Creating %u devices ...\n", num_devices); zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL); if (!zram_devices) { ret = -ENOMEM; @@ -734,6 +728,8 @@ static int __init zram_init(void) goto free_devices; } + pr_info("Created %u device(s) ...\n", num_devices); + return 0; free_devices: -- cgit v0.10.2 From cad683fb9d53fa2cbcf82660e663fa1180f86797 Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Tue, 1 Jan 2013 21:24:22 -0800 Subject: staging: zram: show correct disksize The ->disksize variable stores values in units of bytes, print the correct size in Kb Signed-off-by: Davidlohr Bueso Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 8115be9..10d7592 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -126,8 +126,7 @@ static void zram_set_disksize(struct zram *zram, size_t totalram_bytes) "\tMemory Size: %zu kB\n" "\tSize you selected: %llu kB\n" "Continuing anyway ...\n", - totalram_bytes >> 10, zram->disksize - ); + totalram_bytes >> 10, zram->disksize >> 10); } zram->disksize &= PAGE_MASK; -- cgit v0.10.2 From d178a07c4bd380492b6aca9e5d3985c19ca88fdb Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Tue, 1 Jan 2013 21:24:29 -0800 Subject: staging: zram: drop zram_stat_dec/inc functions It seems like an overkill to have adding and subtracting 1 functions from the 32bit counters. Just do it directly. Signed-off-by: Davidlohr Bueso Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 10d7592..6762b99 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -42,16 +42,6 @@ struct zram *zram_devices; /* Module params (documentation at end) */ static unsigned int num_devices = 1; -static void zram_stat_inc(u32 *v) -{ - *v = *v + 1; -} - -static void zram_stat_dec(u32 *v) -{ - *v = *v - 1; -} - static void zram_stat64_add(struct zram *zram, u64 *v, u64 inc) { spin_lock(&zram->stat64_lock); @@ -144,22 +134,22 @@ static void zram_free_page(struct zram *zram, size_t index) */ if (zram_test_flag(zram, index, ZRAM_ZERO)) { zram_clear_flag(zram, index, ZRAM_ZERO); - zram_stat_dec(&zram->stats.pages_zero); + zram->stats.pages_zero--; } return; } if (unlikely(size > max_zpage_size)) - zram_stat_dec(&zram->stats.bad_compress); + zram->stats.bad_compress--; zs_free(zram->mem_pool, handle); if (size <= PAGE_SIZE / 2) - zram_stat_dec(&zram->stats.good_compress); + zram->stats.good_compress--; zram_stat64_sub(zram, &zram->stats.compr_size, zram->table[index].size); - zram_stat_dec(&zram->stats.pages_stored); + zram->stats.pages_stored--; zram->table[index].handle = 0; zram->table[index].size = 0; @@ -311,7 +301,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, kunmap_atomic(user_mem); if (is_partial_io(bvec)) kfree(uncmem); - zram_stat_inc(&zram->stats.pages_zero); + zram->stats.pages_zero++; zram_set_flag(zram, index, ZRAM_ZERO); ret = 0; goto out; @@ -330,7 +320,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, } if (unlikely(clen > max_zpage_size)) { - zram_stat_inc(&zram->stats.bad_compress); + zram->stats.bad_compress++; src = uncmem; clen = PAGE_SIZE; } @@ -353,9 +343,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, /* Update stats */ zram_stat64_add(zram, &zram->stats.compr_size, clen); - zram_stat_inc(&zram->stats.pages_stored); + zram->stats.pages_stored++; if (clen <= PAGE_SIZE / 2) - zram_stat_inc(&zram->stats.good_compress); + zram->stats.good_compress++; return 0; -- cgit v0.10.2 From 1867fa64ff08b59d2c65f598c4d272397d4863c6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 15 Jan 2013 23:46:58 -0800 Subject: Staging: zcache: delete it Dan Magenheimer says that it is now safe to delete zcache, so quick, before he changes his mind, drop the thing on the floor and run screaming away. Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 329bdb4..db8a512 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -74,8 +74,6 @@ source "drivers/staging/iio/Kconfig" source "drivers/staging/zram/Kconfig" -source "drivers/staging/zcache/Kconfig" - source "drivers/staging/zsmalloc/Kconfig" source "drivers/staging/wlags49_h2/Kconfig" diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index c7ec486..a9d5479 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -31,7 +31,6 @@ obj-$(CONFIG_VME_BUS) += vme/ obj-$(CONFIG_DX_SEP) += sep/ obj-$(CONFIG_IIO) += iio/ obj-$(CONFIG_ZRAM) += zram/ -obj-$(CONFIG_ZCACHE) += zcache/ obj-$(CONFIG_ZSMALLOC) += zsmalloc/ obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig deleted file mode 100644 index 4881839..0000000 --- a/drivers/staging/zcache/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -config ZCACHE - bool "Dynamic compression of swap pages and clean pagecache pages" - depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && ZSMALLOC=y - select CRYPTO_LZO - default n - help - Zcache doubles RAM efficiency while providing a significant - performance boosts on many workloads. Zcache uses - compression and an in-kernel implementation of transcendent - memory to store clean page cache pages and swap in RAM, - providing a noticeable reduction in disk I/O. diff --git a/drivers/staging/zcache/Makefile b/drivers/staging/zcache/Makefile deleted file mode 100644 index 60daa27..0000000 --- a/drivers/staging/zcache/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -zcache-y := zcache-main.o tmem.o - -obj-$(CONFIG_ZCACHE) += zcache.o diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c deleted file mode 100644 index 56c8e60..0000000 --- a/drivers/staging/zcache/tmem.c +++ /dev/null @@ -1,773 +0,0 @@ -/* - * In-kernel transcendent memory (generic implementation) - * - * Copyright (c) 2009-2011, Dan Magenheimer, Oracle Corp. - * - * The primary purpose of Transcendent Memory ("tmem") is to map object-oriented - * "handles" (triples containing a pool id, and object id, and an index), to - * pages in a page-accessible memory (PAM). Tmem references the PAM pages via - * an abstract "pampd" (PAM page-descriptor), which can be operated on by a - * set of functions (pamops). Each pampd contains some representation of - * PAGE_SIZE bytes worth of data. Tmem must support potentially millions of - * pages and must be able to insert, find, and delete these pages at a - * potential frequency of thousands per second concurrently across many CPUs, - * (and, if used with KVM, across many vcpus across many guests). - * Tmem is tracked with a hierarchy of data structures, organized by - * the elements in a handle-tuple: pool_id, object_id, and page index. - * One or more "clients" (e.g. guests) each provide one or more tmem_pools. - * Each pool, contains a hash table of rb_trees of tmem_objs. Each - * tmem_obj contains a radix-tree-like tree of pointers, with intermediate - * nodes called tmem_objnodes. Each leaf pointer in this tree points to - * a pampd, which is accessible only through a small set of callbacks - * registered by the PAM implementation (see tmem_register_pamops). Tmem - * does all memory allocation via a set of callbacks registered by the tmem - * host implementation (e.g. see tmem_register_hostops). - */ - -#include -#include -#include - -#include "tmem.h" - -/* data structure sentinels used for debugging... see tmem.h */ -#define POOL_SENTINEL 0x87658765 -#define OBJ_SENTINEL 0x12345678 -#define OBJNODE_SENTINEL 0xfedcba09 - -/* - * A tmem host implementation must use this function to register callbacks - * for memory allocation. - */ -static struct tmem_hostops tmem_hostops; - -static void tmem_objnode_tree_init(void); - -void tmem_register_hostops(struct tmem_hostops *m) -{ - tmem_objnode_tree_init(); - tmem_hostops = *m; -} - -/* - * A tmem host implementation must use this function to register - * callbacks for a page-accessible memory (PAM) implementation - */ -static struct tmem_pamops tmem_pamops; - -void tmem_register_pamops(struct tmem_pamops *m) -{ - tmem_pamops = *m; -} - -/* - * Oid's are potentially very sparse and tmem_objs may have an indeterminately - * short life, being added and deleted at a relatively high frequency. - * So an rb_tree is an ideal data structure to manage tmem_objs. But because - * of the potentially huge number of tmem_objs, each pool manages a hashtable - * of rb_trees to reduce search, insert, delete, and rebalancing time. - * Each hashbucket also has a lock to manage concurrent access. - * - * The following routines manage tmem_objs. When any tmem_obj is accessed, - * the hashbucket lock must be held. - */ - -static struct tmem_obj -*__tmem_obj_find(struct tmem_hashbucket*hb, struct tmem_oid *oidp, - struct rb_node **parent, struct rb_node ***link) -{ - struct rb_node *_parent = NULL, **rbnode; - struct tmem_obj *obj = NULL; - - rbnode = &hb->obj_rb_root.rb_node; - while (*rbnode) { - BUG_ON(RB_EMPTY_NODE(*rbnode)); - _parent = *rbnode; - obj = rb_entry(*rbnode, struct tmem_obj, - rb_tree_node); - switch (tmem_oid_compare(oidp, &obj->oid)) { - case 0: /* equal */ - goto out; - case -1: - rbnode = &(*rbnode)->rb_left; - break; - case 1: - rbnode = &(*rbnode)->rb_right; - break; - } - } - - if (parent) - *parent = _parent; - if (link) - *link = rbnode; - - obj = NULL; -out: - return obj; -} - - -/* searches for object==oid in pool, returns locked object if found */ -static struct tmem_obj *tmem_obj_find(struct tmem_hashbucket *hb, - struct tmem_oid *oidp) -{ - return __tmem_obj_find(hb, oidp, NULL, NULL); -} - -static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *); - -/* free an object that has no more pampds in it */ -static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb) -{ - struct tmem_pool *pool; - - BUG_ON(obj == NULL); - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pampd_count > 0); - pool = obj->pool; - BUG_ON(pool == NULL); - if (obj->objnode_tree_root != NULL) /* may be "stump" with no leaves */ - tmem_pampd_destroy_all_in_obj(obj); - BUG_ON(obj->objnode_tree_root != NULL); - BUG_ON((long)obj->objnode_count != 0); - atomic_dec(&pool->obj_count); - BUG_ON(atomic_read(&pool->obj_count) < 0); - INVERT_SENTINEL(obj, OBJ); - obj->pool = NULL; - tmem_oid_set_invalid(&obj->oid); - rb_erase(&obj->rb_tree_node, &hb->obj_rb_root); -} - -/* - * initialize, and insert an tmem_object_root (called only if find failed) - */ -static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb, - struct tmem_pool *pool, - struct tmem_oid *oidp) -{ - struct rb_root *root = &hb->obj_rb_root; - struct rb_node **new = NULL, *parent = NULL; - - BUG_ON(pool == NULL); - atomic_inc(&pool->obj_count); - obj->objnode_tree_height = 0; - obj->objnode_tree_root = NULL; - obj->pool = pool; - obj->oid = *oidp; - obj->objnode_count = 0; - obj->pampd_count = 0; - (*tmem_pamops.new_obj)(obj); - SET_SENTINEL(obj, OBJ); - - if (__tmem_obj_find(hb, oidp, &parent, &new)) - BUG(); - - rb_link_node(&obj->rb_tree_node, parent, new); - rb_insert_color(&obj->rb_tree_node, root); -} - -/* - * Tmem is managed as a set of tmem_pools with certain attributes, such as - * "ephemeral" vs "persistent". These attributes apply to all tmem_objs - * and all pampds that belong to a tmem_pool. A tmem_pool is created - * or deleted relatively rarely (for example, when a filesystem is - * mounted or unmounted. - */ - -/* flush all data from a pool and, optionally, free it */ -static void tmem_pool_flush(struct tmem_pool *pool, bool destroy) -{ - struct rb_node *rbnode; - struct tmem_obj *obj; - struct tmem_hashbucket *hb = &pool->hashbucket[0]; - int i; - - BUG_ON(pool == NULL); - for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) { - spin_lock(&hb->lock); - rbnode = rb_first(&hb->obj_rb_root); - while (rbnode != NULL) { - obj = rb_entry(rbnode, struct tmem_obj, rb_tree_node); - rbnode = rb_next(rbnode); - tmem_pampd_destroy_all_in_obj(obj); - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - } - spin_unlock(&hb->lock); - } - if (destroy) - list_del(&pool->pool_list); -} - -/* - * A tmem_obj contains a radix-tree-like tree in which the intermediate - * nodes are called tmem_objnodes. (The kernel lib/radix-tree.c implementation - * is very specialized and tuned for specific uses and is not particularly - * suited for use from this code, though some code from the core algorithms has - * been reused, thus the copyright notices below). Each tmem_objnode contains - * a set of pointers which point to either a set of intermediate tmem_objnodes - * or a set of of pampds. - * - * Portions Copyright (C) 2001 Momchil Velikov - * Portions Copyright (C) 2001 Christoph Hellwig - * Portions Copyright (C) 2005 SGI, Christoph Lameter - */ - -struct tmem_objnode_tree_path { - struct tmem_objnode *objnode; - int offset; -}; - -/* objnode height_to_maxindex translation */ -static unsigned long tmem_objnode_tree_h2max[OBJNODE_TREE_MAX_PATH + 1]; - -static void tmem_objnode_tree_init(void) -{ - unsigned int ht, tmp; - - for (ht = 0; ht < ARRAY_SIZE(tmem_objnode_tree_h2max); ht++) { - tmp = ht * OBJNODE_TREE_MAP_SHIFT; - if (tmp >= OBJNODE_TREE_INDEX_BITS) - tmem_objnode_tree_h2max[ht] = ~0UL; - else - tmem_objnode_tree_h2max[ht] = - (~0UL >> (OBJNODE_TREE_INDEX_BITS - tmp - 1)) >> 1; - } -} - -static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj) -{ - struct tmem_objnode *objnode; - - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pool == NULL); - ASSERT_SENTINEL(obj->pool, POOL); - objnode = (*tmem_hostops.objnode_alloc)(obj->pool); - if (unlikely(objnode == NULL)) - goto out; - objnode->obj = obj; - SET_SENTINEL(objnode, OBJNODE); - memset(&objnode->slots, 0, sizeof(objnode->slots)); - objnode->slots_in_use = 0; - obj->objnode_count++; -out: - return objnode; -} - -static void tmem_objnode_free(struct tmem_objnode *objnode) -{ - struct tmem_pool *pool; - int i; - - BUG_ON(objnode == NULL); - for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) - BUG_ON(objnode->slots[i] != NULL); - ASSERT_SENTINEL(objnode, OBJNODE); - INVERT_SENTINEL(objnode, OBJNODE); - BUG_ON(objnode->obj == NULL); - ASSERT_SENTINEL(objnode->obj, OBJ); - pool = objnode->obj->pool; - BUG_ON(pool == NULL); - ASSERT_SENTINEL(pool, POOL); - objnode->obj->objnode_count--; - objnode->obj = NULL; - (*tmem_hostops.objnode_free)(objnode, pool); -} - -/* - * lookup index in object and return associated pampd (or NULL if not found) - */ -static void **__tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) -{ - unsigned int height, shift; - struct tmem_objnode **slot = NULL; - - BUG_ON(obj == NULL); - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pool == NULL); - ASSERT_SENTINEL(obj->pool, POOL); - - height = obj->objnode_tree_height; - if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) - goto out; - if (height == 0 && obj->objnode_tree_root) { - slot = &obj->objnode_tree_root; - goto out; - } - shift = (height-1) * OBJNODE_TREE_MAP_SHIFT; - slot = &obj->objnode_tree_root; - while (height > 0) { - if (*slot == NULL) - goto out; - slot = (struct tmem_objnode **) - ((*slot)->slots + - ((index >> shift) & OBJNODE_TREE_MAP_MASK)); - shift -= OBJNODE_TREE_MAP_SHIFT; - height--; - } -out: - return slot != NULL ? (void **)slot : NULL; -} - -static void *tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) -{ - struct tmem_objnode **slot; - - slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index); - return slot != NULL ? *slot : NULL; -} - -static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index, - void *new_pampd) -{ - struct tmem_objnode **slot; - void *ret = NULL; - - slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index); - if ((slot != NULL) && (*slot != NULL)) { - void *old_pampd = *(void **)slot; - *(void **)slot = new_pampd; - (*tmem_pamops.free)(old_pampd, obj->pool, NULL, 0); - ret = new_pampd; - } - return ret; -} - -static int tmem_pampd_add_to_obj(struct tmem_obj *obj, uint32_t index, - void *pampd) -{ - int ret = 0; - struct tmem_objnode *objnode = NULL, *newnode, *slot; - unsigned int height, shift; - int offset = 0; - - /* if necessary, extend the tree to be higher */ - if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) { - height = obj->objnode_tree_height + 1; - if (index > tmem_objnode_tree_h2max[height]) - while (index > tmem_objnode_tree_h2max[height]) - height++; - if (obj->objnode_tree_root == NULL) { - obj->objnode_tree_height = height; - goto insert; - } - do { - newnode = tmem_objnode_alloc(obj); - if (!newnode) { - ret = -ENOMEM; - goto out; - } - newnode->slots[0] = obj->objnode_tree_root; - newnode->slots_in_use = 1; - obj->objnode_tree_root = newnode; - obj->objnode_tree_height++; - } while (height > obj->objnode_tree_height); - } -insert: - slot = obj->objnode_tree_root; - height = obj->objnode_tree_height; - shift = (height-1) * OBJNODE_TREE_MAP_SHIFT; - while (height > 0) { - if (slot == NULL) { - /* add a child objnode. */ - slot = tmem_objnode_alloc(obj); - if (!slot) { - ret = -ENOMEM; - goto out; - } - if (objnode) { - - objnode->slots[offset] = slot; - objnode->slots_in_use++; - } else - obj->objnode_tree_root = slot; - } - /* go down a level */ - offset = (index >> shift) & OBJNODE_TREE_MAP_MASK; - objnode = slot; - slot = objnode->slots[offset]; - shift -= OBJNODE_TREE_MAP_SHIFT; - height--; - } - BUG_ON(slot != NULL); - if (objnode) { - objnode->slots_in_use++; - objnode->slots[offset] = pampd; - } else - obj->objnode_tree_root = pampd; - obj->pampd_count++; -out: - return ret; -} - -static void *tmem_pampd_delete_from_obj(struct tmem_obj *obj, uint32_t index) -{ - struct tmem_objnode_tree_path path[OBJNODE_TREE_MAX_PATH + 1]; - struct tmem_objnode_tree_path *pathp = path; - struct tmem_objnode *slot = NULL; - unsigned int height, shift; - int offset; - - BUG_ON(obj == NULL); - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pool == NULL); - ASSERT_SENTINEL(obj->pool, POOL); - height = obj->objnode_tree_height; - if (index > tmem_objnode_tree_h2max[height]) - goto out; - slot = obj->objnode_tree_root; - if (height == 0 && obj->objnode_tree_root) { - obj->objnode_tree_root = NULL; - goto out; - } - shift = (height - 1) * OBJNODE_TREE_MAP_SHIFT; - pathp->objnode = NULL; - do { - if (slot == NULL) - goto out; - pathp++; - offset = (index >> shift) & OBJNODE_TREE_MAP_MASK; - pathp->offset = offset; - pathp->objnode = slot; - slot = slot->slots[offset]; - shift -= OBJNODE_TREE_MAP_SHIFT; - height--; - } while (height > 0); - if (slot == NULL) - goto out; - while (pathp->objnode) { - pathp->objnode->slots[pathp->offset] = NULL; - pathp->objnode->slots_in_use--; - if (pathp->objnode->slots_in_use) { - if (pathp->objnode == obj->objnode_tree_root) { - while (obj->objnode_tree_height > 0 && - obj->objnode_tree_root->slots_in_use == 1 && - obj->objnode_tree_root->slots[0]) { - struct tmem_objnode *to_free = - obj->objnode_tree_root; - - obj->objnode_tree_root = - to_free->slots[0]; - obj->objnode_tree_height--; - to_free->slots[0] = NULL; - to_free->slots_in_use = 0; - tmem_objnode_free(to_free); - } - } - goto out; - } - tmem_objnode_free(pathp->objnode); /* 0 slots used, free it */ - pathp--; - } - obj->objnode_tree_height = 0; - obj->objnode_tree_root = NULL; - -out: - if (slot != NULL) - obj->pampd_count--; - BUG_ON(obj->pampd_count < 0); - return slot; -} - -/* recursively walk the objnode_tree destroying pampds and objnodes */ -static void tmem_objnode_node_destroy(struct tmem_obj *obj, - struct tmem_objnode *objnode, - unsigned int ht) -{ - int i; - - if (ht == 0) - return; - for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) { - if (objnode->slots[i]) { - if (ht == 1) { - obj->pampd_count--; - (*tmem_pamops.free)(objnode->slots[i], - obj->pool, NULL, 0); - objnode->slots[i] = NULL; - continue; - } - tmem_objnode_node_destroy(obj, objnode->slots[i], ht-1); - tmem_objnode_free(objnode->slots[i]); - objnode->slots[i] = NULL; - } - } -} - -static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj) -{ - if (obj->objnode_tree_root == NULL) - return; - if (obj->objnode_tree_height == 0) { - obj->pampd_count--; - (*tmem_pamops.free)(obj->objnode_tree_root, obj->pool, NULL, 0); - } else { - tmem_objnode_node_destroy(obj, obj->objnode_tree_root, - obj->objnode_tree_height); - tmem_objnode_free(obj->objnode_tree_root); - obj->objnode_tree_height = 0; - } - obj->objnode_tree_root = NULL; - (*tmem_pamops.free_obj)(obj->pool, obj); -} - -/* - * Tmem is operated on by a set of well-defined actions: - * "put", "get", "flush", "flush_object", "new pool" and "destroy pool". - * (The tmem ABI allows for subpages and exchanges but these operations - * are not included in this implementation.) - * - * These "tmem core" operations are implemented in the following functions. - */ - -/* - * "Put" a page, e.g. copy a page from the kernel into newly allocated - * PAM space (if such space is available). Tmem_put is complicated by - * a corner case: What if a page with matching handle already exists in - * tmem? To guarantee coherency, one of two actions is necessary: Either - * the data for the page must be overwritten, or the page must be - * "flushed" so that the data is not accessible to a subsequent "get". - * Since these "duplicate puts" are relatively rare, this implementation - * always flushes for simplicity. - */ -int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, - char *data, size_t size, bool raw, bool ephemeral) -{ - struct tmem_obj *obj = NULL, *objfound = NULL, *objnew = NULL; - void *pampd = NULL, *pampd_del = NULL; - int ret = -ENOMEM; - struct tmem_hashbucket *hb; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = objfound = tmem_obj_find(hb, oidp); - if (obj != NULL) { - pampd = tmem_pampd_lookup_in_obj(objfound, index); - if (pampd != NULL) { - /* if found, is a dup put, flush the old one */ - pampd_del = tmem_pampd_delete_from_obj(obj, index); - BUG_ON(pampd_del != pampd); - (*tmem_pamops.free)(pampd, pool, oidp, index); - if (obj->pampd_count == 0) { - objnew = obj; - objfound = NULL; - } - pampd = NULL; - } - } else { - obj = objnew = (*tmem_hostops.obj_alloc)(pool); - if (unlikely(obj == NULL)) { - ret = -ENOMEM; - goto out; - } - tmem_obj_init(obj, hb, pool, oidp); - } - BUG_ON(obj == NULL); - BUG_ON(((objnew != obj) && (objfound != obj)) || (objnew == objfound)); - pampd = (*tmem_pamops.create)(data, size, raw, ephemeral, - obj->pool, &obj->oid, index); - if (unlikely(pampd == NULL)) - goto free; - ret = tmem_pampd_add_to_obj(obj, index, pampd); - if (unlikely(ret == -ENOMEM)) - /* may have partially built objnode tree ("stump") */ - goto delete_and_free; - goto out; - -delete_and_free: - (void)tmem_pampd_delete_from_obj(obj, index); -free: - if (pampd) - (*tmem_pamops.free)(pampd, pool, NULL, 0); - if (objnew) { - tmem_obj_free(objnew, hb); - (*tmem_hostops.obj_free)(objnew, pool); - } -out: - spin_unlock(&hb->lock); - return ret; -} - -/* - * "Get" a page, e.g. if one can be found, copy the tmem page with the - * matching handle from PAM space to the kernel. By tmem definition, - * when a "get" is successful on an ephemeral page, the page is "flushed", - * and when a "get" is successful on a persistent page, the page is retained - * in tmem. Note that to preserve - * coherency, "get" can never be skipped if tmem contains the data. - * That is, if a get is done with a certain handle and fails, any - * subsequent "get" must also fail (unless of course there is a - * "put" done with the same handle). - - */ -int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, - char *data, size_t *size, bool raw, int get_and_free) -{ - struct tmem_obj *obj; - void *pampd; - bool ephemeral = is_ephemeral(pool); - int ret = -1; - struct tmem_hashbucket *hb; - bool free = (get_and_free == 1) || ((get_and_free == 0) && ephemeral); - bool lock_held = false; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - lock_held = true; - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - if (free) - pampd = tmem_pampd_delete_from_obj(obj, index); - else - pampd = tmem_pampd_lookup_in_obj(obj, index); - if (pampd == NULL) - goto out; - if (free) { - if (obj->pampd_count == 0) { - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - obj = NULL; - } - } - if (tmem_pamops.is_remote(pampd)) { - lock_held = false; - spin_unlock(&hb->lock); - } - if (free) - ret = (*tmem_pamops.get_data_and_free)( - data, size, raw, pampd, pool, oidp, index); - else - ret = (*tmem_pamops.get_data)( - data, size, raw, pampd, pool, oidp, index); - if (ret < 0) - goto out; - ret = 0; -out: - if (lock_held) - spin_unlock(&hb->lock); - return ret; -} - -/* - * If a page in tmem matches the handle, "flush" this page from tmem such - * that any subsequent "get" does not succeed (unless, of course, there - * was another "put" with the same handle). - */ -int tmem_flush_page(struct tmem_pool *pool, - struct tmem_oid *oidp, uint32_t index) -{ - struct tmem_obj *obj; - void *pampd; - int ret = -1; - struct tmem_hashbucket *hb; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - pampd = tmem_pampd_delete_from_obj(obj, index); - if (pampd == NULL) - goto out; - (*tmem_pamops.free)(pampd, pool, oidp, index); - if (obj->pampd_count == 0) { - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - } - ret = 0; - -out: - spin_unlock(&hb->lock); - return ret; -} - -/* - * If a page in tmem matches the handle, replace the page so that any - * subsequent "get" gets the new page. Returns 0 if - * there was a page to replace, else returns -1. - */ -int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp, - uint32_t index, void *new_pampd) -{ - struct tmem_obj *obj; - int ret = -1; - struct tmem_hashbucket *hb; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd); - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj); -out: - spin_unlock(&hb->lock); - return ret; -} - -/* - * "Flush" all pages in tmem matching this oid. - */ -int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp) -{ - struct tmem_obj *obj; - struct tmem_hashbucket *hb; - int ret = -1; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - tmem_pampd_destroy_all_in_obj(obj); - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - ret = 0; - -out: - spin_unlock(&hb->lock); - return ret; -} - -/* - * "Flush" all pages (and tmem_objs) from this tmem_pool and disable - * all subsequent access to this tmem_pool. - */ -int tmem_destroy_pool(struct tmem_pool *pool) -{ - int ret = -1; - - if (pool == NULL) - goto out; - tmem_pool_flush(pool, 1); - ret = 0; -out: - return ret; -} - -static LIST_HEAD(tmem_global_pool_list); - -/* - * Create a new tmem_pool with the provided flag and return - * a pool id provided by the tmem host implementation. - */ -void tmem_new_pool(struct tmem_pool *pool, uint32_t flags) -{ - int persistent = flags & TMEM_POOL_PERSIST; - int shared = flags & TMEM_POOL_SHARED; - struct tmem_hashbucket *hb = &pool->hashbucket[0]; - int i; - - for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) { - hb->obj_rb_root = RB_ROOT; - spin_lock_init(&hb->lock); - } - INIT_LIST_HEAD(&pool->pool_list); - atomic_set(&pool->obj_count, 0); - SET_SENTINEL(pool, POOL); - list_add_tail(&pool->pool_list, &tmem_global_pool_list); - pool->persistent = persistent; - pool->shared = shared; -} diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h deleted file mode 100644 index 0d4aa82..0000000 --- a/drivers/staging/zcache/tmem.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * tmem.h - * - * Transcendent memory - * - * Copyright (c) 2009-2011, Dan Magenheimer, Oracle Corp. - */ - -#ifndef _TMEM_H_ -#define _TMEM_H_ - -#include -#include -#include -#include - -/* - * These are pre-defined by the Xen<->Linux ABI - */ -#define TMEM_PUT_PAGE 4 -#define TMEM_GET_PAGE 5 -#define TMEM_FLUSH_PAGE 6 -#define TMEM_FLUSH_OBJECT 7 -#define TMEM_POOL_PERSIST 1 -#define TMEM_POOL_SHARED 2 -#define TMEM_POOL_PRECOMPRESSED 4 -#define TMEM_POOL_PAGESIZE_SHIFT 4 -#define TMEM_POOL_PAGESIZE_MASK 0xf -#define TMEM_POOL_RESERVED_BITS 0x00ffff00 - -/* - * sentinels have proven very useful for debugging but can be removed - * or disabled before final merge. - */ -#define SENTINELS -#ifdef SENTINELS -#define DECL_SENTINEL uint32_t sentinel; -#define SET_SENTINEL(_x, _y) (_x->sentinel = _y##_SENTINEL) -#define INVERT_SENTINEL(_x, _y) (_x->sentinel = ~_y##_SENTINEL) -#define ASSERT_SENTINEL(_x, _y) WARN_ON(_x->sentinel != _y##_SENTINEL) -#define ASSERT_INVERTED_SENTINEL(_x, _y) WARN_ON(_x->sentinel != ~_y##_SENTINEL) -#else -#define DECL_SENTINEL -#define SET_SENTINEL(_x, _y) do { } while (0) -#define INVERT_SENTINEL(_x, _y) do { } while (0) -#define ASSERT_SENTINEL(_x, _y) do { } while (0) -#define ASSERT_INVERTED_SENTINEL(_x, _y) do { } while (0) -#endif - -#define ASSERT_SPINLOCK(_l) lockdep_assert_held(_l) - -/* - * A pool is the highest-level data structure managed by tmem and - * usually corresponds to a large independent set of pages such as - * a filesystem. Each pool has an id, and certain attributes and counters. - * It also contains a set of hash buckets, each of which contains an rbtree - * of objects and a lock to manage concurrency within the pool. - */ - -#define TMEM_HASH_BUCKET_BITS 8 -#define TMEM_HASH_BUCKETS (1<persistent) -#define is_ephemeral(_p) (!(_p->persistent)) - -/* - * An object id ("oid") is large: 192-bits (to ensure, for example, files - * in a modern filesystem can be uniquely identified). - */ - -struct tmem_oid { - uint64_t oid[3]; -}; - -static inline void tmem_oid_set_invalid(struct tmem_oid *oidp) -{ - oidp->oid[0] = oidp->oid[1] = oidp->oid[2] = -1UL; -} - -static inline bool tmem_oid_valid(struct tmem_oid *oidp) -{ - return oidp->oid[0] != -1UL || oidp->oid[1] != -1UL || - oidp->oid[2] != -1UL; -} - -static inline int tmem_oid_compare(struct tmem_oid *left, - struct tmem_oid *right) -{ - int ret; - - if (left->oid[2] == right->oid[2]) { - if (left->oid[1] == right->oid[1]) { - if (left->oid[0] == right->oid[0]) - ret = 0; - else if (left->oid[0] < right->oid[0]) - ret = -1; - else - return 1; - } else if (left->oid[1] < right->oid[1]) - ret = -1; - else - ret = 1; - } else if (left->oid[2] < right->oid[2]) - ret = -1; - else - ret = 1; - return ret; -} - -static inline unsigned tmem_oid_hash(struct tmem_oid *oidp) -{ - return hash_long(oidp->oid[0] ^ oidp->oid[1] ^ oidp->oid[2], - TMEM_HASH_BUCKET_BITS); -} - -/* - * A tmem_obj contains an identifier (oid), pointers to the parent - * pool and the rb_tree to which it belongs, counters, and an ordered - * set of pampds, structured in a radix-tree-like tree. The intermediate - * nodes of the tree are called tmem_objnodes. - */ - -struct tmem_objnode; - -struct tmem_obj { - struct tmem_oid oid; - struct tmem_pool *pool; - struct rb_node rb_tree_node; - struct tmem_objnode *objnode_tree_root; - unsigned int objnode_tree_height; - unsigned long objnode_count; - long pampd_count; - void *extra; /* for private use by pampd implementation */ - DECL_SENTINEL -}; - -#define OBJNODE_TREE_MAP_SHIFT 6 -#define OBJNODE_TREE_MAP_SIZE (1UL << OBJNODE_TREE_MAP_SHIFT) -#define OBJNODE_TREE_MAP_MASK (OBJNODE_TREE_MAP_SIZE-1) -#define OBJNODE_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long)) -#define OBJNODE_TREE_MAX_PATH \ - (OBJNODE_TREE_INDEX_BITS/OBJNODE_TREE_MAP_SHIFT + 2) - -struct tmem_objnode { - struct tmem_obj *obj; - DECL_SENTINEL - void *slots[OBJNODE_TREE_MAP_SIZE]; - unsigned int slots_in_use; -}; - -/* pampd abstract datatype methods provided by the PAM implementation */ -struct tmem_pamops { - void *(*create)(char *, size_t, bool, int, - struct tmem_pool *, struct tmem_oid *, uint32_t); - int (*get_data)(char *, size_t *, bool, void *, struct tmem_pool *, - struct tmem_oid *, uint32_t); - int (*get_data_and_free)(char *, size_t *, bool, void *, - struct tmem_pool *, struct tmem_oid *, - uint32_t); - void (*free)(void *, struct tmem_pool *, struct tmem_oid *, uint32_t); - void (*free_obj)(struct tmem_pool *, struct tmem_obj *); - bool (*is_remote)(void *); - void (*new_obj)(struct tmem_obj *); - int (*replace_in_obj)(void *, struct tmem_obj *); -}; -extern void tmem_register_pamops(struct tmem_pamops *m); - -/* memory allocation methods provided by the host implementation */ -struct tmem_hostops { - struct tmem_obj *(*obj_alloc)(struct tmem_pool *); - void (*obj_free)(struct tmem_obj *, struct tmem_pool *); - struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *); - void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *); -}; -extern void tmem_register_hostops(struct tmem_hostops *m); - -/* core tmem accessor functions */ -extern int tmem_put(struct tmem_pool *, struct tmem_oid *, uint32_t index, - char *, size_t, bool, bool); -extern int tmem_get(struct tmem_pool *, struct tmem_oid *, uint32_t index, - char *, size_t *, bool, int); -extern int tmem_replace(struct tmem_pool *, struct tmem_oid *, uint32_t index, - void *); -extern int tmem_flush_page(struct tmem_pool *, struct tmem_oid *, - uint32_t index); -extern int tmem_flush_object(struct tmem_pool *, struct tmem_oid *); -extern int tmem_destroy_pool(struct tmem_pool *); -extern void tmem_new_pool(struct tmem_pool *, uint32_t); -#endif /* _TMEM_H */ diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c deleted file mode 100644 index 52b43b7..0000000 --- a/drivers/staging/zcache/zcache-main.c +++ /dev/null @@ -1,2077 +0,0 @@ -/* - * zcache.c - * - * Copyright (c) 2010,2011, Dan Magenheimer, Oracle Corp. - * Copyright (c) 2010,2011, Nitin Gupta - * - * Zcache provides an in-kernel "host implementation" for transcendent memory - * and, thus indirectly, for cleancache and frontswap. Zcache includes two - * page-accessible memory [1] interfaces, both utilizing the crypto compression - * API: - * 1) "compression buddies" ("zbud") is used for ephemeral pages - * 2) zsmalloc is used for persistent pages. - * Xvmalloc (based on the TLSF allocator) has very low fragmentation - * so maximizes space efficiency, while zbud allows pairs (and potentially, - * in the future, more than a pair of) compressed pages to be closely linked - * so that reclaiming can be done via the kernel's physical-page-oriented - * "shrinker" interface. - * - * [1] For a definition of page-accessible memory (aka PAM), see: - * http://marc.info/?l=linux-mm&m=127811271605009 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "tmem.h" - -#include "../zsmalloc/zsmalloc.h" - -#ifdef CONFIG_CLEANCACHE -#include -#endif -#ifdef CONFIG_FRONTSWAP -#include -#endif - -#if 0 -/* this is more aggressive but may cause other problems? */ -#define ZCACHE_GFP_MASK (GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN) -#else -#define ZCACHE_GFP_MASK \ - (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC) -#endif - -#define MAX_CLIENTS 16 -#define LOCAL_CLIENT ((uint16_t)-1) - -MODULE_LICENSE("GPL"); - -struct zcache_client { - struct idr tmem_pools; - struct zs_pool *zspool; - bool allocated; - atomic_t refcount; -}; - -static struct zcache_client zcache_host; -static struct zcache_client zcache_clients[MAX_CLIENTS]; - -static inline uint16_t get_client_id_from_client(struct zcache_client *cli) -{ - BUG_ON(cli == NULL); - if (cli == &zcache_host) - return LOCAL_CLIENT; - return cli - &zcache_clients[0]; -} - -static struct zcache_client *get_zcache_client(uint16_t cli_id) -{ - if (cli_id == LOCAL_CLIENT) - return &zcache_host; - - if ((unsigned int)cli_id < MAX_CLIENTS) - return &zcache_clients[cli_id]; - - return NULL; -} - -static inline bool is_local_client(struct zcache_client *cli) -{ - return cli == &zcache_host; -} - -/* crypto API for zcache */ -#define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME -static char zcache_comp_name[ZCACHE_COMP_NAME_SZ]; -static struct crypto_comp * __percpu *zcache_comp_pcpu_tfms; - -enum comp_op { - ZCACHE_COMPOP_COMPRESS, - ZCACHE_COMPOP_DECOMPRESS -}; - -static inline int zcache_comp_op(enum comp_op op, - const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen) -{ - struct crypto_comp *tfm; - int ret; - - BUG_ON(!zcache_comp_pcpu_tfms); - tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, get_cpu()); - BUG_ON(!tfm); - switch (op) { - case ZCACHE_COMPOP_COMPRESS: - ret = crypto_comp_compress(tfm, src, slen, dst, dlen); - break; - case ZCACHE_COMPOP_DECOMPRESS: - ret = crypto_comp_decompress(tfm, src, slen, dst, dlen); - break; - default: - ret = -EINVAL; - } - put_cpu(); - return ret; -} - -/********** - * Compression buddies ("zbud") provides for packing two (or, possibly - * in the future, more) compressed ephemeral pages into a single "raw" - * (physical) page and tracking them with data structures so that - * the raw pages can be easily reclaimed. - * - * A zbud page ("zbpg") is an aligned page containing a list_head, - * a lock, and two "zbud headers". The remainder of the physical - * page is divided up into aligned 64-byte "chunks" which contain - * the compressed data for zero, one, or two zbuds. Each zbpg - * resides on: (1) an "unused list" if it has no zbuds; (2) a - * "buddied" list if it is fully populated with two zbuds; or - * (3) one of PAGE_SIZE/64 "unbuddied" lists indexed by how many chunks - * the one unbuddied zbud uses. The data inside a zbpg cannot be - * read or written unless the zbpg's lock is held. - */ - -#define ZBH_SENTINEL 0x43214321 -#define ZBPG_SENTINEL 0xdeadbeef - -#define ZBUD_MAX_BUDS 2 - -struct zbud_hdr { - uint16_t client_id; - uint16_t pool_id; - struct tmem_oid oid; - uint32_t index; - uint16_t size; /* compressed size in bytes, zero means unused */ - DECL_SENTINEL -}; - -struct zbud_page { - struct list_head bud_list; - spinlock_t lock; - struct zbud_hdr buddy[ZBUD_MAX_BUDS]; - DECL_SENTINEL - /* followed by NUM_CHUNK aligned CHUNK_SIZE-byte chunks */ -}; - -#define CHUNK_SHIFT 6 -#define CHUNK_SIZE (1 << CHUNK_SHIFT) -#define CHUNK_MASK (~(CHUNK_SIZE-1)) -#define NCHUNKS (((PAGE_SIZE - sizeof(struct zbud_page)) & \ - CHUNK_MASK) >> CHUNK_SHIFT) -#define MAX_CHUNK (NCHUNKS-1) - -static struct { - struct list_head list; - unsigned count; -} zbud_unbuddied[NCHUNKS]; -/* list N contains pages with N chunks USED and NCHUNKS-N unused */ -/* element 0 is never used but optimizing that isn't worth it */ -static unsigned long zbud_cumul_chunk_counts[NCHUNKS]; - -struct list_head zbud_buddied_list; -static unsigned long zcache_zbud_buddied_count; - -/* protects the buddied list and all unbuddied lists */ -static DEFINE_SPINLOCK(zbud_budlists_spinlock); - -static LIST_HEAD(zbpg_unused_list); -static unsigned long zcache_zbpg_unused_list_count; - -/* protects the unused page list */ -static DEFINE_SPINLOCK(zbpg_unused_list_spinlock); - -static atomic_t zcache_zbud_curr_raw_pages; -static atomic_t zcache_zbud_curr_zpages; -static unsigned long zcache_zbud_curr_zbytes; -static unsigned long zcache_zbud_cumul_zpages; -static unsigned long zcache_zbud_cumul_zbytes; -static unsigned long zcache_compress_poor; -static unsigned long zcache_mean_compress_poor; - -/* forward references */ -static void *zcache_get_free_page(void); -static void zcache_free_page(void *p); - -/* - * zbud helper functions - */ - -static inline unsigned zbud_max_buddy_size(void) -{ - return MAX_CHUNK << CHUNK_SHIFT; -} - -static inline unsigned zbud_size_to_chunks(unsigned size) -{ - BUG_ON(size == 0 || size > zbud_max_buddy_size()); - return (size + CHUNK_SIZE - 1) >> CHUNK_SHIFT; -} - -static inline int zbud_budnum(struct zbud_hdr *zh) -{ - unsigned offset = (unsigned long)zh & (PAGE_SIZE - 1); - struct zbud_page *zbpg = NULL; - unsigned budnum = -1U; - int i; - - for (i = 0; i < ZBUD_MAX_BUDS; i++) - if (offset == offsetof(typeof(*zbpg), buddy[i])) { - budnum = i; - break; - } - BUG_ON(budnum == -1U); - return budnum; -} - -static char *zbud_data(struct zbud_hdr *zh, unsigned size) -{ - struct zbud_page *zbpg; - char *p; - unsigned budnum; - - ASSERT_SENTINEL(zh, ZBH); - budnum = zbud_budnum(zh); - BUG_ON(size == 0 || size > zbud_max_buddy_size()); - zbpg = container_of(zh, struct zbud_page, buddy[budnum]); - ASSERT_SPINLOCK(&zbpg->lock); - p = (char *)zbpg; - if (budnum == 0) - p += ((sizeof(struct zbud_page) + CHUNK_SIZE - 1) & - CHUNK_MASK); - else if (budnum == 1) - p += PAGE_SIZE - ((size + CHUNK_SIZE - 1) & CHUNK_MASK); - return p; -} - -/* - * zbud raw page management - */ - -static struct zbud_page *zbud_alloc_raw_page(void) -{ - struct zbud_page *zbpg = NULL; - struct zbud_hdr *zh0, *zh1; - bool recycled = 0; - - /* if any pages on the zbpg list, use one */ - spin_lock(&zbpg_unused_list_spinlock); - if (!list_empty(&zbpg_unused_list)) { - zbpg = list_first_entry(&zbpg_unused_list, - struct zbud_page, bud_list); - list_del_init(&zbpg->bud_list); - zcache_zbpg_unused_list_count--; - recycled = 1; - } - spin_unlock(&zbpg_unused_list_spinlock); - if (zbpg == NULL) - /* none on zbpg list, try to get a kernel page */ - zbpg = zcache_get_free_page(); - if (likely(zbpg != NULL)) { - INIT_LIST_HEAD(&zbpg->bud_list); - zh0 = &zbpg->buddy[0]; zh1 = &zbpg->buddy[1]; - spin_lock_init(&zbpg->lock); - if (recycled) { - ASSERT_INVERTED_SENTINEL(zbpg, ZBPG); - SET_SENTINEL(zbpg, ZBPG); - BUG_ON(zh0->size != 0 || tmem_oid_valid(&zh0->oid)); - BUG_ON(zh1->size != 0 || tmem_oid_valid(&zh1->oid)); - } else { - atomic_inc(&zcache_zbud_curr_raw_pages); - INIT_LIST_HEAD(&zbpg->bud_list); - SET_SENTINEL(zbpg, ZBPG); - zh0->size = 0; zh1->size = 0; - tmem_oid_set_invalid(&zh0->oid); - tmem_oid_set_invalid(&zh1->oid); - } - } - return zbpg; -} - -static void zbud_free_raw_page(struct zbud_page *zbpg) -{ - struct zbud_hdr *zh0 = &zbpg->buddy[0], *zh1 = &zbpg->buddy[1]; - - ASSERT_SENTINEL(zbpg, ZBPG); - BUG_ON(!list_empty(&zbpg->bud_list)); - ASSERT_SPINLOCK(&zbpg->lock); - BUG_ON(zh0->size != 0 || tmem_oid_valid(&zh0->oid)); - BUG_ON(zh1->size != 0 || tmem_oid_valid(&zh1->oid)); - INVERT_SENTINEL(zbpg, ZBPG); - spin_unlock(&zbpg->lock); - spin_lock(&zbpg_unused_list_spinlock); - list_add(&zbpg->bud_list, &zbpg_unused_list); - zcache_zbpg_unused_list_count++; - spin_unlock(&zbpg_unused_list_spinlock); -} - -/* - * core zbud handling routines - */ - -static unsigned zbud_free(struct zbud_hdr *zh) -{ - unsigned size; - - ASSERT_SENTINEL(zh, ZBH); - BUG_ON(!tmem_oid_valid(&zh->oid)); - size = zh->size; - BUG_ON(zh->size == 0 || zh->size > zbud_max_buddy_size()); - zh->size = 0; - tmem_oid_set_invalid(&zh->oid); - INVERT_SENTINEL(zh, ZBH); - zcache_zbud_curr_zbytes -= size; - atomic_dec(&zcache_zbud_curr_zpages); - return size; -} - -static void zbud_free_and_delist(struct zbud_hdr *zh) -{ - unsigned chunks; - struct zbud_hdr *zh_other; - unsigned budnum = zbud_budnum(zh), size; - struct zbud_page *zbpg = - container_of(zh, struct zbud_page, buddy[budnum]); - - spin_lock(&zbud_budlists_spinlock); - spin_lock(&zbpg->lock); - if (list_empty(&zbpg->bud_list)) { - /* ignore zombie page... see zbud_evict_pages() */ - spin_unlock(&zbpg->lock); - spin_unlock(&zbud_budlists_spinlock); - return; - } - size = zbud_free(zh); - ASSERT_SPINLOCK(&zbpg->lock); - zh_other = &zbpg->buddy[(budnum == 0) ? 1 : 0]; - if (zh_other->size == 0) { /* was unbuddied: unlist and free */ - chunks = zbud_size_to_chunks(size) ; - BUG_ON(list_empty(&zbud_unbuddied[chunks].list)); - list_del_init(&zbpg->bud_list); - zbud_unbuddied[chunks].count--; - spin_unlock(&zbud_budlists_spinlock); - zbud_free_raw_page(zbpg); - } else { /* was buddied: move remaining buddy to unbuddied list */ - chunks = zbud_size_to_chunks(zh_other->size) ; - list_del_init(&zbpg->bud_list); - zcache_zbud_buddied_count--; - list_add_tail(&zbpg->bud_list, &zbud_unbuddied[chunks].list); - zbud_unbuddied[chunks].count++; - spin_unlock(&zbud_budlists_spinlock); - spin_unlock(&zbpg->lock); - } -} - -static struct zbud_hdr *zbud_create(uint16_t client_id, uint16_t pool_id, - struct tmem_oid *oid, - uint32_t index, struct page *page, - void *cdata, unsigned size) -{ - struct zbud_hdr *zh0, *zh1, *zh = NULL; - struct zbud_page *zbpg = NULL, *ztmp; - unsigned nchunks; - char *to; - int i, found_good_buddy = 0; - - nchunks = zbud_size_to_chunks(size) ; - for (i = MAX_CHUNK - nchunks + 1; i > 0; i--) { - spin_lock(&zbud_budlists_spinlock); - if (!list_empty(&zbud_unbuddied[i].list)) { - list_for_each_entry_safe(zbpg, ztmp, - &zbud_unbuddied[i].list, bud_list) { - if (spin_trylock(&zbpg->lock)) { - found_good_buddy = i; - goto found_unbuddied; - } - } - } - spin_unlock(&zbud_budlists_spinlock); - } - /* didn't find a good buddy, try allocating a new page */ - zbpg = zbud_alloc_raw_page(); - if (unlikely(zbpg == NULL)) - goto out; - /* ok, have a page, now compress the data before taking locks */ - spin_lock(&zbud_budlists_spinlock); - spin_lock(&zbpg->lock); - list_add_tail(&zbpg->bud_list, &zbud_unbuddied[nchunks].list); - zbud_unbuddied[nchunks].count++; - zh = &zbpg->buddy[0]; - goto init_zh; - -found_unbuddied: - ASSERT_SPINLOCK(&zbpg->lock); - zh0 = &zbpg->buddy[0]; zh1 = &zbpg->buddy[1]; - BUG_ON(!((zh0->size == 0) ^ (zh1->size == 0))); - if (zh0->size != 0) { /* buddy0 in use, buddy1 is vacant */ - ASSERT_SENTINEL(zh0, ZBH); - zh = zh1; - } else if (zh1->size != 0) { /* buddy1 in use, buddy0 is vacant */ - ASSERT_SENTINEL(zh1, ZBH); - zh = zh0; - } else - BUG(); - list_del_init(&zbpg->bud_list); - zbud_unbuddied[found_good_buddy].count--; - list_add_tail(&zbpg->bud_list, &zbud_buddied_list); - zcache_zbud_buddied_count++; - -init_zh: - SET_SENTINEL(zh, ZBH); - zh->size = size; - zh->index = index; - zh->oid = *oid; - zh->pool_id = pool_id; - zh->client_id = client_id; - to = zbud_data(zh, size); - memcpy(to, cdata, size); - spin_unlock(&zbpg->lock); - spin_unlock(&zbud_budlists_spinlock); - - zbud_cumul_chunk_counts[nchunks]++; - atomic_inc(&zcache_zbud_curr_zpages); - zcache_zbud_cumul_zpages++; - zcache_zbud_curr_zbytes += size; - zcache_zbud_cumul_zbytes += size; -out: - return zh; -} - -static int zbud_decompress(struct page *page, struct zbud_hdr *zh) -{ - struct zbud_page *zbpg; - unsigned budnum = zbud_budnum(zh); - unsigned int out_len = PAGE_SIZE; - char *to_va, *from_va; - unsigned size; - int ret = 0; - - zbpg = container_of(zh, struct zbud_page, buddy[budnum]); - spin_lock(&zbpg->lock); - if (list_empty(&zbpg->bud_list)) { - /* ignore zombie page... see zbud_evict_pages() */ - ret = -EINVAL; - goto out; - } - ASSERT_SENTINEL(zh, ZBH); - BUG_ON(zh->size == 0 || zh->size > zbud_max_buddy_size()); - to_va = kmap_atomic(page); - size = zh->size; - from_va = zbud_data(zh, size); - ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, from_va, size, - to_va, &out_len); - BUG_ON(ret); - BUG_ON(out_len != PAGE_SIZE); - kunmap_atomic(to_va); -out: - spin_unlock(&zbpg->lock); - return ret; -} - -/* - * The following routines handle shrinking of ephemeral pages by evicting - * pages "least valuable" first. - */ - -static unsigned long zcache_evicted_raw_pages; -static unsigned long zcache_evicted_buddied_pages; -static unsigned long zcache_evicted_unbuddied_pages; - -static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, - uint16_t poolid); -static void zcache_put_pool(struct tmem_pool *pool); - -/* - * Flush and free all zbuds in a zbpg, then free the pageframe - */ -static void zbud_evict_zbpg(struct zbud_page *zbpg) -{ - struct zbud_hdr *zh; - int i, j; - uint32_t pool_id[ZBUD_MAX_BUDS], client_id[ZBUD_MAX_BUDS]; - uint32_t index[ZBUD_MAX_BUDS]; - struct tmem_oid oid[ZBUD_MAX_BUDS]; - struct tmem_pool *pool; - - ASSERT_SPINLOCK(&zbpg->lock); - BUG_ON(!list_empty(&zbpg->bud_list)); - for (i = 0, j = 0; i < ZBUD_MAX_BUDS; i++) { - zh = &zbpg->buddy[i]; - if (zh->size) { - client_id[j] = zh->client_id; - pool_id[j] = zh->pool_id; - oid[j] = zh->oid; - index[j] = zh->index; - j++; - zbud_free(zh); - } - } - spin_unlock(&zbpg->lock); - for (i = 0; i < j; i++) { - pool = zcache_get_pool_by_id(client_id[i], pool_id[i]); - if (pool != NULL) { - tmem_flush_page(pool, &oid[i], index[i]); - zcache_put_pool(pool); - } - } - ASSERT_SENTINEL(zbpg, ZBPG); - spin_lock(&zbpg->lock); - zbud_free_raw_page(zbpg); -} - -/* - * Free nr pages. This code is funky because we want to hold the locks - * protecting various lists for as short a time as possible, and in some - * circumstances the list may change asynchronously when the list lock is - * not held. In some cases we also trylock not only to avoid waiting on a - * page in use by another cpu, but also to avoid potential deadlock due to - * lock inversion. - */ -static void zbud_evict_pages(int nr) -{ - struct zbud_page *zbpg; - int i; - - /* first try freeing any pages on unused list */ -retry_unused_list: - spin_lock_bh(&zbpg_unused_list_spinlock); - if (!list_empty(&zbpg_unused_list)) { - /* can't walk list here, since it may change when unlocked */ - zbpg = list_first_entry(&zbpg_unused_list, - struct zbud_page, bud_list); - list_del_init(&zbpg->bud_list); - zcache_zbpg_unused_list_count--; - atomic_dec(&zcache_zbud_curr_raw_pages); - spin_unlock_bh(&zbpg_unused_list_spinlock); - zcache_free_page(zbpg); - zcache_evicted_raw_pages++; - if (--nr <= 0) - goto out; - goto retry_unused_list; - } - spin_unlock_bh(&zbpg_unused_list_spinlock); - - /* now try freeing unbuddied pages, starting with least space avail */ - for (i = 0; i < MAX_CHUNK; i++) { -retry_unbud_list_i: - spin_lock_bh(&zbud_budlists_spinlock); - if (list_empty(&zbud_unbuddied[i].list)) { - spin_unlock_bh(&zbud_budlists_spinlock); - continue; - } - list_for_each_entry(zbpg, &zbud_unbuddied[i].list, bud_list) { - if (unlikely(!spin_trylock(&zbpg->lock))) - continue; - list_del_init(&zbpg->bud_list); - zbud_unbuddied[i].count--; - spin_unlock(&zbud_budlists_spinlock); - zcache_evicted_unbuddied_pages++; - /* want budlists unlocked when doing zbpg eviction */ - zbud_evict_zbpg(zbpg); - local_bh_enable(); - if (--nr <= 0) - goto out; - goto retry_unbud_list_i; - } - spin_unlock_bh(&zbud_budlists_spinlock); - } - - /* as a last resort, free buddied pages */ -retry_bud_list: - spin_lock_bh(&zbud_budlists_spinlock); - if (list_empty(&zbud_buddied_list)) { - spin_unlock_bh(&zbud_budlists_spinlock); - goto out; - } - list_for_each_entry(zbpg, &zbud_buddied_list, bud_list) { - if (unlikely(!spin_trylock(&zbpg->lock))) - continue; - list_del_init(&zbpg->bud_list); - zcache_zbud_buddied_count--; - spin_unlock(&zbud_budlists_spinlock); - zcache_evicted_buddied_pages++; - /* want budlists unlocked when doing zbpg eviction */ - zbud_evict_zbpg(zbpg); - local_bh_enable(); - if (--nr <= 0) - goto out; - goto retry_bud_list; - } - spin_unlock_bh(&zbud_budlists_spinlock); -out: - return; -} - -static void __init zbud_init(void) -{ - int i; - - INIT_LIST_HEAD(&zbud_buddied_list); - - for (i = 0; i < NCHUNKS; i++) - INIT_LIST_HEAD(&zbud_unbuddied[i].list); -} - -#ifdef CONFIG_SYSFS -/* - * These sysfs routines show a nice distribution of how many zbpg's are - * currently (and have ever been placed) in each unbuddied list. It's fun - * to watch but can probably go away before final merge. - */ -static int zbud_show_unbuddied_list_counts(char *buf) -{ - int i; - char *p = buf; - - for (i = 0; i < NCHUNKS; i++) - p += sprintf(p, "%u ", zbud_unbuddied[i].count); - return p - buf; -} - -static int zbud_show_cumul_chunk_counts(char *buf) -{ - unsigned long i, chunks = 0, total_chunks = 0, sum_total_chunks = 0; - unsigned long total_chunks_lte_21 = 0, total_chunks_lte_32 = 0; - unsigned long total_chunks_lte_42 = 0; - char *p = buf; - - for (i = 0; i < NCHUNKS; i++) { - p += sprintf(p, "%lu ", zbud_cumul_chunk_counts[i]); - chunks += zbud_cumul_chunk_counts[i]; - total_chunks += zbud_cumul_chunk_counts[i]; - sum_total_chunks += i * zbud_cumul_chunk_counts[i]; - if (i == 21) - total_chunks_lte_21 = total_chunks; - if (i == 32) - total_chunks_lte_32 = total_chunks; - if (i == 42) - total_chunks_lte_42 = total_chunks; - } - p += sprintf(p, "<=21:%lu <=32:%lu <=42:%lu, mean:%lu\n", - total_chunks_lte_21, total_chunks_lte_32, total_chunks_lte_42, - chunks == 0 ? 0 : sum_total_chunks / chunks); - return p - buf; -} -#endif - -/********** - * This "zv" PAM implementation combines the slab-based zsmalloc - * with the crypto compression API to maximize the amount of data that can - * be packed into a physical page. - * - * Zv represents a PAM page with the index and object (plus a "size" value - * necessary for decompression) immediately preceding the compressed data. - */ - -#define ZVH_SENTINEL 0x43214321 - -struct zv_hdr { - uint32_t pool_id; - struct tmem_oid oid; - uint32_t index; - size_t size; - DECL_SENTINEL -}; - -/* rudimentary policy limits */ -/* total number of persistent pages may not exceed this percentage */ -static unsigned int zv_page_count_policy_percent = 75; -/* - * byte count defining poor compression; pages with greater zsize will be - * rejected - */ -static unsigned int zv_max_zsize = (PAGE_SIZE / 8) * 7; -/* - * byte count defining poor *mean* compression; pages with greater zsize - * will be rejected until sufficient better-compressed pages are accepted - * driving the mean below this threshold - */ -static unsigned int zv_max_mean_zsize = (PAGE_SIZE / 8) * 5; - -static atomic_t zv_curr_dist_counts[NCHUNKS]; -static atomic_t zv_cumul_dist_counts[NCHUNKS]; - -static unsigned long zv_create(struct zs_pool *pool, uint32_t pool_id, - struct tmem_oid *oid, uint32_t index, - void *cdata, unsigned clen) -{ - struct zv_hdr *zv; - u32 size = clen + sizeof(struct zv_hdr); - int chunks = (size + (CHUNK_SIZE - 1)) >> CHUNK_SHIFT; - unsigned long handle = 0; - - BUG_ON(!irqs_disabled()); - BUG_ON(chunks >= NCHUNKS); - handle = zs_malloc(pool, size); - if (!handle) - goto out; - atomic_inc(&zv_curr_dist_counts[chunks]); - atomic_inc(&zv_cumul_dist_counts[chunks]); - zv = zs_map_object(pool, handle, ZS_MM_WO); - zv->index = index; - zv->oid = *oid; - zv->pool_id = pool_id; - zv->size = clen; - SET_SENTINEL(zv, ZVH); - memcpy((char *)zv + sizeof(struct zv_hdr), cdata, clen); - zs_unmap_object(pool, handle); -out: - return handle; -} - -static void zv_free(struct zs_pool *pool, unsigned long handle) -{ - unsigned long flags; - struct zv_hdr *zv; - uint16_t size; - int chunks; - - zv = zs_map_object(pool, handle, ZS_MM_RW); - ASSERT_SENTINEL(zv, ZVH); - size = zv->size + sizeof(struct zv_hdr); - INVERT_SENTINEL(zv, ZVH); - zs_unmap_object(pool, handle); - - chunks = (size + (CHUNK_SIZE - 1)) >> CHUNK_SHIFT; - BUG_ON(chunks >= NCHUNKS); - atomic_dec(&zv_curr_dist_counts[chunks]); - - local_irq_save(flags); - zs_free(pool, handle); - local_irq_restore(flags); -} - -static void zv_decompress(struct page *page, unsigned long handle) -{ - unsigned int clen = PAGE_SIZE; - char *to_va; - int ret; - struct zv_hdr *zv; - - zv = zs_map_object(zcache_host.zspool, handle, ZS_MM_RO); - BUG_ON(zv->size == 0); - ASSERT_SENTINEL(zv, ZVH); - to_va = kmap_atomic(page); - ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, (char *)zv + sizeof(*zv), - zv->size, to_va, &clen); - kunmap_atomic(to_va); - zs_unmap_object(zcache_host.zspool, handle); - BUG_ON(ret); - BUG_ON(clen != PAGE_SIZE); -} - -#ifdef CONFIG_SYSFS -/* - * show a distribution of compression stats for zv pages. - */ - -static int zv_curr_dist_counts_show(char *buf) -{ - unsigned long i, n, chunks = 0, sum_total_chunks = 0; - char *p = buf; - - for (i = 0; i < NCHUNKS; i++) { - n = atomic_read(&zv_curr_dist_counts[i]); - p += sprintf(p, "%lu ", n); - chunks += n; - sum_total_chunks += i * n; - } - p += sprintf(p, "mean:%lu\n", - chunks == 0 ? 0 : sum_total_chunks / chunks); - return p - buf; -} - -static int zv_cumul_dist_counts_show(char *buf) -{ - unsigned long i, n, chunks = 0, sum_total_chunks = 0; - char *p = buf; - - for (i = 0; i < NCHUNKS; i++) { - n = atomic_read(&zv_cumul_dist_counts[i]); - p += sprintf(p, "%lu ", n); - chunks += n; - sum_total_chunks += i * n; - } - p += sprintf(p, "mean:%lu\n", - chunks == 0 ? 0 : sum_total_chunks / chunks); - return p - buf; -} - -/* - * setting zv_max_zsize via sysfs causes all persistent (e.g. swap) - * pages that don't compress to less than this value (including metadata - * overhead) to be rejected. We don't allow the value to get too close - * to PAGE_SIZE. - */ -static ssize_t zv_max_zsize_show(struct kobject *kobj, - struct kobj_attribute *attr, - char *buf) -{ - return sprintf(buf, "%u\n", zv_max_zsize); -} - -static ssize_t zv_max_zsize_store(struct kobject *kobj, - struct kobj_attribute *attr, - const char *buf, size_t count) -{ - unsigned long val; - int err; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - err = kstrtoul(buf, 10, &val); - if (err || (val == 0) || (val > (PAGE_SIZE / 8) * 7)) - return -EINVAL; - zv_max_zsize = val; - return count; -} - -/* - * setting zv_max_mean_zsize via sysfs causes all persistent (e.g. swap) - * pages that don't compress to less than this value (including metadata - * overhead) to be rejected UNLESS the mean compression is also smaller - * than this value. In other words, we are load-balancing-by-zsize the - * accepted pages. Again, we don't allow the value to get too close - * to PAGE_SIZE. - */ -static ssize_t zv_max_mean_zsize_show(struct kobject *kobj, - struct kobj_attribute *attr, - char *buf) -{ - return sprintf(buf, "%u\n", zv_max_mean_zsize); -} - -static ssize_t zv_max_mean_zsize_store(struct kobject *kobj, - struct kobj_attribute *attr, - const char *buf, size_t count) -{ - unsigned long val; - int err; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - err = kstrtoul(buf, 10, &val); - if (err || (val == 0) || (val > (PAGE_SIZE / 8) * 7)) - return -EINVAL; - zv_max_mean_zsize = val; - return count; -} - -/* - * setting zv_page_count_policy_percent via sysfs sets an upper bound of - * persistent (e.g. swap) pages that will be retained according to: - * (zv_page_count_policy_percent * totalram_pages) / 100) - * when that limit is reached, further puts will be rejected (until - * some pages have been flushed). Note that, due to compression, - * this number may exceed 100; it defaults to 75 and we set an - * arbitary limit of 150. A poor choice will almost certainly result - * in OOM's, so this value should only be changed prudently. - */ -static ssize_t zv_page_count_policy_percent_show(struct kobject *kobj, - struct kobj_attribute *attr, - char *buf) -{ - return sprintf(buf, "%u\n", zv_page_count_policy_percent); -} - -static ssize_t zv_page_count_policy_percent_store(struct kobject *kobj, - struct kobj_attribute *attr, - const char *buf, size_t count) -{ - unsigned long val; - int err; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - err = kstrtoul(buf, 10, &val); - if (err || (val == 0) || (val > 150)) - return -EINVAL; - zv_page_count_policy_percent = val; - return count; -} - -static struct kobj_attribute zcache_zv_max_zsize_attr = { - .attr = { .name = "zv_max_zsize", .mode = 0644 }, - .show = zv_max_zsize_show, - .store = zv_max_zsize_store, -}; - -static struct kobj_attribute zcache_zv_max_mean_zsize_attr = { - .attr = { .name = "zv_max_mean_zsize", .mode = 0644 }, - .show = zv_max_mean_zsize_show, - .store = zv_max_mean_zsize_store, -}; - -static struct kobj_attribute zcache_zv_page_count_policy_percent_attr = { - .attr = { .name = "zv_page_count_policy_percent", - .mode = 0644 }, - .show = zv_page_count_policy_percent_show, - .store = zv_page_count_policy_percent_store, -}; -#endif - -/* - * zcache core code starts here - */ - -/* useful stats not collected by cleancache or frontswap */ -static unsigned long zcache_flush_total; -static unsigned long zcache_flush_found; -static unsigned long zcache_flobj_total; -static unsigned long zcache_flobj_found; -static unsigned long zcache_failed_eph_puts; -static unsigned long zcache_failed_pers_puts; - -/* - * Tmem operations assume the poolid implies the invoking client. - * Zcache only has one client (the kernel itself): LOCAL_CLIENT. - * RAMster has each client numbered by cluster node, and a KVM version - * of zcache would have one client per guest and each client might - * have a poolid==N. - */ -static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid) -{ - struct tmem_pool *pool = NULL; - struct zcache_client *cli = NULL; - - cli = get_zcache_client(cli_id); - if (!cli) - goto out; - - atomic_inc(&cli->refcount); - pool = idr_find(&cli->tmem_pools, poolid); - if (pool != NULL) - atomic_inc(&pool->refcount); -out: - return pool; -} - -static void zcache_put_pool(struct tmem_pool *pool) -{ - struct zcache_client *cli = NULL; - - if (pool == NULL) - BUG(); - cli = pool->client; - atomic_dec(&pool->refcount); - atomic_dec(&cli->refcount); -} - -int zcache_new_client(uint16_t cli_id) -{ - struct zcache_client *cli; - int ret = -1; - - cli = get_zcache_client(cli_id); - - if (cli == NULL) - goto out; - if (cli->allocated) - goto out; - cli->allocated = 1; -#ifdef CONFIG_FRONTSWAP - cli->zspool = zs_create_pool("zcache", ZCACHE_GFP_MASK); - if (cli->zspool == NULL) - goto out; - idr_init(&cli->tmem_pools); -#endif - ret = 0; -out: - return ret; -} - -/* counters for debugging */ -static unsigned long zcache_failed_get_free_pages; -static unsigned long zcache_failed_alloc; -static unsigned long zcache_put_to_flush; - -/* - * for now, used named slabs so can easily track usage; later can - * either just use kmalloc, or perhaps add a slab-like allocator - * to more carefully manage total memory utilization - */ -static struct kmem_cache *zcache_objnode_cache; -static struct kmem_cache *zcache_obj_cache; -static atomic_t zcache_curr_obj_count = ATOMIC_INIT(0); -static unsigned long zcache_curr_obj_count_max; -static atomic_t zcache_curr_objnode_count = ATOMIC_INIT(0); -static unsigned long zcache_curr_objnode_count_max; - -/* - * to avoid memory allocation recursion (e.g. due to direct reclaim), we - * preload all necessary data structures so the hostops callbacks never - * actually do a malloc - */ -struct zcache_preload { - void *page; - struct tmem_obj *obj; - int nr; - struct tmem_objnode *objnodes[OBJNODE_TREE_MAX_PATH]; -}; -static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, }; - -static int zcache_do_preload(struct tmem_pool *pool) -{ - struct zcache_preload *kp; - struct tmem_objnode *objnode; - struct tmem_obj *obj; - void *page; - int ret = -ENOMEM; - - if (unlikely(zcache_objnode_cache == NULL)) - goto out; - if (unlikely(zcache_obj_cache == NULL)) - goto out; - - /* IRQ has already been disabled. */ - kp = &__get_cpu_var(zcache_preloads); - while (kp->nr < ARRAY_SIZE(kp->objnodes)) { - objnode = kmem_cache_alloc(zcache_objnode_cache, - ZCACHE_GFP_MASK); - if (unlikely(objnode == NULL)) { - zcache_failed_alloc++; - goto out; - } - - kp->objnodes[kp->nr++] = objnode; - } - - if (!kp->obj) { - obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK); - if (unlikely(obj == NULL)) { - zcache_failed_alloc++; - goto out; - } - kp->obj = obj; - } - - if (!kp->page) { - page = (void *)__get_free_page(ZCACHE_GFP_MASK); - if (unlikely(page == NULL)) { - zcache_failed_get_free_pages++; - goto out; - } - kp->page = page; - } - - ret = 0; -out: - return ret; -} - -static void *zcache_get_free_page(void) -{ - struct zcache_preload *kp; - void *page; - - kp = &__get_cpu_var(zcache_preloads); - page = kp->page; - BUG_ON(page == NULL); - kp->page = NULL; - return page; -} - -static void zcache_free_page(void *p) -{ - free_page((unsigned long)p); -} - -/* - * zcache implementation for tmem host ops - */ - -static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool) -{ - struct tmem_objnode *objnode = NULL; - unsigned long count; - struct zcache_preload *kp; - - kp = &__get_cpu_var(zcache_preloads); - if (kp->nr <= 0) - goto out; - objnode = kp->objnodes[kp->nr - 1]; - BUG_ON(objnode == NULL); - kp->objnodes[kp->nr - 1] = NULL; - kp->nr--; - count = atomic_inc_return(&zcache_curr_objnode_count); - if (count > zcache_curr_objnode_count_max) - zcache_curr_objnode_count_max = count; -out: - return objnode; -} - -static void zcache_objnode_free(struct tmem_objnode *objnode, - struct tmem_pool *pool) -{ - atomic_dec(&zcache_curr_objnode_count); - BUG_ON(atomic_read(&zcache_curr_objnode_count) < 0); - kmem_cache_free(zcache_objnode_cache, objnode); -} - -static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool) -{ - struct tmem_obj *obj = NULL; - unsigned long count; - struct zcache_preload *kp; - - kp = &__get_cpu_var(zcache_preloads); - obj = kp->obj; - BUG_ON(obj == NULL); - kp->obj = NULL; - count = atomic_inc_return(&zcache_curr_obj_count); - if (count > zcache_curr_obj_count_max) - zcache_curr_obj_count_max = count; - return obj; -} - -static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) -{ - atomic_dec(&zcache_curr_obj_count); - BUG_ON(atomic_read(&zcache_curr_obj_count) < 0); - kmem_cache_free(zcache_obj_cache, obj); -} - -static struct tmem_hostops zcache_hostops = { - .obj_alloc = zcache_obj_alloc, - .obj_free = zcache_obj_free, - .objnode_alloc = zcache_objnode_alloc, - .objnode_free = zcache_objnode_free, -}; - -/* - * zcache implementations for PAM page descriptor ops - */ - -static atomic_t zcache_curr_eph_pampd_count = ATOMIC_INIT(0); -static unsigned long zcache_curr_eph_pampd_count_max; -static atomic_t zcache_curr_pers_pampd_count = ATOMIC_INIT(0); -static unsigned long zcache_curr_pers_pampd_count_max; - -/* forward reference */ -static int zcache_compress(struct page *from, void **out_va, unsigned *out_len); - -static void *zcache_pampd_create(char *data, size_t size, bool raw, int eph, - struct tmem_pool *pool, struct tmem_oid *oid, - uint32_t index) -{ - void *pampd = NULL, *cdata; - unsigned clen; - int ret; - unsigned long count; - struct page *page = (struct page *)(data); - struct zcache_client *cli = pool->client; - uint16_t client_id = get_client_id_from_client(cli); - unsigned long zv_mean_zsize; - unsigned long curr_pers_pampd_count; - u64 total_zsize; - - if (eph) { - ret = zcache_compress(page, &cdata, &clen); - if (ret == 0) - goto out; - if (clen == 0 || clen > zbud_max_buddy_size()) { - zcache_compress_poor++; - goto out; - } - pampd = (void *)zbud_create(client_id, pool->pool_id, oid, - index, page, cdata, clen); - if (pampd != NULL) { - count = atomic_inc_return(&zcache_curr_eph_pampd_count); - if (count > zcache_curr_eph_pampd_count_max) - zcache_curr_eph_pampd_count_max = count; - } - } else { - curr_pers_pampd_count = - atomic_read(&zcache_curr_pers_pampd_count); - if (curr_pers_pampd_count > - (zv_page_count_policy_percent * totalram_pages) / 100) - goto out; - ret = zcache_compress(page, &cdata, &clen); - if (ret == 0) - goto out; - /* reject if compression is too poor */ - if (clen > zv_max_zsize) { - zcache_compress_poor++; - goto out; - } - /* reject if mean compression is too poor */ - if ((clen > zv_max_mean_zsize) && (curr_pers_pampd_count > 0)) { - total_zsize = zs_get_total_size_bytes(cli->zspool); - zv_mean_zsize = div_u64(total_zsize, - curr_pers_pampd_count); - if (zv_mean_zsize > zv_max_mean_zsize) { - zcache_mean_compress_poor++; - goto out; - } - } - pampd = (void *)zv_create(cli->zspool, pool->pool_id, - oid, index, cdata, clen); - if (pampd == NULL) - goto out; - count = atomic_inc_return(&zcache_curr_pers_pampd_count); - if (count > zcache_curr_pers_pampd_count_max) - zcache_curr_pers_pampd_count_max = count; - } -out: - return pampd; -} - -/* - * fill the pageframe corresponding to the struct page with the data - * from the passed pampd - */ -static int zcache_pampd_get_data(char *data, size_t *bufsize, bool raw, - void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index) -{ - int ret = 0; - - BUG_ON(is_ephemeral(pool)); - zv_decompress((struct page *)(data), (unsigned long)pampd); - return ret; -} - -/* - * fill the pageframe corresponding to the struct page with the data - * from the passed pampd - */ -static int zcache_pampd_get_data_and_free(char *data, size_t *bufsize, bool raw, - void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index) -{ - BUG_ON(!is_ephemeral(pool)); - if (zbud_decompress((struct page *)(data), pampd) < 0) - return -EINVAL; - zbud_free_and_delist((struct zbud_hdr *)pampd); - atomic_dec(&zcache_curr_eph_pampd_count); - return 0; -} - -/* - * free the pampd and remove it from any zcache lists - * pampd must no longer be pointed to from any tmem data structures! - */ -static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index) -{ - struct zcache_client *cli = pool->client; - - if (is_ephemeral(pool)) { - zbud_free_and_delist((struct zbud_hdr *)pampd); - atomic_dec(&zcache_curr_eph_pampd_count); - BUG_ON(atomic_read(&zcache_curr_eph_pampd_count) < 0); - } else { - zv_free(cli->zspool, (unsigned long)pampd); - atomic_dec(&zcache_curr_pers_pampd_count); - BUG_ON(atomic_read(&zcache_curr_pers_pampd_count) < 0); - } -} - -static void zcache_pampd_free_obj(struct tmem_pool *pool, struct tmem_obj *obj) -{ -} - -static void zcache_pampd_new_obj(struct tmem_obj *obj) -{ -} - -static int zcache_pampd_replace_in_obj(void *pampd, struct tmem_obj *obj) -{ - return -1; -} - -static bool zcache_pampd_is_remote(void *pampd) -{ - return 0; -} - -static struct tmem_pamops zcache_pamops = { - .create = zcache_pampd_create, - .get_data = zcache_pampd_get_data, - .get_data_and_free = zcache_pampd_get_data_and_free, - .free = zcache_pampd_free, - .free_obj = zcache_pampd_free_obj, - .new_obj = zcache_pampd_new_obj, - .replace_in_obj = zcache_pampd_replace_in_obj, - .is_remote = zcache_pampd_is_remote, -}; - -/* - * zcache compression/decompression and related per-cpu stuff - */ - -static DEFINE_PER_CPU(unsigned char *, zcache_dstmem); -#define ZCACHE_DSTMEM_ORDER 1 - -static int zcache_compress(struct page *from, void **out_va, unsigned *out_len) -{ - int ret = 0; - unsigned char *dmem = __get_cpu_var(zcache_dstmem); - char *from_va; - - BUG_ON(!irqs_disabled()); - if (unlikely(dmem == NULL)) - goto out; /* no buffer or no compressor so can't compress */ - *out_len = PAGE_SIZE << ZCACHE_DSTMEM_ORDER; - from_va = kmap_atomic(from); - mb(); - ret = zcache_comp_op(ZCACHE_COMPOP_COMPRESS, from_va, PAGE_SIZE, dmem, - out_len); - BUG_ON(ret); - *out_va = dmem; - kunmap_atomic(from_va); - ret = 1; -out: - return ret; -} - -static int zcache_comp_cpu_up(int cpu) -{ - struct crypto_comp *tfm; - - tfm = crypto_alloc_comp(zcache_comp_name, 0, 0); - if (IS_ERR(tfm)) - return NOTIFY_BAD; - *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = tfm; - return NOTIFY_OK; -} - -static void zcache_comp_cpu_down(int cpu) -{ - struct crypto_comp *tfm; - - tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu); - crypto_free_comp(tfm); - *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = NULL; -} - -static int zcache_cpu_notifier(struct notifier_block *nb, - unsigned long action, void *pcpu) -{ - int ret, cpu = (long)pcpu; - struct zcache_preload *kp; - - switch (action) { - case CPU_UP_PREPARE: - ret = zcache_comp_cpu_up(cpu); - if (ret != NOTIFY_OK) { - pr_err("zcache: can't allocate compressor transform\n"); - return ret; - } - per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages( - GFP_KERNEL | __GFP_REPEAT, ZCACHE_DSTMEM_ORDER); - break; - case CPU_DEAD: - case CPU_UP_CANCELED: - zcache_comp_cpu_down(cpu); - free_pages((unsigned long)per_cpu(zcache_dstmem, cpu), - ZCACHE_DSTMEM_ORDER); - per_cpu(zcache_dstmem, cpu) = NULL; - kp = &per_cpu(zcache_preloads, cpu); - while (kp->nr) { - kmem_cache_free(zcache_objnode_cache, - kp->objnodes[kp->nr - 1]); - kp->objnodes[kp->nr - 1] = NULL; - kp->nr--; - } - if (kp->obj) { - kmem_cache_free(zcache_obj_cache, kp->obj); - kp->obj = NULL; - } - if (kp->page) { - free_page((unsigned long)kp->page); - kp->page = NULL; - } - break; - default: - break; - } - return NOTIFY_OK; -} - -static struct notifier_block zcache_cpu_notifier_block = { - .notifier_call = zcache_cpu_notifier -}; - -#ifdef CONFIG_SYSFS -#define ZCACHE_SYSFS_RO(_name) \ - static ssize_t zcache_##_name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ - { \ - return sprintf(buf, "%lu\n", zcache_##_name); \ - } \ - static struct kobj_attribute zcache_##_name##_attr = { \ - .attr = { .name = __stringify(_name), .mode = 0444 }, \ - .show = zcache_##_name##_show, \ - } - -#define ZCACHE_SYSFS_RO_ATOMIC(_name) \ - static ssize_t zcache_##_name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ - { \ - return sprintf(buf, "%d\n", atomic_read(&zcache_##_name)); \ - } \ - static struct kobj_attribute zcache_##_name##_attr = { \ - .attr = { .name = __stringify(_name), .mode = 0444 }, \ - .show = zcache_##_name##_show, \ - } - -#define ZCACHE_SYSFS_RO_CUSTOM(_name, _func) \ - static ssize_t zcache_##_name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ - { \ - return _func(buf); \ - } \ - static struct kobj_attribute zcache_##_name##_attr = { \ - .attr = { .name = __stringify(_name), .mode = 0444 }, \ - .show = zcache_##_name##_show, \ - } - -ZCACHE_SYSFS_RO(curr_obj_count_max); -ZCACHE_SYSFS_RO(curr_objnode_count_max); -ZCACHE_SYSFS_RO(flush_total); -ZCACHE_SYSFS_RO(flush_found); -ZCACHE_SYSFS_RO(flobj_total); -ZCACHE_SYSFS_RO(flobj_found); -ZCACHE_SYSFS_RO(failed_eph_puts); -ZCACHE_SYSFS_RO(failed_pers_puts); -ZCACHE_SYSFS_RO(zbud_curr_zbytes); -ZCACHE_SYSFS_RO(zbud_cumul_zpages); -ZCACHE_SYSFS_RO(zbud_cumul_zbytes); -ZCACHE_SYSFS_RO(zbud_buddied_count); -ZCACHE_SYSFS_RO(zbpg_unused_list_count); -ZCACHE_SYSFS_RO(evicted_raw_pages); -ZCACHE_SYSFS_RO(evicted_unbuddied_pages); -ZCACHE_SYSFS_RO(evicted_buddied_pages); -ZCACHE_SYSFS_RO(failed_get_free_pages); -ZCACHE_SYSFS_RO(failed_alloc); -ZCACHE_SYSFS_RO(put_to_flush); -ZCACHE_SYSFS_RO(compress_poor); -ZCACHE_SYSFS_RO(mean_compress_poor); -ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_raw_pages); -ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_zpages); -ZCACHE_SYSFS_RO_ATOMIC(curr_obj_count); -ZCACHE_SYSFS_RO_ATOMIC(curr_objnode_count); -ZCACHE_SYSFS_RO_CUSTOM(zbud_unbuddied_list_counts, - zbud_show_unbuddied_list_counts); -ZCACHE_SYSFS_RO_CUSTOM(zbud_cumul_chunk_counts, - zbud_show_cumul_chunk_counts); -ZCACHE_SYSFS_RO_CUSTOM(zv_curr_dist_counts, - zv_curr_dist_counts_show); -ZCACHE_SYSFS_RO_CUSTOM(zv_cumul_dist_counts, - zv_cumul_dist_counts_show); - -static struct attribute *zcache_attrs[] = { - &zcache_curr_obj_count_attr.attr, - &zcache_curr_obj_count_max_attr.attr, - &zcache_curr_objnode_count_attr.attr, - &zcache_curr_objnode_count_max_attr.attr, - &zcache_flush_total_attr.attr, - &zcache_flobj_total_attr.attr, - &zcache_flush_found_attr.attr, - &zcache_flobj_found_attr.attr, - &zcache_failed_eph_puts_attr.attr, - &zcache_failed_pers_puts_attr.attr, - &zcache_compress_poor_attr.attr, - &zcache_mean_compress_poor_attr.attr, - &zcache_zbud_curr_raw_pages_attr.attr, - &zcache_zbud_curr_zpages_attr.attr, - &zcache_zbud_curr_zbytes_attr.attr, - &zcache_zbud_cumul_zpages_attr.attr, - &zcache_zbud_cumul_zbytes_attr.attr, - &zcache_zbud_buddied_count_attr.attr, - &zcache_zbpg_unused_list_count_attr.attr, - &zcache_evicted_raw_pages_attr.attr, - &zcache_evicted_unbuddied_pages_attr.attr, - &zcache_evicted_buddied_pages_attr.attr, - &zcache_failed_get_free_pages_attr.attr, - &zcache_failed_alloc_attr.attr, - &zcache_put_to_flush_attr.attr, - &zcache_zbud_unbuddied_list_counts_attr.attr, - &zcache_zbud_cumul_chunk_counts_attr.attr, - &zcache_zv_curr_dist_counts_attr.attr, - &zcache_zv_cumul_dist_counts_attr.attr, - &zcache_zv_max_zsize_attr.attr, - &zcache_zv_max_mean_zsize_attr.attr, - &zcache_zv_page_count_policy_percent_attr.attr, - NULL, -}; - -static struct attribute_group zcache_attr_group = { - .attrs = zcache_attrs, - .name = "zcache", -}; - -#endif /* CONFIG_SYSFS */ -/* - * When zcache is disabled ("frozen"), pools can be created and destroyed, - * but all puts (and thus all other operations that require memory allocation) - * must fail. If zcache is unfrozen, accepts puts, then frozen again, - * data consistency requires all puts while frozen to be converted into - * flushes. - */ -static bool zcache_freeze; - -/* - * zcache shrinker interface (only useful for ephemeral pages, so zbud only) - */ -static int shrink_zcache_memory(struct shrinker *shrink, - struct shrink_control *sc) -{ - int ret = -1; - int nr = sc->nr_to_scan; - gfp_t gfp_mask = sc->gfp_mask; - - if (nr >= 0) { - if (!(gfp_mask & __GFP_FS)) - /* does this case really need to be skipped? */ - goto out; - zbud_evict_pages(nr); - } - ret = (int)atomic_read(&zcache_zbud_curr_raw_pages); -out: - return ret; -} - -static struct shrinker zcache_shrinker = { - .shrink = shrink_zcache_memory, - .seeks = DEFAULT_SEEKS, -}; - -/* - * zcache shims between cleancache/frontswap ops and tmem - */ - -static int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp, - uint32_t index, struct page *page) -{ - struct tmem_pool *pool; - int ret = -1; - - BUG_ON(!irqs_disabled()); - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (unlikely(pool == NULL)) - goto out; - if (!zcache_freeze && zcache_do_preload(pool) == 0) { - /* preload does preempt_disable on success */ - ret = tmem_put(pool, oidp, index, (char *)(page), - PAGE_SIZE, 0, is_ephemeral(pool)); - if (ret < 0) { - if (is_ephemeral(pool)) - zcache_failed_eph_puts++; - else - zcache_failed_pers_puts++; - } - } else { - zcache_put_to_flush++; - if (atomic_read(&pool->obj_count) > 0) - /* the put fails whether the flush succeeds or not */ - (void)tmem_flush_page(pool, oidp, index); - } - - zcache_put_pool(pool); -out: - return ret; -} - -static int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp, - uint32_t index, struct page *page) -{ - struct tmem_pool *pool; - int ret = -1; - unsigned long flags; - size_t size = PAGE_SIZE; - - local_irq_save(flags); - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (likely(pool != NULL)) { - if (atomic_read(&pool->obj_count) > 0) - ret = tmem_get(pool, oidp, index, (char *)(page), - &size, 0, is_ephemeral(pool)); - zcache_put_pool(pool); - } - local_irq_restore(flags); - return ret; -} - -static int zcache_flush_page(int cli_id, int pool_id, - struct tmem_oid *oidp, uint32_t index) -{ - struct tmem_pool *pool; - int ret = -1; - unsigned long flags; - - local_irq_save(flags); - zcache_flush_total++; - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (likely(pool != NULL)) { - if (atomic_read(&pool->obj_count) > 0) - ret = tmem_flush_page(pool, oidp, index); - zcache_put_pool(pool); - } - if (ret >= 0) - zcache_flush_found++; - local_irq_restore(flags); - return ret; -} - -static int zcache_flush_object(int cli_id, int pool_id, - struct tmem_oid *oidp) -{ - struct tmem_pool *pool; - int ret = -1; - unsigned long flags; - - local_irq_save(flags); - zcache_flobj_total++; - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (likely(pool != NULL)) { - if (atomic_read(&pool->obj_count) > 0) - ret = tmem_flush_object(pool, oidp); - zcache_put_pool(pool); - } - if (ret >= 0) - zcache_flobj_found++; - local_irq_restore(flags); - return ret; -} - -static int zcache_destroy_pool(int cli_id, int pool_id) -{ - struct tmem_pool *pool = NULL; - struct zcache_client *cli; - int ret = -1; - - if (pool_id < 0) - goto out; - - cli = get_zcache_client(cli_id); - if (cli == NULL) - goto out; - - atomic_inc(&cli->refcount); - pool = idr_find(&cli->tmem_pools, pool_id); - if (pool == NULL) - goto out; - idr_remove(&cli->tmem_pools, pool_id); - /* wait for pool activity on other cpus to quiesce */ - while (atomic_read(&pool->refcount) != 0) - ; - atomic_dec(&cli->refcount); - local_bh_disable(); - ret = tmem_destroy_pool(pool); - local_bh_enable(); - kfree(pool); - pr_info("zcache: destroyed pool id=%d, cli_id=%d\n", - pool_id, cli_id); -out: - return ret; -} - -static int zcache_new_pool(uint16_t cli_id, uint32_t flags) -{ - int poolid = -1; - struct tmem_pool *pool; - struct zcache_client *cli = NULL; - int r; - - cli = get_zcache_client(cli_id); - if (cli == NULL) - goto out; - - atomic_inc(&cli->refcount); - pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC); - if (pool == NULL) { - pr_info("zcache: pool creation failed: out of memory\n"); - goto out; - } - - do { - r = idr_pre_get(&cli->tmem_pools, GFP_ATOMIC); - if (r != 1) { - kfree(pool); - pr_info("zcache: pool creation failed: out of memory\n"); - goto out; - } - r = idr_get_new(&cli->tmem_pools, pool, &poolid); - } while (r == -EAGAIN); - if (r) { - pr_info("zcache: pool creation failed: error %d\n", r); - kfree(pool); - goto out; - } - - atomic_set(&pool->refcount, 0); - pool->client = cli; - pool->pool_id = poolid; - tmem_new_pool(pool, flags); - pr_info("zcache: created %s tmem pool, id=%d, client=%d\n", - flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", - poolid, cli_id); -out: - if (cli != NULL) - atomic_dec(&cli->refcount); - return poolid; -} - -/********** - * Two kernel functionalities currently can be layered on top of tmem. - * These are "cleancache" which is used as a second-chance cache for clean - * page cache pages; and "frontswap" which is used for swap pages - * to avoid writes to disk. A generic "shim" is provided here for each - * to translate in-kernel semantics to zcache semantics. - */ - -#ifdef CONFIG_CLEANCACHE -static void zcache_cleancache_put_page(int pool_id, - struct cleancache_filekey key, - pgoff_t index, struct page *page) -{ - u32 ind = (u32) index; - struct tmem_oid oid = *(struct tmem_oid *)&key; - - if (likely(ind == index)) - (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index, page); -} - -static int zcache_cleancache_get_page(int pool_id, - struct cleancache_filekey key, - pgoff_t index, struct page *page) -{ - u32 ind = (u32) index; - struct tmem_oid oid = *(struct tmem_oid *)&key; - int ret = -1; - - if (likely(ind == index)) - ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index, page); - return ret; -} - -static void zcache_cleancache_flush_page(int pool_id, - struct cleancache_filekey key, - pgoff_t index) -{ - u32 ind = (u32) index; - struct tmem_oid oid = *(struct tmem_oid *)&key; - - if (likely(ind == index)) - (void)zcache_flush_page(LOCAL_CLIENT, pool_id, &oid, ind); -} - -static void zcache_cleancache_flush_inode(int pool_id, - struct cleancache_filekey key) -{ - struct tmem_oid oid = *(struct tmem_oid *)&key; - - (void)zcache_flush_object(LOCAL_CLIENT, pool_id, &oid); -} - -static void zcache_cleancache_flush_fs(int pool_id) -{ - if (pool_id >= 0) - (void)zcache_destroy_pool(LOCAL_CLIENT, pool_id); -} - -static int zcache_cleancache_init_fs(size_t pagesize) -{ - BUG_ON(sizeof(struct cleancache_filekey) != - sizeof(struct tmem_oid)); - BUG_ON(pagesize != PAGE_SIZE); - return zcache_new_pool(LOCAL_CLIENT, 0); -} - -static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize) -{ - /* shared pools are unsupported and map to private */ - BUG_ON(sizeof(struct cleancache_filekey) != - sizeof(struct tmem_oid)); - BUG_ON(pagesize != PAGE_SIZE); - return zcache_new_pool(LOCAL_CLIENT, 0); -} - -static struct cleancache_ops zcache_cleancache_ops = { - .put_page = zcache_cleancache_put_page, - .get_page = zcache_cleancache_get_page, - .invalidate_page = zcache_cleancache_flush_page, - .invalidate_inode = zcache_cleancache_flush_inode, - .invalidate_fs = zcache_cleancache_flush_fs, - .init_shared_fs = zcache_cleancache_init_shared_fs, - .init_fs = zcache_cleancache_init_fs -}; - -struct cleancache_ops zcache_cleancache_register_ops(void) -{ - struct cleancache_ops old_ops = - cleancache_register_ops(&zcache_cleancache_ops); - - return old_ops; -} -#endif - -#ifdef CONFIG_FRONTSWAP -/* a single tmem poolid is used for all frontswap "types" (swapfiles) */ -static int zcache_frontswap_poolid = -1; - -/* - * Swizzling increases objects per swaptype, increasing tmem concurrency - * for heavy swaploads. Later, larger nr_cpus -> larger SWIZ_BITS - * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from - * frontswap_load(), but has side-effects. Hence using 8. - */ -#define SWIZ_BITS 8 -#define SWIZ_MASK ((1 << SWIZ_BITS) - 1) -#define _oswiz(_type, _ind) ((_type << SWIZ_BITS) | (_ind & SWIZ_MASK)) -#define iswiz(_ind) (_ind >> SWIZ_BITS) - -static inline struct tmem_oid oswiz(unsigned type, u32 ind) -{ - struct tmem_oid oid = { .oid = { 0 } }; - oid.oid[0] = _oswiz(type, ind); - return oid; -} - -static int zcache_frontswap_store(unsigned type, pgoff_t offset, - struct page *page) -{ - u64 ind64 = (u64)offset; - u32 ind = (u32)offset; - struct tmem_oid oid = oswiz(type, ind); - int ret = -1; - unsigned long flags; - - BUG_ON(!PageLocked(page)); - if (likely(ind64 == ind)) { - local_irq_save(flags); - ret = zcache_put_page(LOCAL_CLIENT, zcache_frontswap_poolid, - &oid, iswiz(ind), page); - local_irq_restore(flags); - } - return ret; -} - -/* returns 0 if the page was successfully gotten from frontswap, -1 if - * was not present (should never happen!) */ -static int zcache_frontswap_load(unsigned type, pgoff_t offset, - struct page *page) -{ - u64 ind64 = (u64)offset; - u32 ind = (u32)offset; - struct tmem_oid oid = oswiz(type, ind); - int ret = -1; - - BUG_ON(!PageLocked(page)); - if (likely(ind64 == ind)) - ret = zcache_get_page(LOCAL_CLIENT, zcache_frontswap_poolid, - &oid, iswiz(ind), page); - return ret; -} - -/* flush a single page from frontswap */ -static void zcache_frontswap_flush_page(unsigned type, pgoff_t offset) -{ - u64 ind64 = (u64)offset; - u32 ind = (u32)offset; - struct tmem_oid oid = oswiz(type, ind); - - if (likely(ind64 == ind)) - (void)zcache_flush_page(LOCAL_CLIENT, zcache_frontswap_poolid, - &oid, iswiz(ind)); -} - -/* flush all pages from the passed swaptype */ -static void zcache_frontswap_flush_area(unsigned type) -{ - struct tmem_oid oid; - int ind; - - for (ind = SWIZ_MASK; ind >= 0; ind--) { - oid = oswiz(type, ind); - (void)zcache_flush_object(LOCAL_CLIENT, - zcache_frontswap_poolid, &oid); - } -} - -static void zcache_frontswap_init(unsigned ignored) -{ - /* a single tmem poolid is used for all frontswap "types" (swapfiles) */ - if (zcache_frontswap_poolid < 0) - zcache_frontswap_poolid = - zcache_new_pool(LOCAL_CLIENT, TMEM_POOL_PERSIST); -} - -static struct frontswap_ops zcache_frontswap_ops = { - .store = zcache_frontswap_store, - .load = zcache_frontswap_load, - .invalidate_page = zcache_frontswap_flush_page, - .invalidate_area = zcache_frontswap_flush_area, - .init = zcache_frontswap_init -}; - -struct frontswap_ops zcache_frontswap_register_ops(void) -{ - struct frontswap_ops old_ops = - frontswap_register_ops(&zcache_frontswap_ops); - - return old_ops; -} -#endif - -/* - * zcache initialization - * NOTE FOR NOW zcache MUST BE PROVIDED AS A KERNEL BOOT PARAMETER OR - * NOTHING HAPPENS! - */ - -static int zcache_enabled; - -static int __init enable_zcache(char *s) -{ - zcache_enabled = 1; - return 1; -} -__setup("zcache", enable_zcache); - -/* allow independent dynamic disabling of cleancache and frontswap */ - -static int use_cleancache = 1; - -static int __init no_cleancache(char *s) -{ - use_cleancache = 0; - return 1; -} - -__setup("nocleancache", no_cleancache); - -static int use_frontswap = 1; - -static int __init no_frontswap(char *s) -{ - use_frontswap = 0; - return 1; -} - -__setup("nofrontswap", no_frontswap); - -static int __init enable_zcache_compressor(char *s) -{ - strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ); - zcache_enabled = 1; - return 1; -} -__setup("zcache=", enable_zcache_compressor); - - -static int __init zcache_comp_init(void) -{ - int ret = 0; - - /* check crypto algorithm */ - if (*zcache_comp_name != '\0') { - ret = crypto_has_comp(zcache_comp_name, 0, 0); - if (!ret) - pr_info("zcache: %s not supported\n", - zcache_comp_name); - } - if (!ret) - strcpy(zcache_comp_name, "lzo"); - ret = crypto_has_comp(zcache_comp_name, 0, 0); - if (!ret) { - ret = 1; - goto out; - } - pr_info("zcache: using %s compressor\n", zcache_comp_name); - - /* alloc percpu transforms */ - ret = 0; - zcache_comp_pcpu_tfms = alloc_percpu(struct crypto_comp *); - if (!zcache_comp_pcpu_tfms) - ret = 1; -out: - return ret; -} - -static int __init zcache_init(void) -{ - int ret = 0; - -#ifdef CONFIG_SYSFS - ret = sysfs_create_group(mm_kobj, &zcache_attr_group); - if (ret) { - pr_err("zcache: can't create sysfs\n"); - goto out; - } -#endif /* CONFIG_SYSFS */ - - if (zcache_enabled) { - unsigned int cpu; - - tmem_register_hostops(&zcache_hostops); - tmem_register_pamops(&zcache_pamops); - ret = register_cpu_notifier(&zcache_cpu_notifier_block); - if (ret) { - pr_err("zcache: can't register cpu notifier\n"); - goto out; - } - ret = zcache_comp_init(); - if (ret) { - pr_err("zcache: compressor initialization failed\n"); - goto out; - } - for_each_online_cpu(cpu) { - void *pcpu = (void *)(long)cpu; - zcache_cpu_notifier(&zcache_cpu_notifier_block, - CPU_UP_PREPARE, pcpu); - } - } - zcache_objnode_cache = kmem_cache_create("zcache_objnode", - sizeof(struct tmem_objnode), 0, 0, NULL); - zcache_obj_cache = kmem_cache_create("zcache_obj", - sizeof(struct tmem_obj), 0, 0, NULL); - ret = zcache_new_client(LOCAL_CLIENT); - if (ret) { - pr_err("zcache: can't create client\n"); - goto out; - } - -#ifdef CONFIG_CLEANCACHE - if (zcache_enabled && use_cleancache) { - struct cleancache_ops old_ops; - - zbud_init(); - register_shrinker(&zcache_shrinker); - old_ops = zcache_cleancache_register_ops(); - pr_info("zcache: cleancache enabled using kernel " - "transcendent memory and compression buddies\n"); - if (old_ops.init_fs != NULL) - pr_warning("zcache: cleancache_ops overridden"); - } -#endif -#ifdef CONFIG_FRONTSWAP - if (zcache_enabled && use_frontswap) { - struct frontswap_ops old_ops; - - old_ops = zcache_frontswap_register_ops(); - pr_info("zcache: frontswap enabled using kernel " - "transcendent memory and zsmalloc\n"); - if (old_ops.init != NULL) - pr_warning("zcache: frontswap_ops overridden"); - } -#endif -out: - return ret; -} - -module_init(zcache_init) -- cgit v0.10.2 From 4bbc0bc06b8b0cced31ee17beb753ad51a2e47e7 Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Fri, 4 Jan 2013 12:14:00 -0800 Subject: staging: zsmalloc: comment zs_create_pool function Just as with zs_malloc() and zs_map_object(), it is worth formally commenting the zs_create_pool() function. Signed-off-by: Davidlohr Bueso Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c index 09a9d35..eb00772 100644 --- a/drivers/staging/zsmalloc/zsmalloc-main.c +++ b/drivers/staging/zsmalloc/zsmalloc-main.c @@ -798,6 +798,17 @@ fail: return notifier_to_errno(ret); } +/** + * zs_create_pool - Creates an allocation pool to work from. + * @name: name of the pool to be created + * @flags: allocation flags used when growing pool + * + * This function must be called before anything when using + * the zsmalloc allocator. + * + * On success, a pointer to the newly created pool is returned, + * otherwise NULL. + */ struct zs_pool *zs_create_pool(const char *name, gfp_t flags) { int i, ovhd_size; -- cgit v0.10.2 From b5b384b7277aa01b839850fb4092fd247c2bae98 Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Tue, 8 Jan 2013 12:52:32 -0500 Subject: staging: vt6655: s/kmalloc + memset/kzalloc in alloc_rd_info replace kmalloc and memset if the pointer is valid with kzalloc, and remove the check around the null pointer cases as we dont need it. Signed-off-by: Devendra Naga Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h index e54e00b..1a077f9 100644 --- a/drivers/staging/vt6655/device.h +++ b/drivers/staging/vt6655/device.h @@ -882,14 +882,7 @@ inline static bool device_get_ip(PSDevice pInfo) { static inline PDEVICE_RD_INFO alloc_rd_info(void) { - PDEVICE_RD_INFO ptr; - ptr = (PDEVICE_RD_INFO)kmalloc((int)sizeof(DEVICE_RD_INFO), (int)GFP_ATOMIC); - if (ptr == NULL) - return NULL; - else { - memset(ptr,0,sizeof(DEVICE_RD_INFO)); - return ptr; - } + return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC); } static inline PDEVICE_TD_INFO alloc_td_info(void) { -- cgit v0.10.2 From 8473f6544ec84135ce1f4eb8a3f7144a53fe70bb Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Tue, 8 Jan 2013 12:52:33 -0500 Subject: staging: vt6655: checkpatch fixes put opening brace in a new line 4 ---> 8 spaces Signed-off-by: Devendra Naga Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h index 1a077f9..64d923c 100644 --- a/drivers/staging/vt6655/device.h +++ b/drivers/staging/vt6655/device.h @@ -881,8 +881,9 @@ inline static bool device_get_ip(PSDevice pInfo) { -static inline PDEVICE_RD_INFO alloc_rd_info(void) { - return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC); +static inline PDEVICE_RD_INFO alloc_rd_info(void) +{ + return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC); } static inline PDEVICE_TD_INFO alloc_td_info(void) { -- cgit v0.10.2 From d1b46e75fb307132ebbfdd65055bf622cc3f646e Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Tue, 8 Jan 2013 12:52:34 -0500 Subject: staging: vt6655: s/kmalloc + memset / kzalloc replace kmalloc and subsequent memset with kzalloc and drop the null checks and casts and clean the coding style a bit too Signed-off-by: Devendra Naga Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h index 64d923c..e27244c 100644 --- a/drivers/staging/vt6655/device.h +++ b/drivers/staging/vt6655/device.h @@ -886,15 +886,9 @@ static inline PDEVICE_RD_INFO alloc_rd_info(void) return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC); } -static inline PDEVICE_TD_INFO alloc_td_info(void) { - PDEVICE_TD_INFO ptr; - ptr = (PDEVICE_TD_INFO)kmalloc((int)sizeof(DEVICE_TD_INFO), (int)GFP_ATOMIC); - if (ptr == NULL) - return NULL; - else { - memset(ptr,0,sizeof(DEVICE_TD_INFO)); - return ptr; - } +static inline PDEVICE_TD_INFO alloc_td_info(void) +{ + return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC); } /*--------------------- Export Functions --------------------------*/ -- cgit v0.10.2 From 40a0136b5a7113ccf8d17e56c1f25f63427c4022 Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Tue, 8 Jan 2013 12:52:35 -0500 Subject: staging: vt6655: no braces needed for single statement if , for blocks there is only one line inside the if and for blocks, so the braces are not needed Signed-off-by: Devendra Naga Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6655/channel.c b/drivers/staging/vt6655/channel.c index 47c156b..aa76e39 100644 --- a/drivers/staging/vt6655/channel.c +++ b/drivers/staging/vt6655/channel.c @@ -749,9 +749,9 @@ bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex, unsigned char *pbyChannelNumber, unsigned char *pbyMap) { - if (uChannelIndex > CB_MAX_CHANNEL) { + if (uChannelIndex > CB_MAX_CHANNEL) return false; - } + *pbyChannelNumber = sChannelTbl[uChannelIndex].byChannelNumber; *pbyMap = sChannelTbl[uChannelIndex].byMAP; return sChannelTbl[uChannelIndex].bValid; @@ -761,9 +761,9 @@ void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex, unsigned char byMap) { - if (uChannelIndex > CB_MAX_CHANNEL) { + if (uChannelIndex > CB_MAX_CHANNEL) return; - } + sChannelTbl[uChannelIndex].byMAP |= byMap; } @@ -771,9 +771,8 @@ void clear_channel_map_info(void *pDeviceHandler) { unsigned int ii = 0; - for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) { + for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) sChannelTbl[ii].byMAP = 0; - } } unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType) -- cgit v0.10.2 From e78edba113086d3ad61f19830b086974cd698ebd Mon Sep 17 00:00:00 2001 From: Andy Gross Date: Wed, 19 Dec 2012 14:53:37 -0600 Subject: drm/omap: Add PM capabilities Added power management capabilities into the omapdrm and DMM drivers. During suspend, we don't need to do anything to maintain the state of the LUT. We have all the necessary information to recreate the mappings of the GEM object list maintained by the omapdrm driver. On resume, the DMM resume handler will first reprogram the LUT to point to the dummy page. The subsequent resume handler in the omapdrm will call into the DMM and reprogram each of the buffer objects. This will ensure that all of the necessary objects will be pinned into the DMM properly. Order of suspend/resume handlers is done by device creation. We create the DMM device before the omapdrm, so the correct order is maintained. Signed-off-by: Andy Gross Signed-off-by: Rob Clark Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.c b/drivers/staging/omapdrm/omap_dmm_tiler.c index 59bf438..c42c5e5 100644 --- a/drivers/staging/omapdrm/omap_dmm_tiler.c +++ b/drivers/staging/omapdrm/omap_dmm_tiler.c @@ -903,12 +903,46 @@ error: } #endif +#ifdef CONFIG_PM +static int omap_dmm_resume(struct device *dev) +{ + struct tcm_area area; + int i; + + if (!omap_dmm) + return -ENODEV; + + area = (struct tcm_area) { + .is2d = true, + .tcm = NULL, + .p1.x = omap_dmm->container_width - 1, + .p1.y = omap_dmm->container_height - 1, + }; + + /* initialize all LUTs to dummy page entries */ + for (i = 0; i < omap_dmm->num_lut; i++) { + area.tcm = omap_dmm->tcm[i]; + if (fill(&area, NULL, 0, 0, true)) + dev_err(dev, "refill failed"); + } + + return 0; +} + +static const struct dev_pm_ops omap_dmm_pm_ops = { + .resume = omap_dmm_resume, +}; +#endif + struct platform_driver omap_dmm_driver = { .probe = omap_dmm_probe, .remove = omap_dmm_remove, .driver = { .owner = THIS_MODULE, .name = DMM_DRIVER_NAME, +#ifdef CONFIG_PM + .pm = &omap_dmm_pm_ops, +#endif }, }; diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c index ae5ecc2..d246f85 100644 --- a/drivers/staging/omapdrm/omap_drv.c +++ b/drivers/staging/omapdrm/omap_drv.c @@ -368,6 +368,9 @@ static int dev_load(struct drm_device *dev, unsigned long flags) /* well, limp along without an fbdev.. maybe X11 will work? */ } + /* store off drm_device for use in pm ops */ + dev_set_drvdata(dev->dev, dev); + drm_kms_helper_poll_init(dev); return 0; @@ -393,6 +396,8 @@ static int dev_unload(struct drm_device *dev) kfree(dev->dev_private); dev->dev_private = NULL; + dev_set_drvdata(dev->dev, NULL); + return 0; } @@ -558,10 +563,19 @@ static int pdev_remove(struct platform_device *device) return 0; } +#ifdef CONFIG_PM +static const struct dev_pm_ops omapdrm_pm_ops = { + .resume = omap_gem_resume, +}; +#endif + struct platform_driver pdev = { .driver = { .name = DRIVER_NAME, .owner = THIS_MODULE, +#ifdef CONFIG_PM + .pm = &omapdrm_pm_ops, +#endif }, .probe = pdev_probe, .remove = pdev_remove, diff --git a/drivers/staging/omapdrm/omap_drv.h b/drivers/staging/omapdrm/omap_drv.h index cd1f22b..f921027 100644 --- a/drivers/staging/omapdrm/omap_drv.h +++ b/drivers/staging/omapdrm/omap_drv.h @@ -135,6 +135,10 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m); void omap_gem_describe_objects(struct list_head *list, struct seq_file *m); #endif +#ifdef CONFIG_PM +int omap_gem_resume(struct device *dev); +#endif + int omap_irq_enable_vblank(struct drm_device *dev, int crtc); void omap_irq_disable_vblank(struct drm_device *dev, int crtc); irqreturn_t omap_irq_handler(DRM_IRQ_ARGS); diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c index c38992b..08f1e292 100644 --- a/drivers/staging/omapdrm/omap_gem.c +++ b/drivers/staging/omapdrm/omap_gem.c @@ -964,6 +964,34 @@ void *omap_gem_vaddr(struct drm_gem_object *obj) return omap_obj->vaddr; } +#ifdef CONFIG_PM +/* re-pin objects in DMM in resume path: */ +int omap_gem_resume(struct device *dev) +{ + struct drm_device *drm_dev = dev_get_drvdata(dev); + struct omap_drm_private *priv = drm_dev->dev_private; + struct omap_gem_object *omap_obj; + int ret = 0; + + list_for_each_entry(omap_obj, &priv->obj_list, mm_list) { + if (omap_obj->block) { + struct drm_gem_object *obj = &omap_obj->base; + uint32_t npages = obj->size >> PAGE_SHIFT; + WARN_ON(!omap_obj->pages); /* this can't happen */ + ret = tiler_pin(omap_obj->block, + omap_obj->pages, npages, + omap_obj->roll, true); + if (ret) { + dev_err(dev, "could not repin: %d\n", ret); + return ret; + } + } + } + + return 0; +} +#endif + #ifdef CONFIG_DEBUG_FS void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m) { -- cgit v0.10.2 From c6b7ae5550fe2d4090628c366a2d3fba2d3c4293 Mon Sep 17 00:00:00 2001 From: Andy Gross Date: Wed, 19 Dec 2012 14:53:38 -0600 Subject: drm/omap: Add OMAP5 support Add support for OMAP5 processor. The main differences are that the OMAP5 has 2 containers, one for 1D and one for 2D. Each container is 128MiB in size. Signed-off-by: Andy Gross Signed-off-by: Rob Clark Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/omapdrm/omap_dmm_priv.h b/drivers/staging/omapdrm/omap_dmm_priv.h index 273ec12..58bcd6a 100644 --- a/drivers/staging/omapdrm/omap_dmm_priv.h +++ b/drivers/staging/omapdrm/omap_dmm_priv.h @@ -118,6 +118,11 @@ struct pat { #define DESCR_SIZE 128 #define REFILL_BUFFER_SIZE ((4 * 128 * 256) + (3 * DESCR_SIZE)) +/* For OMAP5, a fixed offset is added to all Y coordinates for 1D buffers. + * This is used in programming to address the upper portion of the LUT +*/ +#define OMAP5_LUT_OFFSET 128 + struct dmm; struct dmm_txn { diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.c b/drivers/staging/omapdrm/omap_dmm_tiler.c index c42c5e5..3910215 100644 --- a/drivers/staging/omapdrm/omap_dmm_tiler.c +++ b/drivers/staging/omapdrm/omap_dmm_tiler.c @@ -213,6 +213,11 @@ static void dmm_txn_append(struct dmm_txn *txn, struct pat_area *area, txn->last_pat->next_pa = (uint32_t)pat_pa; pat->area = *area; + + /* adjust Y coordinates based off of container parameters */ + pat->area.y0 += engine->tcm->y_offset; + pat->area.y1 += engine->tcm->y_offset; + pat->ctrl = (struct pat_ctrl){ .start = 1, .lut_id = engine->tcm->lut_id, @@ -622,6 +627,11 @@ static int omap_dmm_probe(struct platform_device *dev) omap_dmm->lut_width = ((pat_geom >> 16) & 0xF) << 5; omap_dmm->lut_height = ((pat_geom >> 24) & 0xF) << 5; + /* increment LUT by one if on OMAP5 */ + /* LUT has twice the height, and is split into a separate container */ + if (omap_dmm->lut_height != omap_dmm->container_height) + omap_dmm->num_lut++; + /* initialize DMM registers */ writel(0x88888888, omap_dmm->base + DMM_PAT_VIEW__0); writel(0x88888888, omap_dmm->base + DMM_PAT_VIEW__1); @@ -701,6 +711,9 @@ static int omap_dmm_probe(struct platform_device *dev) } /* init containers */ + /* Each LUT is associated with a TCM (container manager). We use the + lut_id to denote the lut_id used to identify the correct LUT for + programming during reill operations */ for (i = 0; i < omap_dmm->num_lut; i++) { omap_dmm->tcm[i] = sita_init(omap_dmm->container_width, omap_dmm->container_height, @@ -717,13 +730,23 @@ static int omap_dmm_probe(struct platform_device *dev) /* assign access mode containers to applicable tcm container */ /* OMAP 4 has 1 container for all 4 views */ + /* OMAP 5 has 2 containers, 1 for 2D and 1 for 1D */ containers[TILFMT_8BIT] = omap_dmm->tcm[0]; containers[TILFMT_16BIT] = omap_dmm->tcm[0]; containers[TILFMT_32BIT] = omap_dmm->tcm[0]; - containers[TILFMT_PAGE] = omap_dmm->tcm[0]; + + if (omap_dmm->container_height != omap_dmm->lut_height) { + /* second LUT is used for PAGE mode. Programming must use + y offset that is added to all y coordinates. LUT id is still + 0, because it is the same LUT, just the upper 128 lines */ + containers[TILFMT_PAGE] = omap_dmm->tcm[1]; + omap_dmm->tcm[1]->y_offset = OMAP5_LUT_OFFSET; + omap_dmm->tcm[1]->lut_id = 0; + } else { + containers[TILFMT_PAGE] = omap_dmm->tcm[0]; + } area = (struct tcm_area) { - .is2d = true, .tcm = NULL, .p1.x = omap_dmm->container_width - 1, .p1.y = omap_dmm->container_height - 1, @@ -835,64 +858,81 @@ int tiler_map_show(struct seq_file *s, void *arg) int h_adj; int w_adj; unsigned long flags; + int lut_idx; + if (!omap_dmm) { /* early return if dmm/tiler device is not initialized */ return 0; } - h_adj = omap_dmm->lut_height / ydiv; - w_adj = omap_dmm->lut_width / xdiv; + h_adj = omap_dmm->container_height / ydiv; + w_adj = omap_dmm->container_width / xdiv; - map = kzalloc(h_adj * sizeof(*map), GFP_KERNEL); - global_map = kzalloc((w_adj + 1) * h_adj, GFP_KERNEL); + map = kmalloc(h_adj * sizeof(*map), GFP_KERNEL); + global_map = kmalloc((w_adj + 1) * h_adj, GFP_KERNEL); if (!map || !global_map) goto error; - memset(global_map, ' ', (w_adj + 1) * h_adj); - for (i = 0; i < omap_dmm->lut_height; i++) { - map[i] = global_map + i * (w_adj + 1); - map[i][w_adj] = 0; - } - spin_lock_irqsave(&list_lock, flags); + for (lut_idx = 0; lut_idx < omap_dmm->num_lut; lut_idx++) { + memset(map, 0, sizeof(h_adj * sizeof(*map))); + memset(global_map, ' ', (w_adj + 1) * h_adj); - list_for_each_entry(block, &omap_dmm->alloc_head, alloc_node) { - if (block->fmt != TILFMT_PAGE) { - fill_map(map, xdiv, ydiv, &block->area, *m2dp, true); - if (!*++a2dp) - a2dp = a2d; - if (!*++m2dp) - m2dp = m2d; - map_2d_info(map, xdiv, ydiv, nice, &block->area); - } else { - bool start = read_map_pt(map, xdiv, ydiv, - &block->area.p0) - == ' '; - bool end = read_map_pt(map, xdiv, ydiv, &block->area.p1) - == ' '; - tcm_for_each_slice(a, block->area, p) - fill_map(map, xdiv, ydiv, &a, '=', true); - fill_map_pt(map, xdiv, ydiv, &block->area.p0, + for (i = 0; i < omap_dmm->container_height; i++) { + map[i] = global_map + i * (w_adj + 1); + map[i][w_adj] = 0; + } + + spin_lock_irqsave(&list_lock, flags); + + list_for_each_entry(block, &omap_dmm->alloc_head, alloc_node) { + if (block->area.tcm == omap_dmm->tcm[lut_idx]) { + if (block->fmt != TILFMT_PAGE) { + fill_map(map, xdiv, ydiv, &block->area, + *m2dp, true); + if (!*++a2dp) + a2dp = a2d; + if (!*++m2dp) + m2dp = m2d; + map_2d_info(map, xdiv, ydiv, nice, + &block->area); + } else { + bool start = read_map_pt(map, xdiv, + ydiv, &block->area.p0) == ' '; + bool end = read_map_pt(map, xdiv, ydiv, + &block->area.p1) == ' '; + + tcm_for_each_slice(a, block->area, p) + fill_map(map, xdiv, ydiv, &a, + '=', true); + fill_map_pt(map, xdiv, ydiv, + &block->area.p0, start ? '<' : 'X'); - fill_map_pt(map, xdiv, ydiv, &block->area.p1, + fill_map_pt(map, xdiv, ydiv, + &block->area.p1, end ? '>' : 'X'); - map_1d_info(map, xdiv, ydiv, nice, &block->area); + map_1d_info(map, xdiv, ydiv, nice, + &block->area); + } + } } - } - spin_unlock_irqrestore(&list_lock, flags); + spin_unlock_irqrestore(&list_lock, flags); - if (s) { - seq_printf(s, "BEGIN DMM TILER MAP\n"); - for (i = 0; i < 128; i++) - seq_printf(s, "%03d:%s\n", i, map[i]); - seq_printf(s, "END TILER MAP\n"); - } else { - dev_dbg(omap_dmm->dev, "BEGIN DMM TILER MAP\n"); - for (i = 0; i < 128; i++) - dev_dbg(omap_dmm->dev, "%03d:%s\n", i, map[i]); - dev_dbg(omap_dmm->dev, "END TILER MAP\n"); + if (s) { + seq_printf(s, "CONTAINER %d DUMP BEGIN\n", lut_idx); + for (i = 0; i < 128; i++) + seq_printf(s, "%03d:%s\n", i, map[i]); + seq_printf(s, "CONTAINER %d DUMP END\n", lut_idx); + } else { + dev_dbg(omap_dmm->dev, "CONTAINER %d DUMP BEGIN\n", + lut_idx); + for (i = 0; i < 128; i++) + dev_dbg(omap_dmm->dev, "%03d:%s\n", i, map[i]); + dev_dbg(omap_dmm->dev, "CONTAINER %d DUMP END\n", + lut_idx); + } } error: @@ -913,7 +953,6 @@ static int omap_dmm_resume(struct device *dev) return -ENODEV; area = (struct tcm_area) { - .is2d = true, .tcm = NULL, .p1.x = omap_dmm->container_width - 1, .p1.y = omap_dmm->container_height - 1, diff --git a/drivers/staging/omapdrm/tcm.h b/drivers/staging/omapdrm/tcm.h index d273e3e..a8d5ce4 100644 --- a/drivers/staging/omapdrm/tcm.h +++ b/drivers/staging/omapdrm/tcm.h @@ -59,6 +59,8 @@ struct tcm { u16 width, height; /* container dimensions */ int lut_id; /* Lookup table identifier */ + unsigned int y_offset; /* offset to use for y coordinates */ + /* 'pvt' structure shall contain any tcm details (attr) along with linked list of allocated areas and mutex for mutually exclusive access to the list. It may also contain copies of width and height to notice -- cgit v0.10.2 From 4ee723a96f9313d67e88c7a9d3ae6162d2308f2d Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 9 Jan 2013 00:32:02 -0200 Subject: staging: imx-drm: ipu-common: Remove unused variable Fix the following warning when building with W=1 option: drivers/staging/imx-drm/ipu-v3/ipu-common.c: In function 'ipu_remove': drivers/staging/imx-drm/ipu-v3/ipu-common.c:1145:19: warning: variable 'res' set but not used [-Wunused-but-set-variable] Signed-off-by: Fabio Estevam Acked-by: Sascha Hauer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/imx-drm/ipu-v3/ipu-common.c b/drivers/staging/imx-drm/ipu-v3/ipu-common.c index f7059cd..366f259 100644 --- a/drivers/staging/imx-drm/ipu-v3/ipu-common.c +++ b/drivers/staging/imx-drm/ipu-v3/ipu-common.c @@ -1142,9 +1142,6 @@ failed_ioremap: static int ipu_remove(struct platform_device *pdev) { struct ipu_soc *ipu = platform_get_drvdata(pdev); - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); platform_device_unregister_children(pdev); ipu_submodules_exit(ipu); -- cgit v0.10.2 From cce17b457b3b346e5777ec770feb324663ea2b9b Mon Sep 17 00:00:00 2001 From: Cong Ding Date: Tue, 15 Jan 2013 20:46:50 +0100 Subject: staging: omapdrm/omap_gem_dmabuf.c: fix memory leakage There is a memory leakage in variable sg if it goes to error. Signed-off-by: Cong Ding Signed-off-by: Rob Clark Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c index eabb8b5..27780b8 100644 --- a/drivers/staging/omapdrm/omap_gem_dmabuf.c +++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c @@ -53,10 +53,10 @@ static struct sg_table *omap_gem_map_dma_buf( /* this should be after _get_paddr() to ensure we have pages attached */ omap_gem_dma_sync(obj, dir); -out: - if (ret) - return ERR_PTR(ret); return sg; +out: + kfree(sg); + return ERR_PTR(ret); } static void omap_gem_unmap_dma_buf(struct dma_buf_attachment *attachment, -- cgit v0.10.2 From 5c75af1a451ec14a218c830a8246a1b34fc91e59 Mon Sep 17 00:00:00 2001 From: Lijo Antony Date: Tue, 8 Jan 2013 22:39:01 +0400 Subject: Staging: speakup: buffers.c: checkpatch.pl fixes Fixed two camel case issues. Signed-off-by: Lijo Antony Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/speakup/buffers.c b/drivers/staging/speakup/buffers.c index a2db956..382973e 100644 --- a/drivers/staging/speakup/buffers.c +++ b/drivers/staging/speakup/buffers.c @@ -5,12 +5,12 @@ #include "speakup.h" #include "spk_priv.h" -#define synthBufferSize 8192 /* currently 8K bytes */ +#define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */ -static u_char synth_buffer[synthBufferSize]; /* guess what this is for! */ +static u_char synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */ static u_char *buff_in = synth_buffer; static u_char *buff_out = synth_buffer; -static u_char *buffer_end = synth_buffer+synthBufferSize-1; +static u_char *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1; /* These try to throttle applications by stopping the TTYs * Note: we need to make sure that we will restart them eventually, which is @@ -44,13 +44,13 @@ static void speakup_stop_ttys(void) static int synth_buffer_free(void) { - int bytesFree; + int bytes_free; if (buff_in >= buff_out) - bytesFree = synthBufferSize - (buff_in - buff_out); + bytes_free = SYNTH_BUF_SIZE - (buff_in - buff_out); else - bytesFree = buff_out - buff_in; - return bytesFree; + bytes_free = buff_out - buff_in; + return bytes_free; } int synth_buffer_empty(void) -- cgit v0.10.2 From ed52565565e9ba9e081fd20c83f3166b78b4c2ac Mon Sep 17 00:00:00 2001 From: Lijo Antony Date: Tue, 8 Jan 2013 22:39:02 +0400 Subject: Staging: speakup: keyhelp.c: checkpatch.pl fixes Breaking 2 lines to fit 80 char limit Signed-off-by: Lijo Antony Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c index 4c584ec..5091625 100644 --- a/drivers/staging/speakup/keyhelp.c +++ b/drivers/staging/speakup/keyhelp.c @@ -118,7 +118,8 @@ static void say_key(int key) synth_printf(" %s", spk_msg_get(MSG_STATES_START + i)); } if ((key > 0) && (key <= num_key_names)) - synth_printf(" %s\n", spk_msg_get(MSG_KEYNAMES_START + (key - 1))); + synth_printf(" %s\n", + spk_msg_get(MSG_KEYNAMES_START + (key - 1))); } static int help_init(void) @@ -169,7 +170,9 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) cur_item--; else return -1; - } else if (type == KT_SPKUP && ch == SPEAKUP_HELP && !spk_special_handler) { + } else if (type == KT_SPKUP + && ch == SPEAKUP_HELP + && !spk_special_handler) { spk_special_handler = spk_handle_help; synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO)); build_key_data(); /* rebuild each time in case new mapping */ -- cgit v0.10.2 From b3d07cf5a1045130057ebf39282092c31ceca185 Mon Sep 17 00:00:00 2001 From: Lijo Antony Date: Tue, 8 Jan 2013 22:39:03 +0400 Subject: Staging: speakup: kobjects.c: checkpatch.pl fixes Fixed two "line over 80 characters" warnings reported by checkpatch.pl Signed-off-by: Lijo Antony Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c index 86387f4..35f647c 100644 --- a/drivers/staging/speakup/kobjects.c +++ b/drivers/staging/speakup/kobjects.c @@ -654,16 +654,16 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, if (synth && synth->default_pitch) { param = spk_var_header_by_name("pitch"); if (param) { - spk_set_num_var(synth->default_pitch[value], param, - E_NEW_DEFAULT); + spk_set_num_var(synth->default_pitch[value], + param, E_NEW_DEFAULT); spk_set_num_var(0, param, E_DEFAULT); } } if (synth && synth->default_vol) { param = spk_var_header_by_name("vol"); if (param) { - spk_set_num_var(synth->default_vol[value], param, - E_NEW_DEFAULT); + spk_set_num_var(synth->default_vol[value], + param, E_NEW_DEFAULT); spk_set_num_var(0, param, E_DEFAULT); } } -- cgit v0.10.2 From cb9cc9cae9ebde1148e48c9682205af8518ec0c9 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 9 Jan 2013 10:09:19 +0300 Subject: Staging: bcm: copying more data than intended This was changed to bcm_flash2x_cs_info instead of bcm_flash_cs_info when we got rid of the typedefs. bcm_flash2x_cs_info is quite a bit larger than bcm_flash_cs_info (436 bytes instead of 96) so it would corrupt user memory and it's an info leak. Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index 4ba1a5d..491e2bf 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -1792,7 +1792,7 @@ cntrlEnd: if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info)) return -EINVAL; - if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash2x_cs_info))) + if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash_cs_info))) return -EFAULT; } } -- cgit v0.10.2 From ed73591a5c2ea4a77e89a2ef303a92e2e5c517da Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 9 Jan 2013 13:52:30 -0200 Subject: staging: ipu-di: Change DI address info to dev_dbg Currently when ipuv3 is probed we have: imx-ipuv3 40000000.ipu: DI0 base: 0x5e040000 remapped to a08aa000 imx-ipuv3 40000000.ipu: DI1 base: 0x5e048000 remapped to a08ac000 imx-ipuv3 40000000.ipu: IPUv3EX probed The DI base address and the remapped address are more interesting for debug purposes, so mark this message as dev_dbg instead. Signed-off-by: Fabio Estevam Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/imx-drm/ipu-v3/ipu-di.c b/drivers/staging/imx-drm/ipu-v3/ipu-di.c index 67d974f..ec340da 100644 --- a/drivers/staging/imx-drm/ipu-v3/ipu-di.c +++ b/drivers/staging/imx-drm/ipu-v3/ipu-di.c @@ -677,7 +677,7 @@ int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id, goto failed_clk_register; } - dev_info(dev, "DI%d base: 0x%08lx remapped to %p\n", + dev_dbg(dev, "DI%d base: 0x%08lx remapped to %p\n", id, base, di->base); di->inuse = false; di->ipu = ipu; -- cgit v0.10.2 From 6903098c169026f134455f4c41dd834f085e842d Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Sun, 13 Jan 2013 20:31:16 +0000 Subject: staging: et131x: Only configure regs if link state changes Some config regs get set whenever adjust_link() is called. Change this so that these registers only get set when the link state changes to UP. Also remove unnecessary second assignment of boot_coma. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index e2d5555..82508fb 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -3819,46 +3819,6 @@ static void et131x_adjust_link(struct net_device *netdev) struct et131x_adapter *adapter = netdev_priv(netdev); struct phy_device *phydev = adapter->phydev; - if (netif_carrier_ok(netdev)) { - adapter->boot_coma = 20; - - if (phydev && phydev->speed == SPEED_10) { - /* - * NOTE - Is there a way to query this without - * TruePHY? - * && TRU_QueryCoreType(adapter->hTruePhy, 0)== - * EMI_TRUEPHY_A13O) { - */ - u16 register18; - - et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, - ®ister18); - et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG, - register18 | 0x4); - et131x_mii_write(adapter, PHY_INDEX_REG, - register18 | 0x8402); - et131x_mii_write(adapter, PHY_DATA_REG, - register18 | 511); - et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG, - register18); - } - - et1310_config_flow_control(adapter); - - if (phydev && phydev->speed == SPEED_1000 && - adapter->registry_jumbo_packet > 2048) { - u16 reg; - - et131x_mii_read(adapter, PHY_CONFIG, ®); - reg &= ~ET_PHY_CONFIG_TX_FIFO_DEPTH; - reg |= ET_PHY_CONFIG_FIFO_DEPTH_32; - et131x_mii_write(adapter, PHY_CONFIG, reg); - } - - et131x_set_rx_dma_timer(adapter); - et1310_config_mac_regs2(adapter); - } - if (phydev && phydev->link != adapter->link) { /* * Check to see if we are in coma mode and if @@ -3868,11 +3828,47 @@ static void et131x_adjust_link(struct net_device *netdev) if (et1310_in_phy_coma(adapter)) et1310_disable_phy_coma(adapter); + adapter->link = phydev->link; + phy_print_status(phydev); + if (phydev->link) { adapter->boot_coma = 20; + if (phydev && phydev->speed == SPEED_10) { + /* + * NOTE - Is there a way to query this without + * TruePHY? + * && TRU_QueryCoreType(adapter->hTruePhy, 0)== + * EMI_TRUEPHY_A13O) { + */ + u16 register18; + + et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, + ®ister18); + et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG, + register18 | 0x4); + et131x_mii_write(adapter, PHY_INDEX_REG, + register18 | 0x8402); + et131x_mii_write(adapter, PHY_DATA_REG, + register18 | 511); + et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG, + register18); + } + + et1310_config_flow_control(adapter); + + if (phydev && phydev->speed == SPEED_1000 && + adapter->registry_jumbo_packet > 2048) { + u16 reg; + + et131x_mii_read(adapter, PHY_CONFIG, ®); + reg &= ~ET_PHY_CONFIG_TX_FIFO_DEPTH; + reg |= ET_PHY_CONFIG_FIFO_DEPTH_32; + et131x_mii_write(adapter, PHY_CONFIG, reg); + } + + et131x_set_rx_dma_timer(adapter); + et1310_config_mac_regs2(adapter); } else { - dev_warn(&adapter->pdev->dev, - "Link down - cable problem ?\n"); adapter->boot_coma = 0; if (phydev->speed == SPEED_10) { @@ -3917,9 +3913,6 @@ static void et131x_adjust_link(struct net_device *netdev) et131x_enable_txrx(netdev); } - adapter->link = phydev->link; - - phy_print_status(phydev); } } -- cgit v0.10.2 From 8841d798f42430133a7874430ac634347b31fce5 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sun, 13 Jan 2013 23:05:05 +0300 Subject: Staging: comedi: add a missing break statement This is a static checker fix. From the context it looks like there should be a break here. Signed-off-by: Dan Carpenter Acked-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c index 0c991b9..13747f3 100644 --- a/drivers/staging/comedi/drivers/ni_tiocmd.c +++ b/drivers/staging/comedi/drivers/ni_tiocmd.c @@ -159,6 +159,7 @@ static int ni_tio_input_cmd(struct ni_gpct *counter, struct comedi_async *async) async->inttrig = NULL; mite_dma_arm(counter->mite_chan); retval = ni_tio_arm(counter, 1, cmd->start_arg); + break; case TRIG_OTHER: async->inttrig = NULL; mite_dma_arm(counter->mite_chan); -- cgit v0.10.2 From 7864a0ac4b354355ac335ee705cea9be00234901 Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Mon, 14 Jan 2013 12:29:07 +1000 Subject: staging: slicoss: Stop swearing in slicoss.c I'm assuming that "CRC shit reg" is referencing the CRC register/registry. Please ignore this patch if "shit" is actually in context Signed-off-by: Cruz Julian Bishop Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c index 78578ee..5aa03ee 100644 --- a/drivers/staging/slicoss/slicoss.c +++ b/drivers/staging/slicoss/slicoss.c @@ -209,7 +209,7 @@ static u32 slic_crc_init; /* Is table initialized */ */ static void slic_mcast_init_crc32(void) { - u32 c; /* CRC shit reg */ + u32 c; /* CRC reg */ u32 e = 0; /* Poly X-or pattern */ int i; /* counter */ int k; /* byte being shifted into crc */ @@ -3437,7 +3437,7 @@ static int slic_card_init(struct sliccard *card, struct adapter *adapter) (eecodesize - 2)); /* if the ucdoe chksum flag bit worked, - we wouldn't need this shit + we wouldn't need this */ if (ee_chksum == calc_chksum) card->config.EepromValid = true; -- cgit v0.10.2 From 83682cd2fede86c064abac691a5a7091671cfed6 Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Mon, 14 Jan 2013 12:29:08 +1000 Subject: staging: slicoss: Fix three checkpatch.pl errors in slicoss.c The errors fixed are all instances of "ERROR: do not use assignment in if condition" Signed-off-by: Cruz Julian Bishop Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c index 5aa03ee..b6b99a3 100644 --- a/drivers/staging/slicoss/slicoss.c +++ b/drivers/staging/slicoss/slicoss.c @@ -2930,11 +2930,14 @@ static int slic_if_init(struct adapter *adapter) } if (!adapter->queues_initialized) { - if ((rc = slic_rspqueue_init(adapter))) + rc = slic_rspqueue_init(adapter); + if (rc) goto err; - if ((rc = slic_cmdq_init(adapter))) + rc = slic_cmdq_init(adapter); + if (rc) goto err; - if ((rc = slic_rcvqueue_init(adapter))) + rc = slic_rcvqueue_init(adapter); + if (rc) goto err; adapter->queues_initialized = 1; } -- cgit v0.10.2 From 2fbedf67ed3ad2ee08b96cbc3c56c7d81db14de9 Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Mon, 14 Jan 2013 12:29:09 +1000 Subject: staging: slicoss: Fix space-related checkpatch.pl warnings This fixes all instances of "Please, no spaces at start of a new line" "Please, no spaces before tabs" Please note that I probably got the warning names wrong, but they should be close enough for usage here :) Additional post-commit note: There is one comment on line 230ish in slic.h that appears to have lost it's formatting. It was fine when I was working in Geany, but it caught my eye in the below diff. Sorry if it actually happened! Signed-off-by: Cruz Julian Bishop Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/slicoss/slic.h b/drivers/staging/slicoss/slic.h index ebdcc6f..4c7822b 100644 --- a/drivers/staging/slicoss/slic.h +++ b/drivers/staging/slicoss/slic.h @@ -43,15 +43,15 @@ /* firmware stuff */ #define OASIS_UCODE_VERS_STRING "1.2" -#define OASIS_UCODE_VERS_DATE "2006/03/27 15:10:37" -#define OASIS_UCODE_HOSTIF_ID 3 +#define OASIS_UCODE_VERS_DATE "2006/03/27 15:10:37" +#define OASIS_UCODE_HOSTIF_ID 3 #define MOJAVE_UCODE_VERS_STRING "1.2" -#define MOJAVE_UCODE_VERS_DATE "2006/03/27 15:12:22" -#define MOJAVE_UCODE_HOSTIF_ID 3 +#define MOJAVE_UCODE_VERS_DATE "2006/03/27 15:12:22" +#define MOJAVE_UCODE_HOSTIF_ID 3 #define GB_RCVUCODE_VERS_STRING "1.2" -#define GB_RCVUCODE_VERS_DATE "2006/03/27 15:12:15" +#define GB_RCVUCODE_VERS_DATE "2006/03/27 15:12:15" static u32 OasisRcvUCodeLen = 512; static u32 GBRcvUCodeLen = 512; #define SECTION_SIZE 65536 @@ -65,12 +65,12 @@ struct slic_spinlock { #define SLIC_RSPQ_BUFSINPAGE (PAGE_SIZE / SLIC_RSPBUF_SIZE) struct slic_rspqueue { - u32 offset; - u32 pageindex; - u32 num_pages; - struct slic_rspbuf *rspbuf; - u32 *vaddr[SLIC_RSPQ_PAGES_GB]; - dma_addr_t paddr[SLIC_RSPQ_PAGES_GB]; + u32 offset; + u32 pageindex; + u32 num_pages; + struct slic_rspbuf *rspbuf; + u32 *vaddr[SLIC_RSPQ_PAGES_GB]; + dma_addr_t paddr[SLIC_RSPQ_PAGES_GB]; }; #define SLIC_RCVQ_EXPANSION 1 @@ -82,20 +82,20 @@ struct slic_rspqueue { #define SLIC_RCVQ_FILLTHRESH (SLIC_RCVQ_ENTRIES - SLIC_RCVQ_FILLENTRIES) struct slic_rcvqueue { - struct sk_buff *head; - struct sk_buff *tail; - u32 count; - u32 size; - u32 errors; + struct sk_buff *head; + struct sk_buff *tail; + u32 count; + u32 size; + u32 errors; }; struct slic_rcvbuf_info { - u32 id; - u32 starttime; - u32 stoptime; - u32 slicworld; - u32 lasttime; - u32 lastid; + u32 id; + u32 starttime; + u32 stoptime; + u32 slicworld; + u32 lasttime; + u32 lastid; }; /* SLIC Handle structure. Used to restrict handle values to @@ -113,12 +113,12 @@ struct slic_handle_word { }; struct slic_handle { - struct slic_handle_word token; /* token passed between host and card*/ - ushort type; - void *address; /* actual address of the object*/ - ushort offset; - struct slic_handle *other_handle; - struct slic_handle *next; + struct slic_handle_word token; /* token passed between host and card*/ + ushort type; + void *address; /* actual address of the object*/ + ushort offset; + struct slic_handle *other_handle; + struct slic_handle *next; }; #define SLIC_HANDLE_FREE 0x0000 @@ -134,17 +134,17 @@ struct slic_handle { #define SLIC_HOSTCMD_SIZE 512 struct slic_hostcmd { - struct slic_host64_cmd cmd64; - u32 type; - struct sk_buff *skb; - u32 paddrl; - u32 paddrh; - u32 busy; - u32 cmdsize; - ushort numbufs; - struct slic_handle *pslic_handle;/* handle associated with command */ - struct slic_hostcmd *next; - struct slic_hostcmd *next_all; + struct slic_host64_cmd cmd64; + u32 type; + struct sk_buff *skb; + u32 paddrl; + u32 paddrh; + u32 busy; + u32 cmdsize; + ushort numbufs; + struct slic_handle *pslic_handle;/* handle associated with command */ + struct slic_hostcmd *next; + struct slic_hostcmd *next_all; }; #define SLIC_CMDQ_CMDSINPAGE (PAGE_SIZE / SLIC_HOSTCMD_SIZE) @@ -228,35 +228,35 @@ struct mcast_address { #define SLIC_CARD_STATE(x) ((x == CARD_UP) ? "UP" : "Down") struct slic_iface_stats { - /* - * Stats - */ - u64 xmt_bytes; - u64 xmt_ucast; - u64 xmt_mcast; - u64 xmt_bcast; - u64 xmt_errors; - u64 xmt_discards; - u64 xmit_collisions; - u64 xmit_excess_xmit_collisions; - u64 rcv_bytes; - u64 rcv_ucast; - u64 rcv_mcast; - u64 rcv_bcast; - u64 rcv_errors; - u64 rcv_discards; + /* + * Stats + */ + u64 xmt_bytes; + u64 xmt_ucast; + u64 xmt_mcast; + u64 xmt_bcast; + u64 xmt_errors; + u64 xmt_discards; + u64 xmit_collisions; + u64 xmit_excess_xmit_collisions; + u64 rcv_bytes; + u64 rcv_ucast; + u64 rcv_mcast; + u64 rcv_bcast; + u64 rcv_errors; + u64 rcv_discards; }; struct sliccp_stats { - u64 xmit_tcp_segs; - u64 xmit_tcp_bytes; - u64 rcv_tcp_segs; - u64 rcv_tcp_bytes; + u64 xmit_tcp_segs; + u64 xmit_tcp_bytes; + u64 rcv_tcp_segs; + u64 rcv_tcp_bytes; }; struct slicnet_stats { - struct sliccp_stats tcp; - struct slic_iface_stats iface; + struct sliccp_stats tcp; + struct slic_iface_stats iface; }; #define SLIC_LOADTIMER_PERIOD 1 @@ -285,51 +285,51 @@ struct slicnet_stats { #define SLIC_INTAGG_5GB 100 struct ether_header { - unsigned char ether_dhost[6]; - unsigned char ether_shost[6]; - ushort ether_type; + unsigned char ether_dhost[6]; + unsigned char ether_shost[6]; + ushort ether_type; }; struct sliccard { - uint busnumber; - uint slotnumber; - uint state; - uint cardnum; - uint card_size; - uint adapters_activated; - uint adapters_allocated; - uint adapters_sleeping; - uint gennumber; - u32 events; - u32 loadlevel_current; - u32 load; - uint reset_in_progress; - u32 pingstatus; - u32 bad_pingstatus; - struct timer_list loadtimer; - u32 loadtimerset; - uint config_set; - struct slic_config config; - struct dentry *debugfs_dir; - struct dentry *debugfs_cardinfo; - struct adapter *master; - struct adapter *adapter[SLIC_MAX_PORTS]; - struct sliccard *next; - u32 error_interrupts; - u32 error_rmiss_interrupts; - u32 rcv_interrupts; - u32 xmit_interrupts; - u32 num_isrs; - u32 false_interrupts; - u32 max_isr_rcvs; - u32 max_isr_xmits; - u32 rcv_interrupt_yields; - u32 tx_packets; - u32 debug_ix; - ushort reg_type[32]; - ushort reg_offset[32]; - u32 reg_value[32]; - u32 reg_valueh[32]; + uint busnumber; + uint slotnumber; + uint state; + uint cardnum; + uint card_size; + uint adapters_activated; + uint adapters_allocated; + uint adapters_sleeping; + uint gennumber; + u32 events; + u32 loadlevel_current; + u32 load; + uint reset_in_progress; + u32 pingstatus; + u32 bad_pingstatus; + struct timer_list loadtimer; + u32 loadtimerset; + uint config_set; + struct slic_config config; + struct dentry *debugfs_dir; + struct dentry *debugfs_cardinfo; + struct adapter *master; + struct adapter *adapter[SLIC_MAX_PORTS]; + struct sliccard *next; + u32 error_interrupts; + u32 error_rmiss_interrupts; + u32 rcv_interrupts; + u32 xmit_interrupts; + u32 num_isrs; + u32 false_interrupts; + u32 max_isr_rcvs; + u32 max_isr_xmits; + u32 rcv_interrupt_yields; + u32 tx_packets; + u32 debug_ix; + ushort reg_type[32]; + ushort reg_offset[32]; + u32 reg_value[32]; + u32 reg_valueh[32]; }; #define NUM_CFG_SPACES 2 @@ -337,182 +337,182 @@ struct sliccard { #define NUM_CFG_REG_ULONGS (NUM_CFG_REGS / sizeof(u32)) struct physcard { - struct adapter *adapter[SLIC_MAX_PORTS]; - struct physcard *next; - uint adapters_allocd; + struct adapter *adapter[SLIC_MAX_PORTS]; + struct physcard *next; + uint adapters_allocd; - /* the following is not currently needed - u32 bridge_busnum; - u32 bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS]; - */ +/* the following is not currently needed + u32 bridge_busnum; + u32 bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS]; +*/ }; struct base_driver { - struct slic_spinlock driver_lock; - u32 num_slic_cards; - u32 num_slic_ports; - u32 num_slic_ports_active; - u32 dynamic_intagg; - struct sliccard *slic_card; - struct physcard *phys_card; - uint cardnuminuse[SLIC_MAX_CARDS]; + struct slic_spinlock driver_lock; + u32 num_slic_cards; + u32 num_slic_ports; + u32 num_slic_ports_active; + u32 dynamic_intagg; + struct sliccard *slic_card; + struct physcard *phys_card; + uint cardnuminuse[SLIC_MAX_CARDS]; }; struct slic_shmem { - volatile u32 isr; - volatile u32 linkstatus; - volatile struct slic_stats inicstats; + volatile u32 isr; + volatile u32 linkstatus; + volatile struct slic_stats inicstats; }; struct slic_reg_params { - u32 linkspeed; - u32 linkduplex; - u32 fail_on_bad_eeprom; + u32 linkspeed; + u32 linkduplex; + u32 fail_on_bad_eeprom; }; struct slic_upr { - uint adapter; - u32 upr_request; - u32 upr_data; - u32 upr_data_h; - u32 upr_buffer; - u32 upr_buffer_h; - struct slic_upr *next; + uint adapter; + u32 upr_request; + u32 upr_data; + u32 upr_data_h; + u32 upr_buffer; + u32 upr_buffer_h; + struct slic_upr *next; }; struct slic_ifevents { - uint oflow802; - uint uflow802; - uint Tprtoflow; - uint rcvearly; - uint Bufov; - uint Carre; - uint Longe; - uint Invp; - uint Crc; - uint Drbl; - uint Code; - uint IpHlen; - uint IpLen; - uint IpCsum; - uint TpCsum; - uint TpHlen; + uint oflow802; + uint uflow802; + uint Tprtoflow; + uint rcvearly; + uint Bufov; + uint Carre; + uint Longe; + uint Invp; + uint Crc; + uint Drbl; + uint Code; + uint IpHlen; + uint IpLen; + uint IpCsum; + uint TpCsum; + uint TpHlen; }; struct adapter { - void *ifp; - struct sliccard *card; - uint port; - struct physcard *physcard; - uint physport; - uint cardindex; - uint card_size; - uint chipid; - struct net_device *netdev; - struct net_device *next_netdevice; - struct slic_spinlock adapter_lock; - struct slic_spinlock reset_lock; - struct pci_dev *pcidev; - uint busnumber; - uint slotnumber; - uint functionnumber; - ushort vendid; - ushort devid; - ushort subsysid; - u32 irq; - void __iomem *memorybase; - u32 memorylength; - u32 drambase; - u32 dramlength; - uint queues_initialized; - uint allocated; - uint activated; - u32 intrregistered; - uint isp_initialized; - uint gennumber; - u32 curaddrupper; - struct slic_shmem *pshmem; - dma_addr_t phys_shmem; - u32 isrcopy; - __iomem struct slic_regs *slic_regs; - unsigned char state; - unsigned char linkstate; - unsigned char linkspeed; - unsigned char linkduplex; - uint flags; - unsigned char macaddr[6]; - unsigned char currmacaddr[6]; - u32 macopts; - ushort devflags_prev; - u64 mcastmask; - struct mcast_address *mcastaddrs; - struct slic_upr *upr_list; - uint upr_busy; - struct timer_list pingtimer; - u32 pingtimerset; - struct timer_list loadtimer; - u32 loadtimerset; - struct dentry *debugfs_entry; - struct slic_spinlock upr_lock; - struct slic_spinlock bit64reglock; - struct slic_rspqueue rspqueue; - struct slic_rcvqueue rcvqueue; - struct slic_cmdqueue cmdq_free; - struct slic_cmdqueue cmdq_done; - struct slic_cmdqueue cmdq_all; - struct slic_cmdqmem cmdqmem; - /* - * SLIC Handles - */ - struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS+1]; /* Object handles*/ - struct slic_handle *pfree_slic_handles; /* Free object handles*/ - struct slic_spinlock handle_lock; /* Object handle list lock*/ - ushort slic_handle_ix; - - u32 xmitq_full; - u32 all_reg_writes; - u32 icr_reg_writes; - u32 isr_reg_writes; - u32 error_interrupts; - u32 error_rmiss_interrupts; - u32 rx_errors; - u32 rcv_drops; - u32 rcv_interrupts; - u32 xmit_interrupts; - u32 linkevent_interrupts; - u32 upr_interrupts; - u32 num_isrs; - u32 false_interrupts; - u32 tx_packets; - u32 xmit_completes; - u32 tx_drops; - u32 rcv_broadcasts; - u32 rcv_multicasts; - u32 rcv_unicasts; - u32 max_isr_rcvs; - u32 max_isr_xmits; - u32 rcv_interrupt_yields; - u32 intagg_period; - struct inicpm_state *inicpm_info; - void *pinicpm_info; - struct slic_reg_params reg_params; - struct slic_ifevents if_events; - struct slic_stats inicstats_prev; - struct slicnet_stats slic_stats; + void *ifp; + struct sliccard *card; + uint port; + struct physcard *physcard; + uint physport; + uint cardindex; + uint card_size; + uint chipid; + struct net_device *netdev; + struct net_device *next_netdevice; + struct slic_spinlock adapter_lock; + struct slic_spinlock reset_lock; + struct pci_dev *pcidev; + uint busnumber; + uint slotnumber; + uint functionnumber; + ushort vendid; + ushort devid; + ushort subsysid; + u32 irq; + void __iomem *memorybase; + u32 memorylength; + u32 drambase; + u32 dramlength; + uint queues_initialized; + uint allocated; + uint activated; + u32 intrregistered; + uint isp_initialized; + uint gennumber; + u32 curaddrupper; + struct slic_shmem *pshmem; + dma_addr_t phys_shmem; + u32 isrcopy; + __iomem struct slic_regs *slic_regs; + unsigned char state; + unsigned char linkstate; + unsigned char linkspeed; + unsigned char linkduplex; + uint flags; + unsigned char macaddr[6]; + unsigned char currmacaddr[6]; + u32 macopts; + ushort devflags_prev; + u64 mcastmask; + struct mcast_address *mcastaddrs; + struct slic_upr *upr_list; + uint upr_busy; + struct timer_list pingtimer; + u32 pingtimerset; + struct timer_list loadtimer; + u32 loadtimerset; + struct dentry *debugfs_entry; + struct slic_spinlock upr_lock; + struct slic_spinlock bit64reglock; + struct slic_rspqueue rspqueue; + struct slic_rcvqueue rcvqueue; + struct slic_cmdqueue cmdq_free; + struct slic_cmdqueue cmdq_done; + struct slic_cmdqueue cmdq_all; + struct slic_cmdqmem cmdqmem; + /* + * SLIC Handles + */ + struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS+1]; /* Object handles*/ + struct slic_handle *pfree_slic_handles; /* Free object handles*/ + struct slic_spinlock handle_lock; /* Object handle list lock*/ + ushort slic_handle_ix; + + u32 xmitq_full; + u32 all_reg_writes; + u32 icr_reg_writes; + u32 isr_reg_writes; + u32 error_interrupts; + u32 error_rmiss_interrupts; + u32 rx_errors; + u32 rcv_drops; + u32 rcv_interrupts; + u32 xmit_interrupts; + u32 linkevent_interrupts; + u32 upr_interrupts; + u32 num_isrs; + u32 false_interrupts; + u32 tx_packets; + u32 xmit_completes; + u32 tx_drops; + u32 rcv_broadcasts; + u32 rcv_multicasts; + u32 rcv_unicasts; + u32 max_isr_rcvs; + u32 max_isr_xmits; + u32 rcv_interrupt_yields; + u32 intagg_period; + struct inicpm_state *inicpm_info; + void *pinicpm_info; + struct slic_reg_params reg_params; + struct slic_ifevents if_events; + struct slic_stats inicstats_prev; + struct slicnet_stats slic_stats; }; #define UPDATE_STATS(largestat, newstat, oldstat) \ { \ - if ((newstat) < (oldstat)) \ - (largestat) += ((newstat) + (0xFFFFFFFF - oldstat + 1)); \ - else \ - (largestat) += ((newstat) - (oldstat)); \ + if ((newstat) < (oldstat)) \ + (largestat) += ((newstat) + (0xFFFFFFFF - oldstat + 1)); \ + else \ + (largestat) += ((newstat) - (oldstat)); \ } #define UPDATE_STATS_GB(largestat, newstat, oldstat) \ { \ - (largestat) += ((newstat) - (oldstat)); \ + (largestat) += ((newstat) - (oldstat)); \ } #if BITS_PER_LONG == 64 diff --git a/drivers/staging/slicoss/slichw.h b/drivers/staging/slicoss/slichw.h index 6275d45..21cd02b 100644 --- a/drivers/staging/slicoss/slichw.h +++ b/drivers/staging/slicoss/slichw.h @@ -450,7 +450,7 @@ struct slic_regs { u32 pad34; #define SLIC_DBAR64 0x0108 - u32 slic_cbar64; /* 64 bit Xmt Cmd buf addr regs. */ + u32 slic_cbar64; /* 64 bit Xmt Cmd buf addr regs. */ u32 pad35; #define SLIC_CBAR64 0x0110 @@ -478,11 +478,11 @@ struct slic_regs { u32 slic_read_xf_info; /* Read Transformer info */ u32 pad41; -#define SLIC_READ_XF_INFO 0x0140 +#define SLIC_READ_XF_INFO 0x0140 u32 slic_write_xf_info; /* Write Transformer info */ u32 pad42; -#define SLIC_WRITE_XF_INFO 0x0148 +#define SLIC_WRITE_XF_INFO 0x0148 u32 RSVD1; /* TOE Only */ u32 pad43; diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c index b6b99a3..76fc2e5 100644 --- a/drivers/staging/slicoss/slicoss.c +++ b/drivers/staging/slicoss/slicoss.c @@ -144,24 +144,24 @@ MODULE_DEVICE_TABLE(pci, slic_pci_tbl); #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \ { \ - spin_lock_irqsave(&_adapter->handle_lock.lock, \ + spin_lock_irqsave(&_adapter->handle_lock.lock, \ _adapter->handle_lock.flags); \ - _pslic_handle = _adapter->pfree_slic_handles; \ - if (_pslic_handle) { \ - _adapter->pfree_slic_handles = _pslic_handle->next; \ - } \ - spin_unlock_irqrestore(&_adapter->handle_lock.lock, \ + _pslic_handle = _adapter->pfree_slic_handles; \ + if (_pslic_handle) { \ + _adapter->pfree_slic_handles = _pslic_handle->next; \ + } \ + spin_unlock_irqrestore(&_adapter->handle_lock.lock, \ _adapter->handle_lock.flags); \ } #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \ { \ - _pslic_handle->type = SLIC_HANDLE_FREE; \ - spin_lock_irqsave(&_adapter->handle_lock.lock, \ + _pslic_handle->type = SLIC_HANDLE_FREE; \ + spin_lock_irqsave(&_adapter->handle_lock.lock, \ _adapter->handle_lock.flags); \ - _pslic_handle->next = _adapter->pfree_slic_handles; \ - _adapter->pfree_slic_handles = _pslic_handle; \ - spin_unlock_irqrestore(&_adapter->handle_lock.lock, \ + _pslic_handle->next = _adapter->pfree_slic_handles; \ + _adapter->pfree_slic_handles = _pslic_handle; \ + spin_unlock_irqrestore(&_adapter->handle_lock.lock, \ _adapter->handle_lock.flags); \ } -- cgit v0.10.2 From 8441bf5e063e03e5d307ffb32fd5f77e81c0d397 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 9 Jan 2013 10:10:59 +0300 Subject: staging: sb105x: move dereference under IS_ERR() check Avoid dereverencing the ERR_PTR() by shifting the dereference down a couple lines. Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/sb105x/sb_pci_mp.c b/drivers/staging/sb105x/sb_pci_mp.c index 131afd0c..c34ebff 100644 --- a/drivers/staging/sb105x/sb_pci_mp.c +++ b/drivers/staging/sb105x/sb_pci_mp.c @@ -1563,13 +1563,13 @@ static int mp_open(struct tty_struct *tty, struct file *filp) state = uart_get(drv, line); - mtpt = (struct mp_port *)state->port; - if (IS_ERR(state)) { retval = PTR_ERR(state); goto fail; } + mtpt = (struct mp_port *)state->port; + tty->driver_data = state; tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0; tty->alt_speed = 0; -- cgit v0.10.2 From c803dd48f0539cb6adcbbcf41c758502e1e102cb Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 9 Jan 2013 10:12:14 +0300 Subject: staging: sb105x: clean up interface type test IIR_RS232 is zero so "if (IIR_RS232 == (b_ret & IIR_RS232))" is always true so RS232 was always chosen by default. The test should be "if (0 == (b_ret & 0x30)) { ". The other tests should also be in that format. This does change how the code works... If 0x30 is set then it now defaults to RS232 instead of RS485. Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/sb105x/sb_mp_register.h b/drivers/staging/sb105x/sb_mp_register.h index 5480ae1..a2087f5 100644 --- a/drivers/staging/sb105x/sb_mp_register.h +++ b/drivers/staging/sb105x/sb_mp_register.h @@ -45,7 +45,7 @@ #define IIR_RS232 0x00 /* RS232 type */ #define IIR_RS422 0x10 /* RS422 type */ #define IIR_RS485 0x20 /* RS485 type */ -#define IIR_UNKNOWN 0x30 /* unknown type */ +#define IIR_TYPE_MASK 0x30 /* Interrrupt Mask Register */ #define MP_OPTR_IMR0 0x0C /* port0 ~ port8 */ diff --git a/drivers/staging/sb105x/sb_pci_mp.c b/drivers/staging/sb105x/sb_pci_mp.c index c34ebff..3da44df 100644 --- a/drivers/staging/sb105x/sb_pci_mp.c +++ b/drivers/staging/sb105x/sb_pci_mp.c @@ -2851,18 +2851,12 @@ static void __init multi_init_ports(void) printk("IIR_RET = %x\n",b_ret); } - if(IIR_RS232 == (b_ret & IIR_RS232)) - { - mtpt->interface = RS232; - } - if(IIR_RS422 == (b_ret & IIR_RS422)) - { + /* default to RS232 */ + mtpt->interface = RS232; + if (IIR_RS422 == (b_ret & IIR_TYPE_MASK)) mtpt->interface = RS422PTP; - } - if(IIR_RS485 == (b_ret & IIR_RS485)) - { + if (IIR_RS485 == (b_ret & IIR_TYPE_MASK)) mtpt->interface = RS485NE; - } } } } -- cgit v0.10.2 From f14287b9671d462a54d3b6800832fb519284eb34 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Wed, 16 Jan 2013 22:16:05 -0500 Subject: Staging: usbip: usbipcommon: Fixed single line bracing issue Fixed coding style issue with single line braces. Signed-off-by: Jake Champlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c index 75189fe..75aa5bf 100644 --- a/drivers/staging/usbip/usbip_common.c +++ b/drivers/staging/usbip/usbip_common.c @@ -672,9 +672,8 @@ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb) return 0; /* my Bluetooth dongle gets ISO URBs which are np = 0 */ - if (np == 0) { + if (np == 0) return 0; - } buff = kzalloc(size, GFP_KERNEL); if (!buff) -- cgit v0.10.2 From 7c256647b5ef8094ca3a6f43a442d6d8aac18058 Mon Sep 17 00:00:00 2001 From: Omar Ramirez Luna Date: Thu, 10 Jan 2013 03:36:58 -0600 Subject: staging: tidspbridge: fix potential array out of bounds write The name of the firmware (drv_datap->base_img) could potentially become equal to 255 valid characters (size of exec_file), this will result in an out of bounds write, given that the 255 chars along with a '\0' terminator will be copied into an array of 255 chars. Produce an error on this cases, because the driver expects the NULL ending to be among the 255 char limit. Reported-by: Chen Gang Signed-off-by: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c index 5e43938..ac016ed 100644 --- a/drivers/staging/tidspbridge/rmgr/proc.c +++ b/drivers/staging/tidspbridge/rmgr/proc.c @@ -394,7 +394,7 @@ static int get_exec_file(struct cfg_devnode *dev_node_obj, if (!drv_datap || !drv_datap->base_img) return -EFAULT; - if (strlen(drv_datap->base_img) > size) + if (strlen(drv_datap->base_img) >= size) return -EINVAL; strcpy(exec_file, drv_datap->base_img); -- cgit v0.10.2 From 94c947cd4ec7c886df246f87255dc925e3a0a47f Mon Sep 17 00:00:00 2001 From: Omar Ramirez Luna Date: Thu, 10 Jan 2013 03:36:59 -0600 Subject: staging: tidspbridge: fix memory corruption on long string names The value allocated doesn't match the one that is meant to be stored, resulting in corruption of memory for longer strings that can't be held in such space. Fix by allocating the correct byte value for the string meant to be stored. Signed-off-by: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/rmgr/dbdcd.c b/drivers/staging/tidspbridge/rmgr/dbdcd.c index 9d52c3c..3d2a26f 100644 --- a/drivers/staging/tidspbridge/rmgr/dbdcd.c +++ b/drivers/staging/tidspbridge/rmgr/dbdcd.c @@ -852,8 +852,7 @@ int dcd_register_object(struct dsp_uuid *uuid_obj, goto func_end; } - dcd_key->path = kmalloc(strlen(sz_reg_key) + 1, - GFP_KERNEL); + dcd_key->path = kmalloc(dw_path_size, GFP_KERNEL); if (!dcd_key->path) { kfree(dcd_key); -- cgit v0.10.2 From 49720e0120b55b131f4e210ff66325dbfc8a9eab Mon Sep 17 00:00:00 2001 From: Omar Ramirez Luna Date: Thu, 10 Jan 2013 03:37:00 -0600 Subject: staging: tidspbridge: fix uninitialized variable sym_name On both counts, sym_name could be printed uninitialized, this is solved by moving the pr_* statement to be triggered if the value is assigned. Reported-by: Chen Gang Signed-off-by: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/rmgr/nldr.c b/drivers/staging/tidspbridge/rmgr/nldr.c index 6309221b..ca38050 100644 --- a/drivers/staging/tidspbridge/rmgr/nldr.c +++ b/drivers/staging/tidspbridge/rmgr/nldr.c @@ -1802,8 +1802,6 @@ int nldr_find_addr(struct nldr_nodeobject *nldr_node, u32 sym_addr, bool status1 = false; s32 i = 0; struct lib_node root = { NULL, 0, NULL }; - pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__, (u32) nldr_node, - sym_addr, offset_range, (u32) offset_output, sym_name); if (nldr_node->dynamic && *nldr_node->phase_split) { switch (nldr_node->phase) { @@ -1852,6 +1850,10 @@ int nldr_find_addr(struct nldr_nodeobject *nldr_node, u32 sym_addr, pr_debug("%s: Address 0x%x not found in range %d.\n", __func__, sym_addr, offset_range); status = -ESPIPE; + } else { + pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", + __func__, (u32) nldr_node, sym_addr, offset_range, + (u32) offset_output, sym_name); } return status; diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c index 737f4a9..87dfa92 100644 --- a/drivers/staging/tidspbridge/rmgr/node.c +++ b/drivers/staging/tidspbridge/rmgr/node.c @@ -3012,16 +3012,16 @@ int node_find_addr(struct node_mgr *node_mgr, u32 sym_addr, struct node_object *node_obj; int status = -ENOENT; - pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__, - (unsigned int) node_mgr, - sym_addr, offset_range, - (unsigned int) sym_addr_output, sym_name); - list_for_each_entry(node_obj, &node_mgr->node_list, list_elem) { status = nldr_find_addr(node_obj->nldr_node_obj, sym_addr, offset_range, sym_addr_output, sym_name); - if (!status) + if (!status) { + pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__, + (unsigned int) node_mgr, + sym_addr, offset_range, + (unsigned int) sym_addr_output, sym_name); break; + } } return status; -- cgit v0.10.2 From 4cb55ca1dbd992436a090d05d0e1ab17ea749447 Mon Sep 17 00:00:00 2001 From: Omar Ramirez Luna Date: Thu, 10 Jan 2013 03:37:01 -0600 Subject: staging: tidspbridge: use scm functions to set boot address and mode Instead of ioremapping SCM registers, use the correspondent layer to write into them. This allows us to get rid of a layer violation, since the registers are no longer touched by driver code. Signed-off-by: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/core/tiomap3430.c b/drivers/staging/tidspbridge/core/tiomap3430.c index f619fb3..b770b22 100644 --- a/drivers/staging/tidspbridge/core/tiomap3430.c +++ b/drivers/staging/tidspbridge/core/tiomap3430.c @@ -70,14 +70,9 @@ #define PAGES_II_LVL_TABLE 512 #define PHYS_TO_PAGE(phys) pfn_to_page((phys) >> PAGE_SHIFT) -/* - * This is a totally ugly layer violation, but needed until - * omap_ctrl_set_dsp_boot*() are provided. - */ -#define OMAP3_IVA2_BOOTMOD_IDLE 1 -#define OMAP2_CONTROL_GENERAL 0x270 -#define OMAP343X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190) -#define OMAP343X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194) +/* IVA Boot modes */ +#define DIRECT 0 +#define IDLE 1 /* Forward Declarations: */ static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt); @@ -423,29 +418,14 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt, /* Assert RST1 i.e only the RST only for DSP megacell */ if (!status) { - /* - * XXX: OMAP343X_CTRL_BASE ioremapping MUST be removed once ctrl - * function is made available. - */ - void __iomem *ctrl = ioremap(0x48002000, SZ_4K); - if (!ctrl) { - iounmap(sync_addr); - return -ENOMEM; - } - (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK, OMAP3430_RST1_IVA2_MASK, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL); - /* Mask address with 1K for compatibility */ - __raw_writel(dsp_addr & OMAP3_IVA2_BOOTADDR_MASK, - ctrl + OMAP343X_CONTROL_IVA2_BOOTADDR); - /* - * Set bootmode to self loop if dsp_debug flag is true - */ - __raw_writel((dsp_debug) ? OMAP3_IVA2_BOOTMOD_IDLE : 0, - ctrl + OMAP343X_CONTROL_IVA2_BOOTMOD); - iounmap(ctrl); + /* Mask address with 1K for compatibility */ + pdata->set_bootaddr(dsp_addr & + OMAP3_IVA2_BOOTADDR_MASK); + pdata->set_bootmode(dsp_debug ? IDLE : DIRECT); } } if (!status) { -- cgit v0.10.2 From a679f36152dab84e9187572b2a3e193ddd95f58d Mon Sep 17 00:00:00 2001 From: Omar Ramirez Luna Date: Thu, 10 Jan 2013 03:37:02 -0600 Subject: staging: tidspbridge: remove unused code to handle iva_img There is no way to specify the value of iva_img and since this code is not being used, remove it. This analysis resulted from a report by Chen Gang , mentioning that the existing code was wrongly specifying the size to be copied. Signed-off-by: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/include/dspbridge/proc.h b/drivers/staging/tidspbridge/include/dspbridge/proc.h index 851b356..774a3f6 100644 --- a/drivers/staging/tidspbridge/include/dspbridge/proc.h +++ b/drivers/staging/tidspbridge/include/dspbridge/proc.h @@ -23,8 +23,6 @@ #include #include -extern char *iva_img; - /* * ======== proc_attach ======== * Purpose: diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c index e6f31d8..df0f37e 100644 --- a/drivers/staging/tidspbridge/rmgr/drv_interface.c +++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c @@ -65,7 +65,6 @@ static struct class *bridge_class; static u32 driver_context; static s32 driver_major; static char *base_img; -char *iva_img; static s32 shm_size = 0x500000; /* 5 MB */ static int tc_wordswapon; /* Default value is always false */ #ifdef CONFIG_TIDSPBRIDGE_RECOVERY diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c index ac016ed..e1bdf6e 100644 --- a/drivers/staging/tidspbridge/rmgr/proc.c +++ b/drivers/staging/tidspbridge/rmgr/proc.c @@ -382,7 +382,6 @@ static int get_exec_file(struct cfg_devnode *dev_node_obj, u32 size, char *exec_file) { u8 dev_type; - s32 len; struct drv_data *drv_datap = dev_get_drvdata(bridge); dev_get_dev_type(hdev_obj, (u8 *) &dev_type); @@ -398,9 +397,6 @@ static int get_exec_file(struct cfg_devnode *dev_node_obj, return -EINVAL; strcpy(exec_file, drv_datap->base_img); - } else if (dev_type == IVA_UNIT && iva_img) { - len = strlen(iva_img); - strncpy(exec_file, iva_img, len + 1); } else { return -ENOENT; } -- cgit v0.10.2 From ba1bcf6f23e192e88b7c07d20d6221a0bcb7929e Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 8 Jan 2013 13:27:48 +0000 Subject: staging: comedi: (core): add comedi_dev_from_file_info() Setting `info = comedi_file_info_from_minor(minor)` and `dev = comedi_dev_from_minor(minor)` in the same function is a bit of a waste. The latter function is just a call of the former followed by a conditional return of an embedded pointer (`info->device`) or NULL. The former function uses a spin-lock which is where the wastfulness comes in. Move the "followed by a conditional return of an embedded pointer" part into a new function `comedi_dev_from_file_info` and call this instead of `comedi_dev_from_minor()` in the places where `comedi_file_info_from_minor()` is also called. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index cd2c7d4..7d1e1d5 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -103,14 +103,16 @@ static struct comedi_file_info *comedi_file_info_from_minor(unsigned minor) return info; } -struct comedi_device *comedi_dev_from_minor(unsigned minor) +static struct comedi_device * +comedi_dev_from_file_info(struct comedi_file_info *info) { - struct comedi_file_info *info; - - info = comedi_file_info_from_minor(minor); - return info ? info->device : NULL; } + +struct comedi_device *comedi_dev_from_minor(unsigned minor) +{ + return comedi_dev_from_file_info(comedi_file_info_from_minor(minor)); +} EXPORT_SYMBOL_GPL(comedi_dev_from_minor); static struct comedi_subdevice * @@ -1647,8 +1649,8 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { const unsigned minor = iminor(file->f_dentry->d_inode); - struct comedi_device *dev = comedi_dev_from_minor(minor); struct comedi_file_info *info = comedi_file_info_from_minor(minor); + struct comedi_device *dev = comedi_dev_from_file_info(info); int rc; if (!dev) @@ -1771,7 +1773,7 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma) { const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev = comedi_dev_from_minor(minor); + struct comedi_device *dev = comedi_dev_from_file_info(info); struct comedi_subdevice *s; struct comedi_async *async; unsigned long start = vma->vm_start; @@ -1851,7 +1853,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) unsigned int mask = 0; const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev = comedi_dev_from_minor(minor); + struct comedi_device *dev = comedi_dev_from_file_info(info); struct comedi_subdevice *s; if (!dev) @@ -1897,7 +1899,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev = comedi_dev_from_minor(minor); + struct comedi_device *dev = comedi_dev_from_file_info(info); if (!dev) return -ENODEV; @@ -1992,7 +1994,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); struct comedi_file_info *info = comedi_file_info_from_minor(minor); - struct comedi_device *dev = comedi_dev_from_minor(minor); + struct comedi_device *dev = comedi_dev_from_file_info(info); if (!dev) return -ENODEV; -- cgit v0.10.2 From d18431325be0d485f58097755de5ec90091f336d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 09:46:10 -0700 Subject: staging: comedi: deprecate loading firmware with comedi_config All the comedi drivers have been converted to use the request_firmware() hotplug interface. The COMEDI_DEVCONFIG ioctl support for passing the firmware blob as 'aux_data' is no longer required. Remove the feature and give the user a dev_warn message if it is attempted. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h index c8a8ca1..4233605 100644 --- a/drivers/staging/comedi/comedi.h +++ b/drivers/staging/comedi/comedi.h @@ -41,7 +41,17 @@ /* number of config options in the config structure */ #define COMEDI_NDEVCONFOPTS 32 -/*length of nth chunk of firmware data*/ + +/* + * NOTE: 'comedi_config --init-data' is deprecated + * + * The following indexes in the config options were used by + * comedi_config to pass firmware blobs from user space to the + * comedi drivers. The request_firmware() hotplug interface is + * now used by all comedi drivers instead. + */ + +/* length of nth chunk of firmware data -*/ #define COMEDI_DEVCONF_AUX_DATA3_LENGTH 25 #define COMEDI_DEVCONF_AUX_DATA2_LENGTH 26 #define COMEDI_DEVCONF_AUX_DATA1_LENGTH 27 diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 7d1e1d5..599e775 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -469,8 +469,6 @@ static int do_devconfig_ioctl(struct comedi_device *dev, { struct comedi_devconfig it; int ret; - unsigned char *aux_data = NULL; - int aux_len; if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -491,31 +489,10 @@ static int do_devconfig_ioctl(struct comedi_device *dev, it.board_name[COMEDI_NAMELEN - 1] = 0; - if (comedi_aux_data(it.options, 0) && - it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { - int bit_shift; - aux_len = it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; - if (aux_len < 0) - return -EFAULT; - - aux_data = vmalloc(aux_len); - if (!aux_data) - return -ENOMEM; - - if (copy_from_user(aux_data, - (unsigned char __user * - )comedi_aux_data(it.options, 0), aux_len)) { - vfree(aux_data); - return -EFAULT; - } - it.options[COMEDI_DEVCONF_AUX_DATA_LO] = - (unsigned long)aux_data; - if (sizeof(void *) > sizeof(int)) { - bit_shift = sizeof(int) * 8; - it.options[COMEDI_DEVCONF_AUX_DATA_HI] = - ((unsigned long)aux_data) >> bit_shift; - } else - it.options[COMEDI_DEVCONF_AUX_DATA_HI] = 0; + if (it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { + dev_warn(dev->class_dev, + "comedi_config --init_data is deprecated\n"); + return -EINVAL; } ret = comedi_device_attach(dev, &it); @@ -526,9 +503,6 @@ static int do_devconfig_ioctl(struct comedi_device *dev, } } - if (aux_data) - vfree(aux_data); - return ret; } diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 34a85d3..c3bc4b7 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -461,31 +461,6 @@ static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) return async->buf_read_alloc_count - async->buf_read_count; } -static inline void *comedi_aux_data(int options[], int n) -{ - unsigned long address; - unsigned long address_low; - int bit_shift; - if (sizeof(int) >= sizeof(void *)) - address = options[COMEDI_DEVCONF_AUX_DATA_LO]; - else { - address = options[COMEDI_DEVCONF_AUX_DATA_HI]; - bit_shift = sizeof(int) * 8; - address <<= bit_shift; - address_low = options[COMEDI_DEVCONF_AUX_DATA_LO]; - address_low &= (1UL << bit_shift) - 1; - address |= address_low; - } - if (n >= 1) - address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; - if (n >= 2) - address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH]; - if (n >= 3) - address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH]; - BUG_ON(n > 3); - return (void *)address; -} - int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct comedi_subdevice *s); void comedi_free_subdevice_minor(struct comedi_subdevice *s); -- cgit v0.10.2 From ea082fb1b0ee42b6430c83a6dc9d795381a87264 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:25:06 -0700 Subject: staging: comedi: separate out comedi_buf_* functions Create a new file, comedi_buf.c, to hold all the comedi_async buffer functions. Currently they are all in drivers.c and really don't have any association with that source file. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index f895c0c..51816c3 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,4 +1,5 @@ -comedi-y := comedi_fops.o range.o drivers.o +comedi-y := comedi_fops.o range.o drivers.o \ + comedi_buf.o comedi-$(CONFIG_PROC_FS) += proc.o comedi-$(CONFIG_COMPAT) += comedi_compat32.o diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c new file mode 100644 index 0000000..fe2dcae --- /dev/null +++ b/drivers/staging/comedi/comedi_buf.c @@ -0,0 +1,421 @@ +/* + * comedi_buf.c + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "comedidev.h" +#include "comedi_internal.h" + +int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, + unsigned long new_size) +{ + struct comedi_async *async = s->async; + + /* Round up new_size to multiple of PAGE_SIZE */ + new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK; + + /* if no change is required, do nothing */ + if (async->prealloc_buf && async->prealloc_bufsz == new_size) + return 0; + + /* deallocate old buffer */ + if (async->prealloc_buf) { + vunmap(async->prealloc_buf); + async->prealloc_buf = NULL; + async->prealloc_bufsz = 0; + } + if (async->buf_page_list) { + unsigned i; + for (i = 0; i < async->n_buf_pages; ++i) { + if (async->buf_page_list[i].virt_addr) { + clear_bit(PG_reserved, + &(virt_to_page(async->buf_page_list[i]. + virt_addr)->flags)); + if (s->async_dma_dir != DMA_NONE) { + dma_free_coherent(dev->hw_dev, + PAGE_SIZE, + async-> + buf_page_list + [i].virt_addr, + async-> + buf_page_list + [i].dma_addr); + } else { + free_page((unsigned long) + async->buf_page_list[i]. + virt_addr); + } + } + } + vfree(async->buf_page_list); + async->buf_page_list = NULL; + async->n_buf_pages = 0; + } + /* allocate new buffer */ + if (new_size) { + unsigned i = 0; + unsigned n_pages = new_size >> PAGE_SHIFT; + struct page **pages = NULL; + + async->buf_page_list = + vzalloc(sizeof(struct comedi_buf_page) * n_pages); + if (async->buf_page_list) + pages = vmalloc(sizeof(struct page *) * n_pages); + + if (pages) { + for (i = 0; i < n_pages; i++) { + if (s->async_dma_dir != DMA_NONE) { + async->buf_page_list[i].virt_addr = + dma_alloc_coherent(dev->hw_dev, + PAGE_SIZE, + &async-> + buf_page_list + [i].dma_addr, + GFP_KERNEL | + __GFP_COMP); + } else { + async->buf_page_list[i].virt_addr = + (void *) + get_zeroed_page(GFP_KERNEL); + } + if (async->buf_page_list[i].virt_addr == NULL) + break; + + set_bit(PG_reserved, + &(virt_to_page(async->buf_page_list[i]. + virt_addr)->flags)); + pages[i] = virt_to_page(async->buf_page_list[i]. + virt_addr); + } + } + if (i == n_pages) { + async->prealloc_buf = +#ifdef PAGE_KERNEL_NOCACHE + vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE); +#else + vmap(pages, n_pages, VM_MAP, PAGE_KERNEL); +#endif + } + vfree(pages); + + if (async->prealloc_buf == NULL) { + /* Some allocation failed above. */ + if (async->buf_page_list) { + for (i = 0; i < n_pages; i++) { + if (async->buf_page_list[i].virt_addr == + NULL) { + break; + } + clear_bit(PG_reserved, + &(virt_to_page(async-> + buf_page_list[i]. + virt_addr)->flags)); + if (s->async_dma_dir != DMA_NONE) { + dma_free_coherent(dev->hw_dev, + PAGE_SIZE, + async-> + buf_page_list + [i].virt_addr, + async-> + buf_page_list + [i].dma_addr); + } else { + free_page((unsigned long) + async->buf_page_list + [i].virt_addr); + } + } + vfree(async->buf_page_list); + async->buf_page_list = NULL; + } + return -ENOMEM; + } + async->n_buf_pages = n_pages; + } + async->prealloc_bufsz = new_size; + + return 0; +} + +void comedi_reset_async_buf(struct comedi_async *async) +{ + async->buf_write_alloc_count = 0; + async->buf_write_count = 0; + async->buf_read_alloc_count = 0; + async->buf_read_count = 0; + + async->buf_write_ptr = 0; + async->buf_read_ptr = 0; + + async->cur_chan = 0; + async->scan_progress = 0; + async->munge_chan = 0; + async->munge_count = 0; + async->munge_ptr = 0; + + async->events = 0; +} + +unsigned int comedi_buf_write_n_available(struct comedi_async *async) +{ + unsigned int free_end; + unsigned int nbytes; + + if (async == NULL) + return 0; + + free_end = async->buf_read_count + async->prealloc_bufsz; + nbytes = free_end - async->buf_write_alloc_count; + nbytes -= nbytes % bytes_per_sample(async->subdevice); + /* barrier insures the read of buf_read_count in this + query occurs before any following writes to the buffer which + might be based on the return value from this query. + */ + smp_mb(); + return nbytes; +} + +/* allocates chunk for the writer from free buffer space */ +unsigned int comedi_buf_write_alloc(struct comedi_async *async, + unsigned int nbytes) +{ + unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; + + if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) + nbytes = free_end - async->buf_write_alloc_count; + + async->buf_write_alloc_count += nbytes; + /* barrier insures the read of buf_read_count above occurs before + we write data to the write-alloc'ed buffer space */ + smp_mb(); + return nbytes; +} +EXPORT_SYMBOL(comedi_buf_write_alloc); + +/* allocates nothing unless it can completely fulfill the request */ +unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, + unsigned int nbytes) +{ + unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; + + if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) + nbytes = 0; + + async->buf_write_alloc_count += nbytes; + /* barrier insures the read of buf_read_count above occurs before + we write data to the write-alloc'ed buffer space */ + smp_mb(); + return nbytes; +} + +/* munging is applied to data by core as it passes between user + * and kernel space */ +static unsigned int comedi_buf_munge(struct comedi_async *async, + unsigned int num_bytes) +{ + struct comedi_subdevice *s = async->subdevice; + unsigned int count = 0; + const unsigned num_sample_bytes = bytes_per_sample(s); + + if (s->munge == NULL || (async->cmd.flags & CMDF_RAWDATA)) { + async->munge_count += num_bytes; + BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); + return num_bytes; + } + /* don't munge partial samples */ + num_bytes -= num_bytes % num_sample_bytes; + while (count < num_bytes) { + int block_size; + + block_size = num_bytes - count; + if (block_size < 0) { + dev_warn(s->device->class_dev, + "%s: %s: bug! block_size is negative\n", + __FILE__, __func__); + break; + } + if ((int)(async->munge_ptr + block_size - + async->prealloc_bufsz) > 0) + block_size = async->prealloc_bufsz - async->munge_ptr; + + s->munge(s->device, s, async->prealloc_buf + async->munge_ptr, + block_size, async->munge_chan); + + smp_wmb(); /* barrier insures data is munged in buffer + * before munge_count is incremented */ + + async->munge_chan += block_size / num_sample_bytes; + async->munge_chan %= async->cmd.chanlist_len; + async->munge_count += block_size; + async->munge_ptr += block_size; + async->munge_ptr %= async->prealloc_bufsz; + count += block_size; + } + BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); + return count; +} + +/* transfers a chunk from writer to filled buffer space */ +unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes) +{ + if ((int)(async->buf_write_count + nbytes - + async->buf_write_alloc_count) > 0) { + dev_info(async->subdevice->device->class_dev, + "attempted to write-free more bytes than have been write-allocated.\n"); + nbytes = async->buf_write_alloc_count - async->buf_write_count; + } + async->buf_write_count += nbytes; + async->buf_write_ptr += nbytes; + comedi_buf_munge(async, async->buf_write_count - async->munge_count); + if (async->buf_write_ptr >= async->prealloc_bufsz) + async->buf_write_ptr %= async->prealloc_bufsz; + + return nbytes; +} +EXPORT_SYMBOL(comedi_buf_write_free); + +unsigned int comedi_buf_read_n_available(struct comedi_async *async) +{ + unsigned num_bytes; + + if (async == NULL) + return 0; + num_bytes = async->munge_count - async->buf_read_count; + /* barrier insures the read of munge_count in this + query occurs before any following reads of the buffer which + might be based on the return value from this query. + */ + smp_rmb(); + return num_bytes; +} +EXPORT_SYMBOL(comedi_buf_read_n_available); + +/* allocates a chunk for the reader from filled (and munged) buffer space */ +unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes) +{ + if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) > + 0) { + nbytes = async->munge_count - async->buf_read_alloc_count; + } + async->buf_read_alloc_count += nbytes; + /* barrier insures read of munge_count occurs before we actually read + data out of buffer */ + smp_rmb(); + return nbytes; +} +EXPORT_SYMBOL(comedi_buf_read_alloc); + +/* transfers control of a chunk from reader to free buffer space */ +unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes) +{ + /* barrier insures data has been read out of + * buffer before read count is incremented */ + smp_mb(); + if ((int)(async->buf_read_count + nbytes - + async->buf_read_alloc_count) > 0) { + dev_info(async->subdevice->device->class_dev, + "attempted to read-free more bytes than have been read-allocated.\n"); + nbytes = async->buf_read_alloc_count - async->buf_read_count; + } + async->buf_read_count += nbytes; + async->buf_read_ptr += nbytes; + async->buf_read_ptr %= async->prealloc_bufsz; + return nbytes; +} +EXPORT_SYMBOL(comedi_buf_read_free); + +int comedi_buf_put(struct comedi_async *async, short x) +{ + unsigned int n = comedi_buf_write_alloc_strict(async, sizeof(short)); + + if (n < sizeof(short)) { + async->events |= COMEDI_CB_ERROR; + return 0; + } + *(short *)(async->prealloc_buf + async->buf_write_ptr) = x; + comedi_buf_write_free(async, sizeof(short)); + return 1; +} +EXPORT_SYMBOL(comedi_buf_put); + +int comedi_buf_get(struct comedi_async *async, short *x) +{ + unsigned int n = comedi_buf_read_n_available(async); + + if (n < sizeof(short)) + return 0; + comedi_buf_read_alloc(async, sizeof(short)); + *x = *(short *)(async->prealloc_buf + async->buf_read_ptr); + comedi_buf_read_free(async, sizeof(short)); + return 1; +} +EXPORT_SYMBOL(comedi_buf_get); + +void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, + const void *data, unsigned int num_bytes) +{ + unsigned int write_ptr = async->buf_write_ptr + offset; + + if (write_ptr >= async->prealloc_bufsz) + write_ptr %= async->prealloc_bufsz; + + while (num_bytes) { + unsigned int block_size; + + if (write_ptr + num_bytes > async->prealloc_bufsz) + block_size = async->prealloc_bufsz - write_ptr; + else + block_size = num_bytes; + + memcpy(async->prealloc_buf + write_ptr, data, block_size); + + data += block_size; + num_bytes -= block_size; + + write_ptr = 0; + } +} +EXPORT_SYMBOL(comedi_buf_memcpy_to); + +void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, + void *dest, unsigned int nbytes) +{ + void *src; + unsigned int read_ptr = async->buf_read_ptr + offset; + + if (read_ptr >= async->prealloc_bufsz) + read_ptr %= async->prealloc_bufsz; + + while (nbytes) { + unsigned int block_size; + + src = async->prealloc_buf + read_ptr; + + if (nbytes >= async->prealloc_bufsz - read_ptr) + block_size = async->prealloc_bufsz - read_ptr; + else + block_size = nbytes; + + memcpy(dest, src, block_size); + nbytes -= block_size; + dest += block_size; + read_ptr = 0; + } +} +EXPORT_SYMBOL(comedi_buf_memcpy_from); diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index b67a0c9..dca26f5 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -430,404 +430,6 @@ static int insn_rw_emulate_bits(struct comedi_device *dev, return 1; } -int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, - unsigned long new_size) -{ - struct comedi_async *async = s->async; - - /* Round up new_size to multiple of PAGE_SIZE */ - new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK; - - /* if no change is required, do nothing */ - if (async->prealloc_buf && async->prealloc_bufsz == new_size) - return 0; - - /* deallocate old buffer */ - if (async->prealloc_buf) { - vunmap(async->prealloc_buf); - async->prealloc_buf = NULL; - async->prealloc_bufsz = 0; - } - if (async->buf_page_list) { - unsigned i; - for (i = 0; i < async->n_buf_pages; ++i) { - if (async->buf_page_list[i].virt_addr) { - clear_bit(PG_reserved, - &(virt_to_page(async->buf_page_list[i]. - virt_addr)->flags)); - if (s->async_dma_dir != DMA_NONE) { - dma_free_coherent(dev->hw_dev, - PAGE_SIZE, - async-> - buf_page_list - [i].virt_addr, - async-> - buf_page_list - [i].dma_addr); - } else { - free_page((unsigned long) - async->buf_page_list[i]. - virt_addr); - } - } - } - vfree(async->buf_page_list); - async->buf_page_list = NULL; - async->n_buf_pages = 0; - } - /* allocate new buffer */ - if (new_size) { - unsigned i = 0; - unsigned n_pages = new_size >> PAGE_SHIFT; - struct page **pages = NULL; - - async->buf_page_list = - vzalloc(sizeof(struct comedi_buf_page) * n_pages); - if (async->buf_page_list) - pages = vmalloc(sizeof(struct page *) * n_pages); - - if (pages) { - for (i = 0; i < n_pages; i++) { - if (s->async_dma_dir != DMA_NONE) { - async->buf_page_list[i].virt_addr = - dma_alloc_coherent(dev->hw_dev, - PAGE_SIZE, - &async-> - buf_page_list - [i].dma_addr, - GFP_KERNEL | - __GFP_COMP); - } else { - async->buf_page_list[i].virt_addr = - (void *) - get_zeroed_page(GFP_KERNEL); - } - if (async->buf_page_list[i].virt_addr == NULL) - break; - - set_bit(PG_reserved, - &(virt_to_page(async->buf_page_list[i]. - virt_addr)->flags)); - pages[i] = virt_to_page(async->buf_page_list[i]. - virt_addr); - } - } - if (i == n_pages) { - async->prealloc_buf = -#ifdef PAGE_KERNEL_NOCACHE - vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE); -#else - vmap(pages, n_pages, VM_MAP, PAGE_KERNEL); -#endif - } - vfree(pages); - - if (async->prealloc_buf == NULL) { - /* Some allocation failed above. */ - if (async->buf_page_list) { - for (i = 0; i < n_pages; i++) { - if (async->buf_page_list[i].virt_addr == - NULL) { - break; - } - clear_bit(PG_reserved, - &(virt_to_page(async-> - buf_page_list[i]. - virt_addr)->flags)); - if (s->async_dma_dir != DMA_NONE) { - dma_free_coherent(dev->hw_dev, - PAGE_SIZE, - async-> - buf_page_list - [i].virt_addr, - async-> - buf_page_list - [i].dma_addr); - } else { - free_page((unsigned long) - async->buf_page_list - [i].virt_addr); - } - } - vfree(async->buf_page_list); - async->buf_page_list = NULL; - } - return -ENOMEM; - } - async->n_buf_pages = n_pages; - } - async->prealloc_bufsz = new_size; - - return 0; -} - -/* munging is applied to data by core as it passes between user - * and kernel space */ -static unsigned int comedi_buf_munge(struct comedi_async *async, - unsigned int num_bytes) -{ - struct comedi_subdevice *s = async->subdevice; - unsigned int count = 0; - const unsigned num_sample_bytes = bytes_per_sample(s); - - if (s->munge == NULL || (async->cmd.flags & CMDF_RAWDATA)) { - async->munge_count += num_bytes; - BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); - return num_bytes; - } - /* don't munge partial samples */ - num_bytes -= num_bytes % num_sample_bytes; - while (count < num_bytes) { - int block_size; - - block_size = num_bytes - count; - if (block_size < 0) { - dev_warn(s->device->class_dev, - "%s: %s: bug! block_size is negative\n", - __FILE__, __func__); - break; - } - if ((int)(async->munge_ptr + block_size - - async->prealloc_bufsz) > 0) - block_size = async->prealloc_bufsz - async->munge_ptr; - - s->munge(s->device, s, async->prealloc_buf + async->munge_ptr, - block_size, async->munge_chan); - - smp_wmb(); /* barrier insures data is munged in buffer - * before munge_count is incremented */ - - async->munge_chan += block_size / num_sample_bytes; - async->munge_chan %= async->cmd.chanlist_len; - async->munge_count += block_size; - async->munge_ptr += block_size; - async->munge_ptr %= async->prealloc_bufsz; - count += block_size; - } - BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); - return count; -} - -unsigned int comedi_buf_write_n_available(struct comedi_async *async) -{ - unsigned int free_end; - unsigned int nbytes; - - if (async == NULL) - return 0; - - free_end = async->buf_read_count + async->prealloc_bufsz; - nbytes = free_end - async->buf_write_alloc_count; - nbytes -= nbytes % bytes_per_sample(async->subdevice); - /* barrier insures the read of buf_read_count in this - query occurs before any following writes to the buffer which - might be based on the return value from this query. - */ - smp_mb(); - return nbytes; -} - -/* allocates chunk for the writer from free buffer space */ -unsigned int comedi_buf_write_alloc(struct comedi_async *async, - unsigned int nbytes) -{ - unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - - if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) - nbytes = free_end - async->buf_write_alloc_count; - - async->buf_write_alloc_count += nbytes; - /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ - smp_mb(); - return nbytes; -} -EXPORT_SYMBOL(comedi_buf_write_alloc); - -/* allocates nothing unless it can completely fulfill the request */ -unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, - unsigned int nbytes) -{ - unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - - if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) - nbytes = 0; - - async->buf_write_alloc_count += nbytes; - /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ - smp_mb(); - return nbytes; -} - -/* transfers a chunk from writer to filled buffer space */ -unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes) -{ - if ((int)(async->buf_write_count + nbytes - - async->buf_write_alloc_count) > 0) { - dev_info(async->subdevice->device->class_dev, - "attempted to write-free more bytes than have been write-allocated.\n"); - nbytes = async->buf_write_alloc_count - async->buf_write_count; - } - async->buf_write_count += nbytes; - async->buf_write_ptr += nbytes; - comedi_buf_munge(async, async->buf_write_count - async->munge_count); - if (async->buf_write_ptr >= async->prealloc_bufsz) - async->buf_write_ptr %= async->prealloc_bufsz; - - return nbytes; -} -EXPORT_SYMBOL(comedi_buf_write_free); - -/* allocates a chunk for the reader from filled (and munged) buffer space */ -unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes) -{ - if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) > - 0) { - nbytes = async->munge_count - async->buf_read_alloc_count; - } - async->buf_read_alloc_count += nbytes; - /* barrier insures read of munge_count occurs before we actually read - data out of buffer */ - smp_rmb(); - return nbytes; -} -EXPORT_SYMBOL(comedi_buf_read_alloc); - -/* transfers control of a chunk from reader to free buffer space */ -unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes) -{ - /* barrier insures data has been read out of - * buffer before read count is incremented */ - smp_mb(); - if ((int)(async->buf_read_count + nbytes - - async->buf_read_alloc_count) > 0) { - dev_info(async->subdevice->device->class_dev, - "attempted to read-free more bytes than have been read-allocated.\n"); - nbytes = async->buf_read_alloc_count - async->buf_read_count; - } - async->buf_read_count += nbytes; - async->buf_read_ptr += nbytes; - async->buf_read_ptr %= async->prealloc_bufsz; - return nbytes; -} -EXPORT_SYMBOL(comedi_buf_read_free); - -void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, - const void *data, unsigned int num_bytes) -{ - unsigned int write_ptr = async->buf_write_ptr + offset; - - if (write_ptr >= async->prealloc_bufsz) - write_ptr %= async->prealloc_bufsz; - - while (num_bytes) { - unsigned int block_size; - - if (write_ptr + num_bytes > async->prealloc_bufsz) - block_size = async->prealloc_bufsz - write_ptr; - else - block_size = num_bytes; - - memcpy(async->prealloc_buf + write_ptr, data, block_size); - - data += block_size; - num_bytes -= block_size; - - write_ptr = 0; - } -} -EXPORT_SYMBOL(comedi_buf_memcpy_to); - -void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, - void *dest, unsigned int nbytes) -{ - void *src; - unsigned int read_ptr = async->buf_read_ptr + offset; - - if (read_ptr >= async->prealloc_bufsz) - read_ptr %= async->prealloc_bufsz; - - while (nbytes) { - unsigned int block_size; - - src = async->prealloc_buf + read_ptr; - - if (nbytes >= async->prealloc_bufsz - read_ptr) - block_size = async->prealloc_bufsz - read_ptr; - else - block_size = nbytes; - - memcpy(dest, src, block_size); - nbytes -= block_size; - dest += block_size; - read_ptr = 0; - } -} -EXPORT_SYMBOL(comedi_buf_memcpy_from); - -unsigned int comedi_buf_read_n_available(struct comedi_async *async) -{ - unsigned num_bytes; - - if (async == NULL) - return 0; - num_bytes = async->munge_count - async->buf_read_count; - /* barrier insures the read of munge_count in this - query occurs before any following reads of the buffer which - might be based on the return value from this query. - */ - smp_rmb(); - return num_bytes; -} -EXPORT_SYMBOL(comedi_buf_read_n_available); - -int comedi_buf_get(struct comedi_async *async, short *x) -{ - unsigned int n = comedi_buf_read_n_available(async); - - if (n < sizeof(short)) - return 0; - comedi_buf_read_alloc(async, sizeof(short)); - *x = *(short *)(async->prealloc_buf + async->buf_read_ptr); - comedi_buf_read_free(async, sizeof(short)); - return 1; -} -EXPORT_SYMBOL(comedi_buf_get); - -int comedi_buf_put(struct comedi_async *async, short x) -{ - unsigned int n = comedi_buf_write_alloc_strict(async, sizeof(short)); - - if (n < sizeof(short)) { - async->events |= COMEDI_CB_ERROR; - return 0; - } - *(short *)(async->prealloc_buf + async->buf_write_ptr) = x; - comedi_buf_write_free(async, sizeof(short)); - return 1; -} -EXPORT_SYMBOL(comedi_buf_put); - -void comedi_reset_async_buf(struct comedi_async *async) -{ - async->buf_write_alloc_count = 0; - async->buf_write_count = 0; - async->buf_read_alloc_count = 0; - async->buf_read_count = 0; - - async->buf_write_ptr = 0; - async->buf_read_ptr = 0; - - async->cur_chan = 0; - async->scan_progress = 0; - async->munge_chan = 0; - async->munge_count = 0; - async->munge_ptr = 0; - - async->events = 0; -} - int comedi_auto_config(struct device *hardware_device, struct comedi_driver *driver, unsigned long context) { -- cgit v0.10.2 From 718c4d68d9491e8bc16a614d193b257efc41723e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:25:54 -0700 Subject: staging: comedi: comedi_buf: factor out common code to free the async buffer The function comedi_buf_alloc() uses two loops to free the async buffer's buf_page_list. The first one is used at the beginning to deallocate the current buffer. The second is used to cleanup if the new buffer allocation fails. Factor out the common code to a new function. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index fe2dcae..3f01b0b 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -22,6 +22,43 @@ #include "comedidev.h" #include "comedi_internal.h" +static void __comedi_buf_free(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned n_pages) +{ + struct comedi_async *async = s->async; + struct comedi_buf_page *buf; + unsigned i; + + if (async->prealloc_buf) { + vunmap(async->prealloc_buf); + async->prealloc_buf = NULL; + async->prealloc_bufsz = 0; + } + + if (!async->buf_page_list) + return; + + for (i = 0; i < n_pages; ++i) { + buf = &async->buf_page_list[i]; + if (buf->virt_addr) { + clear_bit(PG_reserved, + &(virt_to_page(buf->virt_addr)->flags)); + if (s->async_dma_dir != DMA_NONE) { + dma_free_coherent(dev->hw_dev, + PAGE_SIZE, + buf->virt_addr, + buf->dma_addr); + } else { + free_page((unsigned long)buf->virt_addr); + } + } + } + vfree(async->buf_page_list); + async->buf_page_list = NULL; + async->n_buf_pages = 0; +} + int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, unsigned long new_size) { @@ -34,39 +71,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, if (async->prealloc_buf && async->prealloc_bufsz == new_size) return 0; - /* deallocate old buffer */ - if (async->prealloc_buf) { - vunmap(async->prealloc_buf); - async->prealloc_buf = NULL; - async->prealloc_bufsz = 0; - } - if (async->buf_page_list) { - unsigned i; - for (i = 0; i < async->n_buf_pages; ++i) { - if (async->buf_page_list[i].virt_addr) { - clear_bit(PG_reserved, - &(virt_to_page(async->buf_page_list[i]. - virt_addr)->flags)); - if (s->async_dma_dir != DMA_NONE) { - dma_free_coherent(dev->hw_dev, - PAGE_SIZE, - async-> - buf_page_list - [i].virt_addr, - async-> - buf_page_list - [i].dma_addr); - } else { - free_page((unsigned long) - async->buf_page_list[i]. - virt_addr); - } - } - } - vfree(async->buf_page_list); - async->buf_page_list = NULL; - async->n_buf_pages = 0; - } + /* deallocate old buffer */ + __comedi_buf_free(dev, s, async->n_buf_pages); + /* allocate new buffer */ if (new_size) { unsigned i = 0; @@ -114,36 +121,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, } vfree(pages); - if (async->prealloc_buf == NULL) { - /* Some allocation failed above. */ - if (async->buf_page_list) { - for (i = 0; i < n_pages; i++) { - if (async->buf_page_list[i].virt_addr == - NULL) { - break; - } - clear_bit(PG_reserved, - &(virt_to_page(async-> - buf_page_list[i]. - virt_addr)->flags)); - if (s->async_dma_dir != DMA_NONE) { - dma_free_coherent(dev->hw_dev, - PAGE_SIZE, - async-> - buf_page_list - [i].virt_addr, - async-> - buf_page_list - [i].dma_addr); - } else { - free_page((unsigned long) - async->buf_page_list - [i].virt_addr); - } - } - vfree(async->buf_page_list); - async->buf_page_list = NULL; - } + if (!async->prealloc_buf) { + /* Some allocation failed above */ + __comedi_buf_free(dev, s, n_pages); return -ENOMEM; } async->n_buf_pages = n_pages; -- cgit v0.10.2 From 6bd764573179f3f7c165b1ee093aff2d7ad3c59e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:26:26 -0700 Subject: staging: comedi: comedi_buf: factor out new buffer allocation code The function comedi_buf_alloc() first frees any allocated buffer then, optionally, allocates a new buffer. Factor out the new buffer allocation code to a new function. This allows reducing the indent level and makes the code a bit cleaner. Also, cleanup to factored out code to make it a bit more concise. Use a local variable for the current comedi_buf_page being allocated. This cleans up the ugly line breaks used to keep the lines < 80 chars. Move the #ifdef'ery for the page protection determination out of the vmap() call. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 3f01b0b..2fc8981 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -22,6 +22,12 @@ #include "comedidev.h" #include "comedi_internal.h" +#ifdef PAGE_KERNEL_NOCACHE +#define COMEDI_PAGE_PROTECTION PAGE_KERNEL_NOCACHE +#else +#define COMEDI_PAGE_PROTECTION PAGE_KERNEL +#endif + static void __comedi_buf_free(struct comedi_device *dev, struct comedi_subdevice *s, unsigned n_pages) @@ -59,6 +65,48 @@ static void __comedi_buf_free(struct comedi_device *dev, async->n_buf_pages = 0; } +static void __comedi_buf_alloc(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned n_pages) +{ + struct comedi_async *async = s->async; + struct page **pages = NULL; + struct comedi_buf_page *buf; + unsigned i; + + async->buf_page_list = vzalloc(sizeof(*buf) * n_pages); + if (async->buf_page_list) + pages = vmalloc(sizeof(struct page *) * n_pages); + + if (!pages) + return; + + for (i = 0; i < n_pages; i++) { + buf = &async->buf_page_list[i]; + if (s->async_dma_dir != DMA_NONE) + buf->virt_addr = dma_alloc_coherent(dev->hw_dev, + PAGE_SIZE, + &buf->dma_addr, + GFP_KERNEL | + __GFP_COMP); + else + buf->virt_addr = (void *)get_zeroed_page(GFP_KERNEL); + if (!buf->virt_addr) + break; + + set_bit(PG_reserved, &(virt_to_page(buf->virt_addr)->flags)); + + pages[i] = virt_to_page(buf->virt_addr); + } + + /* vmap the prealloc_buf if all the pages were allocated */ + if (i == n_pages) + async->prealloc_buf = vmap(pages, n_pages, VM_MAP, + COMEDI_PAGE_PROTECTION); + + vfree(pages); +} + int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, unsigned long new_size) { @@ -74,55 +122,14 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, /* deallocate old buffer */ __comedi_buf_free(dev, s, async->n_buf_pages); - /* allocate new buffer */ + /* allocate new buffer */ if (new_size) { - unsigned i = 0; unsigned n_pages = new_size >> PAGE_SHIFT; - struct page **pages = NULL; - - async->buf_page_list = - vzalloc(sizeof(struct comedi_buf_page) * n_pages); - if (async->buf_page_list) - pages = vmalloc(sizeof(struct page *) * n_pages); - - if (pages) { - for (i = 0; i < n_pages; i++) { - if (s->async_dma_dir != DMA_NONE) { - async->buf_page_list[i].virt_addr = - dma_alloc_coherent(dev->hw_dev, - PAGE_SIZE, - &async-> - buf_page_list - [i].dma_addr, - GFP_KERNEL | - __GFP_COMP); - } else { - async->buf_page_list[i].virt_addr = - (void *) - get_zeroed_page(GFP_KERNEL); - } - if (async->buf_page_list[i].virt_addr == NULL) - break; - - set_bit(PG_reserved, - &(virt_to_page(async->buf_page_list[i]. - virt_addr)->flags)); - pages[i] = virt_to_page(async->buf_page_list[i]. - virt_addr); - } - } - if (i == n_pages) { - async->prealloc_buf = -#ifdef PAGE_KERNEL_NOCACHE - vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE); -#else - vmap(pages, n_pages, VM_MAP, PAGE_KERNEL); -#endif - } - vfree(pages); + + __comedi_buf_alloc(dev, s, n_pages); if (!async->prealloc_buf) { - /* Some allocation failed above */ + /* allocation failed */ __comedi_buf_free(dev, s, n_pages); return -ENOMEM; } -- cgit v0.10.2 From 61c9fb0eb08bc9b7164a6181b0062d9959406a34 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:27:07 -0700 Subject: staging: comedi: comedi_buf: rename comedi_reset_async_buf() For aesthetic reasons, rename this function to comedi_buf_reset(). This makes all the asynchronous buffer functions have the same namespace. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 2fc8981..9392453 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -140,7 +140,7 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, return 0; } -void comedi_reset_async_buf(struct comedi_async *async) +void comedi_buf_reset(struct comedi_async *async) { async->buf_write_alloc_count = 0; async->buf_write_count = 0; diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 599e775..3e82ab9 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -408,7 +408,7 @@ static void do_become_nonbusy(struct comedi_device *dev, comedi_set_subdevice_runflags(s, SRF_RUNNING, 0); if (async) { - comedi_reset_async_buf(async); + comedi_buf_reset(async); async->inttrig = NULL; kfree(async->cmd.chanlist); async->cmd.chanlist = NULL; @@ -1338,7 +1338,7 @@ static int do_cmd_ioctl(struct comedi_device *dev, goto cleanup; } - comedi_reset_async_buf(async); + comedi_buf_reset(async); async->cb_mask = COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR | diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index e70ef051..9e94f2d 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -13,9 +13,10 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, int comedi_alloc_board_minor(struct device *hardware_device); void comedi_free_board_minor(unsigned minor); int comedi_find_board_minor(struct device *hardware_device); -void comedi_reset_async_buf(struct comedi_async *async); + int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, unsigned long new_size); +void comedi_buf_reset(struct comedi_async *async); extern unsigned int comedi_default_buf_size_kb; extern unsigned int comedi_default_buf_maxsize_kb; -- cgit v0.10.2 From f8f76e909b8cc6696071e69cf4be07714c95bcb4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:27:48 -0700 Subject: staging: comedi: comedi_buf: factor out common comedi_buf_write_alloc_* code The only difference between comedi_buf_write_alloc() and the *_strict() version is that the *_strict() one will only allocate the chunk if it can completely fulfill the request. Factor out the common code and add a flag parameter to indicate the 'strict' usage. Change the exported functions so they are just wrappers around the common function. Cleanup the common function a bit and use the comedi_buf_write_n_available() helper to determine the number of bytes available. comedi_buf_write_n_available() is not used outside this module so make it static. Since the only caller is __comedi_buf_write_alloc(), which will always have a valid async pointer and already has a memory barrier, we can remove the unnecessary (async == NULL) test as well as the smp_mb(). Also, the rounding of the sample size can be removed since the caller does not need it. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 9392453..2f38a87 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -159,22 +159,30 @@ void comedi_buf_reset(struct comedi_async *async) async->events = 0; } -unsigned int comedi_buf_write_n_available(struct comedi_async *async) +static unsigned int comedi_buf_write_n_available(struct comedi_async *async) { - unsigned int free_end; - unsigned int nbytes; + unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - if (async == NULL) - return 0; + return free_end - async->buf_write_alloc_count; +} - free_end = async->buf_read_count + async->prealloc_bufsz; - nbytes = free_end - async->buf_write_alloc_count; - nbytes -= nbytes % bytes_per_sample(async->subdevice); - /* barrier insures the read of buf_read_count in this - query occurs before any following writes to the buffer which - might be based on the return value from this query. +static unsigned int __comedi_buf_write_alloc(struct comedi_async *async, + unsigned int nbytes, + int strict) +{ + unsigned int available = comedi_buf_write_n_available(async); + + if (nbytes > available) + nbytes = strict ? 0 : available; + + async->buf_write_alloc_count += nbytes; + + /* + * ensure the async buffer 'counts' are read and updated + * before we write data to the write-alloc'ed buffer space */ smp_mb(); + return nbytes; } @@ -182,16 +190,7 @@ unsigned int comedi_buf_write_n_available(struct comedi_async *async) unsigned int comedi_buf_write_alloc(struct comedi_async *async, unsigned int nbytes) { - unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - - if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) - nbytes = free_end - async->buf_write_alloc_count; - - async->buf_write_alloc_count += nbytes; - /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ - smp_mb(); - return nbytes; + return __comedi_buf_write_alloc(async, nbytes, 0); } EXPORT_SYMBOL(comedi_buf_write_alloc); @@ -199,16 +198,7 @@ EXPORT_SYMBOL(comedi_buf_write_alloc); unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, unsigned int nbytes) { - unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - - if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) - nbytes = 0; - - async->buf_write_alloc_count += nbytes; - /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ - smp_mb(); - return nbytes; + return __comedi_buf_write_alloc(async, nbytes, 1); } /* munging is applied to data by core as it passes between user diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index c3bc4b7..bf0fd8d 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -438,7 +438,6 @@ comedi_to_usb_interface(struct comedi_device *dev) int comedi_buf_put(struct comedi_async *async, short x); int comedi_buf_get(struct comedi_async *async, short *x); -unsigned int comedi_buf_write_n_available(struct comedi_async *async); unsigned int comedi_buf_write_alloc(struct comedi_async *async, unsigned int nbytes); unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, -- cgit v0.10.2 From 47181eab71a81a919bf74eee570d6db59c6cf298 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:28:20 -0700 Subject: staging: comedi: comedi_buf: remove comedi_buf_write_alloc_strict This function is only called by comedi_buf_put(). Remove it and just call __comedi_buf_write_alloc() directly with the strict flag set. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 2f38a87..1b269a7 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -194,13 +194,6 @@ unsigned int comedi_buf_write_alloc(struct comedi_async *async, } EXPORT_SYMBOL(comedi_buf_write_alloc); -/* allocates nothing unless it can completely fulfill the request */ -unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, - unsigned int nbytes) -{ - return __comedi_buf_write_alloc(async, nbytes, 1); -} - /* munging is applied to data by core as it passes between user * and kernel space */ static unsigned int comedi_buf_munge(struct comedi_async *async, @@ -319,7 +312,7 @@ EXPORT_SYMBOL(comedi_buf_read_free); int comedi_buf_put(struct comedi_async *async, short x) { - unsigned int n = comedi_buf_write_alloc_strict(async, sizeof(short)); + unsigned int n = __comedi_buf_write_alloc(async, sizeof(short), 1); if (n < sizeof(short)) { async->events |= COMEDI_CB_ERROR; diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index bf0fd8d..cbfb614 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -440,8 +440,6 @@ int comedi_buf_get(struct comedi_async *async, short *x); unsigned int comedi_buf_write_alloc(struct comedi_async *async, unsigned int nbytes); -unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, - unsigned int nbytes); unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes); unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes); unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes); -- cgit v0.10.2 From 8d4be669479d95a0c6eb4b6a538460f0ab35c4f7 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:29:19 -0700 Subject: staging: comedi: comedi_buf: cleanup comedi_buf_munge() Refactor this function so there is a single return point and only one BUG_ON check. The BUG_ON needs to be looked at to see if it can be safely removed. Clarify the test in the munge loop that checks for a block copy that would extend pass the end of the prealloc_buf. Reword the comment about the need for the smp_wmb(). Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 1b269a7..95cbe36 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -194,8 +194,10 @@ unsigned int comedi_buf_write_alloc(struct comedi_async *async, } EXPORT_SYMBOL(comedi_buf_write_alloc); -/* munging is applied to data by core as it passes between user - * and kernel space */ +/* + * munging is applied to data by core as it passes between user + * and kernel space + */ static unsigned int comedi_buf_munge(struct comedi_async *async, unsigned int num_bytes) { @@ -203,40 +205,46 @@ static unsigned int comedi_buf_munge(struct comedi_async *async, unsigned int count = 0; const unsigned num_sample_bytes = bytes_per_sample(s); - if (s->munge == NULL || (async->cmd.flags & CMDF_RAWDATA)) { + if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) { async->munge_count += num_bytes; - BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); - return num_bytes; - } - /* don't munge partial samples */ - num_bytes -= num_bytes % num_sample_bytes; - while (count < num_bytes) { - int block_size; - - block_size = num_bytes - count; - if (block_size < 0) { - dev_warn(s->device->class_dev, - "%s: %s: bug! block_size is negative\n", - __FILE__, __func__); - break; + count = num_bytes; + } else { + /* don't munge partial samples */ + num_bytes -= num_bytes % num_sample_bytes; + while (count < num_bytes) { + int block_size = num_bytes - count; + unsigned int buf_end; + + if (block_size < 0) { + dev_warn(s->device->class_dev, + "%s: %s: bug! block_size is negative\n", + __FILE__, __func__); + break; + } + + buf_end = async->prealloc_bufsz - async->munge_ptr; + if (block_size > buf_end) + block_size = buf_end; + + s->munge(s->device, s, + async->prealloc_buf + async->munge_ptr, + block_size, async->munge_chan); + + /* + * ensure data is munged in buffer before the + * async buffer munge_count is incremented + */ + smp_wmb(); + + async->munge_chan += block_size / num_sample_bytes; + async->munge_chan %= async->cmd.chanlist_len; + async->munge_count += block_size; + async->munge_ptr += block_size; + async->munge_ptr %= async->prealloc_bufsz; + count += block_size; } - if ((int)(async->munge_ptr + block_size - - async->prealloc_bufsz) > 0) - block_size = async->prealloc_bufsz - async->munge_ptr; - - s->munge(s->device, s, async->prealloc_buf + async->munge_ptr, - block_size, async->munge_chan); - - smp_wmb(); /* barrier insures data is munged in buffer - * before munge_count is incremented */ - - async->munge_chan += block_size / num_sample_bytes; - async->munge_chan %= async->cmd.chanlist_len; - async->munge_count += block_size; - async->munge_ptr += block_size; - async->munge_ptr %= async->prealloc_bufsz; - count += block_size; } + BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); return count; } -- cgit v0.10.2 From d21af4cbfb7fccbccedc1d9e143a14aee6b1c9ad Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:29:53 -0700 Subject: staging: comedi: comedi_buf: clarify comedi_buf_write_free() Use the helper comedi_buf_write_n_allocated() to clarify the check to make sure the number of bytes to free is not more than the number of bytes allocated. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 95cbe36..fd2a92e 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -252,11 +252,12 @@ static unsigned int comedi_buf_munge(struct comedi_async *async, /* transfers a chunk from writer to filled buffer space */ unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes) { - if ((int)(async->buf_write_count + nbytes - - async->buf_write_alloc_count) > 0) { + unsigned int allocated = comedi_buf_write_n_allocated(async); + + if (nbytes > allocated) { dev_info(async->subdevice->device->class_dev, "attempted to write-free more bytes than have been write-allocated.\n"); - nbytes = async->buf_write_alloc_count - async->buf_write_count; + nbytes = allocated; } async->buf_write_count += nbytes; async->buf_write_ptr += nbytes; -- cgit v0.10.2 From 43f9137df461f6365f76b46f404fd6775eab7d51 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:30:22 -0700 Subject: staging: comedi: comedi_buf: cleanup comedi_buf_read_n_available() For aesthetic reasons, cleanup this function a bit. Change the (async == NULL) test to simply (!async). Reword the comment about the need for the smp_rmb().. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index fd2a92e..06dd544 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -273,14 +273,17 @@ unsigned int comedi_buf_read_n_available(struct comedi_async *async) { unsigned num_bytes; - if (async == NULL) + if (!async) return 0; + num_bytes = async->munge_count - async->buf_read_count; - /* barrier insures the read of munge_count in this - query occurs before any following reads of the buffer which - might be based on the return value from this query. + + /* + * ensure the async buffer 'counts' are read before we + * attempt to read data from the buffer */ smp_rmb(); + return num_bytes; } EXPORT_SYMBOL(comedi_buf_read_n_available); -- cgit v0.10.2 From 034cbd17922a8b6c64b227360314167c15c1f031 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:30:49 -0700 Subject: staging: comedi: comedi_buf: clarify comedi_buf_read_alloc() Clarify the check to make sure the number of bytes to allocate is available. Reword the comment about the need for the smp_rmb(). Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 06dd544..971f739 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -291,14 +291,20 @@ EXPORT_SYMBOL(comedi_buf_read_n_available); /* allocates a chunk for the reader from filled (and munged) buffer space */ unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes) { - if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) > - 0) { - nbytes = async->munge_count - async->buf_read_alloc_count; - } + unsigned int available; + + available = async->munge_count - async->buf_read_alloc_count; + if (nbytes > available) + nbytes = available; + async->buf_read_alloc_count += nbytes; - /* barrier insures read of munge_count occurs before we actually read - data out of buffer */ + + /* + * ensure the async buffer 'counts' are read before we + * attempt to read data from the read-alloc'ed buffer space + */ smp_rmb(); + return nbytes; } EXPORT_SYMBOL(comedi_buf_read_alloc); -- cgit v0.10.2 From 3abfa1066b9e98df434868eda9ba91d7012d45c6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:31:16 -0700 Subject: staging: comedi: comedi_buf: clarify comedi_buf_read_free() Reword the comment about the need for the smp_mb(). Clarify the check to make sure the number of bytes to free is not more than the number of bytes allocated. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 971f739..70d2901 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -312,14 +312,19 @@ EXPORT_SYMBOL(comedi_buf_read_alloc); /* transfers control of a chunk from reader to free buffer space */ unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes) { - /* barrier insures data has been read out of - * buffer before read count is incremented */ + unsigned int allocated; + + /* + * ensure data has been read out of buffer before + * the async read count is incremented + */ smp_mb(); - if ((int)(async->buf_read_count + nbytes - - async->buf_read_alloc_count) > 0) { + + allocated = comedi_buf_read_n_allocated(async); + if (nbytes > allocated) { dev_info(async->subdevice->device->class_dev, "attempted to read-free more bytes than have been read-allocated.\n"); - nbytes = async->buf_read_alloc_count - async->buf_read_count; + nbytes = allocated; } async->buf_read_count += nbytes; async->buf_read_ptr += nbytes; -- cgit v0.10.2 From 5b2b64b7510292f4b1e6363edb6f53c39828672e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:31:46 -0700 Subject: staging: comedi: comedi_buf: don't expose comedi_buf_read_n_allocated() This helper function is only called in comedi_buf.c. Move it there and make it static so it's not exposed globally. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 70d2901..891cf89 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -309,6 +309,11 @@ unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes) } EXPORT_SYMBOL(comedi_buf_read_alloc); +static unsigned int comedi_buf_read_n_allocated(struct comedi_async *async) +{ + return async->buf_read_alloc_count - async->buf_read_count; +} + /* transfers control of a chunk from reader to free buffer space */ unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes) { diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index cbfb614..4d5a35e 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -453,11 +453,6 @@ static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async) return async->buf_write_alloc_count - async->buf_write_count; } -static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) -{ - return async->buf_read_alloc_count - async->buf_read_count; -} - int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct comedi_subdevice *s); void comedi_free_subdevice_minor(struct comedi_subdevice *s); -- cgit v0.10.2 From 8bd650f91be07fb84adc2e47fb1379b7223b95a4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:32:18 -0700 Subject: staging: comedi: comedi_buf: don't expose comedi_buf_write_n_allocated() This helper function is only called by the comedi core in comedi_buf.c and comedi_fops.c. For aesthetic reasons, move it to comedi_buf.c and remove the inline. Move the prototype from comedidev.h to comedi_internal.h so it's not exposed outside the comedi core. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 891cf89..c562346 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -249,6 +249,11 @@ static unsigned int comedi_buf_munge(struct comedi_async *async, return count; } +unsigned int comedi_buf_write_n_allocated(struct comedi_async *async) +{ + return async->buf_write_alloc_count - async->buf_write_count; +} + /* transfers a chunk from writer to filled buffer space */ unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes) { diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index 9e94f2d..5e6f05b 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -17,6 +17,7 @@ int comedi_find_board_minor(struct device *hardware_device); int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, unsigned long new_size); void comedi_buf_reset(struct comedi_async *async); +unsigned int comedi_buf_write_n_allocated(struct comedi_async *async); extern unsigned int comedi_default_buf_size_kb; extern unsigned int comedi_default_buf_maxsize_kb; diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 4d5a35e..140678d 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -448,10 +448,6 @@ void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, const void *source, unsigned int num_bytes); void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, void *destination, unsigned int num_bytes); -static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async) -{ - return async->buf_write_alloc_count - async->buf_write_count; -} int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct comedi_subdevice *s); -- cgit v0.10.2 From 8ae560a14abaf2b76fb486ad08fea9c6c5be640f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 9 Jan 2013 13:32:56 -0700 Subject: staging: comedi: comedi_buf: reorder exported function prototypes For aesthetic reasons, reorder the prototypes for the exported comedi_buf_* functions in comedidev.h to follow the function declarations in comedi_buf.c. Also, change a couple of the return values from 'unsigned' to 'unsigned int' to match the value actually returned. Signed-off-by: H Hartley Sweeten Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index c562346..ac5f0a9 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -255,7 +255,8 @@ unsigned int comedi_buf_write_n_allocated(struct comedi_async *async) } /* transfers a chunk from writer to filled buffer space */ -unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes) +unsigned int comedi_buf_write_free(struct comedi_async *async, + unsigned int nbytes) { unsigned int allocated = comedi_buf_write_n_allocated(async); @@ -294,7 +295,8 @@ unsigned int comedi_buf_read_n_available(struct comedi_async *async) EXPORT_SYMBOL(comedi_buf_read_n_available); /* allocates a chunk for the reader from filled (and munged) buffer space */ -unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes) +unsigned int comedi_buf_read_alloc(struct comedi_async *async, + unsigned int nbytes) { unsigned int available; @@ -320,7 +322,8 @@ static unsigned int comedi_buf_read_n_allocated(struct comedi_async *async) } /* transfers control of a chunk from reader to free buffer space */ -unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes) +unsigned int comedi_buf_read_free(struct comedi_async *async, + unsigned int nbytes) { unsigned int allocated; diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 140678d..85b84b0 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -435,15 +435,16 @@ comedi_to_usb_interface(struct comedi_device *dev) return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; } -int comedi_buf_put(struct comedi_async *async, short x); -int comedi_buf_get(struct comedi_async *async, short *x); - -unsigned int comedi_buf_write_alloc(struct comedi_async *async, - unsigned int nbytes); -unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes); -unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes); -unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes); -unsigned int comedi_buf_read_n_available(struct comedi_async *async); +unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); +unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); + +unsigned int comedi_buf_read_n_available(struct comedi_async *); +unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int); +unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int); + +int comedi_buf_put(struct comedi_async *, short); +int comedi_buf_get(struct comedi_async *, short *); + void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, const void *source, unsigned int num_bytes); void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, -- cgit v0.10.2 From 305a6f3896350bbfa59c0021f59600bbbb2e9590 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 10 Jan 2013 10:36:58 -0700 Subject: staging: comedi: comedi_buf: remove BUG_ON in comedi_buf_munge() The condition that would trigger this BUG_ON can never occur. The 'munge_count' will be equal to 'buf_write_count' if all the data in the buffer has been munged. Or, the 'munge_count' will be less than the 'buf_write_count' if any partial samples in the buffer were not munged. The 'munge_count' will never be greater than the 'buf_write_count'. Remove the unnecessary BUG_ON. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index ac5f0a9..7d516a0 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -245,7 +245,6 @@ static unsigned int comedi_buf_munge(struct comedi_async *async, } } - BUG_ON((int)(async->munge_count - async->buf_write_count) > 0); return count; } -- cgit v0.10.2 From a8f40f463fda58b90206173be73dc199beb7395f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 10 Jan 2013 10:37:27 -0700 Subject: staging: comedi: comedi_buf: remove unreachable dev_warn in comedi_buf_munge() Due to the 'while(count < num_bytes)' the computed 'block_size' will always be a value greater than 0. Remove the unreachable dev_warn and the (block_size < 0) test. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 7d516a0..9d11f416 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -215,13 +215,6 @@ static unsigned int comedi_buf_munge(struct comedi_async *async, int block_size = num_bytes - count; unsigned int buf_end; - if (block_size < 0) { - dev_warn(s->device->class_dev, - "%s: %s: bug! block_size is negative\n", - __FILE__, __func__); - break; - } - buf_end = async->prealloc_bufsz - async->munge_ptr; if (block_size > buf_end) block_size = buf_end; -- cgit v0.10.2 From 6166ce878771edfe2d0fb9e719d5c4d4d4b82157 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 10 Jan 2013 10:37:56 -0700 Subject: staging: comedi: comedi_buf: remove noise in comedi_buf_write_free() If an attempt is made to free more bytes than have been allocated a dev_info message is output and the number of bytes to free is adjusted to the allocated size. Telling the user this happened is just noise. Remove the message. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 9d11f416..17162d9 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -252,11 +252,9 @@ unsigned int comedi_buf_write_free(struct comedi_async *async, { unsigned int allocated = comedi_buf_write_n_allocated(async); - if (nbytes > allocated) { - dev_info(async->subdevice->device->class_dev, - "attempted to write-free more bytes than have been write-allocated.\n"); + if (nbytes > allocated) nbytes = allocated; - } + async->buf_write_count += nbytes; async->buf_write_ptr += nbytes; comedi_buf_munge(async, async->buf_write_count - async->munge_count); -- cgit v0.10.2 From 215040e1238fa18caf5edf9bcd68126ecd8a6b2d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 10 Jan 2013 10:38:20 -0700 Subject: staging: comedi: comedi_buf: remove noise in comedi_buf_read_free() If an attempt is made to free more bytes than have been allocated a dev_info message is output and the number of bytes to free is adjusted to the allocated size. Telling the user this happened is just noise. Remove the message. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 17162d9..9b997ae 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -324,11 +324,9 @@ unsigned int comedi_buf_read_free(struct comedi_async *async, smp_mb(); allocated = comedi_buf_read_n_allocated(async); - if (nbytes > allocated) { - dev_info(async->subdevice->device->class_dev, - "attempted to read-free more bytes than have been read-allocated.\n"); + if (nbytes > allocated) nbytes = allocated; - } + async->buf_read_count += nbytes; async->buf_read_ptr += nbytes; async->buf_read_ptr %= async->prealloc_bufsz; -- cgit v0.10.2 From d1e1501e3129f215ec182bb0c69305655d429f80 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Thu, 17 Jan 2013 08:55:30 -0500 Subject: Staging: Comedi: ni_tio: Fixed spacing issue Fixed coding style issue from spaces to tabs. Signed-off-by: Jake Champlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c index 98f8789..2252877 100644 --- a/drivers/staging/comedi/drivers/ni_tio.c +++ b/drivers/staging/comedi/drivers/ni_tio.c @@ -276,7 +276,7 @@ static inline unsigned NI_660x_RTSI_Second_Gate_Select(unsigned n) } static const unsigned int counter_status_mask = - COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING; + COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING; static int __init ni_tio_init_module(void) { -- cgit v0.10.2 From d607ffac4cbd22599f2b006465c722104cc1cd1b Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:48 +0100 Subject: staging/comedi: Add macro for registering a comedi PCMCIA driver This patch introduces a new macro 'module_comedi_pcmcia_driver' for comedi PCMCIA drivers which do not do anything special in module init/exit. This eliminates a lot of boilerplate. Adapted from 'module_comedi_pci_driver' Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 85b84b0..6211d44 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -316,6 +316,27 @@ void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *); module_driver(__comedi_driver, comedi_pci_driver_register, \ comedi_pci_driver_unregister, &(__pci_driver)) +struct pcmcia_driver; + +int comedi_pcmcia_driver_register(struct comedi_driver *, + struct pcmcia_driver *); +void comedi_pcmcia_driver_unregister(struct comedi_driver *, + struct pcmcia_driver *); + +/** + * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver + * @__comedi_driver: comedi_driver struct + * @__pcmcia_driver: pcmcia_driver struct + * + * Helper macro for comedi PCMCIA drivers which do not do anything special + * in module init/exit. This eliminates a lot of boilerplate. Each + * module may only use this macro once, and calling it replaces + * module_init() and module_exit() + */ +#define module_comedi_pcmcia_driver(__comedi_driver, __pcmcia_driver) \ + module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ + comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) + struct usb_driver; int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index dca26f5..8b681ac 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -556,6 +558,36 @@ void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver, } EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister); +#if IS_ENABLED(CONFIG_PCMCIA) +int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, + struct pcmcia_driver *pcmcia_driver) +{ + int ret; + + ret = comedi_driver_register(comedi_driver); + if (ret < 0) + return ret; + + ret = pcmcia_register_driver(pcmcia_driver); + if (ret < 0) { + comedi_driver_unregister(comedi_driver); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register); + +void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, + struct pcmcia_driver *pcmcia_driver) +{ + pcmcia_unregister_driver(pcmcia_driver); + comedi_driver_unregister(comedi_driver); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); + +#endif + #if IS_ENABLED(CONFIG_USB) int comedi_usb_driver_register(struct comedi_driver *comedi_driver, -- cgit v0.10.2 From cb798ccfa0653afe56dd85a48057c1222d19e0b8 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:49 +0100 Subject: staging/comedi/ni_daq_dio24: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 7b33335..dd22691 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -318,31 +318,4 @@ static struct pcmcia_driver dio24_cs_driver = { .name = "ni_daq_dio24", }; -static int __init init_dio24_cs(void) -{ - printk("ni_daq_dio24: HOLA SOY YO!\n"); - pcmcia_register_driver(&dio24_cs_driver); - return 0; -} - -static void __exit exit_dio24_cs(void) -{ - pcmcia_unregister_driver(&dio24_cs_driver); -} - -int __init init_module(void) -{ - int ret; - - ret = init_dio24_cs(); - if (ret < 0) - return ret; - - return comedi_driver_register(&driver_dio24); -} - -void __exit cleanup_module(void) -{ - exit_dio24_cs(); - comedi_driver_unregister(&driver_dio24); -} +module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver); -- cgit v0.10.2 From 235bee772b0fa4cf059c669bcaa733da08b4894c Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:50 +0100 Subject: staging/comedi/ni_mio_cs: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Also removed the superflous #ifdef MODULE Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 76c6a13..b5c5d58 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -408,8 +408,6 @@ static int ni_getboardtype(struct comedi_device *dev, return 0; } -#ifdef MODULE - static const struct pcmcia_device_id ni_mio_cs_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */ @@ -434,20 +432,4 @@ static struct pcmcia_driver ni_mio_cs_driver = { .name = "ni_mio_cs", }; -int init_module(void) -{ - pcmcia_register_driver(&ni_mio_cs_driver); - comedi_driver_register(&driver_ni_mio_cs); - return 0; -} - -void cleanup_module(void) -{ - pcmcia_unregister_driver(&ni_mio_cs_driver); -#if 0 - while (cur_dev != NULL) - cs_detach(cur_dev->handle); -#endif - comedi_driver_unregister(&driver_ni_mio_cs); -} -#endif +module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver); -- cgit v0.10.2 From f3493a973d5e8985e2c61730257ffa43cbabdb09 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:51 +0100 Subject: staging/comedi/quatech_daqp_cs: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Also removed the superflous #ifdef MODULE Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index ef0cdaa..55d8cc6 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -1038,9 +1038,6 @@ static int daqp_cs_resume(struct pcmcia_device *link) } /*====================================================================*/ - -#ifdef MODULE - static const struct pcmcia_device_id daqp_cs_id_table[] = { PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0027), PCMCIA_DEVICE_NULL @@ -1061,17 +1058,4 @@ static struct pcmcia_driver daqp_cs_driver = { .name = "quatech_daqp_cs", }; -int __init init_module(void) -{ - pcmcia_register_driver(&daqp_cs_driver); - comedi_driver_register(&driver_daqp); - return 0; -} - -void __exit cleanup_module(void) -{ - comedi_driver_unregister(&driver_daqp); - pcmcia_unregister_driver(&daqp_cs_driver); -} - -#endif +module_comedi_pcmcia_driver(driver_daqp, daqp_cs_driver); -- cgit v0.10.2 From 66bf1ed6f6d8364a67c1c15c2fd2885b0f268405 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:52 +0100 Subject: staging/comedi/cb_das16_cs: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index 93731de..e253fc0 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -548,30 +548,7 @@ static struct pcmcia_driver das16cs_driver = { .id_table = das16cs_id_table, }; -static int __init das16cs_init(void) -{ - int ret; - - ret = comedi_driver_register(&driver_das16cs); - if (ret < 0) - return ret; - - ret = pcmcia_register_driver(&das16cs_driver); - if (ret < 0) { - comedi_driver_unregister(&driver_das16cs); - return ret; - } - - return 0; -} -module_init(das16cs_init); - -static void __exit das16cs_exit(void) -{ - pcmcia_unregister_driver(&das16cs_driver); - comedi_driver_unregister(&driver_das16cs); -} -module_exit(das16cs_exit); +module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver); MODULE_AUTHOR("David A. Schleef "); MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16"); -- cgit v0.10.2 From 7915ce0e6ffef01fc78f157c5158c139f2e7c441 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:53 +0100 Subject: staging/comedi/das08_cs: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index 0242623..73a2418 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -181,31 +181,7 @@ static struct pcmcia_driver das08_cs_driver = { .id_table = das08_cs_id_table, }; -static int __init das08_cs_init_module(void) -{ - int ret; - - ret = comedi_driver_register(&driver_das08_cs); - if (ret < 0) - return ret; - - ret = pcmcia_register_driver(&das08_cs_driver); - if (ret < 0) { - comedi_driver_unregister(&driver_das08_cs); - return ret; - } - - return 0; - -} -module_init(das08_cs_init_module); - -static void __exit das08_cs_exit_module(void) -{ - pcmcia_unregister_driver(&das08_cs_driver); - comedi_driver_unregister(&driver_das08_cs); -} -module_exit(das08_cs_exit_module); +module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver); MODULE_AUTHOR("David A. Schleef , " "Frank Mori Hess "); -- cgit v0.10.2 From 8ee8f77d9f0f932d9d542a3b2053e092b18ee2b8 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:54 +0100 Subject: staging/comedi/ni_daq_700: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index 68d7c6a..ff0e199 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -334,30 +334,7 @@ static struct pcmcia_driver daq700_cs_driver = { .id_table = daq700_cs_ids, }; -static int __init daq700_cs_init(void) -{ - int ret; - - ret = comedi_driver_register(&daq700_driver); - if (ret < 0) - return ret; - - ret = pcmcia_register_driver(&daq700_cs_driver); - if (ret < 0) { - comedi_driver_unregister(&daq700_driver); - return ret; - } - - return 0; -} -module_init(daq700_cs_init); - -static void __exit daq700_cs_exit(void) -{ - pcmcia_unregister_driver(&daq700_cs_driver); - comedi_driver_unregister(&daq700_driver); -} -module_exit(daq700_cs_exit); +module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver); MODULE_AUTHOR("Fred Brooks "); MODULE_DESCRIPTION( -- cgit v0.10.2 From 952bf230a5d8bae3ffc27c9b91b2475eda909727 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 14 Jan 2013 22:00:55 +0100 Subject: staging/comedi/ni_labpc_cs: Convert to module_comedi_pcmcia_driver This patch removes the boring init/exit functions with the new module_comedi_pcmcia_driver macro. Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index bfe19fa..b26496d 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -282,33 +282,4 @@ static struct pcmcia_driver labpc_cs_driver = { .name = "daqcard-1200", }; -static int __init init_labpc_cs(void) -{ - pcmcia_register_driver(&labpc_cs_driver); - return 0; -} - -static void __exit exit_labpc_cs(void) -{ - pcmcia_unregister_driver(&labpc_cs_driver); -} - -static int __init labpc_init_module(void) -{ - int ret; - - ret = init_labpc_cs(); - if (ret < 0) - return ret; - - return comedi_driver_register(&driver_labpc_cs); -} - -static void __exit labpc_exit_module(void) -{ - exit_labpc_cs(); - comedi_driver_unregister(&driver_labpc_cs); -} - -module_init(labpc_init_module); -module_exit(labpc_exit_module); +module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver); -- cgit v0.10.2 From be1a3e38ad7ba682f1a71e61ba16289061627217 Mon Sep 17 00:00:00 2001 From: John Stultz Date: Fri, 11 Jan 2013 15:46:22 -0800 Subject: staging: alarm-dev: Drop pre Android 1.0 _OLD ioctls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per Colin's comment: "The "support old userspace code" comment for those two ioctls has been there since pre-Android 1.0. Those apis are not exposed to Android apps, I don't see any problem deleting them." Thus this patch removes the ANDROID_ALARM_SET_OLD and ANDROID_ALARM_SET_AND_WAIT_OLD ioctl compatability logic. Cc: Serban Constantinescu Cc: Arve HjønnevÃ¥g Cc: Colin Cross Cc: Android Kernel Team Signed-off-by: John Stultz Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c index a9b293f..d423850 100644 --- a/drivers/staging/android/alarm-dev.c +++ b/drivers/staging/android/alarm-dev.c @@ -42,10 +42,6 @@ do { \ ANDROID_ALARM_RTC_WAKEUP_MASK | \ ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK) -/* support old userspace code */ -#define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t) /* set alarm */ -#define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t) - static int alarm_opened; static DEFINE_SPINLOCK(alarm_slock); static struct wakeup_source alarm_wake_lock; @@ -142,15 +138,6 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) spin_unlock_irqrestore(&alarm_slock, flags); break; - case ANDROID_ALARM_SET_OLD: - case ANDROID_ALARM_SET_AND_WAIT_OLD: - if (get_user(new_alarm_time.tv_sec, (int __user *)arg)) { - rv = -EFAULT; - goto err1; - } - new_alarm_time.tv_nsec = 0; - goto from_old_alarm_set; - case ANDROID_ALARM_SET_AND_WAIT(0): case ANDROID_ALARM_SET(0): if (copy_from_user(&new_alarm_time, (void __user *)arg, @@ -158,7 +145,6 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) rv = -EFAULT; goto err1; } -from_old_alarm_set: spin_lock_irqsave(&alarm_slock, flags); alarm_dbg(IO, "alarm %d set %ld.%09ld\n", alarm_type, @@ -167,8 +153,8 @@ from_old_alarm_set: devalarm_start(&alarms[alarm_type], timespec_to_ktime(new_alarm_time)); spin_unlock_irqrestore(&alarm_slock, flags); - if (ANDROID_ALARM_BASE_CMD(cmd) != ANDROID_ALARM_SET_AND_WAIT(0) - && cmd != ANDROID_ALARM_SET_AND_WAIT_OLD) + if (ANDROID_ALARM_BASE_CMD(cmd) != + ANDROID_ALARM_SET_AND_WAIT(0)) break; /* fall though */ case ANDROID_ALARM_WAIT: -- cgit v0.10.2 From cec8bb73a2c603034b04b5d56e16878d0b0ef2dd Mon Sep 17 00:00:00 2001 From: John Stultz Date: Fri, 11 Jan 2013 15:46:23 -0800 Subject: staging: alarm-dev: Refactor alarm-dev ioctl code in prep for compat_ioctl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup the Android alarm-dev driver's ioctl code to refactor it in preparation for compat_ioctl support. Cc: Serban Constantinescu Cc: Arve HjønnevÃ¥g Cc: Colin Cross Cc: Android Kernel Team Signed-off-by: John Stultz Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c index d423850..43af3b3 100644 --- a/drivers/staging/android/alarm-dev.c +++ b/drivers/staging/android/alarm-dev.c @@ -92,18 +92,116 @@ static void devalarm_cancel(struct devalarm *alrm) hrtimer_cancel(&alrm->u.hrt); } +static void alarm_clear(enum android_alarm_type alarm_type) +{ + uint32_t alarm_type_mask = 1U << alarm_type; + unsigned long flags; -static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) + spin_lock_irqsave(&alarm_slock, flags); + alarm_dbg(IO, "alarm %d clear\n", alarm_type); + devalarm_try_to_cancel(&alarms[alarm_type]); + if (alarm_pending) { + alarm_pending &= ~alarm_type_mask; + if (!alarm_pending && !wait_pending) + __pm_relax(&alarm_wake_lock); + } + alarm_enabled &= ~alarm_type_mask; + spin_unlock_irqrestore(&alarm_slock, flags); + +} + +static void alarm_set(enum android_alarm_type alarm_type, + struct timespec *ts) +{ + uint32_t alarm_type_mask = 1U << alarm_type; + unsigned long flags; + + spin_lock_irqsave(&alarm_slock, flags); + alarm_dbg(IO, "alarm %d set %ld.%09ld\n", + alarm_type, ts->tv_sec, ts->tv_nsec); + alarm_enabled |= alarm_type_mask; + devalarm_start(&alarms[alarm_type], timespec_to_ktime(*ts)); + spin_unlock_irqrestore(&alarm_slock, flags); +} + +static int alarm_wait(void) { - int rv = 0; unsigned long flags; - struct timespec new_alarm_time; - struct timespec new_rtc_time; - struct timespec tmp_time; + int rv = 0; + + spin_lock_irqsave(&alarm_slock, flags); + alarm_dbg(IO, "alarm wait\n"); + if (!alarm_pending && wait_pending) { + __pm_relax(&alarm_wake_lock); + wait_pending = 0; + } + spin_unlock_irqrestore(&alarm_slock, flags); + + rv = wait_event_interruptible(alarm_wait_queue, alarm_pending); + if (rv) + return rv; + + spin_lock_irqsave(&alarm_slock, flags); + rv = alarm_pending; + wait_pending = 1; + alarm_pending = 0; + spin_unlock_irqrestore(&alarm_slock, flags); + + return rv; +} + +static int alarm_set_rtc(struct timespec *ts) +{ struct rtc_time new_rtc_tm; struct rtc_device *rtc_dev; + unsigned long flags; + int rv = 0; + + rtc_time_to_tm(ts->tv_sec, &new_rtc_tm); + rtc_dev = alarmtimer_get_rtcdev(); + rv = do_settimeofday(ts); + if (rv < 0) + return rv; + if (rtc_dev) + rv = rtc_set_time(rtc_dev, &new_rtc_tm); + + spin_lock_irqsave(&alarm_slock, flags); + alarm_pending |= ANDROID_ALARM_TIME_CHANGE_MASK; + wake_up(&alarm_wait_queue); + spin_unlock_irqrestore(&alarm_slock, flags); + + return rv; +} + +static int alarm_get_time(enum android_alarm_type alarm_type, + struct timespec *ts) +{ + int rv = 0; + + switch (alarm_type) { + case ANDROID_ALARM_RTC_WAKEUP: + case ANDROID_ALARM_RTC: + getnstimeofday(ts); + break; + case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP: + case ANDROID_ALARM_ELAPSED_REALTIME: + get_monotonic_boottime(ts); + break; + case ANDROID_ALARM_SYSTEMTIME: + ktime_get_ts(ts); + break; + default: + rv = -EINVAL; + } + return rv; +} + +static long alarm_do_ioctl(struct file *file, unsigned int cmd, + struct timespec *ts) +{ + int rv = 0; + unsigned long flags; enum android_alarm_type alarm_type = ANDROID_ALARM_IOCTL_TO_TYPE(cmd); - uint32_t alarm_type_mask = 1U << alarm_type; if (alarm_type >= ANDROID_ALARM_TYPE_COUNT) return -EINVAL; @@ -126,102 +224,54 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) switch (ANDROID_ALARM_BASE_CMD(cmd)) { case ANDROID_ALARM_CLEAR(0): - spin_lock_irqsave(&alarm_slock, flags); - alarm_dbg(IO, "alarm %d clear\n", alarm_type); - devalarm_try_to_cancel(&alarms[alarm_type]); - if (alarm_pending) { - alarm_pending &= ~alarm_type_mask; - if (!alarm_pending && !wait_pending) - __pm_relax(&alarm_wake_lock); - } - alarm_enabled &= ~alarm_type_mask; - spin_unlock_irqrestore(&alarm_slock, flags); + alarm_clear(alarm_type); break; - - case ANDROID_ALARM_SET_AND_WAIT(0): case ANDROID_ALARM_SET(0): - if (copy_from_user(&new_alarm_time, (void __user *)arg, - sizeof(new_alarm_time))) { - rv = -EFAULT; - goto err1; - } - spin_lock_irqsave(&alarm_slock, flags); - alarm_dbg(IO, "alarm %d set %ld.%09ld\n", - alarm_type, - new_alarm_time.tv_sec, new_alarm_time.tv_nsec); - alarm_enabled |= alarm_type_mask; - devalarm_start(&alarms[alarm_type], - timespec_to_ktime(new_alarm_time)); - spin_unlock_irqrestore(&alarm_slock, flags); - if (ANDROID_ALARM_BASE_CMD(cmd) != - ANDROID_ALARM_SET_AND_WAIT(0)) - break; + alarm_set(alarm_type, ts); + break; + case ANDROID_ALARM_SET_AND_WAIT(0): + alarm_set(alarm_type, ts); /* fall though */ case ANDROID_ALARM_WAIT: - spin_lock_irqsave(&alarm_slock, flags); - alarm_dbg(IO, "alarm wait\n"); - if (!alarm_pending && wait_pending) { - __pm_relax(&alarm_wake_lock); - wait_pending = 0; - } - spin_unlock_irqrestore(&alarm_slock, flags); - rv = wait_event_interruptible(alarm_wait_queue, alarm_pending); - if (rv) - goto err1; - spin_lock_irqsave(&alarm_slock, flags); - rv = alarm_pending; - wait_pending = 1; - alarm_pending = 0; - spin_unlock_irqrestore(&alarm_slock, flags); + rv = alarm_wait(); break; case ANDROID_ALARM_SET_RTC: - if (copy_from_user(&new_rtc_time, (void __user *)arg, - sizeof(new_rtc_time))) { - rv = -EFAULT; - goto err1; - } - rtc_time_to_tm(new_rtc_time.tv_sec, &new_rtc_tm); - rtc_dev = alarmtimer_get_rtcdev(); - rv = do_settimeofday(&new_rtc_time); - if (rv < 0) - goto err1; - if (rtc_dev) - rv = rtc_set_time(rtc_dev, &new_rtc_tm); - spin_lock_irqsave(&alarm_slock, flags); - alarm_pending |= ANDROID_ALARM_TIME_CHANGE_MASK; - wake_up(&alarm_wait_queue); - spin_unlock_irqrestore(&alarm_slock, flags); - if (rv < 0) - goto err1; + rv = alarm_set_rtc(ts); break; case ANDROID_ALARM_GET_TIME(0): - switch (alarm_type) { - case ANDROID_ALARM_RTC_WAKEUP: - case ANDROID_ALARM_RTC: - getnstimeofday(&tmp_time); - break; - case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP: - case ANDROID_ALARM_ELAPSED_REALTIME: - get_monotonic_boottime(&tmp_time); - break; - case ANDROID_ALARM_SYSTEMTIME: - ktime_get_ts(&tmp_time); - break; - default: - rv = -EINVAL; - goto err1; - } - if (copy_to_user((void __user *)arg, &tmp_time, - sizeof(tmp_time))) { - rv = -EFAULT; - goto err1; - } + rv = alarm_get_time(alarm_type, ts); break; default: rv = -EINVAL; } -err1: + return rv; +} + +static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + + struct timespec ts; + int rv; + + switch (ANDROID_ALARM_BASE_CMD(cmd)) { + case ANDROID_ALARM_SET_AND_WAIT(0): + case ANDROID_ALARM_SET(0): + case ANDROID_ALARM_SET_RTC: + if (copy_from_user(&ts, (void __user *)arg, sizeof(ts))) + return -EFAULT; + break; + } + + rv = alarm_do_ioctl(file, cmd, &ts); + + switch (ANDROID_ALARM_BASE_CMD(cmd)) { + case ANDROID_ALARM_GET_TIME(0): + if (copy_to_user((void __user *)arg, &ts, sizeof(ts))) + return -EFAULT; + break; + } + return rv; } -- cgit v0.10.2 From 532572b94815e1ede5d9c5434ddb94835df4429e Mon Sep 17 00:00:00 2001 From: John Stultz Date: Fri, 11 Jan 2013 15:46:24 -0800 Subject: staging: alarm-dev: Implement compat_ioctl support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement compat_ioctl support for the alarm-dev ioctl. Cc: Serban Constantinescu Cc: Arve HjønnevÃ¥g Cc: Colin Cross Cc: Android Kernel Team Signed-off-by: John Stultz Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c index 43af3b3..ceb1c64 100644 --- a/drivers/staging/android/alarm-dev.c +++ b/drivers/staging/android/alarm-dev.c @@ -274,6 +274,38 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return rv; } +#ifdef CONFIG_COMPAT +static long alarm_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + + struct timespec ts; + int rv; + + switch (ANDROID_ALARM_BASE_CMD(cmd)) { + case ANDROID_ALARM_SET_AND_WAIT_COMPAT(0): + case ANDROID_ALARM_SET_COMPAT(0): + case ANDROID_ALARM_SET_RTC_COMPAT: + if (compat_get_timespec(&ts, (void __user *)arg)) + return -EFAULT; + /* fall through */ + case ANDROID_ALARM_GET_TIME_COMPAT(0): + cmd = ANDROID_ALARM_COMPAT_TO_NORM(cmd); + break; + } + + rv = alarm_do_ioctl(file, cmd, &ts); + + switch (ANDROID_ALARM_BASE_CMD(cmd)) { + case ANDROID_ALARM_GET_TIME(0): /* NOTE: we modified cmd above */ + if (compat_put_timespec(&ts, (void __user *)arg)) + return -EFAULT; + break; + } + + return rv; +} +#endif static int alarm_open(struct inode *inode, struct file *file) { @@ -355,6 +387,9 @@ static const struct file_operations alarm_fops = { .unlocked_ioctl = alarm_ioctl, .open = alarm_open, .release = alarm_release, +#ifdef CONFIG_COMPAT + .compat_ioctl = alarm_compat_ioctl, +#endif }; static struct miscdevice alarm_device = { diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h index d0cafd6..4fd32f3 100644 --- a/drivers/staging/android/android_alarm.h +++ b/drivers/staging/android/android_alarm.h @@ -18,6 +18,7 @@ #include #include +#include enum android_alarm_type { /* return code bit numbers or set alarm arg */ @@ -59,4 +60,22 @@ enum android_alarm_return_flags { #define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) #define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) + +#ifdef CONFIG_COMPAT +#define ANDROID_ALARM_SET_COMPAT(type) ALARM_IOW(2, type, \ + struct compat_timespec) +#define ANDROID_ALARM_SET_AND_WAIT_COMPAT(type) ALARM_IOW(3, type, \ + struct compat_timespec) +#define ANDROID_ALARM_GET_TIME_COMPAT(type) ALARM_IOW(4, type, \ + struct compat_timespec) +#define ANDROID_ALARM_SET_RTC_COMPAT _IOW('a', 5, \ + struct compat_timespec) +#define ANDROID_ALARM_IOCTL_NR(cmd) (_IOC_NR(cmd) & ((1<<4)-1)) +#define ANDROID_ALARM_COMPAT_TO_NORM(cmd) \ + ALARM_IOW(ANDROID_ALARM_IOCTL_NR(cmd), \ + ANDROID_ALARM_IOCTL_TO_TYPE(cmd), \ + struct timespec) + +#endif + #endif -- cgit v0.10.2 From d56131def640daa8b802dd7ddbffff30846005ac Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Thu, 17 Jan 2013 23:15:22 +0000 Subject: staging: vt6656: change bssdb/rxtx/wpa2 to new structures Use struct vnt_private struct vnt_manager Move vnt_manager from sMgmtObj to vnt_mgmt. This patch cleans up function declarations, definitions and local variables where appropriate replacing types defined in "type.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index d1757cf..59765b0 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -91,9 +91,9 @@ const WORD awHWRetry1[5][5] = { /*--------------------- Static Functions --------------------------*/ -void s_vCheckSensitivity(void *hDeviceContext); -void s_vCheckPreEDThreshold(void *hDeviceContext); -void s_uCalculateLinkQual(void *hDeviceContext); +static void s_vCheckSensitivity(struct vnt_private *pDevice); +static void s_vCheckPreEDThreshold(struct vnt_private *pDevice); +static void s_uCalculateLinkQual(struct vnt_private *pDevice); /*--------------------- Export Variables --------------------------*/ @@ -114,20 +114,19 @@ void s_uCalculateLinkQual(void *hDeviceContext); * -*/ -PKnownBSS BSSpSearchBSSList(void *hDeviceContext, - PBYTE pbyDesireBSSID, - PBYTE pbyDesireSSID, - CARD_PHY_TYPE ePhyType) +PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice, + u8 *pbyDesireBSSID, u8 *pbyDesireSSID, + CARD_PHY_TYPE ePhyType) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PBYTE pbyBSSID = NULL; - PWLAN_IE_SSID pSSID = NULL; - PKnownBSS pCurrBSS = NULL; - PKnownBSS pSelect = NULL; - BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00}; - unsigned int ii = 0; - unsigned int jj = 0; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u8 *pbyBSSID = NULL; + PWLAN_IE_SSID pSSID = NULL; + PKnownBSS pCurrBSS = NULL; + PKnownBSS pSelect = NULL; + u8 ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + int ii = 0; + int jj = 0; + if (pbyDesireBSSID != NULL) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID); @@ -262,11 +261,10 @@ pDevice->bSameBSSMaxNum = jj; -*/ -void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID) +void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ii; for (ii = 0; ii < MAX_BSS_NUM; ii++) { if (bKeepCurrBSSID) { @@ -298,14 +296,12 @@ void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID) * TRUE if found. * -*/ -PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext, - PBYTE abyBSSID, - PWLAN_IE_SSID pSSID) +PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *pDevice, + u8 *abyBSSID, PWLAN_IE_SSID pSSID) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PKnownBSS pBSSList = NULL; - unsigned int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + PKnownBSS pBSSList = NULL; + int ii; for (ii = 0; ii < MAX_BSS_NUM; ii++) { pBSSList = &(pMgmt->sBSSList[ii]); @@ -336,32 +332,30 @@ PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext, * -*/ -BOOL BSSbInsertToBSSList(void *hDeviceContext, - PBYTE abyBSSIDAddr, +int BSSbInsertToBSSList(struct vnt_private *pDevice, + u8 *abyBSSIDAddr, u64 qwTimestamp, - WORD wBeaconInterval, - WORD wCapInfo, - BYTE byCurrChannel, - PWLAN_IE_SSID pSSID, - PWLAN_IE_SUPP_RATES pSuppRates, - PWLAN_IE_SUPP_RATES pExtSuppRates, - PERPObject psERP, - PWLAN_IE_RSN pRSN, - PWLAN_IE_RSN_EXT pRSNWPA, - PWLAN_IE_COUNTRY pIE_Country, - PWLAN_IE_QUIET pIE_Quiet, - unsigned int uIELength, - PBYTE pbyIEs, - void *pRxPacketContext) + u16 wBeaconInterval, + u16 wCapInfo, + u8 byCurrChannel, + PWLAN_IE_SSID pSSID, + PWLAN_IE_SUPP_RATES pSuppRates, + PWLAN_IE_SUPP_RATES pExtSuppRates, + PERPObject psERP, + PWLAN_IE_RSN pRSN, + PWLAN_IE_RSN_EXT pRSNWPA, + PWLAN_IE_COUNTRY pIE_Country, + PWLAN_IE_QUIET pIE_Quiet, + u32 uIELength, + u8 *pbyIEs, + void *pRxPacketContext) { - - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext; - PKnownBSS pBSSList = NULL; - unsigned int ii; - BOOL bParsingQuiet = FALSE; - + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct vnt_rx_mgmt *pRxPacket = + (struct vnt_rx_mgmt *)pRxPacketContext; + PKnownBSS pBSSList = NULL; + unsigned int ii; + BOOL bParsingQuiet = FALSE; pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]); @@ -516,31 +510,31 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext, -*/ // TODO: input structure modify -BOOL BSSbUpdateToBSSList(void *hDeviceContext, +int BSSbUpdateToBSSList(struct vnt_private *pDevice, u64 qwTimestamp, - WORD wBeaconInterval, - WORD wCapInfo, - BYTE byCurrChannel, - BOOL bChannelHit, - PWLAN_IE_SSID pSSID, - PWLAN_IE_SUPP_RATES pSuppRates, - PWLAN_IE_SUPP_RATES pExtSuppRates, - PERPObject psERP, - PWLAN_IE_RSN pRSN, - PWLAN_IE_RSN_EXT pRSNWPA, - PWLAN_IE_COUNTRY pIE_Country, - PWLAN_IE_QUIET pIE_Quiet, - PKnownBSS pBSSList, - unsigned int uIELength, - PBYTE pbyIEs, - void *pRxPacketContext) + u16 wBeaconInterval, + u16 wCapInfo, + u8 byCurrChannel, + int bChannelHit, + PWLAN_IE_SSID pSSID, + PWLAN_IE_SUPP_RATES pSuppRates, + PWLAN_IE_SUPP_RATES pExtSuppRates, + PERPObject psERP, + PWLAN_IE_RSN pRSN, + PWLAN_IE_RSN_EXT pRSNWPA, + PWLAN_IE_COUNTRY pIE_Country, + PWLAN_IE_QUIET pIE_Quiet, + PKnownBSS pBSSList, + u32 uIELength, + u8 *pbyIEs, + void *pRxPacketContext) { - int ii, jj; - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext; - signed long ldBm, ldBmSum; - BOOL bParsingQuiet = FALSE; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct vnt_rx_mgmt *pRxPacket = + (struct vnt_rx_mgmt *)pRxPacketContext; + int ii, jj; + signed long ldBm, ldBmSum; + BOOL bParsingQuiet = FALSE; if (pBSSList == NULL) return FALSE; @@ -658,13 +652,11 @@ BOOL BSSbUpdateToBSSList(void *hDeviceContext, * -*/ -BOOL BSSbIsSTAInNodeDB(void *hDeviceContext, - PBYTE abyDstAddr, - unsigned int *puNodeIndex) +int BSSbIsSTAInNodeDB(struct vnt_private *pDevice, + u8 *abyDstAddr, u32 *puNodeIndex) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + unsigned int ii; // Index = 0 reserved for AP Node for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) { @@ -692,15 +684,14 @@ BOOL BSSbIsSTAInNodeDB(void *hDeviceContext, * None * -*/ -void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex) +void BSSvCreateOneNode(struct vnt_private *pDevice, u32 *puNodeIndex) { + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ii; + u32 BigestCount = 0; + u32 SelectIndex; + struct sk_buff *skb; - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int ii; - unsigned int BigestCount = 0; - unsigned int SelectIndex; - struct sk_buff *skb; // Index = 0 reserved for AP Node (In STA mode) // Index = 0 reserved for Broadcast/MultiCast (In AP mode) SelectIndex = 1; @@ -753,13 +744,11 @@ void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex) * -*/ -void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex) +void BSSvRemoveOneNode(struct vnt_private *pDevice, u32 uNodeIndex) { - - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - struct sk_buff *skb; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; + struct sk_buff *skb; while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL) @@ -780,14 +769,11 @@ void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex) * -*/ -void BSSvUpdateAPNode(void *hDeviceContext, - PWORD pwCapInfo, - PWLAN_IE_SUPP_RATES pSuppRates, - PWLAN_IE_SUPP_RATES pExtSuppRates) +void BSSvUpdateAPNode(struct vnt_private *pDevice, u16 *pwCapInfo, + PWLAN_IE_SUPP_RATES pSuppRates, PWLAN_IE_SUPP_RATES pExtSuppRates) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int uRateLen = WLAN_RATES_MAXLEN; + struct vnt_manager *pMgmt = &(pDevice->sMgmtObj); + u32 uRateLen = WLAN_RATES_MAXLEN; memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); @@ -832,10 +818,9 @@ void BSSvUpdateAPNode(void *hDeviceContext, * -*/ -void BSSvAddMulticastNode(void *hDeviceContext) +void BSSvAddMulticastNode(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; if (!pDevice->bEnableHostWEP) memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); @@ -871,15 +856,14 @@ void BSSvAddMulticastNode(void *hDeviceContext) * -*/ -void BSSvSecondCallBack(void *hDeviceContext) +void BSSvSecondCallBack(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int ii; - PWLAN_IE_SSID pItemSSID, pCurrSSID; - unsigned int uSleepySTACnt = 0; - unsigned int uNonShortSlotSTACnt = 0; - unsigned int uLongPreambleSTACnt = 0; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ii; + PWLAN_IE_SSID pItemSSID, pCurrSSID; + u32 uSleepySTACnt = 0; + u32 uNonShortSlotSTACnt = 0; + u32 uLongPreambleSTACnt = 0; spin_lock_irq(&pDevice->lock); @@ -925,7 +909,7 @@ if(pDevice->byReAssocCount > 0) { pMgmt->eLastState = pMgmt->eCurrState ; - s_uCalculateLinkQual((void *)pDevice); + s_uCalculateLinkQual(pDevice); for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) { @@ -1065,8 +1049,8 @@ if(pDevice->byReAssocCount > 0) { if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS if (pDevice->bUpdateBBVGA) { - /* s_vCheckSensitivity((void *) pDevice); */ - s_vCheckPreEDThreshold((void *) pDevice); + s_vCheckSensitivity(pDevice); + s_vCheckPreEDThreshold(pDevice); } if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) && @@ -1167,8 +1151,8 @@ else { if (pMgmt->eCurrState == WMAC_STATE_JOINTED) { if (pDevice->bUpdateBBVGA) { - /* s_vCheckSensitivity((void *) pDevice); */ - s_vCheckPreEDThreshold((void *) pDevice); + s_vCheckSensitivity(pDevice); + s_vCheckPreEDThreshold(pDevice); } if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) { DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount); @@ -1205,22 +1189,19 @@ else { * -*/ -void BSSvUpdateNodeTxCounter(void *hDeviceContext, - PSStatCounter pStatistic, - BYTE byTSR, - BYTE byPktNO) +void BSSvUpdateNodeTxCounter(struct vnt_private *pDevice, + PSStatCounter pStatistic, u8 byTSR, u8 byPktNO) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int uNodeIndex = 0; - BYTE byTxRetry; - WORD wRate; - WORD wFallBackRate = RATE_1M; - BYTE byFallBack; - unsigned int ii; - PBYTE pbyDestAddr; - BYTE byPktNum; - WORD wFIFOCtl; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u32 uNodeIndex = 0; + u8 byTxRetry; + u16 wRate; + u16 wFallBackRate = RATE_1M; + u8 byFallBack; + int ii; + u8 *pbyDestAddr; + u8 byPktNum; + u16 wFIFOCtl; byPktNum = (byPktNO & 0x0F) >> 4; byTxRetry = (byTSR & 0xF0) >> 4; @@ -1368,13 +1349,11 @@ void BSSvUpdateNodeTxCounter(void *hDeviceContext, * -*/ -void BSSvClearNodeDBTable(void *hDeviceContext, - unsigned int uStartIndex) +void BSSvClearNodeDBTable(struct vnt_private *pDevice, u32 uStartIndex) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - struct sk_buff *skb; - unsigned int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct sk_buff *skb; + int ii; for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) { if (pMgmt->sNodeDBTable[ii].bActive) { @@ -1390,12 +1369,11 @@ void BSSvClearNodeDBTable(void *hDeviceContext, } }; -void s_vCheckSensitivity(void *hDeviceContext) +static void s_vCheckSensitivity(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PKnownBSS pBSSList = NULL; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - int ii; + PKnownBSS pBSSList = NULL; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ii; if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) || ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) { @@ -1422,7 +1400,7 @@ void s_vCheckSensitivity(void *hDeviceContext) if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) { pDevice->uBBVGADiffCount++; if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) - bScheduleCommand((void *) pDevice, + bScheduleCommand(pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL); } else { @@ -1433,13 +1411,12 @@ void s_vCheckSensitivity(void *hDeviceContext) } } -void s_uCalculateLinkQual(void *hDeviceContext) +static void s_uCalculateLinkQual(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - unsigned long TxOkRatio, TxCnt; - unsigned long RxOkRatio, RxCnt; - unsigned long RssiRatio; - long ldBm; + unsigned long TxOkRatio, TxCnt; + unsigned long RxOkRatio, RxCnt; + unsigned long RssiRatio; + long ldBm; TxCnt = pDevice->scStatistic.TxNoRetryOkCount + pDevice->scStatistic.TxRetryOkCount + @@ -1476,21 +1453,21 @@ else pDevice->scStatistic.TxRetryOkCount = 0; } -void BSSvClearAnyBSSJoinRecord(void *hDeviceContext) +void BSSvClearAnyBSSJoinRecord(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int ii; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ii; for (ii = 0; ii < MAX_BSS_NUM; ii++) - pMgmt->sBSSList[ii].bSelected = FALSE; + pMgmt->sBSSList[ii].bSelected = FALSE; + + return; } -void s_vCheckPreEDThreshold(void *hDeviceContext) +static void s_vCheckPreEDThreshold(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PKnownBSS pBSSList = NULL; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + PKnownBSS pBSSList = NULL; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) || ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) { diff --git a/drivers/staging/vt6656/bssdb.h b/drivers/staging/vt6656/bssdb.h index 125edc2..9b1bf6a 100644 --- a/drivers/staging/vt6656/bssdb.h +++ b/drivers/staging/vt6656/bssdb.h @@ -226,80 +226,70 @@ typedef struct tagKnownNodeDB { /*--------------------- Export Functions --------------------------*/ -PKnownBSS BSSpSearchBSSList(void *hDeviceContext, - PBYTE pbyDesireBSSID, - PBYTE pbyDesireSSID, - CARD_PHY_TYPE ePhyType); +PKnownBSS BSSpSearchBSSList(struct vnt_private *, u8 *pbyDesireBSSID, + u8 *pbyDesireSSID, CARD_PHY_TYPE ePhyType); -PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext, - PBYTE abyBSSID, - PWLAN_IE_SSID pSSID); +PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *, u8 *abyBSSID, + PWLAN_IE_SSID pSSID); -void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID); +void BSSvClearBSSList(struct vnt_private *, int bKeepCurrBSSID); -BOOL BSSbInsertToBSSList(void *hDeviceContext, - PBYTE abyBSSIDAddr, +int BSSbInsertToBSSList(struct vnt_private *, + u8 *abyBSSIDAddr, u64 qwTimestamp, - WORD wBeaconInterval, - WORD wCapInfo, - BYTE byCurrChannel, - PWLAN_IE_SSID pSSID, - PWLAN_IE_SUPP_RATES pSuppRates, - PWLAN_IE_SUPP_RATES pExtSuppRates, - PERPObject psERP, - PWLAN_IE_RSN pRSN, - PWLAN_IE_RSN_EXT pRSNWPA, - PWLAN_IE_COUNTRY pIE_Country, - PWLAN_IE_QUIET pIE_Quiet, - unsigned int uIELength, - PBYTE pbyIEs, - void *pRxPacketContext); - -BOOL BSSbUpdateToBSSList(void *hDeviceContext, + u16 wBeaconInterval, + u16 wCapInfo, + u8 byCurrChannel, + PWLAN_IE_SSID pSSID, + PWLAN_IE_SUPP_RATES pSuppRates, + PWLAN_IE_SUPP_RATES pExtSuppRates, + PERPObject psERP, + PWLAN_IE_RSN pRSN, + PWLAN_IE_RSN_EXT pRSNWPA, + PWLAN_IE_COUNTRY pIE_Country, + PWLAN_IE_QUIET pIE_Quiet, + u32 uIELength, + u8 *pbyIEs, + void *pRxPacketContext); + +int BSSbUpdateToBSSList(struct vnt_private *, u64 qwTimestamp, - WORD wBeaconInterval, - WORD wCapInfo, - BYTE byCurrChannel, - BOOL bChannelHit, - PWLAN_IE_SSID pSSID, - PWLAN_IE_SUPP_RATES pSuppRates, - PWLAN_IE_SUPP_RATES pExtSuppRates, - PERPObject psERP, - PWLAN_IE_RSN pRSN, - PWLAN_IE_RSN_EXT pRSNWPA, - PWLAN_IE_COUNTRY pIE_Country, - PWLAN_IE_QUIET pIE_Quiet, - PKnownBSS pBSSList, - unsigned int uIELength, - PBYTE pbyIEs, - void *pRxPacketContext); - -BOOL BSSbIsSTAInNodeDB(void *hDeviceContext, - PBYTE abyDstAddr, - unsigned int *puNodeIndex); - -void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex); - -void BSSvUpdateAPNode(void *hDeviceContext, - PWORD pwCapInfo, - PWLAN_IE_SUPP_RATES pItemRates, - PWLAN_IE_SUPP_RATES pExtSuppRates); - -void BSSvSecondCallBack(void *hDeviceContext); - -void BSSvUpdateNodeTxCounter(void *hDeviceContext, - PSStatCounter pStatistic, - BYTE byTSR, - BYTE byPktNO); - -void BSSvRemoveOneNode(void *hDeviceContext, - unsigned int uNodeIndex); - -void BSSvAddMulticastNode(void *hDeviceContext); - -void BSSvClearNodeDBTable(void *hDeviceContext, - unsigned int uStartIndex); - -void BSSvClearAnyBSSJoinRecord(void *hDeviceContext); + u16 wBeaconInterval, + u16 wCapInfo, + u8 byCurrChannel, + int bChannelHit, + PWLAN_IE_SSID pSSID, + PWLAN_IE_SUPP_RATES pSuppRates, + PWLAN_IE_SUPP_RATES pExtSuppRates, + PERPObject psERP, + PWLAN_IE_RSN pRSN, + PWLAN_IE_RSN_EXT pRSNWPA, + PWLAN_IE_COUNTRY pIE_Country, + PWLAN_IE_QUIET pIE_Quiet, + PKnownBSS pBSSList, + u32 uIELength, + u8 *pbyIEs, + void *pRxPacketContext); + +int BSSbIsSTAInNodeDB(struct vnt_private *, PBYTE abyDstAddr, + u32 *puNodeIndex); + +void BSSvCreateOneNode(struct vnt_private *, u32 *puNodeIndex); + +void BSSvUpdateAPNode(struct vnt_private *, u16 *pwCapInfo, + PWLAN_IE_SUPP_RATES pItemRates, PWLAN_IE_SUPP_RATES pExtSuppRates); + +void BSSvSecondCallBack(struct vnt_private *); + +void BSSvUpdateNodeTxCounter(struct vnt_private *, PSStatCounter pStatistic, + u8 byTSR, u8 byPktNO); + +void BSSvRemoveOneNode(struct vnt_private *, u32 uNodeIndex); + +void BSSvAddMulticastNode(struct vnt_private *); + +void BSSvClearNodeDBTable(struct vnt_private *, u32 uStartIndex); + +void BSSvClearAnyBSSJoinRecord(struct vnt_private *); #endif /* __BSSDB_H__ */ diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index 83c04e1..bb014c0 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -106,174 +106,64 @@ const WORD wFB_Opt1[2][5] = { /*--------------------- Static Functions --------------------------*/ -static -void -s_vSaveTxPktInfo( - PSDevice pDevice, - BYTE byPktNum, - PBYTE pbyDestAddr, - WORD wPktLength, - WORD wFIFOCtl -); - -static -void * -s_vGetFreeContext( - PSDevice pDevice - ); - - -static -void -s_vGenerateTxParameter( - PSDevice pDevice, - BYTE byPktType, - WORD wCurrentRate, - void *pTxBufHead, - void *pvRrvTime, - void *pvRTS, - void *pvCTS, - unsigned int cbFrameSize, - BOOL bNeedACK, - unsigned int uDMAIdx, - PSEthernetHeader psEthHeader - ); - - -static unsigned int s_uFillDataHead( - PSDevice pDevice, - BYTE byPktType, - WORD wCurrentRate, - void *pTxDataHead, - unsigned int cbFrameLength, - unsigned int uDMAIdx, - BOOL bNeedAck, - unsigned int uFragIdx, - unsigned int cbLastFragmentSize, - unsigned int uMACfragNum, - BYTE byFBOption - ); - - - - -static -void -s_vGenerateMACHeader ( - PSDevice pDevice, - PBYTE pbyBufferAddr, - WORD wDuration, - PSEthernetHeader psEthHeader, - BOOL bNeedEncrypt, - WORD wFragType, - unsigned int uDMAIdx, - unsigned int uFragIdx - ); - -static -void -s_vFillTxKey( - PSDevice pDevice, - PBYTE pbyBuf, - PBYTE pbyIVHead, - PSKeyItem pTransmitKey, - PBYTE pbyHdrBuf, - WORD wPayloadLen, - PBYTE pMICHDR - ); - -static -void -s_vSWencryption ( - PSDevice pDevice, - PSKeyItem pTransmitKey, - PBYTE pbyPayloadHead, - WORD wPayloadSize - ); - -static unsigned int s_uGetTxRsvTime( - PSDevice pDevice, - BYTE byPktType, - unsigned int cbFrameLength, - WORD wRate, - BOOL bNeedAck - ); - - -static unsigned int s_uGetRTSCTSRsvTime( - PSDevice pDevice, - BYTE byRTSRsvType, - BYTE byPktType, - unsigned int cbFrameLength, - WORD wCurrentRate - ); - -static -void -s_vFillCTSHead ( - PSDevice pDevice, - unsigned int uDMAIdx, - BYTE byPktType, - void *pvCTS, - unsigned int cbFrameLength, - BOOL bNeedAck, - BOOL bDisCRC, - WORD wCurrentRate, - BYTE byFBOption - ); - -static -void -s_vFillRTSHead( - PSDevice pDevice, - BYTE byPktType, - void *pvRTS, - unsigned int cbFrameLength, - BOOL bNeedAck, - BOOL bDisCRC, - PSEthernetHeader psEthHeader, - WORD wCurrentRate, - BYTE byFBOption - ); - -static unsigned int s_uGetDataDuration( - PSDevice pDevice, - BYTE byDurType, - unsigned int cbFrameLength, - BYTE byPktType, - WORD wRate, - BOOL bNeedAck, - unsigned int uFragIdx, - unsigned int cbLastFragmentSize, - unsigned int uMACfragNum, - BYTE byFBOption - ); - - -static -unsigned int -s_uGetRTSCTSDuration ( - PSDevice pDevice, - BYTE byDurType, - unsigned int cbFrameLength, - BYTE byPktType, - WORD wRate, - BOOL bNeedAck, - BYTE byFBOption - ); +static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, + u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl); + +static void *s_vGetFreeContext(struct vnt_private *pDevice); + +static void s_vGenerateTxParameter(struct vnt_private *pDevice, + u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime, + void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx, + PSEthernetHeader psEthHeader); + +static u32 s_uFillDataHead(struct vnt_private *pDevice, + u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength, + u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize, + u32 uMACfragNum, u8 byFBOption); + + +static void s_vGenerateMACHeader(struct vnt_private *pDevice, + u8 *pbyBufferAddr, u16 wDuration, PSEthernetHeader psEthHeader, + int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx); + +static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf, + u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen, + u8 *pMICHDR); + +static void s_vSWencryption(struct vnt_private *pDevice, + PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize); + +static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType, + u32 cbFrameLength, u16 wRate, int bNeedAck); + +static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType, + u8 byPktType, u32 cbFrameLength, u16 wCurrentRate); + +static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx, + u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck, + int bDisCRC, u16 wCurrentRate, u8 byFBOption); + +static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType, + void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC, + PSEthernetHeader psEthHeader, u16 wCurrentRate, u8 byFBOption); + +static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType, + u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, + u32 uFragIdx, u32 cbLastFragmentSize, u32 uMACfragNum, + u8 byFBOption); + +static unsigned int s_uGetRTSCTSDuration(struct vnt_private *pDevice, + u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate, + int bNeedAck, u8 byFBOption); /*--------------------- Export Variables --------------------------*/ -static -void * -s_vGetFreeContext( - PSDevice pDevice - ) +static void *s_vGetFreeContext(struct vnt_private *pDevice) { - PUSB_SEND_CONTEXT pContext = NULL; - PUSB_SEND_CONTEXT pReturnContext = NULL; - unsigned int ii; + PUSB_SEND_CONTEXT pContext = NULL; + PUSB_SEND_CONTEXT pReturnContext = NULL; + int ii; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n"); @@ -292,11 +182,10 @@ s_vGetFreeContext( } -static -void -s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLength, WORD wFIFOCtl) +static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, + u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl) { - PSStatCounter pStatistic=&(pDevice->scStatistic); + PSStatCounter pStatistic = &pDevice->scStatistic; if (is_broadcast_ether_addr(pbyDestAddr)) pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD; @@ -312,24 +201,15 @@ s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLe ETH_ALEN); } -static -void -s_vFillTxKey ( - PSDevice pDevice, - PBYTE pbyBuf, - PBYTE pbyIVHead, - PSKeyItem pTransmitKey, - PBYTE pbyHdrBuf, - WORD wPayloadLen, - PBYTE pMICHDR - ) +static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf, + u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, + u16 wPayloadLen, u8 *pMICHDR) { - PDWORD pdwIV = (PDWORD) pbyIVHead; - PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4); - WORD wValue; - PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf; - DWORD dwRevIVCounter; - + u32 *pdwIV = (u32 *)pbyIVHead; + u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4); + u16 wValue; + PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf; + u32 dwRevIVCounter; //Fill TXKEY @@ -430,18 +310,12 @@ s_vFillTxKey ( } -static -void -s_vSWencryption ( - PSDevice pDevice, - PSKeyItem pTransmitKey, - PBYTE pbyPayloadHead, - WORD wPayloadSize - ) +static void s_vSWencryption(struct vnt_private *pDevice, + PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize) { - unsigned int cbICVlen = 4; - DWORD dwICV = 0xFFFFFFFFL; - PDWORD pdwICV; + u32 cbICVlen = 4; + u32 dwICV = 0xffffffff; + u32 *pdwICV; if (pTransmitKey == NULL) return; @@ -479,17 +353,10 @@ s_vSWencryption ( PK_TYPE_11GB 2 PK_TYPE_11GA 3 */ -static -unsigned int -s_uGetTxRsvTime ( - PSDevice pDevice, - BYTE byPktType, - unsigned int cbFrameLength, - WORD wRate, - BOOL bNeedAck - ) +static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType, + u32 cbFrameLength, u16 wRate, int bNeedAck) { - unsigned int uDataTime, uAckTime; + u32 uDataTime, uAckTime; uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate); if (byPktType == PK_TYPE_11B) {//llb,CCK mode @@ -507,17 +374,10 @@ s_uGetTxRsvTime ( } //byFreqType: 0=>5GHZ 1=>2.4GHZ -static -unsigned int -s_uGetRTSCTSRsvTime ( - PSDevice pDevice, - BYTE byRTSRsvType, - BYTE byPktType, - unsigned int cbFrameLength, - WORD wCurrentRate - ) +static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, + u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate) { - unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime; + u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime; uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0; @@ -549,23 +409,13 @@ s_uGetRTSCTSRsvTime ( } //byFreqType 0: 5GHz, 1:2.4Ghz -static -unsigned int -s_uGetDataDuration ( - PSDevice pDevice, - BYTE byDurType, - unsigned int cbFrameLength, - BYTE byPktType, - WORD wRate, - BOOL bNeedAck, - unsigned int uFragIdx, - unsigned int cbLastFragmentSize, - unsigned int uMACfragNum, - BYTE byFBOption - ) +static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType, + u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, + u32 uFragIdx, u32 cbLastFragmentSize, u32 uMACfragNum, + u8 byFBOption) { - BOOL bLastFrag = 0; - unsigned int uAckTime = 0, uNextPktTime = 0; + int bLastFrag = 0; + u32 uAckTime = 0, uNextPktTime = 0; if (uFragIdx == (uMACfragNum-1)) { bLastFrag = 1; @@ -718,19 +568,11 @@ s_uGetDataDuration ( //byFreqType: 0=>5GHZ 1=>2.4GHZ -static -unsigned int -s_uGetRTSCTSDuration ( - PSDevice pDevice, - BYTE byDurType, - unsigned int cbFrameLength, - BYTE byPktType, - WORD wRate, - BOOL bNeedAck, - BYTE byFBOption - ) +static u32 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType, + u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, + u8 byFBOption) { - unsigned int uCTSTime = 0, uDurTime = 0; + u32 uCTSTime = 0, uDurTime = 0; switch (byDurType) { @@ -814,24 +656,10 @@ s_uGetRTSCTSDuration ( } - - - -static -unsigned int -s_uFillDataHead ( - PSDevice pDevice, - BYTE byPktType, - WORD wCurrentRate, - void *pTxDataHead, - unsigned int cbFrameLength, - unsigned int uDMAIdx, - BOOL bNeedAck, - unsigned int uFragIdx, - unsigned int cbLastFragmentSize, - unsigned int uMACfragNum, - BYTE byFBOption - ) +static u32 s_uFillDataHead(struct vnt_private *pDevice, + u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength, + u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize, + u32 uMACfragNum, u8 byFBOption) { if (pTxDataHead == NULL) { @@ -959,25 +787,12 @@ s_uFillDataHead ( return 0; } - - - -static -void -s_vFillRTSHead ( - PSDevice pDevice, - BYTE byPktType, - void *pvRTS, - unsigned int cbFrameLength, - BOOL bNeedAck, - BOOL bDisCRC, - PSEthernetHeader psEthHeader, - WORD wCurrentRate, - BYTE byFBOption - ) +static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType, + void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC, + PSEthernetHeader psEthHeader, u16 wCurrentRate, u8 byFBOption) { - unsigned int uRTSFrameLen = 20; - WORD wLen = 0x0000; + u32 uRTSFrameLen = 20; + u16 wLen = 0; if (pvRTS == NULL) return; @@ -1190,22 +1005,12 @@ s_vFillRTSHead ( } } -static -void -s_vFillCTSHead ( - PSDevice pDevice, - unsigned int uDMAIdx, - BYTE byPktType, - void *pvCTS, - unsigned int cbFrameLength, - BOOL bNeedAck, - BOOL bDisCRC, - WORD wCurrentRate, - BYTE byFBOption - ) +static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx, + u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck, + int bDisCRC, u16 wCurrentRate, u8 byFBOption) { - unsigned int uCTSFrameLen = 14; - WORD wLen = 0x0000; + u32 uCTSFrameLen = 14; + u16 wLen = 0; if (pvCTS == NULL) { return; @@ -1290,27 +1095,15 @@ s_vFillCTSHead ( * -*/ -static -void -s_vGenerateTxParameter ( - PSDevice pDevice, - BYTE byPktType, - WORD wCurrentRate, - void *pTxBufHead, - void *pvRrvTime, - void *pvRTS, - void *pvCTS, - unsigned int cbFrameSize, - BOOL bNeedACK, - unsigned int uDMAIdx, - PSEthernetHeader psEthHeader - ) +static void s_vGenerateTxParameter(struct vnt_private *pDevice, + u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime, + void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx, + PSEthernetHeader psEthHeader) { - unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */ - WORD wFifoCtl; - BOOL bDisCRC = FALSE; - BYTE byFBOption = AUTO_FB_NONE; -// WORD wCurrentRate = pDevice->wCurrentRate; + u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */ + u16 wFifoCtl; + int bDisCRC = FALSE; + u8 byFBOption = AUTO_FB_NONE; //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n"); PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead; @@ -1407,52 +1200,37 @@ s_vGenerateTxParameter ( unsigned int cbFragmentSize,//Hdr+payoad+FCS */ - -BOOL -s_bPacketToWirelessUsb( - PSDevice pDevice, - BYTE byPktType, - PBYTE usbPacketBuf, - BOOL bNeedEncryption, - unsigned int uSkbPacketLen, - unsigned int uDMAIdx, - PSEthernetHeader psEthHeader, - PBYTE pPacket, - PSKeyItem pTransmitKey, - unsigned int uNodeIndex, - WORD wCurrentRate, - unsigned int *pcbHeaderLen, - unsigned int *pcbTotalLen - ) +static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, + u8 *usbPacketBuf, int bNeedEncryption, u32 uSkbPacketLen, u32 uDMAIdx, + PSEthernetHeader psEthHeader, u8 *pPacket, PSKeyItem pTransmitKey, + u32 uNodeIndex, u16 wCurrentRate, u32 *pcbHeaderLen, u32 *pcbTotalLen) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int cbFrameSize, cbFrameBodySize; - PTX_BUFFER pTxBufHead; - unsigned int cb802_1_H_len; - unsigned int cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, - cbMACHdLen = 0, cbFCSlen = 4; - unsigned int cbMICHDR = 0; - BOOL bNeedACK,bRTS; - PBYTE pbyType,pbyMacHdr,pbyIVHead,pbyPayloadHead,pbyTxBufferAddr; - BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; - BYTE abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; - unsigned int uDuration; - unsigned int cbHeaderLength = 0, uPadding = 0; - void *pvRrvTime; - PSMICHDRHead pMICHDR; - void *pvRTS; - void *pvCTS; - void *pvTxDataHd; - BYTE byFBOption = AUTO_FB_NONE,byFragType; - WORD wTxBufSize; - DWORD dwMICKey0,dwMICKey1,dwMIC_Priority,dwCRC; - PDWORD pdwMIC_L,pdwMIC_R; - BOOL bSoftWEP = FALSE; - - - + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u32 cbFrameSize, cbFrameBodySize; + PTX_BUFFER pTxBufHead; + u32 cb802_1_H_len; + u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0; + u32 cbFCSlen = 4, cbMICHDR = 0; + int bNeedACK, bRTS; + u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr; + u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; + u8 abySNAP_Bridgetunnel[ETH_ALEN] + = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; + u32 uDuration; + u32 cbHeaderLength = 0, uPadding = 0; + void *pvRrvTime; + PSMICHDRHead pMICHDR; + void *pvRTS; + void *pvCTS; + void *pvTxDataHd; + u8 byFBOption = AUTO_FB_NONE, byFragType; + u16 wTxBufSize; + u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC; + u32 *pdwMIC_L, *pdwMIC_R; + int bSoftWEP = FALSE; + + pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; - pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; if (bNeedEncryption && pTransmitKey->pvKeyTable) { if (((PSKeyTable)&pTransmitKey->pvKeyTable)->bSoftWEP == TRUE) bSoftWEP = TRUE; /* WEP 256 */ @@ -1839,19 +1617,11 @@ s_bPacketToWirelessUsb( * -*/ -void -s_vGenerateMACHeader ( - PSDevice pDevice, - PBYTE pbyBufferAddr, - WORD wDuration, - PSEthernetHeader psEthHeader, - BOOL bNeedEncrypt, - WORD wFragType, - unsigned int uDMAIdx, - unsigned int uFragIdx - ) +static void s_vGenerateMACHeader(struct vnt_private *pDevice, + u8 *pbyBufferAddr, u16 wDuration, PSEthernetHeader psEthHeader, + int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx) { - PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr; + PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr; memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV))); @@ -1940,39 +1710,25 @@ s_vGenerateMACHeader ( * -*/ -CMD_STATUS csMgmt_xmit( - PSDevice pDevice, - PSTxMgmtPacket pPacket - ) +CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, + struct vnt_tx_mgmt *pPacket) { - BYTE byPktType; - PBYTE pbyTxBufferAddr; - void *pvRTS; - PSCTS pCTS; - void *pvTxDataHd; - unsigned int uDuration; - unsigned int cbReqCount; - PS802_11Header pMACHeader; - unsigned int cbHeaderSize; - unsigned int cbFrameBodySize; - BOOL bNeedACK; - BOOL bIsPSPOLL = FALSE; - PSTxBufHead pTxBufHead; - unsigned int cbFrameSize; - unsigned int cbIVlen = 0; - unsigned int cbICVlen = 0; - unsigned int cbMIClen = 0; - unsigned int cbFCSlen = 4; - unsigned int uPadding = 0; - WORD wTxBufSize; - unsigned int cbMacHdLen; - SEthernetHeader sEthHeader; - void *pvRrvTime; - void *pMICHDR; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - WORD wCurrentRate = RATE_1M; - PTX_BUFFER pTX_Buffer; - PUSB_SEND_CONTEXT pContext; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + PTX_BUFFER pTX_Buffer; + PSTxBufHead pTxBufHead; + PUSB_SEND_CONTEXT pContext; + PS802_11Header pMACHeader; + PSCTS pCTS; + SEthernetHeader sEthHeader; + u8 byPktType, *pbyTxBufferAddr; + void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR; + u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize; + int bNeedACK, bIsPSPOLL = FALSE; + u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; + u32 uPadding = 0; + u16 wTxBufSize; + u32 cbMacHdLen; + u16 wCurrentRate = RATE_1M; @@ -2231,26 +1987,22 @@ CMD_STATUS csMgmt_xmit( } -CMD_STATUS -csBeacon_xmit( - PSDevice pDevice, - PSTxMgmtPacket pPacket - ) +CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, + struct vnt_tx_mgmt *pPacket) { - - unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN; - unsigned int cbHeaderSize = 0; - WORD wTxBufSize = sizeof(STxShortBufHead); - PSTxShortBufHead pTxBufHead; - PS802_11Header pMACHeader; - PSTxDataHead_ab pTxDataHead; - WORD wCurrentRate; - unsigned int cbFrameBodySize; - unsigned int cbReqCount; - PBEACON_BUFFER pTX_Buffer; - PBYTE pbyTxBufferAddr; - PUSB_SEND_CONTEXT pContext; - CMD_STATUS status; + u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN; + u32 cbHeaderSize = 0; + u16 wTxBufSize = sizeof(STxShortBufHead); + PSTxShortBufHead pTxBufHead; + PS802_11Header pMACHeader; + PSTxDataHead_ab pTxDataHead; + u16 wCurrentRate; + u32 cbFrameBodySize; + u32 cbReqCount; + PBEACON_BUFFER pTX_Buffer; + u8 *pbyTxBufferAddr; + PUSB_SEND_CONTEXT pContext; + CMD_STATUS status; pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice); @@ -2321,56 +2073,38 @@ csBeacon_xmit( } - - - -void -vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) { - - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BYTE byPktType; - PBYTE pbyTxBufferAddr; - void *pvRTS; - void *pvCTS; - void *pvTxDataHd; - unsigned int uDuration; - unsigned int cbReqCount; - PS802_11Header pMACHeader; - unsigned int cbHeaderSize; - unsigned int cbFrameBodySize; - BOOL bNeedACK; - BOOL bIsPSPOLL = FALSE; - PSTxBufHead pTxBufHead; - unsigned int cbFrameSize; - unsigned int cbIVlen = 0; - unsigned int cbICVlen = 0; - unsigned int cbMIClen = 0; - unsigned int cbFCSlen = 4; - unsigned int uPadding = 0; - unsigned int cbMICHDR = 0; - unsigned int uLength = 0; - DWORD dwMICKey0, dwMICKey1; - DWORD dwMIC_Priority; - PDWORD pdwMIC_L; - PDWORD pdwMIC_R; - WORD wTxBufSize; - unsigned int cbMacHdLen; - SEthernetHeader sEthHeader; - void *pvRrvTime; - void *pMICHDR; - WORD wCurrentRate = RATE_1M; - PUWLAN_80211HDR p80211Header; - unsigned int uNodeIndex = 0; - BOOL bNodeExist = FALSE; - SKeyItem STempKey; - PSKeyItem pTransmitKey = NULL; - PBYTE pbyIVHead; - PBYTE pbyPayloadHead; - PBYTE pbyMacHdr; - unsigned int cbExtSuppRate = 0; - PTX_BUFFER pTX_Buffer; - PUSB_SEND_CONTEXT pContext; -// PWLAN_IE pItem; +void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) +{ + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u8 byPktType; + u8 *pbyTxBufferAddr; + void *pvRTS, *pvCTS, *pvTxDataHd; + u32 uDuration, cbReqCount; + PS802_11Header pMACHeader; + u32 cbHeaderSize, cbFrameBodySize; + int bNeedACK, bIsPSPOLL = FALSE; + PSTxBufHead pTxBufHead; + u32 cbFrameSize; + u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; + u32 uPadding = 0; + u32 cbMICHDR = 0, uLength = 0; + u32 dwMICKey0, dwMICKey1; + u32 dwMIC_Priority; + u32 *pdwMIC_L, *pdwMIC_R; + u16 wTxBufSize; + u32 cbMacHdLen; + SEthernetHeader sEthHeader; + void *pvRrvTime, *pMICHDR; + u32 wCurrentRate = RATE_1M; + PUWLAN_80211HDR p80211Header; + u32 uNodeIndex = 0; + int bNodeExist = FALSE; + SKeyItem STempKey; + PSKeyItem pTransmitKey = NULL; + u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr; + u32 cbExtSuppRate = 0; + PTX_BUFFER pTX_Buffer; + PUSB_SEND_CONTEXT pContext; pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; @@ -2729,29 +2463,30 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) { * Return Value: NULL */ -int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb) +int nsDMA_tx_packet(struct vnt_private *pDevice, + u32 uDMAIdx, struct sk_buff *skb) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int BytesToWrite = 0, uHeaderLen = 0; - unsigned int uNodeIndex = 0; - BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - WORD wAID; - BYTE byPktType; - BOOL bNeedEncryption = FALSE; - PSKeyItem pTransmitKey = NULL; - SKeyItem STempKey; - unsigned int ii; - BOOL bTKIP_UseGTK = FALSE; - BOOL bNeedDeAuth = FALSE; - PBYTE pbyBSSID; - BOOL bNodeExist = FALSE; - PUSB_SEND_CONTEXT pContext; - BOOL fConvertedPacket; - PTX_BUFFER pTX_Buffer; - unsigned int status; - WORD wKeepRate = pDevice->wCurrentRate; - struct net_device_stats* pStats = &pDevice->stats; - BOOL bTxeapol_key = FALSE; + struct net_device_stats *pStats = &pDevice->stats; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u32 BytesToWrite = 0, uHeaderLen = 0; + u32 uNodeIndex = 0; + u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; + u16 wAID; + u8 byPktType; + int bNeedEncryption = FALSE; + PSKeyItem pTransmitKey = NULL; + SKeyItem STempKey; + int ii; + int bTKIP_UseGTK = FALSE; + int bNeedDeAuth = FALSE; + u8 *pbyBSSID; + int bNodeExist = FALSE; + PUSB_SEND_CONTEXT pContext; + BOOL fConvertedPacket; + PTX_BUFFER pTX_Buffer; + u32 status; + u16 wKeepRate = pDevice->wCurrentRate; + int bTxeapol_key = FALSE; if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { @@ -3125,28 +2860,22 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb) * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE */ - -BOOL -bRelayPacketSend ( - PSDevice pDevice, - PBYTE pbySkbData, - unsigned int uDataLen, - unsigned int uNodeIndex - ) +int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, + u32 uNodeIndex) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int BytesToWrite = 0, uHeaderLen = 0; - BYTE byPktType = PK_TYPE_11B; - BOOL bNeedEncryption = FALSE; - SKeyItem STempKey; - PSKeyItem pTransmitKey = NULL; - PBYTE pbyBSSID; - PUSB_SEND_CONTEXT pContext; - BYTE byPktTyp; - BOOL fConvertedPacket; - PTX_BUFFER pTX_Buffer; - unsigned int status; - WORD wKeepRate = pDevice->wCurrentRate; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u32 BytesToWrite = 0, uHeaderLen = 0; + u8 byPktType = PK_TYPE_11B; + int bNeedEncryption = FALSE; + SKeyItem STempKey; + PSKeyItem pTransmitKey = NULL; + u8 *pbyBSSID; + PUSB_SEND_CONTEXT pContext; + u8 byPktTyp; + int fConvertedPacket; + PTX_BUFFER pTX_Buffer; + u32 status; + u16 wKeepRate = pDevice->wCurrentRate; diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h index dd2198a..9f53702 100644 --- a/drivers/staging/vt6656/rxtx.h +++ b/drivers/staging/vt6656/rxtx.h @@ -665,30 +665,11 @@ typedef struct tagSBEACON_BUFFER /*--------------------- Export Functions --------------------------*/ -BOOL -bPacketToWirelessUsb( - PSDevice pDevice, - BYTE byPktType, - PBYTE usbPacketBuf, - BOOL bNeedEncrypt, - unsigned int cbPayloadSize, - unsigned int uDMAIdx, - PSEthernetHeader psEthHeader, - PBYTE pPacket, - PSKeyItem pTransmitKey, - unsigned int uNodeIndex, - WORD wCurrentRate, - unsigned int *pcbHeaderLen, - unsigned int *pcbTotalLen - ); - -void vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb); -int nsDMA_tx_packet(PSDevice pDevice, - unsigned int uDMAIdx, - struct sk_buff *skb); -CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket); -CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket); -BOOL bRelayPacketSend(PSDevice pDevice, PBYTE pbySkbData, - unsigned int uDataLen, unsigned int uNodeIndex); +void vDMA0_tx_80211(struct vnt_private *, struct sk_buff *skb); +int nsDMA_tx_packet(struct vnt_private *, u32 uDMAIdx, struct sk_buff *skb); +CMD_STATUS csMgmt_xmit(struct vnt_private *, struct vnt_tx_mgmt *); +CMD_STATUS csBeacon_xmit(struct vnt_private *, struct vnt_tx_mgmt *); +int bRelayPacketSend(struct vnt_private *, u8 *pbySkbData, u32 uDataLen, + u32 uNodeIndex); #endif /* __RXTX_H__ */ diff --git a/drivers/staging/vt6656/wpa2.c b/drivers/staging/vt6656/wpa2.c index 616e24d..99b4589 100644 --- a/drivers/staging/vt6656/wpa2.c +++ b/drivers/staging/vt6656/wpa2.c @@ -260,19 +260,16 @@ WPA2vParseRSN ( * Return Value: length of IEs. * -*/ -unsigned int -WPA2uSetIEs(void *pMgmtHandle, - PWLAN_IE_RSN pRSNIEs - ) +unsigned int WPA2uSetIEs(void *pMgmtHandle, PWLAN_IE_RSN pRSNIEs) { - PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle; - PBYTE pbyBuffer = NULL; - unsigned int ii = 0; - PWORD pwPMKID = NULL; + struct vnt_manager *pMgmt = (struct vnt_manager *)pMgmtHandle; + u8 *pbyBuffer = NULL; + int ii = 0; + u16 *pwPMKID = NULL; + + if (pRSNIEs == NULL) + return 0; - if (pRSNIEs == NULL) { - return(0); - } if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) && (pMgmt->pCurrBSS != NULL)) { -- cgit v0.10.2 From 45c73bb125eb763448c6d2d708e6a9baf0416ae5 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Thu, 17 Jan 2013 23:17:21 +0000 Subject: staging: vt6656: datarate/dpc/hostap/power use new structures. Use struct vnt_private struct vnt_manager Move vnt_manager from sMgmtObj to vnt_mgmt. This patch cleans up function declarations, definitions and local variables where appropriate replacing types defined in "type.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/datarate.c b/drivers/staging/vt6656/datarate.c index 5c2719f..eefe7bb 100644 --- a/drivers/staging/vt6656/datarate.c +++ b/drivers/staging/vt6656/datarate.c @@ -188,28 +188,19 @@ RATEwGetRateIdx( * Return Value: none * -*/ -void RATEvParseMaxRate( - void *pDeviceHandler, - PWLAN_IE_SUPP_RATES pItemRates, - PWLAN_IE_SUPP_RATES pItemExtRates, - BOOL bUpdateBasicRate, - PWORD pwMaxBasicRate, - PWORD pwMaxSuppRate, - PWORD pwSuppRate, - PBYTE pbyTopCCKRate, - PBYTE pbyTopOFDMRate - ) -{ -PSDevice pDevice = (PSDevice) pDeviceHandler; -unsigned int ii; -BYTE byHighSuppRate = 0; -BYTE byRate = 0; -WORD wOldBasicRate = pDevice->wBasicRate; -unsigned int uRateLen; +void RATEvParseMaxRate(struct vnt_private *pDevice, + PWLAN_IE_SUPP_RATES pItemRates, PWLAN_IE_SUPP_RATES pItemExtRates, + int bUpdateBasicRate, u16 *pwMaxBasicRate, u16 *pwMaxSuppRate, + u16 *pwSuppRate, u8 *pbyTopCCKRate, u8 *pbyTopOFDMRate) +{ + int ii; + u8 byHighSuppRate = 0, byRate = 0; + u16 wOldBasicRate = pDevice->wBasicRate; + u32 uRateLen; - if (pItemRates == NULL) - return; + if (pItemRates == NULL) + return; *pwSuppRate = 0; uRateLen = pItemRates->len; @@ -301,27 +292,24 @@ unsigned int uRateLen; #define AUTORATE_TXCNT_THRESHOLD 20 #define AUTORATE_INC_THRESHOLD 30 -void -RATEvTxRateFallBack( - void *pDeviceHandler, - PKnownNodeDB psNodeDBTable - ) +void RATEvTxRateFallBack(struct vnt_private *pDevice, + PKnownNodeDB psNodeDBTable) { -PSDevice pDevice = (PSDevice) pDeviceHandler; -PSMgmtObject pMgmt = &(pDevice->sMgmtObj); -WORD wIdxDownRate = 0; -unsigned int ii; -BOOL bAutoRate[MAX_RATE] = {TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE}; -DWORD dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540}; -DWORD dwThroughput = 0; -WORD wIdxUpRate = 0; -DWORD dwTxDiff = 0; - - if (pMgmt->eScanState != WMAC_NO_SCANNING) { - // Don't do Fallback when scanning Channel - return; - } - psNodeDBTable->uTimeCount ++; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u16 wIdxDownRate = 0; + int ii; + int bAutoRate[MAX_RATE] = {TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, + TRUE, TRUE, TRUE, TRUE, TRUE}; + u32 dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, + 240, 360, 480, 540}; + u32 dwThroughput = 0; + u16 wIdxUpRate = 0; + u32 dwTxDiff = 0; + + if (pMgmt->eScanState != WMAC_NO_SCANNING) + return; /* Don't do Fallback when scanning Channel */ + + psNodeDBTable->uTimeCount++; if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE]) dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE]; diff --git a/drivers/staging/vt6656/datarate.h b/drivers/staging/vt6656/datarate.h index c6f5163..1320507 100644 --- a/drivers/staging/vt6656/datarate.h +++ b/drivers/staging/vt6656/datarate.h @@ -29,6 +29,7 @@ #ifndef __DATARATE_H__ #define __DATARATE_H__ + /*--------------------- Export Definitions -------------------------*/ #define FALLBACK_PKT_COLLECT_TR_H 50 // pkts @@ -69,24 +70,13 @@ -void -RATEvParseMaxRate( - void *pDeviceHandler, - PWLAN_IE_SUPP_RATES pItemRates, - PWLAN_IE_SUPP_RATES pItemExtRates, - BOOL bUpdateBasicRate, - PWORD pwMaxBasicRate, - PWORD pwMaxSuppRate, - PWORD pwSuppRate, - PBYTE pbyTopCCKRate, - PBYTE pbyTopOFDMRate - ); +void RATEvParseMaxRate(struct vnt_private *, PWLAN_IE_SUPP_RATES pItemRates, + PWLAN_IE_SUPP_RATES pItemExtRates, int bUpdateBasicRate, + u16 *pwMaxBasicRate, u16 *pwMaxSuppRate, u16 *pwSuppRate, + u8 *pbyTopCCKRate, u8 *pbyTopOFDMRate); -void -RATEvTxRateFallBack( - void *pDeviceHandler, - PKnownNodeDB psNodeDBTable - ); +void RATEvTxRateFallBack(struct vnt_private *pDevice, + PKnownNodeDB psNodeDBTable); BYTE RATEuSetIE( diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index 8f21bc7..b627860 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -84,61 +84,23 @@ s_vGetDASA( PSEthernetHeader psEthHeader ); -static -void -s_vProcessRxMACHeader ( - PSDevice pDevice, - PBYTE pbyRxBufferAddr, - unsigned int cbPacketSize, - BOOL bIsWEP, - BOOL bExtIV, - unsigned int *pcbHeadSize - ); - -static BOOL s_bAPModeRxCtl( - PSDevice pDevice, - PBYTE pbyFrame, - signed int iSANodeIndex - ); - - - -static BOOL s_bAPModeRxData ( - PSDevice pDevice, - struct sk_buff *skb, - unsigned int FrameSize, - unsigned int cbHeaderOffset, - signed int iSANodeIndex, - signed int iDANodeIndex - ); +static void s_vProcessRxMACHeader(struct vnt_private *pDevice, + u8 *pbyRxBufferAddr, u32 cbPacketSize, int bIsWEP, int bExtIV, + u32 *pcbHeadSize); +static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, + s32 iSANodeIndex); -static BOOL s_bHandleRxEncryption( - PSDevice pDevice, - PBYTE pbyFrame, - unsigned int FrameSize, - PBYTE pbyRsr, - PBYTE pbyNewRsr, - PSKeyItem * pKeyOut, - int * pbExtIV, - PWORD pwRxTSC15_0, - PDWORD pdwRxTSC47_16 - ); - -static BOOL s_bHostWepRxEncryption( +static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, + u32 FrameSize, u32 cbHeaderOffset, s32 iSANodeIndex, s32 iDANodeIndex); - PSDevice pDevice, - PBYTE pbyFrame, - unsigned int FrameSize, - PBYTE pbyRsr, - BOOL bOnFly, - PSKeyItem pKey, - PBYTE pbyNewRsr, - int * pbExtIV, - PWORD pwRxTSC15_0, - PDWORD pdwRxTSC47_16 +static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, + u32 FrameSize, u8 *pbyRsr, u8 *pbyNewRsr, PSKeyItem *pKeyOut, + s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16); - ); +static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, + u32 FrameSize, u8 *pbyRsr, int bOnFly, PSKeyItem pKey, u8 *pbyNewRsr, + s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16); /*--------------------- Export Variables --------------------------*/ @@ -159,22 +121,16 @@ static BOOL s_bHostWepRxEncryption( * Return Value: None * -*/ -static -void -s_vProcessRxMACHeader ( - PSDevice pDevice, - PBYTE pbyRxBufferAddr, - unsigned int cbPacketSize, - BOOL bIsWEP, - BOOL bExtIV, - unsigned int *pcbHeadSize - ) + +static void s_vProcessRxMACHeader(struct vnt_private *pDevice, + u8 *pbyRxBufferAddr, u32 cbPacketSize, int bIsWEP, int bExtIV, + u32 *pcbHeadSize) { - PBYTE pbyRxBuffer; - unsigned int cbHeaderSize = 0; - PWORD pwType; - PS802_11Header pMACHeader; - int ii; + u8 *pbyRxBuffer; + u32 cbHeaderSize = 0; + u16 *pwType; + PS802_11Header pMACHeader; + int ii; pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize); @@ -310,56 +266,39 @@ s_vGetDASA ( } - - -BOOL -RXbBulkInProcessData ( - PSDevice pDevice, - PRCB pRCB, - unsigned long BytesToIndicate - ) +int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, + unsigned long BytesToIndicate) { - - struct net_device_stats* pStats=&pDevice->stats; - struct sk_buff* skb; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PSRxMgmtPacket pRxPacket = &(pMgmt->sRxPacket); - PS802_11Header p802_11Header; - PBYTE pbyRsr; - PBYTE pbyNewRsr; - PBYTE pbyRSSI; + struct net_device_stats *pStats = &pDevice->stats; + struct sk_buff *skb; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct vnt_rx_mgmt *pRxPacket = &pMgmt->sRxPacket; + PS802_11Header p802_11Header; + u8 *pbyRsr, *pbyNewRsr, *pbyRSSI, *pbyFrame; u64 *pqwTSFTime; - PBYTE pbyFrame; - BOOL bDeFragRx = FALSE; - unsigned int cbHeaderOffset; + u32 bDeFragRx = FALSE; + u32 cbHeaderOffset, cbIVOffset; u32 FrameSize; - WORD wEtherType = 0; - signed int iSANodeIndex = -1; - signed int iDANodeIndex = -1; - unsigned int ii; - unsigned int cbIVOffset; - PBYTE pbyRxSts; - PBYTE pbyRxRate; - PBYTE pbySQ; - PBYTE pby3SQ; - unsigned int cbHeaderSize; - PSKeyItem pKey = NULL; - WORD wRxTSC15_0 = 0; - DWORD dwRxTSC47_16 = 0; - SKeyItem STempKey; - // 802.11h RPI - /* signed long ldBm = 0; */ - BOOL bIsWEP = FALSE; - BOOL bExtIV = FALSE; + u16 wEtherType = 0; + s32 iSANodeIndex = -1, iDANodeIndex = -1; + int ii; + u8 *pbyRxSts, *pbyRxRate, *pbySQ, *pby3SQ; + u32 cbHeaderSize; + PSKeyItem pKey = NULL; + u16 wRxTSC15_0 = 0; + u32 dwRxTSC47_16 = 0; + SKeyItem STempKey; + /* signed long ldBm = 0; */ + int bIsWEP = FALSE; int bExtIV = FALSE; u32 dwWbkStatus; - PRCB pRCBIndicate = pRCB; - PBYTE pbyDAddress; - PWORD pwPLCP_Length; - BYTE abyVaildRate[MAX_RATE] = {2,4,11,22,12,18,24,36,48,72,96,108}; - WORD wPLCPwithPadding; - PS802_11Header pMACHeader; - BOOL bRxeapol_key = FALSE; - + PRCB pRCBIndicate = pRCB; + u8 *pbyDAddress; + u16 *pwPLCP_Length; + u8 abyVaildRate[MAX_RATE] + = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108}; + u16 wPLCPwithPadding; + PS802_11Header pMACHeader; + int bRxeapol_key = FALSE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n"); @@ -985,16 +924,12 @@ RXbBulkInProcessData ( return TRUE; } - -static BOOL s_bAPModeRxCtl ( - PSDevice pDevice, - PBYTE pbyFrame, - signed int iSANodeIndex - ) +static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, + s32 iSANodeIndex) { - PS802_11Header p802_11Header; - CMD_STATUS Status; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &(pDevice->sMgmtObj); + PS802_11Header p802_11Header; + CMD_STATUS Status; if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) { @@ -1096,24 +1031,16 @@ static BOOL s_bAPModeRxCtl ( } -static BOOL s_bHandleRxEncryption ( - PSDevice pDevice, - PBYTE pbyFrame, - unsigned int FrameSize, - PBYTE pbyRsr, - PBYTE pbyNewRsr, - PSKeyItem * pKeyOut, - int * pbExtIV, - PWORD pwRxTSC15_0, - PDWORD pdwRxTSC47_16 - ) +static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, + u32 FrameSize, u8 *pbyRsr, u8 *pbyNewRsr, PSKeyItem *pKeyOut, + s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16) { - unsigned int PayloadLen = FrameSize; - PBYTE pbyIV; - BYTE byKeyIdx; - PSKeyItem pKey = NULL; - BYTE byDecMode = KEY_CTL_WEP; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u32 PayloadLen = FrameSize; + u8 *pbyIV; + u8 byKeyIdx; + PSKeyItem pKey = NULL; + u8 byDecMode = KEY_CTL_WEP; *pwRxTSC15_0 = 0; @@ -1241,31 +1168,19 @@ static BOOL s_bHandleRxEncryption ( return TRUE; } - -static BOOL s_bHostWepRxEncryption ( - PSDevice pDevice, - PBYTE pbyFrame, - unsigned int FrameSize, - PBYTE pbyRsr, - BOOL bOnFly, - PSKeyItem pKey, - PBYTE pbyNewRsr, - int * pbExtIV, - PWORD pwRxTSC15_0, - PDWORD pdwRxTSC47_16 - ) +static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, + u32 FrameSize, u8 *pbyRsr, int bOnFly, PSKeyItem pKey, u8 *pbyNewRsr, + s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - unsigned int PayloadLen = FrameSize; - PBYTE pbyIV; - BYTE byKeyIdx; - BYTE byDecMode = KEY_CTL_WEP; - PS802_11Header pMACHeader; - - + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + PS802_11Header pMACHeader; + u32 PayloadLen = FrameSize; + u8 *pbyIV; + u8 byKeyIdx; + u8 byDecMode = KEY_CTL_WEP; - *pwRxTSC15_0 = 0; - *pdwRxTSC47_16 = 0; + *pwRxTSC15_0 = 0; + *pdwRxTSC47_16 = 0; pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN; if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) && @@ -1372,26 +1287,16 @@ static BOOL s_bHostWepRxEncryption ( return TRUE; } - - -static BOOL s_bAPModeRxData ( - PSDevice pDevice, - struct sk_buff *skb, - unsigned int FrameSize, - unsigned int cbHeaderOffset, - signed int iSANodeIndex, - signed int iDANodeIndex - ) - +static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, + u32 FrameSize, u32 cbHeaderOffset, s32 iSANodeIndex, s32 iDANodeIndex) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BOOL bRelayAndForward = FALSE; - BOOL bRelayOnly = FALSE; - BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - WORD wAID; - + struct sk_buff *skbcpy; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int bRelayAndForward = FALSE; + int bRelayOnly = FALSE; + u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; + u16 wAID; - struct sk_buff* skbcpy = NULL; if (FrameSize > CB_MAX_BUF_SIZE) return FALSE; @@ -1468,11 +1373,10 @@ static BOOL s_bAPModeRxData ( -void RXvWorkItem(void *Context) +void RXvWorkItem(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice) Context; - int ntStatus; - PRCB pRCB=NULL; + int ntStatus; + PRCB pRCB = NULL; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n"); spin_lock_irq(&pDevice->lock); @@ -1492,13 +1396,9 @@ void RXvWorkItem(void *Context) } -void -RXvFreeRCB( - PRCB pRCB, - BOOL bReAllocSkb - ) +void RXvFreeRCB(PRCB pRCB, int bReAllocSkb) { - PSDevice pDevice = (PSDevice)pRCB->pDevice; + struct vnt_private *pDevice = pRCB->pDevice; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n"); @@ -1537,12 +1437,11 @@ RXvFreeRCB( } -void RXvMngWorkItem(void *Context) +void RXvMngWorkItem(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice) Context; - PRCB pRCB=NULL; - PSRxMgmtPacket pRxPacket; - BOOL bReAllocSkb = FALSE; + PRCB pRCB = NULL; + struct vnt_rx_mgmt *pRxPacket; + int bReAllocSkb = FALSE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n"); diff --git a/drivers/staging/vt6656/dpc.h b/drivers/staging/vt6656/dpc.h index d4fca43..786c523 100644 --- a/drivers/staging/vt6656/dpc.h +++ b/drivers/staging/vt6656/dpc.h @@ -45,17 +45,9 @@ void RXvWorkItem(void *Context); void RXvMngWorkItem(void *Context); -void -RXvFreeRCB( - PRCB pRCB, - BOOL bReAllocSkb - ); - -BOOL -RXbBulkInProcessData( - PSDevice pDevice, - PRCB pRCB, - unsigned long BytesToIndicate - ); +void RXvFreeRCB(PRCB pRCB, int bReAllocSkb); + +int RXbBulkInProcessData(struct vnt_private *, PRCB pRCB, + unsigned long BytesToIndicate); #endif /* __RXTX_H__ */ diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c index 3322855..432961c 100644 --- a/drivers/staging/vt6656/hostap.c +++ b/drivers/staging/vt6656/hostap.c @@ -60,13 +60,13 @@ static int msglevel =MSG_LEVEL_INFO; * */ -static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) +static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked) { - PSDevice apdev_priv; + struct vnt_private *apdev_priv; struct net_device *dev = pDevice->dev; int ret; const struct net_device_ops apdev_netdev_ops = { - .ndo_start_xmit = pDevice->tx_80211, + .ndo_start_xmit = pDevice->tx_80211, }; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); @@ -120,7 +120,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) * */ -static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) +static int hostap_disable_hostapd(struct vnt_private *pDevice, int rtnl_locked) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); @@ -157,7 +157,8 @@ static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) * */ -int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked) +int vt6656_hostap_set_hostapd(struct vnt_private *pDevice, + int val, int rtnl_locked) { if (val < 0 || val > 1) return -EINVAL; @@ -187,8 +188,8 @@ int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked) * Return Value: * */ -static int hostap_remove_sta(PSDevice pDevice, - struct viawget_hostapd_param *param) +static int hostap_remove_sta(struct vnt_private *pDevice, + struct viawget_hostapd_param *param) { unsigned int uNodeIndex; @@ -215,16 +216,15 @@ static int hostap_remove_sta(PSDevice pDevice, * Return Value: * */ -static int hostap_add_sta(PSDevice pDevice, - struct viawget_hostapd_param *param) +static int hostap_add_sta(struct vnt_private *pDevice, + struct viawget_hostapd_param *param) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; unsigned int uNodeIndex; + if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) + BSSvCreateOneNode(pDevice, &uNodeIndex); - if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { - BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); - } memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN); pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC; pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability; @@ -275,10 +275,10 @@ static int hostap_add_sta(PSDevice pDevice, * */ -static int hostap_get_info_sta(PSDevice pDevice, - struct viawget_hostapd_param *param) +static int hostap_get_info_sta(struct vnt_private *pDevice, + struct viawget_hostapd_param *param) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; unsigned int uNodeIndex; if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { @@ -308,10 +308,10 @@ static int hostap_get_info_sta(PSDevice pDevice, * Return Value: * */ -static int hostap_set_flags_sta(PSDevice pDevice, - struct viawget_hostapd_param *param) +static int hostap_set_flags_sta(struct vnt_private *pDevice, + struct viawget_hostapd_param *param) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; unsigned int uNodeIndex; if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { @@ -342,10 +342,10 @@ static int hostap_set_flags_sta(PSDevice pDevice, * Return Value: * */ -static int hostap_set_generic_element(PSDevice pDevice, +static int hostap_set_generic_element(struct vnt_private *pDevice, struct viawget_hostapd_param *param) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; @@ -388,7 +388,7 @@ static int hostap_set_generic_element(PSDevice pDevice, * */ -static void hostap_flush_sta(PSDevice pDevice) +static void hostap_flush_sta(struct vnt_private *pDevice) { // reserved node index =0 for multicast node. BSSvClearNodeDBTable(pDevice, 1); @@ -410,21 +410,20 @@ static void hostap_flush_sta(PSDevice pDevice) * Return Value: * */ -static int hostap_set_encryption(PSDevice pDevice, - struct viawget_hostapd_param *param, - int param_len) +static int hostap_set_encryption(struct vnt_private *pDevice, + struct viawget_hostapd_param *param, int param_len) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - DWORD dwKeyIndex = 0; - BYTE abyKey[MAX_KEY_LEN]; - BYTE abySeq[MAX_KEY_LEN]; - NDIS_802_11_KEY_RSC KeyRSC; - BYTE byKeyDecMode = KEY_CTL_WEP; - int ret = 0; - int iNodeIndex = -1; - int ii; - BOOL bKeyTableFull = FALSE; - WORD wKeyCtl = 0; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u32 dwKeyIndex = 0; + u8 abyKey[MAX_KEY_LEN]; + u8 abySeq[MAX_KEY_LEN]; + NDIS_802_11_KEY_RSC KeyRSC; + u8 byKeyDecMode = KEY_CTL_WEP; + int ret = 0; + s32 iNodeIndex = -1; + int ii; + int bKeyTableFull = FALSE; + u16 wKeyCtl = 0; param->u.crypt.err = 0; @@ -647,14 +646,14 @@ static int hostap_set_encryption(PSDevice pDevice, * Return Value: * */ -static int hostap_get_encryption(PSDevice pDevice, +static int hostap_get_encryption(struct vnt_private *pDevice, struct viawget_hostapd_param *param, int param_len) { - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - int ret = 0; - int ii; - int iNodeIndex =0; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int ret = 0; + int ii; + s32 iNodeIndex = 0; param->u.crypt.err = 0; @@ -692,7 +691,7 @@ static int hostap_get_encryption(PSDevice pDevice, * */ -int vt6656_hostap_ioctl(PSDevice pDevice, struct iw_point *p) +int vt6656_hostap_ioctl(struct vnt_private *pDevice, struct iw_point *p) { struct viawget_hostapd_param *param; int ret = 0; diff --git a/drivers/staging/vt6656/hostap.h b/drivers/staging/vt6656/hostap.h index b660aee..f5656cd 100644 --- a/drivers/staging/vt6656/hostap.h +++ b/drivers/staging/vt6656/hostap.h @@ -61,7 +61,7 @@ #define ARPHRD_IEEE80211 801 #endif -int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked); -int vt6656_hostap_ioctl(PSDevice pDevice, struct iw_point *p); +int vt6656_hostap_set_hostapd(struct vnt_private *, int val, int rtnl_locked); +int vt6656_hostap_ioctl(struct vnt_private *, struct iw_point *p); #endif /* __HOSTAP_H__ */ diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c index ab3a554..43965bc 100644 --- a/drivers/staging/vt6656/power.c +++ b/drivers/staging/vt6656/power.c @@ -70,12 +70,10 @@ static int msglevel = MSG_LEVEL_INFO; * */ -void PSvEnablePowerSaving(void *hDeviceContext, - WORD wListenInterval) +void PSvEnablePowerSaving(struct vnt_private *pDevice, u16 wListenInterval) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u16 wAID = pMgmt->wCurrAID | BIT14 | BIT15; /* set period of power up before TBTT */ MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT); @@ -136,10 +134,8 @@ void PSvEnablePowerSaving(void *hDeviceContext, * */ -void PSvDisablePowerSaving(void *hDeviceContext) +void PSvDisablePowerSaving(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - /* PSMgmtObject pMgmt = &(pDevice->sMgmtObj); */ /* disable power saving hw function */ CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_DISABLE_PS, 0, @@ -168,13 +164,11 @@ void PSvDisablePowerSaving(void *hDeviceContext) * FALSE, if fail */ -BOOL PSbConsiderPowerDown(void *hDeviceContext, - BOOL bCheckRxDMA, - BOOL bCheckCountToWakeUp) +int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, + int bCheckCountToWakeUp) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BYTE byData; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + u8 byData; /* check if already in Doze mode */ ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, @@ -225,15 +219,17 @@ BOOL PSbConsiderPowerDown(void *hDeviceContext, * */ -void PSvSendPSPOLL(void *hDeviceContext) +void PSvSendPSPOLL(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - PSTxMgmtPacket pTxPacket = NULL; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + struct vnt_tx_mgmt *pTxPacket = NULL; + + memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_HDR_ADDR2_LEN); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyPSPacketPool; + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); - memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN); - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16( ( WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) | @@ -263,11 +259,10 @@ void PSvSendPSPOLL(void *hDeviceContext) * */ -BOOL PSbSendNullPacket(void *hDeviceContext) +int PSbSendNullPacket(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSTxMgmtPacket pTxPacket = NULL; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); + struct vnt_tx_mgmt *pTxPacket = NULL; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; u16 flags = 0; if (pDevice->bLinkPass == FALSE) @@ -278,9 +273,11 @@ BOOL PSbSendNullPacket(void *hDeviceContext) return FALSE; } - memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN); - pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; - pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); + memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt) + + WLAN_NULLDATA_FR_MAXLEN); + pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyPSPacketPool; + pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket + + sizeof(struct vnt_tx_mgmt)); flags = WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL); @@ -318,11 +315,10 @@ BOOL PSbSendNullPacket(void *hDeviceContext) * */ -BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext) +int PSbIsNextTBTTWakeUp(struct vnt_private *pDevice) { - PSDevice pDevice = (PSDevice)hDeviceContext; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); - BOOL bWakeUp = FALSE; + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; + int bWakeUp = FALSE; if (pMgmt->wListenInterval >= 2) { if (pMgmt->wCountToWakeUp == 0) diff --git a/drivers/staging/vt6656/power.h b/drivers/staging/vt6656/power.h index 41bffe5..879b10c 100644 --- a/drivers/staging/vt6656/power.h +++ b/drivers/staging/vt6656/power.h @@ -48,14 +48,12 @@ /* PSDevice pDevice */ /* PSDevice hDeviceContext */ -BOOL PSbConsiderPowerDown(void *hDeviceContext, - BOOL bCheckRxDMA, - BOOL bCheckCountToWakeUp); - -void PSvDisablePowerSaving(void *hDeviceContext); -void PSvEnablePowerSaving(void *hDeviceContext, WORD wListenInterval); -void PSvSendPSPOLL(void *hDeviceContext); -BOOL PSbSendNullPacket(void *hDeviceContext); -BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext); +int PSbConsiderPowerDown(struct vnt_private *, int bCheckRxDMA, + int bCheckCountToWakeUp); +void PSvDisablePowerSaving(struct vnt_private *); +void PSvEnablePowerSaving(struct vnt_private *, u16 wListenInterval); +void PSvSendPSPOLL(struct vnt_private *); +int PSbSendNullPacket(struct vnt_private *); +int PSbIsNextTBTTWakeUp(struct vnt_private *); #endif /* __POWER_H__ */ -- cgit v0.10.2 From 14c5ef57714d21ff8234aa9a756765e9cb38f837 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Thu, 17 Jan 2013 23:19:37 +0000 Subject: staging: vt6656: staging: vt6656 change remaining to vnt_mgmt and remove typedef. Use struct vnt_manager Move vnt_manager from sMgmtObj to vnt_mgmt. and remove typedef from structures vnt_private vnt_manager vnt_rx_mgmt vnt_tx_mgmt Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index 59765b0..79339fd 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -772,7 +772,7 @@ void BSSvRemoveOneNode(struct vnt_private *pDevice, u32 uNodeIndex) void BSSvUpdateAPNode(struct vnt_private *pDevice, u16 *pwCapInfo, PWLAN_IE_SUPP_RATES pSuppRates, PWLAN_IE_SUPP_RATES pExtSuppRates) { - struct vnt_manager *pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; u32 uRateLen = WLAN_RATES_MAXLEN; memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 93983d9..7d725bb 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -513,7 +513,7 @@ void vUpdateIFS(struct vnt_private *pDevice) } pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot; - pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrSuppRates; + pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt.abyCurrSuppRates; for (ii = 0; ii < pItemRates->len; ii++) { byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); if (RATEwGetRateIdx(byRate) > RATE_11M) { @@ -522,7 +522,8 @@ void vUpdateIFS(struct vnt_private *pDevice) } } if (bOFDMRate == FALSE) { - pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrExtSuppRates; + pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt + .abyCurrExtSuppRates; for (ii = 0; ii < pItemRates->len; ii++) { byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); if (RATEwGetRateIdx(byRate) > RATE_11M) { @@ -1035,12 +1036,11 @@ int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode, { int bResult = TRUE; - if (byCount == 0) { - pDevice->sMgmtObj.uCurrChannel = byNewChannel; - CARDbSetMediaChannel(pDevice, byNewChannel); - - return bResult; - } + if (byCount == 0) { + pDevice->vnt_mgmt.uCurrChannel = byNewChannel; + CARDbSetMediaChannel(pDevice, byNewChannel); + return bResult; + } pDevice->byChannelSwitchCount = byCount; pDevice->byNewChannel = byNewChannel; pDevice->bChannelSwitch = TRUE; diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index eb8a311..1d2e234 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -392,7 +392,7 @@ typedef struct __device_opt { } OPTIONS, *POPTIONS; -typedef struct vnt_private { +struct vnt_private { // netdev struct usb_device* usb; @@ -524,9 +524,8 @@ typedef struct vnt_private { unsigned long RcvBuffersInUse; - // 802.11 management + /* 802.11 management */ struct vnt_manager vnt_mgmt; - SMgmtObject sMgmtObj; u64 qwCurrTSF; unsigned int cbBulkInMax; @@ -815,7 +814,7 @@ typedef struct vnt_private { struct iw_statistics wstats; // wireless stats BOOL bCommit; -} DEVICE_INFO, *PSDevice; +}; diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index b627860..6c98172 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -850,9 +850,9 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, RSC += wRxTSC15_0; memcpy(&(pKey->KeyRSC), &RSC, sizeof(u64)); - if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) && - (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) { - // check RSC + if (pDevice->vnt_mgmt.eCurrMode == WMAC_MODE_ESS_STA && + pDevice->vnt_mgmt.eCurrState == WMAC_STATE_ASSOC) { + /* check RSC */ if ( (wRxTSC15_0 < wLocalTSC15_0) && (dwRxTSC47_16 <= dwLocalTSC47_16) && !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) { @@ -927,7 +927,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, s32 iSANodeIndex) { - struct vnt_manager *pMgmt = &(pDevice->sMgmtObj); + struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PS802_11Header p802_11Header; CMD_STATUS Status; @@ -1456,7 +1456,7 @@ void RXvMngWorkItem(struct vnt_private *pDevice) } ASSERT(pRCB);// cannot be NULL pRxPacket = &(pRCB->sMngPacket); - vMgrRxManagePacket((void *) pDevice, &(pDevice->sMgmtObj), pRxPacket); + vMgrRxManagePacket(pDevice, &pDevice->vnt_mgmt, pRxPacket); pRCB->Ref--; if(pRCB->Ref == 0) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList); diff --git a/drivers/staging/vt6656/mac.c b/drivers/staging/vt6656/mac.c index dd732bc..76d307b 100644 --- a/drivers/staging/vt6656/mac.c +++ b/drivers/staging/vt6656/mac.c @@ -246,10 +246,9 @@ void MACvSetKeyEntry(struct vnt_private *pDevice, u16 wKeyCtl, u32 uEntryIdx, int ii; u8 pbyData[24]; - if ( pDevice->byLocalID <= MAC_REVISION_A1 ) { - if ( pDevice->sMgmtObj.byCSSPK == KEY_CTL_CCMP ) - return; - } + if (pDevice->byLocalID <= MAC_REVISION_A1) + if (pDevice->vnt_mgmt.byCSSPK == KEY_CTL_CCMP) + return; wOffset = MISCFIFO_KEYETRY0; wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE); diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index a316d89..99ac7eb 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -706,7 +706,7 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) spin_lock_init(&pDevice->lock); pDevice->tx_80211 = device_dma0_tx_80211; - pDevice->sMgmtObj.pAdapter = (void *) pDevice; + pDevice->vnt_mgmt.pAdapter = (void *) pDevice; netdev->netdev_ops = &device_netdev_ops; netdev->wireless_handlers = @@ -986,7 +986,8 @@ static int device_open(struct net_device *dev) // Init for Key Management KeyvInitTable(pDevice,&pDevice->sKey); - memcpy(pDevice->sMgmtObj.abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN); + memcpy(pDevice->vnt_mgmt.abyMACAddr, + pDevice->abyCurrentNetAddr, ETH_ALEN); memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN); pDevice->bStopTx0Pkt = FALSE; pDevice->bStopDataPkt = FALSE; @@ -1001,7 +1002,7 @@ static int device_open(struct net_device *dev) tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice); tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice); tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice); - add_timer(&(pDevice->sMgmtObj.sTimerSecondCallback)); + add_timer(&pDevice->vnt_mgmt.sTimerSecondCallback); pDevice->int_interval = 100; //Max 100 microframes. pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; @@ -1035,14 +1036,10 @@ static int device_open(struct net_device *dev) pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; } - if (pDevice->sMgmtObj.eConfigMode == WMAC_CONFIG_AP) { + if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP) bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL); - } - else { - //mike:mark@2008-11-10 - bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); - /* bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL); */ - } + else + bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); netif_stop_queue(pDevice->dev); diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c index 06cff8b..5785eec 100644 --- a/drivers/staging/vt6656/rf.c +++ b/drivers/staging/vt6656/rf.c @@ -888,14 +888,22 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226Pwr); bResult &= IFRFbWriteEmbedded(pDevice, 0x03C6A200+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); - if (pDevice->sMgmtObj.eScanState != WMAC_NO_SCANNING) { - // scanning, the channel number is pDevice->uScanChannel - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"@@@@ RFbRawSetPower> 11B mode uCurrChannel[%d]\n", pDevice->sMgmtObj.uScanChannel); - bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226D0LoCurrentTable[pDevice->sMgmtObj.uScanChannel-1]); //RobertYu:20060420, sometimes didn't change channel just set power with different rate - } else { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"@@@@ RFbRawSetPower> 11B mode uCurrChannel[%d]\n", pDevice->sMgmtObj.uCurrChannel); - bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226D0LoCurrentTable[pDevice->sMgmtObj.uCurrChannel-1]); //RobertYu:20060420, sometimes didn't change channel just set power with different rate - } + if (pDevice->vnt_mgmt.eScanState != WMAC_NO_SCANNING) { + /* scanning, channel number is pDevice->uScanChannel */ + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "RFbRawSetPower> 11B mode uCurrChannel[%d]\n", + pDevice->vnt_mgmt.uScanChannel); + bResult &= IFRFbWriteEmbedded(pDevice, + dwVT3226D0LoCurrentTable[pDevice-> + vnt_mgmt.uScanChannel - 1]); + } else { + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "RFbRawSetPower> 11B mode uCurrChannel[%d]\n", + pDevice->vnt_mgmt.uCurrChannel); + bResult &= IFRFbWriteEmbedded(pDevice, + dwVT3226D0LoCurrentTable[pDevice-> + vnt_mgmt.uCurrChannel - 1]); + } bResult &= IFRFbWriteEmbedded(pDevice, 0x015C0800+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); //RobertYu:20060420, ok now, new switching power (mini-pci can have bigger power consumption) } else { diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index bb014c0..536d314 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -1511,10 +1511,10 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, /////////////////////////////////////////////////////////////////// - if (pDevice->sMgmtObj.eAuthenMode == WMAC_AUTH_WPANONE) { - dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]); - dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]); - } + if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) { + dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); + dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); + } else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) { dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]); dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]); diff --git a/drivers/staging/vt6656/wmgr.h b/drivers/staging/vt6656/wmgr.h index 86c1505..5112f53 100644 --- a/drivers/staging/vt6656/wmgr.h +++ b/drivers/staging/vt6656/wmgr.h @@ -219,15 +219,15 @@ typedef enum tagWMAC_POWER_MODE { /* Tx Management Packet descriptor */ -typedef struct vnt_tx_mgmt { +struct vnt_tx_mgmt { PUWLAN_80211HDR p80211Header; u32 cbMPDULen; u32 cbPayloadLen; -} STxMgmtPacket, *PSTxMgmtPacket; +}; /* Rx Management Packet descriptor */ -typedef struct vnt_rx_mgmt { +struct vnt_rx_mgmt { PUWLAN_80211HDR p80211Header; u64 qwLocalTSF; u32 cbMPDULen; @@ -236,10 +236,10 @@ typedef struct vnt_rx_mgmt { u8 bySQ; u8 byRxRate; u8 byRxChannel; -} SRxMgmtPacket, *PSRxMgmtPacket; +}; -typedef struct vnt_manager { +struct vnt_manager { void *pAdapter; // MAC address BYTE abyMACAddr[WLAN_ADDR_LEN]; @@ -391,7 +391,7 @@ typedef struct vnt_manager { struct sk_buff skb; -} SMgmtObject, *PSMgmtObject; +}; /*--------------------- Export Macros ------------------------------*/ -- cgit v0.10.2 From 61462ab32f8b5a3d133b734455c3a8d6b6d1de7c Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Thu, 17 Jan 2013 23:21:50 +0000 Subject: staging: vt6656: cleanup struct vnt_private Where appropriate replacing types defined in "type.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index 1d2e234..e153beb 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -393,426 +393,403 @@ typedef struct __device_opt { struct vnt_private { + /* netdev */ + struct usb_device *usb; + struct net_device *dev; + struct net_device_stats stats; -// netdev - struct usb_device* usb; - struct net_device* dev; - struct net_device_stats stats; + OPTIONS sOpts; + struct tasklet_struct CmdWorkItem; + struct tasklet_struct EventWorkItem; + struct tasklet_struct ReadWorkItem; + struct tasklet_struct RxMngWorkItem; - OPTIONS sOpts; + u32 rx_buf_sz; + int multicast_limit; + u8 byRxMode; - struct tasklet_struct CmdWorkItem; - struct tasklet_struct EventWorkItem; - struct tasklet_struct ReadWorkItem; - struct tasklet_struct RxMngWorkItem; + spinlock_t lock; - u32 rx_buf_sz; - int multicast_limit; - BYTE byRxMode; + u32 rx_bytes; - spinlock_t lock; + u8 byRevId; - u32 rx_bytes; + u32 flags; + unsigned long Flags; - BYTE byRevId; + SCache sDupRxCache; - u32 flags; - unsigned long Flags; + SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG]; + u32 cbDFCB; + u32 cbFreeDFCB; + u32 uCurrentDFCBIdx; - SCache sDupRxCache; - SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG]; - unsigned int cbDFCB; - unsigned int cbFreeDFCB; - unsigned int uCurrentDFCBIdx; + /* USB */ + struct urb *pControlURB; + struct urb *pInterruptURB; + struct usb_ctrlrequest sUsbCtlRequest; + u32 int_interval; - // +++USB - - struct urb *pControlURB; - struct urb *pInterruptURB; - struct usb_ctrlrequest sUsbCtlRequest; - - unsigned int int_interval; - // - // Variables to track resources for the BULK In Pipe - // - PRCB pRCBMem; - PRCB apRCB[CB_MAX_RX_DESC]; - unsigned int cbRD; - PRCB FirstRecvFreeList; - PRCB LastRecvFreeList; - unsigned int NumRecvFreeList; - PRCB FirstRecvMngList; - PRCB LastRecvMngList; - unsigned int NumRecvMngList; - BOOL bIsRxWorkItemQueued; - BOOL bIsRxMngWorkItemQueued; + /* Variables to track resources for the BULK In Pipe */ + PRCB pRCBMem; + PRCB apRCB[CB_MAX_RX_DESC]; + u32 cbRD; + PRCB FirstRecvFreeList; + PRCB LastRecvFreeList; + u32 NumRecvFreeList; + PRCB FirstRecvMngList; + PRCB LastRecvMngList; + u32 NumRecvMngList; + int bIsRxWorkItemQueued; + int bIsRxMngWorkItemQueued; unsigned long ulRcvRefCount; /* packets that have not returned back */ - // - // Variables to track resources for the BULK Out Pipe - // - - PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC]; - unsigned int cbTD; - - // - // Variables to track resources for the Interrupt In Pipe - // - INT_BUFFER intBuf; - BOOL fKillEventPollingThread; - BOOL bEventAvailable; + /* Variables to track resources for the BULK Out Pipe */ + PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC]; + u32 cbTD; + /* Variables to track resources for the Interrupt In Pipe */ + INT_BUFFER intBuf; + int fKillEventPollingThread; + int bEventAvailable; - //default config from file by user setting - DEFAULT_CONFIG config_file; + /* default config from file by user setting */ + DEFAULT_CONFIG config_file; - // - // Statistic for USB - // protect with spinlock - unsigned long ulBulkInPosted; - unsigned long ulBulkInError; - unsigned long ulBulkInContCRCError; - unsigned long ulBulkInBytesRead; + /* Statistic for USB */ + unsigned long ulBulkInPosted; + unsigned long ulBulkInError; + unsigned long ulBulkInContCRCError; + unsigned long ulBulkInBytesRead; - unsigned long ulBulkOutPosted; - unsigned long ulBulkOutError; - unsigned long ulBulkOutContCRCError; - unsigned long ulBulkOutBytesWrite; + unsigned long ulBulkOutPosted; + unsigned long ulBulkOutError; + unsigned long ulBulkOutContCRCError; + unsigned long ulBulkOutBytesWrite; - unsigned long ulIntInPosted; - unsigned long ulIntInError; - unsigned long ulIntInContCRCError; - unsigned long ulIntInBytesRead; + unsigned long ulIntInPosted; + unsigned long ulIntInError; + unsigned long ulIntInContCRCError; + unsigned long ulIntInBytesRead; - // Version control - WORD wFirmwareVersion; - BYTE byLocalID; - BYTE byRFType; - BYTE byBBRxConf; + /* Version control */ + u16 wFirmwareVersion; + u8 byLocalID; + u8 byRFType; + u8 byBBRxConf; - BYTE byZoneType; - BOOL bZoneRegExist; + u8 byZoneType; + int bZoneRegExist; - BYTE byOriginalZonetype; + u8 byOriginalZonetype; - BOOL bLinkPass; // link status: OK or fail - BYTE abyCurrentNetAddr[ETH_ALEN]; - BYTE abyPermanentNetAddr[ETH_ALEN]; - // SW network address - /* u8 abySoftwareNetAddr[ETH_ALEN]; */ - BOOL bExistSWNetAddr; + int bLinkPass; /* link status: OK or fail */ + u8 abyCurrentNetAddr[ETH_ALEN]; + u8 abyPermanentNetAddr[ETH_ALEN]; - // Adapter statistics - SStatCounter scStatistic; - // 802.11 counter - SDot11Counters s802_11Counter; + int bExistSWNetAddr; - // - // Maintain statistical debug info. - // - unsigned long packetsReceived; - unsigned long packetsReceivedDropped; - unsigned long packetsReceivedOverflow; - unsigned long packetsSent; - unsigned long packetsSentDropped; - unsigned long SendContextsInUse; - unsigned long RcvBuffersInUse; + /* Adapter statistics */ + SStatCounter scStatistic; + /* 802.11 counter */ + SDot11Counters s802_11Counter; + /* Maintain statistical debug info. */ + unsigned long packetsReceived; + unsigned long packetsReceivedDropped; + unsigned long packetsReceivedOverflow; + unsigned long packetsSent; + unsigned long packetsSentDropped; + unsigned long SendContextsInUse; + unsigned long RcvBuffersInUse; /* 802.11 management */ struct vnt_manager vnt_mgmt; u64 qwCurrTSF; - unsigned int cbBulkInMax; - BOOL bPSRxBeacon; - - // 802.11 MAC specific - unsigned int uCurrRSSI; - BYTE byCurrSQ; - - - //Antenna Diversity - BOOL bTxRxAntInv; - DWORD dwRxAntennaSel; - DWORD dwTxAntennaSel; - BYTE byAntennaCount; - BYTE byRxAntennaMode; - BYTE byTxAntennaMode; - BYTE byRadioCtl; - BYTE bHWRadioOff; - - //SQ3 functions for antenna diversity - struct timer_list TimerSQ3Tmax1; - struct timer_list TimerSQ3Tmax2; - struct timer_list TimerSQ3Tmax3; - - BOOL bDiversityRegCtlON; - BOOL bDiversityEnable; - unsigned long ulDiversityNValue; - unsigned long ulDiversityMValue; - BYTE byTMax; - BYTE byTMax2; - BYTE byTMax3; - unsigned long ulSQ3TH; - - unsigned long uDiversityCnt; - BYTE byAntennaState; - unsigned long ulRatio_State0; - unsigned long ulRatio_State1; - unsigned long ulSQ3_State0; - unsigned long ulSQ3_State1; - - unsigned long aulSQ3Val[MAX_RATE]; - unsigned long aulPktNum[MAX_RATE]; + u32 cbBulkInMax; + int bPSRxBeacon; + + /* 802.11 MAC specific */ + u32 uCurrRSSI; + u8 byCurrSQ; + + /* Antenna Diversity */ + int bTxRxAntInv; + u32 dwRxAntennaSel; + u32 dwTxAntennaSel; + u8 byAntennaCount; + u8 byRxAntennaMode; + u8 byTxAntennaMode; + u8 byRadioCtl; + u8 bHWRadioOff; + + /* SQ3 functions for antenna diversity */ + struct timer_list TimerSQ3Tmax1; + struct timer_list TimerSQ3Tmax2; + struct timer_list TimerSQ3Tmax3; + + int bDiversityRegCtlON; + int bDiversityEnable; + unsigned long ulDiversityNValue; + unsigned long ulDiversityMValue; + u8 byTMax; + u8 byTMax2; + u8 byTMax3; + unsigned long ulSQ3TH; + + unsigned long uDiversityCnt; + u8 byAntennaState; + unsigned long ulRatio_State0; + unsigned long ulRatio_State1; + unsigned long ulSQ3_State0; + unsigned long ulSQ3_State1; + + unsigned long aulSQ3Val[MAX_RATE]; + unsigned long aulPktNum[MAX_RATE]; /* IFS & Cw */ - unsigned int uSIFS; /* Current SIFS */ - unsigned int uDIFS; /* Current DIFS */ - unsigned int uEIFS; /* Current EIFS */ - unsigned int uSlot; /* Current SlotTime */ - unsigned int uCwMin; /* Current CwMin */ - unsigned int uCwMax; /* CwMax is fixed on 1023 */ - - // PHY parameter - BYTE bySIFS; - BYTE byDIFS; - BYTE byEIFS; - BYTE bySlot; - BYTE byCWMaxMin; - - // Rate - VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G - VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) - WORD wBasicRate; - BYTE byACKRate; - BYTE byTopOFDMBasicRate; - BYTE byTopCCKBasicRate; - - - DWORD dwAotoRateTxOkCnt; - DWORD dwAotoRateTxFailCnt; - DWORD dwErrorRateThreshold[13]; - DWORD dwTPTable[MAX_RATE]; - BYTE abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //DWORD alignment - - BYTE byMinChannel; - BYTE byMaxChannel; - unsigned int uConnectionRate; - - BYTE byPreambleType; - BYTE byShortPreamble; - // CARD_PHY_TYPE - BYTE eConfigPHYMode; - - // For RF Power table - BYTE byCCKPwr; - BYTE byOFDMPwrG; - BYTE byOFDMPwrA; - BYTE byCurPwr; - BYTE abyCCKPwrTbl[14]; - BYTE abyOFDMPwrTbl[14]; - BYTE abyOFDMAPwrTbl[42]; - - WORD wCurrentRate; - WORD wRTSThreshold; - WORD wFragmentationThreshold; - BYTE byShortRetryLimit; - BYTE byLongRetryLimit; - CARD_OP_MODE eOPMode; - BOOL bBSSIDFilter; - WORD wMaxTransmitMSDULifetime; - BYTE abyBSSID[ETH_ALEN]; - BYTE abyDesireBSSID[ETH_ALEN]; - WORD wCTSDuration; // update while speed change - WORD wACKDuration; // update while speed change - WORD wRTSTransmitLen; // update while speed change - BYTE byRTSServiceField; // update while speed change - BYTE byRTSSignalField; // update while speed change - - DWORD dwMaxReceiveLifetime; // dot11MaxReceiveLifetime - - BOOL bCCK; - BOOL bEncryptionEnable; - BOOL bLongHeader; - BOOL bSoftwareGenCrcErr; - BOOL bShortSlotTime; - BOOL bProtectMode; - BOOL bNonERPPresent; - BOOL bBarkerPreambleMd; - - BYTE byERPFlag; - WORD wUseProtectCntDown; - - BOOL bRadioControlOff; - BOOL bRadioOff; - - // Power save - BOOL bEnablePSMode; - WORD wListenInterval; - BOOL bPWBitOn; - WMAC_POWER_MODE ePSMode; - unsigned long ulPSModeWaitTx; - BOOL bPSModeTxBurst; - - // Beacon releated - WORD wSeqCounter; - BOOL bBeaconBufReady; - BOOL bBeaconSent; - BOOL bFixRate; - BYTE byCurrentCh; - unsigned int uScanTime; - - CMD_STATE eCommandState; - - CMD_CODE eCommand; - BOOL bBeaconTx; - BYTE byScanBBType; - - BOOL bStopBeacon; - BOOL bStopDataPkt; - BOOL bStopTx0Pkt; - unsigned int uAutoReConnectTime; - unsigned int uIsroamingTime; - - // 802.11 counter - - CMD_ITEM eCmdQueue[CMD_Q_SIZE]; - unsigned int uCmdDequeueIdx; - unsigned int uCmdEnqueueIdx; - unsigned int cbFreeCmdQueue; - BOOL bCmdRunning; - BOOL bCmdClear; - BOOL bNeedRadioOFF; - - BOOL bEnableRoaming; - BOOL bIsRoaming; - BOOL bFastRoaming; - BYTE bSameBSSMaxNum; - BYTE bSameBSSCurNum; - BOOL bRoaming; - BOOL b11hEable; - unsigned long ulTxPower; - - // Encryption - NDIS_802_11_WEP_STATUS eEncryptionStatus; - BOOL bTransmitKey; - -//mike add :save old Encryption - NDIS_802_11_WEP_STATUS eOldEncryptionStatus; - - SKeyManagement sKey; - DWORD dwIVCounter; - - - RC4Ext SBox; - BYTE abyPRNG[WLAN_WEPMAX_KEYLEN+3]; - BYTE byKeyIndex; - - BOOL bAES; - - unsigned int uKeyLength; - BYTE abyKey[WLAN_WEP232_KEYLEN]; - - // for AP mode - unsigned int uAssocCount; - BOOL bMoreData; - - // QoS - BOOL bGrpAckPolicy; - - - BYTE byAutoFBCtrl; - - BOOL bTxMICFail; - BOOL bRxMICFail; - - - // For Update BaseBand VGA Gain Offset - BOOL bUpdateBBVGA; - unsigned int uBBVGADiffCount; - BYTE byBBVGANew; - BYTE byBBVGACurrent; - BYTE abyBBVGA[BB_VGA_LEVEL]; - signed long ldBmThreshold[BB_VGA_LEVEL]; - - BYTE byBBPreEDRSSI; - BYTE byBBPreEDIndex; - + u32 uSIFS; /* Current SIFS */ + u32 uDIFS; /* Current DIFS */ + u32 uEIFS; /* Current EIFS */ + u32 uSlot; /* Current SlotTime */ + u32 uCwMin; /* Current CwMin */ + u32 uCwMax; /* CwMax is fixed on 1023 */ + + /* PHY parameter */ + u8 bySIFS; + u8 byDIFS; + u8 byEIFS; + u8 bySlot; + u8 byCWMaxMin; + + /* Rate */ + VIA_BB_TYPE byBBType; /* 0: 11A, 1:11B, 2:11G */ + VIA_PKT_TYPE byPacketType; /* 0:11a 1:11b 2:11gb 3:11ga */ + u16 wBasicRate; + u8 byACKRate; + u8 byTopOFDMBasicRate; + u8 byTopCCKBasicRate; + + + u32 dwAotoRateTxOkCnt; + u32 dwAotoRateTxFailCnt; + u32 dwErrorRateThreshold[13]; + u32 dwTPTable[MAX_RATE]; + u8 abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */ + + u8 byMinChannel; + u8 byMaxChannel; + u32 uConnectionRate; + + u8 byPreambleType; + u8 byShortPreamble; + /* CARD_PHY_TYPE */ + u8 eConfigPHYMode; + + /* For RF Power table */ + u8 byCCKPwr; + u8 byOFDMPwrG; + u8 byOFDMPwrA; + u8 byCurPwr; + u8 abyCCKPwrTbl[14]; + u8 abyOFDMPwrTbl[14]; + u8 abyOFDMAPwrTbl[42]; + + u16 wCurrentRate; + u16 wRTSThreshold; + u16 wFragmentationThreshold; + u8 byShortRetryLimit; + u8 byLongRetryLimit; + CARD_OP_MODE eOPMode; + int bBSSIDFilter; + u16 wMaxTransmitMSDULifetime; + u8 abyBSSID[ETH_ALEN]; + u8 abyDesireBSSID[ETH_ALEN]; + + u16 wCTSDuration; /* update while speed change */ + u16 wACKDuration; + u16 wRTSTransmitLen; + u8 byRTSServiceField; + u8 byRTSSignalField; + + u32 dwMaxReceiveLifetime; /* dot11MaxReceiveLifetime */ + + int bCCK; + int bEncryptionEnable; + int bLongHeader; + int bSoftwareGenCrcErr; + int bShortSlotTime; + int bProtectMode; + int bNonERPPresent; + int bBarkerPreambleMd; + + u8 byERPFlag; + u16 wUseProtectCntDown; + + int bRadioControlOff; + int bRadioOff; + + /* Power save */ + int bEnablePSMode; + u16 wListenInterval; + int bPWBitOn; + WMAC_POWER_MODE ePSMode; + unsigned long ulPSModeWaitTx; + int bPSModeTxBurst; + + /* Beacon releated */ + u16 wSeqCounter; + int bBeaconBufReady; + int bBeaconSent; + int bFixRate; + u8 byCurrentCh; + u32 uScanTime; + + CMD_STATE eCommandState; + + CMD_CODE eCommand; + int bBeaconTx; + u8 byScanBBType; + + int bStopBeacon; + int bStopDataPkt; + int bStopTx0Pkt; + u32 uAutoReConnectTime; + u32 uIsroamingTime; + + /* 802.11 counter */ + + CMD_ITEM eCmdQueue[CMD_Q_SIZE]; + u32 uCmdDequeueIdx; + u32 uCmdEnqueueIdx; + u32 cbFreeCmdQueue; + int bCmdRunning; + int bCmdClear; + int bNeedRadioOFF; + + int bEnableRoaming; + int bIsRoaming; + int bFastRoaming; + u8 bSameBSSMaxNum; + u8 bSameBSSCurNum; + int bRoaming; + int b11hEable; + unsigned long ulTxPower; + + /* Encryption */ + NDIS_802_11_WEP_STATUS eEncryptionStatus; + int bTransmitKey; + NDIS_802_11_WEP_STATUS eOldEncryptionStatus; + SKeyManagement sKey; + u32 dwIVCounter; + + + RC4Ext SBox; + u8 abyPRNG[WLAN_WEPMAX_KEYLEN+3]; + u8 byKeyIndex; + + int bAES; + + u32 uKeyLength; + u8 abyKey[WLAN_WEP232_KEYLEN]; + + /* for AP mode */ + u32 uAssocCount; + int bMoreData; + + /* QoS */ + int bGrpAckPolicy; + + + u8 byAutoFBCtrl; + + int bTxMICFail; + int bRxMICFail; + + + /* For Update BaseBand VGA Gain Offset */ + int bUpdateBBVGA; + u32 uBBVGADiffCount; + u8 byBBVGANew; + u8 byBBVGACurrent; + u8 abyBBVGA[BB_VGA_LEVEL]; + signed long ldBmThreshold[BB_VGA_LEVEL]; + + u8 byBBPreEDRSSI; + u8 byBBPreEDIndex; + + + int bRadioCmd; + u32 dwDiagRefCount; + + /* For FOE Tuning */ + u8 byFOETuning; + + /* For Auto Power Tunning */ + u8 byAutoPwrTunning; + + /* BaseBand Loopback Use */ + u8 byBBCR4d; + u8 byBBCRc9; + u8 byBBCR88; + u8 byBBCR09; + + /* command timer */ + struct timer_list sTimerCommand; - BOOL bRadioCmd; - DWORD dwDiagRefCount; + struct timer_list sTimerTxData; + unsigned long nTxDataTimeCout; + int fTxDataInSleep; + int IsTxDataTrigger; - // For FOE Tuning - BYTE byFOETuning; + int fWPA_Authened; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */ + u8 byReAssocCount; + u8 byLinkWaitCount; - // For Auto Power Tunning + SEthernetHeader sTxEthHeader; + SEthernetHeader sRxEthHeader; + u8 abyBroadcastAddr[ETH_ALEN]; + u8 abySNAP_RFC1042[ETH_ALEN]; + u8 abySNAP_Bridgetunnel[ETH_ALEN]; - BYTE byAutoPwrTunning; + /* Pre-Authentication & PMK cache */ + SPMKID gsPMKID; + SPMKIDCandidateEvent gsPMKIDCandidate; - // BaseBand Loopback Use - BYTE byBBCR4d; - BYTE byBBCRc9; - BYTE byBBCR88; - BYTE byBBCR09; - // command timer - struct timer_list sTimerCommand; + /* for 802.11h */ + int b11hEnable; - struct timer_list sTimerTxData; - unsigned long nTxDataTimeCout; - BOOL fTxDataInSleep; - BOOL IsTxDataTrigger; + int bChannelSwitch; + u8 byNewChannel; + u8 byChannelSwitchCount; - BOOL fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? - BYTE byReAssocCount; //mike add:re-association retry times! - BYTE byLinkWaitCount; + /* WPA supplicant daemon */ + int bWPADEVUp; + int bwextstep0; + int bwextstep1; + int bwextstep2; + int bwextstep3; + int bWPASuppWextEnabled; - SEthernetHeader sTxEthHeader; - SEthernetHeader sRxEthHeader; - BYTE abyBroadcastAddr[ETH_ALEN]; - BYTE abySNAP_RFC1042[ETH_ALEN]; - BYTE abySNAP_Bridgetunnel[ETH_ALEN]; - - // Pre-Authentication & PMK cache - SPMKID gsPMKID; - SPMKIDCandidateEvent gsPMKIDCandidate; - - - // for 802.11h - BOOL b11hEnable; - - BOOL bChannelSwitch; - BYTE byNewChannel; - BYTE byChannelSwitchCount; - - //WPA supplicant daemon - struct net_device *wpadev; - BOOL bWPADEVUp; - //-- + /* user space daemon: hostapd, is used for HOSTAP */ + int bEnableHostapd; + int bEnable8021x; + int bEnableHostWEP; + struct net_device *apdev; + int (*tx_80211)(struct sk_buff *skb, struct net_device *dev); - BOOL bwextstep0; - BOOL bwextstep1; - BOOL bwextstep2; - BOOL bwextstep3; - BOOL bWPASuppWextEnabled; + u32 uChannel; -#ifdef HOSTAP - // user space daemon: hostapd, is used for HOSTAP - BOOL bEnableHostapd; - BOOL bEnable8021x; - BOOL bEnableHostWEP; - struct net_device *apdev; - int (*tx_80211)(struct sk_buff *skb, struct net_device *dev); -#endif - unsigned int uChannel; + struct iw_statistics wstats; /* wireless stats */ - struct iw_statistics wstats; // wireless stats - BOOL bCommit; + int bCommit; }; -- cgit v0.10.2 From 0e0a824e0b108a5baae31713bd2b84e40b05f626 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Thu, 17 Jan 2013 23:23:37 +0000 Subject: staging: vt6656: cleanup vnt_manger. Where appropriate replacing types defined in "type.h" with linux/types.h. Signed-off-by: Malcolm Priestley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/wmgr.h b/drivers/staging/vt6656/wmgr.h index 5112f53..83aed45 100644 --- a/drivers/staging/vt6656/wmgr.h +++ b/drivers/staging/vt6656/wmgr.h @@ -241,155 +241,146 @@ struct vnt_rx_mgmt { struct vnt_manager { void *pAdapter; - // MAC address - BYTE abyMACAddr[WLAN_ADDR_LEN]; - - // Configuration Mode - WMAC_CONFIG_MODE eConfigMode; // MAC pre-configed mode - - CARD_PHY_TYPE eCurrentPHYMode; - - - // Operation state variables - WMAC_CURRENT_MODE eCurrMode; // MAC current connection mode - WMAC_BSS_STATE eCurrState; // MAC current BSS state - WMAC_BSS_STATE eLastState; // MAC last BSS state - - PKnownBSS pCurrBSS; - BYTE byCSSGK; - BYTE byCSSPK; - -// BYTE abyNewSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN]; -// BYTE abyNewExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN]; - BOOL bCurrBSSIDFilterOn; - - // Current state vars - unsigned int uCurrChannel; - BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; - BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; - BYTE abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; - BYTE abyCurrBSSID[WLAN_BSSID_LEN]; - WORD wCurrCapInfo; - WORD wCurrAID; - unsigned int uRSSITrigger; - WORD wCurrATIMWindow; - WORD wCurrBeaconPeriod; - BOOL bIsDS; - BYTE byERPContext; - - CMD_STATE eCommandState; - unsigned int uScanChannel; - - // Desire joinning BSS vars - BYTE abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; - BYTE abyDesireBSSID[WLAN_BSSID_LEN]; - -//restore BSS info for Ad-Hoc mode - BYTE abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; - - // Adhoc or AP configuration vars - WORD wIBSSBeaconPeriod; - WORD wIBSSATIMWindow; - unsigned int uIBSSChannel; - BYTE abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; - BYTE byAPBBType; - BYTE abyWPAIE[MAX_WPA_IE_LEN]; - WORD wWPAIELen; - - unsigned int uAssocCount; - BOOL bMoreData; - - // Scan state vars - WMAC_SCAN_STATE eScanState; - WMAC_SCAN_TYPE eScanType; - unsigned int uScanStartCh; - unsigned int uScanEndCh; - WORD wScanSteps; - unsigned int uScanBSSType; - // Desire scannig vars - BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; - BYTE abyScanBSSID[WLAN_BSSID_LEN]; - - // Privacy - WMAC_AUTHENTICATION_MODE eAuthenMode; - BOOL bShareKeyAlgorithm; - BYTE abyChallenge[WLAN_CHALLENGE_LEN]; - BOOL bPrivacyInvoked; - - // Received beacon state vars - BOOL bInTIM; - BOOL bMulticastTIM; - BYTE byDTIMCount; - BYTE byDTIMPeriod; - - // Power saving state vars - WMAC_POWER_MODE ePSMode; - WORD wListenInterval; - WORD wCountToWakeUp; - BOOL bInTIMWake; - PBYTE pbyPSPacketPool; + + /* MAC address */ + u8 abyMACAddr[WLAN_ADDR_LEN]; + + /* Configuration Mode */ + WMAC_CONFIG_MODE eConfigMode; /* MAC pre-configed mode */ + + CARD_PHY_TYPE eCurrentPHYMode; + + /* Operation state variables */ + WMAC_CURRENT_MODE eCurrMode; /* MAC current connection mode */ + WMAC_BSS_STATE eCurrState; /* MAC current BSS state */ + WMAC_BSS_STATE eLastState; /* MAC last BSS state */ + + PKnownBSS pCurrBSS; + u8 byCSSGK; + u8 byCSSPK; + + int bCurrBSSIDFilterOn; + + /* Current state vars */ + u32 uCurrChannel; + u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + u8 abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; + u8 abyCurrBSSID[WLAN_BSSID_LEN]; + u16 wCurrCapInfo; + u16 wCurrAID; + u32 uRSSITrigger; + u16 wCurrATIMWindow; + u16 wCurrBeaconPeriod; + int bIsDS; + u8 byERPContext; + + CMD_STATE eCommandState; + u32 uScanChannel; + + /* Desire joinning BSS vars */ + u8 abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; + u8 abyDesireBSSID[WLAN_BSSID_LEN]; + + /*restore BSS info for Ad-Hoc mode */ + u8 abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; + + /* Adhoc or AP configuration vars */ + u16 wIBSSBeaconPeriod; + u16 wIBSSATIMWindow; + u32 uIBSSChannel; + u8 abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; + u8 byAPBBType; + u8 abyWPAIE[MAX_WPA_IE_LEN]; + u16 wWPAIELen; + + u32 uAssocCount; + int bMoreData; + + /* Scan state vars */ + WMAC_SCAN_STATE eScanState; + WMAC_SCAN_TYPE eScanType; + u32 uScanStartCh; + u32 uScanEndCh; + u16 wScanSteps; + u32 uScanBSSType; + /* Desire scannig vars */ + u8 abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; + u8 abyScanBSSID[WLAN_BSSID_LEN]; + + /* Privacy */ + WMAC_AUTHENTICATION_MODE eAuthenMode; + int bShareKeyAlgorithm; + u8 abyChallenge[WLAN_CHALLENGE_LEN]; + int bPrivacyInvoked; + + /* Received beacon state vars */ + int bInTIM; + int bMulticastTIM; + u8 byDTIMCount; + u8 byDTIMPeriod; + + /* Power saving state vars */ + WMAC_POWER_MODE ePSMode; + u16 wListenInterval; + u16 wCountToWakeUp; + int bInTIMWake; + u8 *pbyPSPacketPool; u8 byPSPacketPool[sizeof(struct vnt_tx_mgmt) + WLAN_NULLDATA_FR_MAXLEN]; - BOOL bRxBeaconInTBTTWake; - BYTE abyPSTxMap[MAX_NODE_NUM + 1]; + int bRxBeaconInTBTTWake; + u8 abyPSTxMap[MAX_NODE_NUM + 1]; - // management command related - unsigned int uCmdBusy; - unsigned int uCmdHostAPBusy; + /* management command related */ + u32 uCmdBusy; + u32 uCmdHostAPBusy; - // management packet pool - PBYTE pbyMgmtPacketPool; + /* management packet pool */ + u8 *pbyMgmtPacketPool; u8 byMgmtPacketPool[sizeof(struct vnt_tx_mgmt) + WLAN_A3FR_MAXLEN]; - // One second callback timer - struct timer_list sTimerSecondCallback; + /* One second callback timer */ + struct timer_list sTimerSecondCallback; /* Temporarily Rx Mgmt Packet Descriptor */ struct vnt_rx_mgmt sRxPacket; - // link list of known bss's (scan results) - KnownBSS sBSSList[MAX_BSS_NUM]; + /* link list of known bss's (scan results) */ + KnownBSS sBSSList[MAX_BSS_NUM]; /* link list of same bss's */ - KnownBSS pSameBSS[6] ; - BOOL Cisco_cckm ; - BYTE Roam_dbm; - - // table list of known node - // sNodeDBList[0] is reserved for AP under Infra mode - // sNodeDBList[0] is reserved for Multicast under adhoc/AP mode - KnownNodeDB sNodeDBTable[MAX_NODE_NUM + 1]; - - - - // WPA2 PMKID Cache - SPMKIDCache gsPMKIDCache; - BOOL bRoaming; - - // rate fall back vars - - - - // associate info - SAssocInfo sAssocInfo; - - - // for 802.11h - BOOL b11hEnable; - BOOL bSwitchChannel; - BYTE byNewChannel; - PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep; - unsigned int uLengthOfRepEIDs; + KnownBSS pSameBSS[6]; + int Cisco_cckm; + u8 Roam_dbm; + + /* table list of known node */ + /* sNodeDBList[0] is reserved for AP under Infra mode */ + /* sNodeDBList[0] is reserved for Multicast under adhoc/AP mode */ + KnownNodeDB sNodeDBTable[MAX_NODE_NUM + 1]; + + /* WPA2 PMKID Cache */ + SPMKIDCache gsPMKIDCache; + int bRoaming; + + /* associate info */ + SAssocInfo sAssocInfo; + + /* for 802.11h */ + int b11hEnable; + int bSwitchChannel; + u8 byNewChannel; + PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep; + u32 uLengthOfRepEIDs; u8 abyCurrentMSRReq[sizeof(struct vnt_tx_mgmt) + WLAN_A3FR_MAXLEN]; u8 abyCurrentMSRRep[sizeof(struct vnt_tx_mgmt) + WLAN_A3FR_MAXLEN]; - BYTE abyIECountry[WLAN_A3FR_MAXLEN]; - BYTE abyIBSSDFSOwner[6]; - BYTE byIBSSDFSRecovery; + u8 abyIECountry[WLAN_A3FR_MAXLEN]; + u8 abyIBSSDFSOwner[6]; + u8 byIBSSDFSRecovery; - struct sk_buff skb; + struct sk_buff skb; }; -- cgit v0.10.2 From 60ad45f84e3a510522313450f731a21ae0460a28 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:35:46 -0700 Subject: staging: comedi: addi_apci_2200: separate from addi_common.c This driver is for a simple 16 channel digital output (relays), 8 channel digital input board. Using the addi-data "common" code introduces a lot of bloat. Copy the code in addi_common.c to this driver and remove the #include that caused addi_common.c to be compiled with this driver. This will allow removing the bloat. Rename the auto_attach and detach functions so they have namespace associated with this driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 7c2c5db..84f33aa 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -4,9 +4,12 @@ #include "addi-data/addi_common.h" +#ifndef COMEDI_SUBD_TTLIO +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#endif + #include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci2200.c" -#include "addi-data/addi_common.c" static const struct addi_board apci2200_boardtypes[] = { { @@ -29,11 +32,316 @@ static const struct addi_board apci2200_boardtypes[] = { }, }; +static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + const struct addi_board *this_board = comedi_board(dev); + struct addi_private *devpriv = dev->private; + unsigned short w_Address = CR_CHAN(insn->chanspec); + unsigned short w_Data; + + w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc, + this_board->pc_EepromChip, 2 * w_Address); + data[0] = w_Data; + + return insn->n; +} + +static irqreturn_t v_ADDI_Interrupt(int irq, void *d) +{ + struct comedi_device *dev = d; + const struct addi_board *this_board = comedi_board(dev); + + this_board->interrupt(irq, d); + return IRQ_RETVAL(1); +} + +static int i_ADDI_Reset(struct comedi_device *dev) +{ + const struct addi_board *this_board = comedi_board(dev); + + this_board->reset(dev); + return 0; +} + +static const void *addi_find_boardinfo(struct comedi_device *dev, + struct pci_dev *pcidev) +{ + const void *p = dev->driver->board_name; + const struct addi_board *this_board; + int i; + + for (i = 0; i < dev->driver->num_names; i++) { + this_board = p; + if (this_board->i_VendorId == pcidev->vendor && + this_board->i_DeviceId == pcidev->device) + return this_board; + p += dev->driver->offset; + } + return NULL; +} + +static int apci2200_auto_attach(struct comedi_device *dev, + unsigned long context_unused) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + const struct addi_board *this_board; + struct addi_private *devpriv; + struct comedi_subdevice *s; + int ret, n_subdevices; + unsigned int dw_Dummy; + + this_board = addi_find_boardinfo(dev, pcidev); + if (!this_board) + return -ENODEV; + dev->board_ptr = this_board; + dev->board_name = this_board->pc_DriverName; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + ret = comedi_pci_enable(pcidev, dev->board_name); + if (ret) + return ret; + + if (!this_board->pc_EepromChip || + strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { + /* board does not have an eeprom or is not ADDIDATA_9054 */ + if (this_board->i_IorangeBase1) + dev->iobase = pci_resource_start(pcidev, 1); + else + dev->iobase = pci_resource_start(pcidev, 0); + + devpriv->iobase = dev->iobase; + devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); + devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); + } else { + /* board has an ADDIDATA_9054 eeprom */ + dev->iobase = pci_resource_start(pcidev, 2); + devpriv->iobase = pci_resource_start(pcidev, 2); + devpriv->dw_AiBase = ioremap(pci_resource_start(pcidev, 3), + this_board->i_IorangeBase3); + } + devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); + + /* Initialize parameters that can be overridden in EEPROM */ + devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; + devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; + devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; + devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; + devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; + devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; + devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; + devpriv->s_EeParameters.i_Dma = this_board->i_Dma; + devpriv->s_EeParameters.i_Timer = this_board->i_Timer; + devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = + this_board->ui_MinAcquisitiontimeNs; + devpriv->s_EeParameters.ui_MinDelaytimeNs = + this_board->ui_MinDelaytimeNs; + + /* ## */ + + if (pcidev->irq > 0) { + ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, + dev->board_name, dev); + if (ret == 0) + dev->irq = pcidev->irq; + } + + /* Read eepeom and fill addi_board Structure */ + + if (this_board->i_PCIEeprom) { + if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { + /* Set 3 wait stait */ + if (!(strcmp(dev->board_name, "apci035"))) + outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); + else + outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); + + /* Enable the interrupt for the controller */ + dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); + outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); + } + addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); + } + + n_subdevices = 7; + ret = comedi_alloc_subdevices(dev, n_subdevices); + if (ret) + return ret; + + /* Allocate and Initialise AI Subdevice Structures */ + s = &dev->subdevices[0]; + if ((devpriv->s_EeParameters.i_NbrAiChannel) + || (this_board->i_NbrAiChannelDiff)) { + dev->read_subdev = s; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_COMMON | SDF_GROUND + | SDF_DIFF; + if (devpriv->s_EeParameters.i_NbrAiChannel) { + s->n_chan = + devpriv->s_EeParameters.i_NbrAiChannel; + devpriv->b_SingelDiff = 0; + } else { + s->n_chan = this_board->i_NbrAiChannelDiff; + devpriv->b_SingelDiff = 1; + } + s->maxdata = devpriv->s_EeParameters.i_AiMaxdata; + s->len_chanlist = this_board->i_AiChannelList; + s->range_table = this_board->pr_AiRangelist; + + /* Set the initialisation flag */ + devpriv->b_AiInitialisation = 1; + + s->insn_config = this_board->ai_config; + s->insn_read = this_board->ai_read; + s->insn_write = this_board->ai_write; + s->insn_bits = this_board->ai_bits; + s->do_cmdtest = this_board->ai_cmdtest; + s->do_cmd = this_board->ai_cmd; + s->cancel = this_board->ai_cancel; + + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise AO Subdevice Structures */ + s = &dev->subdevices[1]; + if (devpriv->s_EeParameters.i_NbrAoChannel) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; + s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrAoChannel; + s->range_table = this_board->pr_AoRangelist; + s->insn_config = this_board->ao_config; + s->insn_write = this_board->ao_write; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + /* Allocate and Initialise DI Subdevice Structures */ + s = &dev->subdevices[2]; + if (devpriv->s_EeParameters.i_NbrDiChannel) { + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel; + s->maxdata = 1; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrDiChannel; + s->range_table = &range_digital; + s->io_bits = 0; /* all bits input */ + s->insn_config = this_board->di_config; + s->insn_read = this_board->di_read; + s->insn_write = this_board->di_write; + s->insn_bits = this_board->di_bits; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + /* Allocate and Initialise DO Subdevice Structures */ + s = &dev->subdevices[3]; + if (devpriv->s_EeParameters.i_NbrDoChannel) { + s->type = COMEDI_SUBD_DO; + s->subdev_flags = + SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; + s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrDoChannel; + s->range_table = &range_digital; + s->io_bits = 0xf; /* all bits output */ + + /* insn_config - for digital output memory */ + s->insn_config = this_board->do_config; + s->insn_write = this_board->do_write; + s->insn_bits = this_board->do_bits; + s->insn_read = this_board->do_read; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise Timer Subdevice Structures */ + s = &dev->subdevices[4]; + if (devpriv->s_EeParameters.i_Timer) { + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 1; + s->maxdata = 0; + s->len_chanlist = 1; + s->range_table = &range_digital; + + s->insn_write = this_board->timer_write; + s->insn_read = this_board->timer_read; + s->insn_config = this_board->timer_config; + s->insn_bits = this_board->timer_bits; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise TTL */ + s = &dev->subdevices[5]; + if (this_board->i_NbrTTLChannel) { + s->type = COMEDI_SUBD_TTLIO; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrTTLChannel; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->len_chanlist = this_board->i_NbrTTLChannel; + s->range_table = &range_digital; + s->insn_config = this_board->ttl_config; + s->insn_bits = this_board->ttl_bits; + s->insn_read = this_board->ttl_read; + s->insn_write = this_board->ttl_write; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* EEPROM */ + s = &dev->subdevices[6]; + if (this_board->i_PCIEeprom) { + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 256; + s->maxdata = 0xffff; + s->insn_read = i_ADDIDATA_InsnReadEeprom; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + i_ADDI_Reset(dev); + return 0; +} + +static void apci2200_detach(struct comedi_device *dev) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + struct addi_private *devpriv = dev->private; + + if (devpriv) { + if (dev->iobase) + i_ADDI_Reset(dev); + if (dev->irq) + free_irq(dev->irq, dev); + if (devpriv->dw_AiBase) + iounmap(devpriv->dw_AiBase); + } + if (pcidev) { + if (dev->iobase) + comedi_pci_disable(pcidev); + } +} + static struct comedi_driver apci2200_driver = { .driver_name = "addi_apci_2200", .module = THIS_MODULE, - .auto_attach = addi_auto_attach, - .detach = i_ADDI_Detach, + .auto_attach = apci2200_auto_attach, + .detach = apci2200_detach, .num_names = ARRAY_SIZE(apci2200_boardtypes), .board_name = &apci2200_boardtypes[0].pc_DriverName, .offset = sizeof(struct addi_board), -- cgit v0.10.2 From 49a91dfed55f157a0e4148d6b961179932a54dc7 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:36:10 -0700 Subject: staging: comedi: addi_apci_2200: board does not have ttl i/o The board supported by this driver does not have ttl i/o. Remove the subdevice init for it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 84f33aa..f4bf3ab 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -4,10 +4,6 @@ #include "addi-data/addi_common.h" -#ifndef COMEDI_SUBD_TTLIO -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#endif - #include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci2200.c" @@ -285,22 +281,7 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise TTL */ s = &dev->subdevices[5]; - if (this_board->i_NbrTTLChannel) { - s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = - SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrTTLChannel; - s->maxdata = 1; - s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; - s->range_table = &range_digital; - s->insn_config = this_board->ttl_config; - s->insn_bits = this_board->ttl_bits; - s->insn_read = this_board->ttl_read; - s->insn_write = this_board->ttl_write; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* EEPROM */ s = &dev->subdevices[6]; -- cgit v0.10.2 From ed03043c9a000255834800fcf8f02c6e8f5ba21f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:36:30 -0700 Subject: staging: comedi: addi_apci_2200: board does not have analog outputs The board supported by this driver does not have analog outputs. Remove the subdevice init for it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index f4bf3ab..2cda2cd 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -208,19 +208,8 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise AO Subdevice Structures */ s = &dev->subdevices[1]; - if (devpriv->s_EeParameters.i_NbrAoChannel) { - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; - s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrAoChannel; - s->range_table = this_board->pr_AoRangelist; - s->insn_config = this_board->ao_config; - s->insn_write = this_board->ao_write; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; + /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; if (devpriv->s_EeParameters.i_NbrDiChannel) { -- cgit v0.10.2 From fbaedea7c24572a9c6e767e19a9a39cf7e2b1747 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:36:50 -0700 Subject: staging: comedi: addi_apci_2200: board does not have analog inputs The board supported by this driver does not have analog inputs. Remove the subdevice init for it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 2cda2cd..17686ce 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -172,39 +172,7 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise AI Subdevice Structures */ s = &dev->subdevices[0]; - if ((devpriv->s_EeParameters.i_NbrAiChannel) - || (this_board->i_NbrAiChannelDiff)) { - dev->read_subdev = s; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = - SDF_READABLE | SDF_COMMON | SDF_GROUND - | SDF_DIFF; - if (devpriv->s_EeParameters.i_NbrAiChannel) { - s->n_chan = - devpriv->s_EeParameters.i_NbrAiChannel; - devpriv->b_SingelDiff = 0; - } else { - s->n_chan = this_board->i_NbrAiChannelDiff; - devpriv->b_SingelDiff = 1; - } - s->maxdata = devpriv->s_EeParameters.i_AiMaxdata; - s->len_chanlist = this_board->i_AiChannelList; - s->range_table = this_board->pr_AiRangelist; - - /* Set the initialisation flag */ - devpriv->b_AiInitialisation = 1; - - s->insn_config = this_board->ai_config; - s->insn_read = this_board->ai_read; - s->insn_write = this_board->ai_write; - s->insn_bits = this_board->ai_bits; - s->do_cmdtest = this_board->ai_cmdtest; - s->do_cmd = this_board->ai_cmd; - s->cancel = this_board->ai_cancel; - - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* Allocate and Initialise AO Subdevice Structures */ s = &dev->subdevices[1]; -- cgit v0.10.2 From df9f604d407231566b64799a9e1a0c6de8065dc6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:37:11 -0700 Subject: staging: comedi: addi_apci_2200: remove eeprom support code Reading the eeprom on the board supported by this driver is not necessary. All the information required is in the boardinfo. Remove the eeprom support code since it's not really interesting or useful. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 17686ce..77c8fe5 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -1,10 +1,8 @@ #include "../comedidev.h" #include "comedi_fc.h" -#include "amcc_s5933.h" #include "addi-data/addi_common.h" -#include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci2200.c" static const struct addi_board apci2200_boardtypes[] = { @@ -28,23 +26,6 @@ static const struct addi_board apci2200_boardtypes[] = { }, }; -static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - const struct addi_board *this_board = comedi_board(dev); - struct addi_private *devpriv = dev->private; - unsigned short w_Address = CR_CHAN(insn->chanspec); - unsigned short w_Data; - - w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc, - this_board->pc_EepromChip, 2 * w_Address); - data[0] = w_Data; - - return insn->n; -} - static irqreturn_t v_ADDI_Interrupt(int irq, void *d) { struct comedi_device *dev = d; @@ -87,7 +68,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, struct addi_private *devpriv; struct comedi_subdevice *s; int ret, n_subdevices; - unsigned int dw_Dummy; this_board = addi_find_boardinfo(dev, pcidev); if (!this_board) @@ -148,23 +128,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - /* Read eepeom and fill addi_board Structure */ - - if (this_board->i_PCIEeprom) { - if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { - /* Set 3 wait stait */ - if (!(strcmp(dev->board_name, "apci035"))) - outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); - else - outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); - - /* Enable the interrupt for the controller */ - dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); - outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); - } - addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); - } - n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) @@ -242,15 +205,7 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* EEPROM */ s = &dev->subdevices[6]; - if (this_board->i_PCIEeprom) { - s->type = COMEDI_SUBD_MEMORY; - s->subdev_flags = SDF_READABLE | SDF_INTERNAL; - s->n_chan = 256; - s->maxdata = 0xffff; - s->insn_read = i_ADDIDATA_InsnReadEeprom; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; i_ADDI_Reset(dev); return 0; -- cgit v0.10.2 From fb1e4e2e0b8a5b57ca861b6fc6d9f4af0bbb568e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:37:38 -0700 Subject: staging: comedi: addi_apci_2200: absorb i_APCI2200_Reset() This is the only 'reset' function used by the driver, remove it from the boardinfo and absorb the code from hwdrv_apci2200.c into the driver. Rename the CamelCase function i_ADDI_Reset() to apci2200_reset(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c index 9d4a117..d4c03f9 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c @@ -229,35 +229,3 @@ static int i_APCI2200_ReadWatchdog(struct comedi_device *dev, APCI2200_WATCHDOG_STATUS) & 0x1; return insn->n; } - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI2200_Reset(struct comedi_device *dev) | | -+----------------------------------------------------------------------------+ -| Task :resets all the registers | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : | -| | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI2200_Reset(struct comedi_device *dev) -{ - struct addi_private *devpriv = dev->private; - - outw(0x0, devpriv->iobase + APCI2200_DIGITAL_OP); /* RESETS THE DIGITAL OUTPUTS */ - outw(0x0, - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); - outw(0x0, - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE); - outw(0x0, - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE + 2); - return 0; -} diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 77c8fe5..6320136 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -17,7 +17,6 @@ static const struct addi_board apci2200_boardtypes[] = { .i_NbrDiChannel = 8, .i_NbrDoChannel = 16, .i_Timer = 1, - .reset = i_APCI2200_Reset, .di_bits = apci2200_di_insn_bits, .do_bits = apci2200_do_insn_bits, .timer_config = i_APCI2200_ConfigWatchdog, @@ -35,11 +34,18 @@ static irqreturn_t v_ADDI_Interrupt(int irq, void *d) return IRQ_RETVAL(1); } -static int i_ADDI_Reset(struct comedi_device *dev) +static int apci2200_reset(struct comedi_device *dev) { - const struct addi_board *this_board = comedi_board(dev); + struct addi_private *devpriv = dev->private; + + outw(0x0, devpriv->iobase + APCI2200_DIGITAL_OP); + outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); + outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE); + outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE + 2); - this_board->reset(dev); return 0; } @@ -207,7 +213,7 @@ static int apci2200_auto_attach(struct comedi_device *dev, s = &dev->subdevices[6]; s->type = COMEDI_SUBD_UNUSED; - i_ADDI_Reset(dev); + apci2200_reset(dev); return 0; } @@ -218,7 +224,7 @@ static void apci2200_detach(struct comedi_device *dev) if (devpriv) { if (dev->iobase) - i_ADDI_Reset(dev); + apci2200_reset(dev); if (dev->irq) free_irq(dev->irq, dev); if (devpriv->dw_AiBase) -- cgit v0.10.2 From a0ba8a299049d3c997b69a7cee23a1432aac9417 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:38:01 -0700 Subject: staging: comedi: addi_apci_2200: simplify the PCI bar reading The board supported by this driver has a 93x76 eeprom. Knowing this information allows simplifying the code that reads the PCI bars to get the iobase addresses. Also, since the 'dw_AiBase' is not ioremap'ed we can remove the iounmap in the detach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 6320136..49847ba 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -90,24 +90,10 @@ static int apci2200_auto_attach(struct comedi_device *dev, if (ret) return ret; - if (!this_board->pc_EepromChip || - strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { - /* board does not have an eeprom or is not ADDIDATA_9054 */ - if (this_board->i_IorangeBase1) - dev->iobase = pci_resource_start(pcidev, 1); - else - dev->iobase = pci_resource_start(pcidev, 0); - - devpriv->iobase = dev->iobase; - devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); - } else { - /* board has an ADDIDATA_9054 eeprom */ - dev->iobase = pci_resource_start(pcidev, 2); - devpriv->iobase = pci_resource_start(pcidev, 2); - devpriv->dw_AiBase = ioremap(pci_resource_start(pcidev, 3), - this_board->i_IorangeBase3); - } + dev->iobase = pci_resource_start(pcidev, 1); + devpriv->iobase = dev->iobase; + devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); + devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); /* Initialize parameters that can be overridden in EEPROM */ @@ -227,8 +213,6 @@ static void apci2200_detach(struct comedi_device *dev) apci2200_reset(dev); if (dev->irq) free_irq(dev->irq, dev); - if (devpriv->dw_AiBase) - iounmap(devpriv->dw_AiBase); } if (pcidev) { if (dev->iobase) -- cgit v0.10.2 From aad474484174022ced3fd5b0df5d43f78fa39be6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:38:25 -0700 Subject: staging: comedi: addi_apci_2200: remove unnecessary info from boardinfo Remove the information from the boardinfo that was only needed to work out the usage of the PCI bars. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c index d4c03f9..e4a422e 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c @@ -48,9 +48,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour /********* Definitions for APCI-2200 card *****/ -/* Card Specific information */ -#define APCI2200_ADDRESS_RANGE 64 - /* DIGITAL INPUT-OUTPUT DEFINE */ #define APCI2200_DIGITAL_OP 4 diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 49847ba..1205fe9 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -10,10 +10,6 @@ static const struct addi_board apci2200_boardtypes[] = { .pc_DriverName = "apci2200", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x1005, - .i_IorangeBase0 = 4, - .i_IorangeBase1 = APCI2200_ADDRESS_RANGE, - .i_PCIEeprom = ADDIDATA_EEPROM, - .pc_EepromChip = ADDIDATA_93C76, .i_NbrDiChannel = 8, .i_NbrDoChannel = 16, .i_Timer = 1, -- cgit v0.10.2 From 1d967a0356765cbef8351418613da83bb3d0d85a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:38:44 -0700 Subject: staging: comedi: addi_apci_2200: remove devpriv->iobase usage The iobase address stored in devpriv->iobase is also stored in dev->iobase. Use that instead. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c index e4a422e..3217203 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c @@ -65,9 +65,7 @@ static int apci2200_di_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; - - data[1] = inw(devpriv->iobase + APCI2200_DIGITAL_IP); + data[1] = inw(dev->iobase + APCI2200_DIGITAL_IP); return insn->n; } @@ -77,16 +75,15 @@ static int apci2200_do_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; unsigned int mask = data[0]; unsigned int bits = data[1]; - s->state = inw(devpriv->iobase + APCI2200_DIGITAL_OP); + s->state = inw(dev->iobase + APCI2200_DIGITAL_OP); if (mask) { s->state &= ~mask; s->state |= (bits & mask); - outw(s->state, devpriv->iobase + APCI2200_DIGITAL_OP); + outw(s->state, dev->iobase + APCI2200_DIGITAL_OP); } data[1] = s->state; @@ -120,21 +117,16 @@ static int i_APCI2200_ConfigWatchdog(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; - if (data[0] == 0) { /* Disable the watchdog */ - outw(0x0, - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); + outw(0x0, dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); /* Loading the Reload value */ - outw(data[1], - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE); + outw(data[1], dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE); data[1] = data[1] >> 16; - outw(data[1], - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE + 2); + outw(data[1], dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE + 2); } /* if(data[0]==0) */ else { printk("\nThe input parameters are wrong\n"); @@ -170,21 +162,18 @@ static int i_APCI2200_StartStopWriteWatchdog(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; - switch (data[0]) { case 0: /* stop the watchdog */ - outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); /* disable the watchdog */ + outw(0x0, dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); break; case 1: /* start the watchdog */ - outw(0x0001, - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); + outw(0x0001, dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); break; case 2: /* Software trigger */ - outw(0x0201, - devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); + outw(0x0201, dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); break; default: printk("\nSpecified functionality does not exist\n"); @@ -219,10 +208,7 @@ static int i_APCI2200_ReadWatchdog(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; - - data[0] = - inw(devpriv->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_STATUS) & 0x1; + data[0] = inw(dev->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_STATUS) & 0x1; return insn->n; } diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 1205fe9..cd1ac41 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -32,14 +32,12 @@ static irqreturn_t v_ADDI_Interrupt(int irq, void *d) static int apci2200_reset(struct comedi_device *dev) { - struct addi_private *devpriv = dev->private; - - outw(0x0, devpriv->iobase + APCI2200_DIGITAL_OP); - outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + + outw(0x0, dev->iobase + APCI2200_DIGITAL_OP); + outw(0x0, dev->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); - outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + + outw(0x0, dev->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_RELOAD_VALUE); - outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + + outw(0x0, dev->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_RELOAD_VALUE + 2); return 0; @@ -87,7 +85,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, return ret; dev->iobase = pci_resource_start(pcidev, 1); - devpriv->iobase = dev->iobase; devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); -- cgit v0.10.2 From c64f13006d04c7f0c4ecbfcaf1c02f91ecd0b207 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:39:06 -0700 Subject: staging: comedi: addi_apci_2200: don't read the unused PCI bars This driver only uses PCI bar 1 (dev->iobase), don't bother reading the unused PCI bars. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index cd1ac41..490870b 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -85,9 +85,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, return ret; dev->iobase = pci_resource_start(pcidev, 1); - devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); - devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); /* Initialize parameters that can be overridden in EEPROM */ devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; -- cgit v0.10.2 From dfc252583cc0dc7d164ebd84b4aba0f545e8401e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:39:24 -0700 Subject: staging: comedi: addi_apci_2200: remove use of devpriv->s_EeParameters This driver no longer reads the eeprom to find the board specific data, all the necessary data is in the boardinfo. Use the boardinfo directly instead of passing it through devpriv->s_EeParameters. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 490870b..cc0111c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -86,21 +86,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 1); - /* Initialize parameters that can be overridden in EEPROM */ - devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; - devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; - devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; - devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; - devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; - devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; - devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; - devpriv->s_EeParameters.i_Dma = this_board->i_Dma; - devpriv->s_EeParameters.i_Timer = this_board->i_Timer; - devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = - this_board->ui_MinAcquisitiontimeNs; - devpriv->s_EeParameters.ui_MinDelaytimeNs = - this_board->ui_MinDelaytimeNs; - /* ## */ if (pcidev->irq > 0) { @@ -125,13 +110,12 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; - if (devpriv->s_EeParameters.i_NbrDiChannel) { + if (this_board->i_NbrDiChannel) { s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel; + s->n_chan = this_board->i_NbrDiChannel; s->maxdata = 1; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDiChannel; + s->len_chanlist = this_board->i_NbrDiChannel; s->range_table = &range_digital; s->io_bits = 0; /* all bits input */ s->insn_config = this_board->di_config; @@ -143,14 +127,13 @@ static int apci2200_auto_attach(struct comedi_device *dev, } /* Allocate and Initialise DO Subdevice Structures */ s = &dev->subdevices[3]; - if (devpriv->s_EeParameters.i_NbrDoChannel) { + if (this_board->i_NbrDoChannel) { s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; - s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDoChannel; + s->n_chan = this_board->i_NbrDoChannel; + s->maxdata = this_board->i_DoMaxdata; + s->len_chanlist = this_board->i_NbrDoChannel; s->range_table = &range_digital; s->io_bits = 0xf; /* all bits output */ @@ -165,7 +148,7 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; - if (devpriv->s_EeParameters.i_Timer) { + if (this_board->i_Timer) { s->type = COMEDI_SUBD_TIMER; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 1; -- cgit v0.10.2 From 903b6c94bb51808d9619d9c17179202ff1a808f4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:39:41 -0700 Subject: staging: comedi: addi_apci_2200: remove interrupt support code This board does not have any interrupt capable devices. Remove the unused interrupt support code. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index cc0111c..8d41c4f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -21,15 +21,6 @@ static const struct addi_board apci2200_boardtypes[] = { }, }; -static irqreturn_t v_ADDI_Interrupt(int irq, void *d) -{ - struct comedi_device *dev = d; - const struct addi_board *this_board = comedi_board(dev); - - this_board->interrupt(irq, d); - return IRQ_RETVAL(1); -} - static int apci2200_reset(struct comedi_device *dev) { outw(0x0, dev->iobase + APCI2200_DIGITAL_OP); @@ -86,15 +77,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 1); - /* ## */ - - if (pcidev->irq > 0) { - ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, - dev->board_name, dev); - if (ret == 0) - dev->irq = pcidev->irq; - } - n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) @@ -184,8 +166,6 @@ static void apci2200_detach(struct comedi_device *dev) if (devpriv) { if (dev->iobase) apci2200_reset(dev); - if (dev->irq) - free_irq(dev->irq, dev); } if (pcidev) { if (dev->iobase) -- cgit v0.10.2 From 41542073f5c21c724fdb004a568bffb0f217d7b8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:40:01 -0700 Subject: staging: comedi: addi_apci_2200: cleanup digital input subdevice The board supported by this driver always has a digital input subdevice. Remove the boardinfo for it and just open-code the relevant data in the subdevice init. Remove the SDF_GROUND and SDF_COMMON from the subdevice 'subdev_flags'. These flags only have meaning for analog input/output subdevices. Remove the subdevice 'len_chanlist' initialization. This variable only has meaning for subdevices that support asynchronous commands. Remove the subdevice 'io_bits' initialization. Digital input subdevices don't use this variable. Remove the subdevice function pointers that evaluate to NULL based on the boardinfo data. Move the apci2200_di_insn_bits() function from the hwdrv_apci2200.c file into the main driver file. For aesthetic reasons, rename the #define used for the register used to read the digital inputs. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c index 3217203..f9784e9 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c @@ -51,7 +51,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour /* DIGITAL INPUT-OUTPUT DEFINE */ #define APCI2200_DIGITAL_OP 4 -#define APCI2200_DIGITAL_IP 0 /* TIMER COUNTER WATCHDOG DEFINES */ @@ -60,16 +59,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour #define APCI2200_WATCHDOG_RELOAD_VALUE 4 #define APCI2200_WATCHDOG_STATUS 16 -static int apci2200_di_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - data[1] = inw(dev->iobase + APCI2200_DIGITAL_IP); - - return insn->n; -} - static int apci2200_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 8d41c4f..3db402c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -5,15 +5,18 @@ #include "addi-data/hwdrv_apci2200.c" +/* + * I/O Register Map + */ +#define APCI2200_DI_REG 0x00 + static const struct addi_board apci2200_boardtypes[] = { { .pc_DriverName = "apci2200", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x1005, - .i_NbrDiChannel = 8, .i_NbrDoChannel = 16, .i_Timer = 1, - .di_bits = apci2200_di_insn_bits, .do_bits = apci2200_do_insn_bits, .timer_config = i_APCI2200_ConfigWatchdog, .timer_write = i_APCI2200_StartStopWriteWatchdog, @@ -21,6 +24,16 @@ static const struct addi_board apci2200_boardtypes[] = { }, }; +static int apci2200_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + data[1] = inw(dev->iobase + APCI2200_DI_REG); + + return insn->n; +} + static int apci2200_reset(struct comedi_device *dev) { outw(0x0, dev->iobase + APCI2200_DIGITAL_OP); @@ -92,21 +105,13 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; - if (this_board->i_NbrDiChannel) { - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrDiChannel; - s->maxdata = 1; - s->len_chanlist = this_board->i_NbrDiChannel; - s->range_table = &range_digital; - s->io_bits = 0; /* all bits input */ - s->insn_config = this_board->di_config; - s->insn_read = this_board->di_read; - s->insn_write = this_board->di_write; - s->insn_bits = this_board->di_bits; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci2200_di_insn_bits; + /* Allocate and Initialise DO Subdevice Structures */ s = &dev->subdevices[3]; if (this_board->i_NbrDoChannel) { -- cgit v0.10.2 From 7828f09660947ea7c15c4f02475d7789755939bc Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:40:31 -0700 Subject: staging: comedi: addi_apci_2200: cleanup digital output subdevice The board supported by this driver always has a digital output subdevice. Remove the boardinfo for it and just open-code the relevant data in the subdevice init. Remove the SDF_GROUND and SDF_COMMON from the subdevice 'subdev_flags'. These flags only have meaning for analog input/output subdevices. Also, remove the SDF_READABLE flag, it is not required by output only subdevices. Remove the subdevice 'len_chanlist' initialization. This variable only has meaning for subdevices that support asynchronous commands. Remove the subdevice 'io_bits' initialization. Digital output subdevices don't use this variable. Remove the subdevice function pointers that evaluate to NULL based on the boardinfo data. Move the apci2200_do_insn_bits() function from the hwdrv_apci2200.c file into the main driver file. For aesthetic reasons, rename the #define used for the register used to read/write the digital outputs.. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c index f9784e9..4d32509 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c @@ -46,12 +46,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour +----------+-----------+------------------------------------------------+ */ -/********* Definitions for APCI-2200 card *****/ - -/* DIGITAL INPUT-OUTPUT DEFINE */ - -#define APCI2200_DIGITAL_OP 4 - /* TIMER COUNTER WATCHDOG DEFINES */ #define APCI2200_WATCHDOG 0x08 @@ -59,27 +53,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour #define APCI2200_WATCHDOG_RELOAD_VALUE 4 #define APCI2200_WATCHDOG_STATUS 16 -static int apci2200_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - unsigned int mask = data[0]; - unsigned int bits = data[1]; - - s->state = inw(dev->iobase + APCI2200_DIGITAL_OP); - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - outw(s->state, dev->iobase + APCI2200_DIGITAL_OP); - } - - data[1] = s->state; - - return insn->n; -} - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2200_ConfigWatchdog(struct comedi_device *dev, diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 3db402c..15a84e5 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -9,15 +9,14 @@ * I/O Register Map */ #define APCI2200_DI_REG 0x00 +#define APCI2200_DO_REG 0x04 static const struct addi_board apci2200_boardtypes[] = { { .pc_DriverName = "apci2200", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x1005, - .i_NbrDoChannel = 16, .i_Timer = 1, - .do_bits = apci2200_do_insn_bits, .timer_config = i_APCI2200_ConfigWatchdog, .timer_write = i_APCI2200_StartStopWriteWatchdog, .timer_read = i_APCI2200_ReadWatchdog, @@ -34,9 +33,30 @@ static int apci2200_di_insn_bits(struct comedi_device *dev, return insn->n; } +static int apci2200_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int mask = data[0]; + unsigned int bits = data[1]; + + s->state = inw(dev->iobase + APCI2200_DO_REG); + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + outw(s->state, dev->iobase + APCI2200_DO_REG); + } + + data[1] = s->state; + + return insn->n; +} + static int apci2200_reset(struct comedi_device *dev) { - outw(0x0, dev->iobase + APCI2200_DIGITAL_OP); + outw(0x0, dev->iobase + APCI2200_DO_REG); outw(0x0, dev->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); outw(0x0, dev->iobase + APCI2200_WATCHDOG + @@ -114,24 +134,12 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise DO Subdevice Structures */ s = &dev->subdevices[3]; - if (this_board->i_NbrDoChannel) { - s->type = COMEDI_SUBD_DO; - s->subdev_flags = - SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrDoChannel; - s->maxdata = this_board->i_DoMaxdata; - s->len_chanlist = this_board->i_NbrDoChannel; - s->range_table = &range_digital; - s->io_bits = 0xf; /* all bits output */ - - /* insn_config - for digital output memory */ - s->insn_config = this_board->do_config; - s->insn_write = this_board->do_write; - s->insn_bits = this_board->do_bits; - s->insn_read = this_board->do_read; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci2200_do_insn_bits; /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; -- cgit v0.10.2 From 2abcf87aeea500d28a953d4b02450f76820f899d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:41:01 -0700 Subject: staging: comedi: introduce addi_watchdog driver Many of the ADDI-DATA drivers have a "watchdog" subdevice that can be used to monitor digital output activity. All the digital outputs are released (set to 0) if the digital outputs are not accessed, or the watchdog it not pinged, before the timeout of the watchdog occurs. The only difference in the drivers for the watchdog subdevice is the base address used to talk to the watchdog registers. Instead of duplicating the code needed to support this watchdog, introduce a helper module, similar to the 8255 module. This module will be select'ed by the drivers that can use it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 36eec32..8f2bef3 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -567,6 +567,13 @@ config COMEDI_8255_PCI To compile this driver as a module, choose M here: the module will be called 8255_pci. +config COMEDI_ADDI_WATCHDOG + tristate + ---help--- + Provides support for the watchdog subdevice found on many ADDI-DATA + boards. This module will be automatically selected when needed. The + module will be called addi_watchdog. + config COMEDI_ADDI_APCI_035 tristate "ADDI-DATA APCI_035 support" ---help--- diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index 3a04e30..fd74e7e 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_COMEDI_POC) += poc.o # Comedi PCI drivers obj-$(CONFIG_COMEDI_8255_PCI) += 8255_pci.o +obj-$(CONFIG_COMEDI_ADDI_WATCHDOG) += addi_watchdog.o obj-$(CONFIG_COMEDI_ADDI_APCI_035) += addi_apci_035.o obj-$(CONFIG_COMEDI_ADDI_APCI_1032) += addi_apci_1032.o obj-$(CONFIG_COMEDI_ADDI_APCI_1500) += addi_apci_1500.o diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c new file mode 100644 index 0000000..b944503 --- /dev/null +++ b/drivers/staging/comedi/drivers/addi_watchdog.c @@ -0,0 +1,172 @@ +/* + * COMEDI driver for the watchdog subdevice found on some addi-data boards + * Copyright (c) 2013 H Hartley Sweeten + * + * Based on implementations in various addi-data COMEDI drivers. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1998 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "../comedidev.h" +#include "addi_watchdog.h" + +/* + * Register offsets/defines for the addi-data watchdog + */ +#define ADDI_WDOG_REG 0x00 +#define ADDI_WDOG_RELOAD_REG 0x04 +#define ADDI_WDOG_TIMEBASE 0x08 +#define ADDI_WDOG_CTRL_REG 0x0c +#define ADDI_WDOG_CTRL_ENABLE (1 << 0) +#define ADDI_WDOG_CTRL_SW_TRIG (1 << 9) +#define ADDI_WDOG_STATUS_REG 0x10 +#define ADDI_WDOG_STATUS_ENABLED (1 << 0) +#define ADDI_WDOG_STATUS_SW_TRIG (1 << 1) + +struct addi_watchdog_private { + unsigned long iobase; + unsigned int wdog_ctrl; +}; + +/* + * The watchdog subdevice is configured with two INSN_CONFIG instructions: + * + * Enable the watchdog and set the reload timeout: + * data[0] = INSN_CONFIG_ARM + * data[1] = timeout reload value + * + * Disable the watchdog: + * data[0] = INSN_CONFIG_DISARM + */ +static int addi_watchdog_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct addi_watchdog_private *spriv = s->private; + unsigned int reload; + + switch (data[0]) { + case INSN_CONFIG_ARM: + spriv->wdog_ctrl = ADDI_WDOG_CTRL_ENABLE; + reload = data[1] & s->maxdata; + outw(reload, spriv->iobase + ADDI_WDOG_RELOAD_REG); + + /* Time base is 20ms, let the user know the timeout */ + dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n", + 20 * reload + 20); + break; + case INSN_CONFIG_DISARM: + spriv->wdog_ctrl = 0; + break; + default: + return -EINVAL; + } + + outw(spriv->wdog_ctrl, spriv->iobase + ADDI_WDOG_CTRL_REG); + + return insn->n; +} + +static int addi_watchdog_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct addi_watchdog_private *spriv = s->private; + int i; + + for (i = 0; i < insn->n; i++) + data[i] = inl(spriv->iobase + ADDI_WDOG_STATUS_REG); + + return insn->n; +} + +static int addi_watchdog_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct addi_watchdog_private *spriv = s->private; + int i; + + if (spriv->wdog_ctrl == 0) { + dev_warn(dev->class_dev, "watchdog is disabled\n"); + return -EINVAL; + } + + /* "ping" the watchdog */ + for (i = 0; i < insn->n; i++) { + outw(spriv->wdog_ctrl | ADDI_WDOG_CTRL_SW_TRIG, + spriv->iobase + ADDI_WDOG_CTRL_REG); + } + + return insn->n; +} + +void addi_watchdog_reset(unsigned long iobase) +{ + outl(0x0, iobase + ADDI_WDOG_CTRL_REG); + outl(0x0, iobase + ADDI_WDOG_RELOAD_REG); +} +EXPORT_SYMBOL_GPL(addi_watchdog_reset); + +int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase) +{ + struct addi_watchdog_private *spriv; + + spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); + if (!spriv) + return -ENOMEM; + + spriv->iobase = iobase; + + s->private = spriv; + + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 1; + s->maxdata = 0xff; + s->insn_config = addi_watchdog_insn_config; + s->insn_read = addi_watchdog_insn_read; + s->insn_write = addi_watchdog_insn_write; + + return 0; +} +EXPORT_SYMBOL_GPL(addi_watchdog_init); + +void addi_watchdog_cleanup(struct comedi_subdevice *s) +{ + kfree(s->private); +} +EXPORT_SYMBOL_GPL(addi_watchdog_cleanup); + +static int __init addi_watchdog_module_init(void) +{ + return 0; +} +module_init(addi_watchdog_module_init); + +static void __exit addi_watchdog_module_exit(void) +{ +} +module_exit(addi_watchdog_module_exit); + +MODULE_DESCRIPTION("ADDI-DATA Watchdog subdevice"); +MODULE_AUTHOR("H Hartley Sweeten "); +MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/addi_watchdog.h b/drivers/staging/comedi/drivers/addi_watchdog.h new file mode 100644 index 0000000..f374a7b --- /dev/null +++ b/drivers/staging/comedi/drivers/addi_watchdog.h @@ -0,0 +1,10 @@ +#ifndef _ADDI_WATCHDOG_H +#define _ADDI_WATCHDOG_H + +#include "../comedidev.h" + +void addi_watchdog_reset(unsigned long iobase); +int addi_watchdog_init(struct comedi_subdevice *, unsigned long iobase); +void addi_watchdog_cleanup(struct comedi_subdevice *s); + +#endif -- cgit v0.10.2 From 5b62fe2a03e9d25569c0fa0b81b96ac6f0c9b5fd Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Jan 2013 17:41:25 -0700 Subject: staging: comedi: addi_apci_2032: use addi_watchdog module Use the addi_watchdog module to provide support for the watchdog subdevice. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 8f2bef3..39cf735 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -626,6 +626,7 @@ config COMEDI_ADDI_APCI_16XX config COMEDI_ADDI_APCI_2032 tristate "ADDI-DATA APCI_2032 support" + select COMEDI_ADDI_WATCHDOG ---help--- Enable support for ADDI-DATA APCI_2032 cards diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 31e1259..4660ec7 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -30,6 +30,7 @@ */ #include "../comedidev.h" +#include "addi_watchdog.h" #include "comedi_fc.h" /* @@ -45,18 +46,6 @@ #define APCI2032_STATUS_REG 0x0c #define APCI2032_STATUS_IRQ (1 << 0) #define APCI2032_WDOG_REG 0x10 -#define APCI2032_WDOG_RELOAD_REG 0x14 -#define APCI2032_WDOG_TIMEBASE 0x18 -#define APCI2032_WDOG_CTRL_REG 0x1c -#define APCI2032_WDOG_CTRL_ENABLE (1 << 0) -#define APCI2032_WDOG_CTRL_SW_TRIG (1 << 9) -#define APCI2032_WDOG_STATUS_REG 0x20 -#define APCI2032_WDOG_STATUS_ENABLED (1 << 0) -#define APCI2032_WDOG_STATUS_SW_TRIG (1 << 1) - -struct apci2032_private { - unsigned int wdog_ctrl; -}; struct apci2032_int_private { spinlock_t spinlock; @@ -86,81 +75,6 @@ static int apci2032_do_insn_bits(struct comedi_device *dev, return insn->n; } -/* - * The watchdog subdevice is configured with two INSN_CONFIG instructions: - * - * Enable the watchdog and set the reload timeout: - * data[0] = INSN_CONFIG_ARM - * data[1] = timeout reload value - * - * Disable the watchdog: - * data[0] = INSN_CONFIG_DISARM - */ -static int apci2032_wdog_insn_config(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci2032_private *devpriv = dev->private; - unsigned int reload; - - switch (data[0]) { - case INSN_CONFIG_ARM: - devpriv->wdog_ctrl = APCI2032_WDOG_CTRL_ENABLE; - reload = data[1] & s->maxdata; - outw(reload, dev->iobase + APCI2032_WDOG_RELOAD_REG); - - /* Time base is 20ms, let the user know the timeout */ - dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n", - 20 * reload + 20); - break; - case INSN_CONFIG_DISARM: - devpriv->wdog_ctrl = 0; - break; - default: - return -EINVAL; - } - - outw(devpriv->wdog_ctrl, dev->iobase + APCI2032_WDOG_CTRL_REG); - - return insn->n; -} - -static int apci2032_wdog_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci2032_private *devpriv = dev->private; - int i; - - if (devpriv->wdog_ctrl == 0) { - dev_warn(dev->class_dev, "watchdog is disabled\n"); - return -EINVAL; - } - - /* "ping" the watchdog */ - for (i = 0; i < insn->n; i++) { - outw(devpriv->wdog_ctrl | APCI2032_WDOG_CTRL_SW_TRIG, - dev->iobase + APCI2032_WDOG_CTRL_REG); - } - - return insn->n; -} - -static int apci2032_wdog_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - int i; - - for (i = 0; i < insn->n; i++) - data[i] = inl(dev->iobase + APCI2032_WDOG_STATUS_REG); - - return insn->n; -} - static int apci2032_int_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -357,8 +271,8 @@ static int apci2032_reset(struct comedi_device *dev) { outl(0x0, dev->iobase + APCI2032_DO_REG); outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); - outl(0x0, dev->iobase + APCI2032_WDOG_CTRL_REG); - outl(0x0, dev->iobase + APCI2032_WDOG_RELOAD_REG); + + addi_watchdog_reset(dev->iobase + APCI2032_WDOG_REG); return 0; } @@ -367,17 +281,11 @@ static int apci2032_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - struct apci2032_private *devpriv; struct comedi_subdevice *s; int ret; dev->board_name = dev->driver->driver_name; - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - ret = comedi_pci_enable(pcidev, dev->board_name); if (ret) return ret; @@ -406,13 +314,9 @@ static int apci2032_auto_attach(struct comedi_device *dev, /* Initialize the watchdog subdevice */ s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 1; - s->maxdata = 0xff; - s->insn_write = apci2032_wdog_insn_write; - s->insn_read = apci2032_wdog_insn_read; - s->insn_config = apci2032_wdog_insn_config; + ret = addi_watchdog_init(s, dev->iobase + APCI2032_WDOG_REG); + if (ret) + return ret; /* Initialize the interrupt subdevice */ s = &dev->subdevices[2]; @@ -451,6 +355,8 @@ static void apci2032_detach(struct comedi_device *dev) free_irq(dev->irq, dev); if (dev->read_subdev) kfree(dev->read_subdev->private); + if (dev->subdevices) + addi_watchdog_cleanup(&dev->subdevices[1]); if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); -- cgit v0.10.2 From 368463328badaa5431416574d9a1f60de8ae04cf Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:40:31 -0700 Subject: staging: comedi: addi_apci_16xx: separate from addi_common.c This driver is for two simple ttl digital output boards. One with 48 channels the other with 96. Using the addi-data "common" code introduces a lot of bloat. Copy the code in addi_common.c to this driver and remove the #include that caused addi_common.c to be compiled with this driver. This will allow removing the bloat. Rename the auto_attach and detach functions so they have namespace associated with this driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index ab9a96a..658943b 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -4,9 +4,12 @@ #include "addi-data/addi_common.h" +#ifndef COMEDI_SUBD_TTLIO +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#endif + #include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci16xx.c" -#include "addi-data/addi_common.c" static const struct addi_board apci16xx_boardtypes[] = { { @@ -36,11 +39,316 @@ static const struct addi_board apci16xx_boardtypes[] = { }, }; +static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + const struct addi_board *this_board = comedi_board(dev); + struct addi_private *devpriv = dev->private; + unsigned short w_Address = CR_CHAN(insn->chanspec); + unsigned short w_Data; + + w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc, + this_board->pc_EepromChip, 2 * w_Address); + data[0] = w_Data; + + return insn->n; +} + +static irqreturn_t v_ADDI_Interrupt(int irq, void *d) +{ + struct comedi_device *dev = d; + const struct addi_board *this_board = comedi_board(dev); + + this_board->interrupt(irq, d); + return IRQ_RETVAL(1); +} + +static int i_ADDI_Reset(struct comedi_device *dev) +{ + const struct addi_board *this_board = comedi_board(dev); + + this_board->reset(dev); + return 0; +} + +static const void *addi_find_boardinfo(struct comedi_device *dev, + struct pci_dev *pcidev) +{ + const void *p = dev->driver->board_name; + const struct addi_board *this_board; + int i; + + for (i = 0; i < dev->driver->num_names; i++) { + this_board = p; + if (this_board->i_VendorId == pcidev->vendor && + this_board->i_DeviceId == pcidev->device) + return this_board; + p += dev->driver->offset; + } + return NULL; +} + +static int apci16xx_auto_attach(struct comedi_device *dev, + unsigned long context_unused) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + const struct addi_board *this_board; + struct addi_private *devpriv; + struct comedi_subdevice *s; + int ret, n_subdevices; + unsigned int dw_Dummy; + + this_board = addi_find_boardinfo(dev, pcidev); + if (!this_board) + return -ENODEV; + dev->board_ptr = this_board; + dev->board_name = this_board->pc_DriverName; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + ret = comedi_pci_enable(pcidev, dev->board_name); + if (ret) + return ret; + + if (!this_board->pc_EepromChip || + strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { + /* board does not have an eeprom or is not ADDIDATA_9054 */ + if (this_board->i_IorangeBase1) + dev->iobase = pci_resource_start(pcidev, 1); + else + dev->iobase = pci_resource_start(pcidev, 0); + + devpriv->iobase = dev->iobase; + devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); + devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); + } else { + /* board has an ADDIDATA_9054 eeprom */ + dev->iobase = pci_resource_start(pcidev, 2); + devpriv->iobase = pci_resource_start(pcidev, 2); + devpriv->dw_AiBase = ioremap(pci_resource_start(pcidev, 3), + this_board->i_IorangeBase3); + } + devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); + + /* Initialize parameters that can be overridden in EEPROM */ + devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; + devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; + devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; + devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; + devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; + devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; + devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; + devpriv->s_EeParameters.i_Dma = this_board->i_Dma; + devpriv->s_EeParameters.i_Timer = this_board->i_Timer; + devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = + this_board->ui_MinAcquisitiontimeNs; + devpriv->s_EeParameters.ui_MinDelaytimeNs = + this_board->ui_MinDelaytimeNs; + + /* ## */ + + if (pcidev->irq > 0) { + ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, + dev->board_name, dev); + if (ret == 0) + dev->irq = pcidev->irq; + } + + /* Read eepeom and fill addi_board Structure */ + + if (this_board->i_PCIEeprom) { + if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { + /* Set 3 wait stait */ + if (!(strcmp(dev->board_name, "apci035"))) + outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); + else + outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); + + /* Enable the interrupt for the controller */ + dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); + outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); + } + addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); + } + + n_subdevices = 7; + ret = comedi_alloc_subdevices(dev, n_subdevices); + if (ret) + return ret; + + /* Allocate and Initialise AI Subdevice Structures */ + s = &dev->subdevices[0]; + if ((devpriv->s_EeParameters.i_NbrAiChannel) + || (this_board->i_NbrAiChannelDiff)) { + dev->read_subdev = s; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_COMMON | SDF_GROUND + | SDF_DIFF; + if (devpriv->s_EeParameters.i_NbrAiChannel) { + s->n_chan = + devpriv->s_EeParameters.i_NbrAiChannel; + devpriv->b_SingelDiff = 0; + } else { + s->n_chan = this_board->i_NbrAiChannelDiff; + devpriv->b_SingelDiff = 1; + } + s->maxdata = devpriv->s_EeParameters.i_AiMaxdata; + s->len_chanlist = this_board->i_AiChannelList; + s->range_table = this_board->pr_AiRangelist; + + /* Set the initialisation flag */ + devpriv->b_AiInitialisation = 1; + + s->insn_config = this_board->ai_config; + s->insn_read = this_board->ai_read; + s->insn_write = this_board->ai_write; + s->insn_bits = this_board->ai_bits; + s->do_cmdtest = this_board->ai_cmdtest; + s->do_cmd = this_board->ai_cmd; + s->cancel = this_board->ai_cancel; + + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise AO Subdevice Structures */ + s = &dev->subdevices[1]; + if (devpriv->s_EeParameters.i_NbrAoChannel) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; + s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrAoChannel; + s->range_table = this_board->pr_AoRangelist; + s->insn_config = this_board->ao_config; + s->insn_write = this_board->ao_write; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + /* Allocate and Initialise DI Subdevice Structures */ + s = &dev->subdevices[2]; + if (devpriv->s_EeParameters.i_NbrDiChannel) { + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel; + s->maxdata = 1; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrDiChannel; + s->range_table = &range_digital; + s->io_bits = 0; /* all bits input */ + s->insn_config = this_board->di_config; + s->insn_read = this_board->di_read; + s->insn_write = this_board->di_write; + s->insn_bits = this_board->di_bits; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + /* Allocate and Initialise DO Subdevice Structures */ + s = &dev->subdevices[3]; + if (devpriv->s_EeParameters.i_NbrDoChannel) { + s->type = COMEDI_SUBD_DO; + s->subdev_flags = + SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; + s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrDoChannel; + s->range_table = &range_digital; + s->io_bits = 0xf; /* all bits output */ + + /* insn_config - for digital output memory */ + s->insn_config = this_board->do_config; + s->insn_write = this_board->do_write; + s->insn_bits = this_board->do_bits; + s->insn_read = this_board->do_read; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise Timer Subdevice Structures */ + s = &dev->subdevices[4]; + if (devpriv->s_EeParameters.i_Timer) { + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 1; + s->maxdata = 0; + s->len_chanlist = 1; + s->range_table = &range_digital; + + s->insn_write = this_board->timer_write; + s->insn_read = this_board->timer_read; + s->insn_config = this_board->timer_config; + s->insn_bits = this_board->timer_bits; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise TTL */ + s = &dev->subdevices[5]; + if (this_board->i_NbrTTLChannel) { + s->type = COMEDI_SUBD_TTLIO; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrTTLChannel; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->len_chanlist = this_board->i_NbrTTLChannel; + s->range_table = &range_digital; + s->insn_config = this_board->ttl_config; + s->insn_bits = this_board->ttl_bits; + s->insn_read = this_board->ttl_read; + s->insn_write = this_board->ttl_write; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* EEPROM */ + s = &dev->subdevices[6]; + if (this_board->i_PCIEeprom) { + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 256; + s->maxdata = 0xffff; + s->insn_read = i_ADDIDATA_InsnReadEeprom; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + i_ADDI_Reset(dev); + return 0; +} + +static void apci16xx_detach(struct comedi_device *dev) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + struct addi_private *devpriv = dev->private; + + if (devpriv) { + if (dev->iobase) + i_ADDI_Reset(dev); + if (dev->irq) + free_irq(dev->irq, dev); + if (devpriv->dw_AiBase) + iounmap(devpriv->dw_AiBase); + } + if (pcidev) { + if (dev->iobase) + comedi_pci_disable(pcidev); + } +} + static struct comedi_driver apci16xx_driver = { .driver_name = "addi_apci_16xx", .module = THIS_MODULE, - .auto_attach = addi_auto_attach, - .detach = i_ADDI_Detach, + .auto_attach = apci16xx_auto_attach, + .detach = apci16xx_detach, .num_names = ARRAY_SIZE(apci16xx_boardtypes), .board_name = &apci16xx_boardtypes[0].pc_DriverName, .offset = sizeof(struct addi_board), -- cgit v0.10.2 From 564aa830e61df7c10d36cab31dd975a4fe003c97 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:41:07 -0700 Subject: staging: comedi: addi_apci_16xx: board does not have analog inputs The boards supported by this driver do not have analog inputs. Remove the subdevice init for them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 658943b..6417b35 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -183,39 +183,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* Allocate and Initialise AI Subdevice Structures */ s = &dev->subdevices[0]; - if ((devpriv->s_EeParameters.i_NbrAiChannel) - || (this_board->i_NbrAiChannelDiff)) { - dev->read_subdev = s; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = - SDF_READABLE | SDF_COMMON | SDF_GROUND - | SDF_DIFF; - if (devpriv->s_EeParameters.i_NbrAiChannel) { - s->n_chan = - devpriv->s_EeParameters.i_NbrAiChannel; - devpriv->b_SingelDiff = 0; - } else { - s->n_chan = this_board->i_NbrAiChannelDiff; - devpriv->b_SingelDiff = 1; - } - s->maxdata = devpriv->s_EeParameters.i_AiMaxdata; - s->len_chanlist = this_board->i_AiChannelList; - s->range_table = this_board->pr_AiRangelist; - - /* Set the initialisation flag */ - devpriv->b_AiInitialisation = 1; - - s->insn_config = this_board->ai_config; - s->insn_read = this_board->ai_read; - s->insn_write = this_board->ai_write; - s->insn_bits = this_board->ai_bits; - s->do_cmdtest = this_board->ai_cmdtest; - s->do_cmd = this_board->ai_cmd; - s->cancel = this_board->ai_cancel; - - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* Allocate and Initialise AO Subdevice Structures */ s = &dev->subdevices[1]; -- cgit v0.10.2 From b985cf427d95f49be2b534ce7d3bd3150d2725f4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:41:31 -0700 Subject: staging: comedi: addi_apci_16xx: board does not have analog outputs The boards supported by this driver do not have analog outputs. Remove the subdevice init for them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 6417b35..918daa1 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -187,19 +187,8 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* Allocate and Initialise AO Subdevice Structures */ s = &dev->subdevices[1]; - if (devpriv->s_EeParameters.i_NbrAoChannel) { - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; - s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrAoChannel; - s->range_table = this_board->pr_AoRangelist; - s->insn_config = this_board->ao_config; - s->insn_write = this_board->ao_write; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; + /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; if (devpriv->s_EeParameters.i_NbrDiChannel) { -- cgit v0.10.2 From 9c0c93a844dbc5bf55594baed4e31c7ddc7cb7ed Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:41:52 -0700 Subject: staging: comedi: addi_apci_16xx: board does not have digital inputs The boards supported by this driver do not have digital inputs. Remove the subdevice init for them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 918daa1..7a43fa3 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -191,22 +191,8 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; - if (devpriv->s_EeParameters.i_NbrDiChannel) { - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel; - s->maxdata = 1; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDiChannel; - s->range_table = &range_digital; - s->io_bits = 0; /* all bits input */ - s->insn_config = this_board->di_config; - s->insn_read = this_board->di_read; - s->insn_write = this_board->di_write; - s->insn_bits = this_board->di_bits; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; + /* Allocate and Initialise DO Subdevice Structures */ s = &dev->subdevices[3]; if (devpriv->s_EeParameters.i_NbrDoChannel) { -- cgit v0.10.2 From 243a55c57e9842c2a9fcc90018156dafb6642064 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:42:13 -0700 Subject: staging: comedi: addi_apci_16xx: board does not have digital outputs The boards supported by this driver do not have digital outputs. Remove the subdevice init for them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 7a43fa3..4812c90 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -195,25 +195,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* Allocate and Initialise DO Subdevice Structures */ s = &dev->subdevices[3]; - if (devpriv->s_EeParameters.i_NbrDoChannel) { - s->type = COMEDI_SUBD_DO; - s->subdev_flags = - SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; - s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDoChannel; - s->range_table = &range_digital; - s->io_bits = 0xf; /* all bits output */ - - /* insn_config - for digital output memory */ - s->insn_config = this_board->do_config; - s->insn_write = this_board->do_write; - s->insn_bits = this_board->do_bits; - s->insn_read = this_board->do_read; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; -- cgit v0.10.2 From a03953fbd896354e1f9a1e165d9c0c8a571a4a00 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:42:35 -0700 Subject: staging: comedi: addi_apci_16xx: board does not have a timer The boards supported by this driver do not have a timer subdevice. Remove the subdevice init for it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 4812c90..67f117a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -199,21 +199,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; - if (devpriv->s_EeParameters.i_Timer) { - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = 1; - s->maxdata = 0; - s->len_chanlist = 1; - s->range_table = &range_digital; - - s->insn_write = this_board->timer_write; - s->insn_read = this_board->timer_read; - s->insn_config = this_board->timer_config; - s->insn_bits = this_board->timer_bits; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* Allocate and Initialise TTL */ s = &dev->subdevices[5]; -- cgit v0.10.2 From 4d59827aecebf3f0253eae08ced09343244f3466 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:43:00 -0700 Subject: staging: comedi: addi_apci_16xx: remove eeprom support code Reading the eeprom on the boards supported by this driver is not necessary. All the information required is in the boardinfo. Remove the eeprom support code since it's not really interesting or useful. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 67f117a..1af5921 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -1,6 +1,5 @@ #include "../comedidev.h" #include "comedi_fc.h" -#include "amcc_s5933.h" #include "addi-data/addi_common.h" @@ -8,7 +7,6 @@ #define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ #endif -#include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci16xx.c" static const struct addi_board apci16xx_boardtypes[] = { @@ -39,23 +37,6 @@ static const struct addi_board apci16xx_boardtypes[] = { }, }; -static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - const struct addi_board *this_board = comedi_board(dev); - struct addi_private *devpriv = dev->private; - unsigned short w_Address = CR_CHAN(insn->chanspec); - unsigned short w_Data; - - w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc, - this_board->pc_EepromChip, 2 * w_Address); - data[0] = w_Data; - - return insn->n; -} - static irqreturn_t v_ADDI_Interrupt(int irq, void *d) { struct comedi_device *dev = d; @@ -98,7 +79,6 @@ static int apci16xx_auto_attach(struct comedi_device *dev, struct addi_private *devpriv; struct comedi_subdevice *s; int ret, n_subdevices; - unsigned int dw_Dummy; this_board = addi_find_boardinfo(dev, pcidev); if (!this_board) @@ -159,23 +139,6 @@ static int apci16xx_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - /* Read eepeom and fill addi_board Structure */ - - if (this_board->i_PCIEeprom) { - if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { - /* Set 3 wait stait */ - if (!(strcmp(dev->board_name, "apci035"))) - outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); - else - outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); - - /* Enable the interrupt for the controller */ - dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); - outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); - } - addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); - } - n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) @@ -222,15 +185,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* EEPROM */ s = &dev->subdevices[6]; - if (this_board->i_PCIEeprom) { - s->type = COMEDI_SUBD_MEMORY; - s->subdev_flags = SDF_READABLE | SDF_INTERNAL; - s->n_chan = 256; - s->maxdata = 0xffff; - s->insn_read = i_ADDIDATA_InsnReadEeprom; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; i_ADDI_Reset(dev); return 0; -- cgit v0.10.2 From 58b6728c8cecd5022be68b3ac513d7055b869710 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:43:23 -0700 Subject: staging: comedi: addi_apci_16xx: remove i_APCI16XX_Reset() The 'reset' function for this driver doesn't do anything. Remove it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c index 5958a9c..e549601 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c @@ -787,21 +787,3 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, return i_ReturnValue; } - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI2200_Reset(struct comedi_device *dev) | +----------------------------------------------------------------------------+ -| Task :resets all the registers | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : - | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI16XX_Reset(struct comedi_device *dev) -{ - return 0; -} diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 1af5921..e384d4c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -17,7 +17,6 @@ static const struct addi_board apci16xx_boardtypes[] = { .i_IorangeBase0 = 128, .i_PCIEeprom = ADDIDATA_NO_EEPROM, .i_NbrTTLChannel = 48, - .reset = i_APCI16XX_Reset, .ttl_config = i_APCI16XX_InsnConfigInitTTLIO, .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO, .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue, @@ -29,7 +28,6 @@ static const struct addi_board apci16xx_boardtypes[] = { .i_IorangeBase0 = 128, .i_PCIEeprom = ADDIDATA_NO_EEPROM, .i_NbrTTLChannel = 96, - .reset = i_APCI16XX_Reset, .ttl_config = i_APCI16XX_InsnConfigInitTTLIO, .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO, .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue, @@ -46,14 +44,6 @@ static irqreturn_t v_ADDI_Interrupt(int irq, void *d) return IRQ_RETVAL(1); } -static int i_ADDI_Reset(struct comedi_device *dev) -{ - const struct addi_board *this_board = comedi_board(dev); - - this_board->reset(dev); - return 0; -} - static const void *addi_find_boardinfo(struct comedi_device *dev, struct pci_dev *pcidev) { @@ -187,7 +177,6 @@ static int apci16xx_auto_attach(struct comedi_device *dev, s = &dev->subdevices[6]; s->type = COMEDI_SUBD_UNUSED; - i_ADDI_Reset(dev); return 0; } @@ -197,8 +186,6 @@ static void apci16xx_detach(struct comedi_device *dev) struct addi_private *devpriv = dev->private; if (devpriv) { - if (dev->iobase) - i_ADDI_Reset(dev); if (dev->irq) free_irq(dev->irq, dev); if (devpriv->dw_AiBase) -- cgit v0.10.2 From 046e0d10bda65c2b096627765b302b3123beee47 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:43:48 -0700 Subject: staging: comedi: addi_apci_16xx: remove interrupt support code The boards supported by this driver do not have any interrupt capable devices. Remove the unused interrupt support code. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index e384d4c..ba4b0b1 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -35,15 +35,6 @@ static const struct addi_board apci16xx_boardtypes[] = { }, }; -static irqreturn_t v_ADDI_Interrupt(int irq, void *d) -{ - struct comedi_device *dev = d; - const struct addi_board *this_board = comedi_board(dev); - - this_board->interrupt(irq, d); - return IRQ_RETVAL(1); -} - static const void *addi_find_boardinfo(struct comedi_device *dev, struct pci_dev *pcidev) { @@ -120,15 +111,6 @@ static int apci16xx_auto_attach(struct comedi_device *dev, devpriv->s_EeParameters.ui_MinDelaytimeNs = this_board->ui_MinDelaytimeNs; - /* ## */ - - if (pcidev->irq > 0) { - ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, - dev->board_name, dev); - if (ret == 0) - dev->irq = pcidev->irq; - } - n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) @@ -186,8 +168,6 @@ static void apci16xx_detach(struct comedi_device *dev) struct addi_private *devpriv = dev->private; if (devpriv) { - if (dev->irq) - free_irq(dev->irq, dev); if (devpriv->dw_AiBase) iounmap(devpriv->dw_AiBase); } -- cgit v0.10.2 From ebea8c69d323acfc13f85b067a8608ec10794638 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:44:11 -0700 Subject: staging: comedi: addi_apci_16xx: simplify PCI bar reading The boards supported by this driver do not have an eeprom. Knowing this information allows simplifying the code that reads the PCI bars to get the iobase addresses. The only 'iobase' actually used by this driver is found in PCI bar 0. Don't bother reading the other PCI bars. Also, since 'dw_AiBase' is not ioremap'ed we can remove the check and iounmap in the detach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index ba4b0b1..e87ae35 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -14,8 +14,6 @@ static const struct addi_board apci16xx_boardtypes[] = { .pc_DriverName = "apci1648", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x1009, - .i_IorangeBase0 = 128, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, .i_NbrTTLChannel = 48, .ttl_config = i_APCI16XX_InsnConfigInitTTLIO, .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO, @@ -25,8 +23,6 @@ static const struct addi_board apci16xx_boardtypes[] = { .pc_DriverName = "apci1696", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x100A, - .i_IorangeBase0 = 128, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, .i_NbrTTLChannel = 96, .ttl_config = i_APCI16XX_InsnConfigInitTTLIO, .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO, @@ -76,25 +72,8 @@ static int apci16xx_auto_attach(struct comedi_device *dev, if (ret) return ret; - if (!this_board->pc_EepromChip || - strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { - /* board does not have an eeprom or is not ADDIDATA_9054 */ - if (this_board->i_IorangeBase1) - dev->iobase = pci_resource_start(pcidev, 1); - else - dev->iobase = pci_resource_start(pcidev, 0); - - devpriv->iobase = dev->iobase; - devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); - } else { - /* board has an ADDIDATA_9054 eeprom */ - dev->iobase = pci_resource_start(pcidev, 2); - devpriv->iobase = pci_resource_start(pcidev, 2); - devpriv->dw_AiBase = ioremap(pci_resource_start(pcidev, 3), - this_board->i_IorangeBase3); - } - devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); + dev->iobase = pci_resource_start(pcidev, 0); + devpriv->iobase = dev->iobase; /* Initialize parameters that can be overridden in EEPROM */ devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; @@ -165,12 +144,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, static void apci16xx_detach(struct comedi_device *dev) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - struct addi_private *devpriv = dev->private; - if (devpriv) { - if (devpriv->dw_AiBase) - iounmap(devpriv->dw_AiBase); - } if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); -- cgit v0.10.2 From 13962d976f5798b8ad0b970654bb878101b24fb4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:45:07 -0700 Subject: staging: comedi: addi_apci_16xx: remove unnecessary comments A lot of the comments in hwdrv_apci16xx.c have whitespace damage and are simply unnecessary. Just remove them to make the code a bit more readable. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c index e549601..ec39b6f 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c @@ -100,7 +100,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour | -101 : Data size error | +----------------------------------------------------------------------------+ */ - static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -114,97 +113,53 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, unsigned char b_NumberOfPort = (unsigned char) (this_board->i_NbrTTLChannel / 8); - /************************/ /* Test the buffer size */ - /************************/ - if (insn->n >= 1) { - /*******************/ /* Get the command */ - /* **************** */ - b_Command = (unsigned char) data[0]; - /********************/ /* Test the command */ - /********************/ - if ((b_Command == APCI16XX_TTL_INIT) || (b_Command == APCI16XX_TTL_INITDIRECTION) || (b_Command == APCI16XX_TTL_OUTPUTMEMORY)) { - /***************************************/ /* Test the initialisation buffer size */ - /***************************************/ - if ((b_Command == APCI16XX_TTL_INITDIRECTION) && ((unsigned char) (insn->n - 1) != b_NumberOfPort)) { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY) && ((unsigned char) (insn->n) != 2)) { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } } else { - /************************/ - /* Config command error */ - /************************/ - printk("\nCommand selection error"); i_ReturnValue = -100; } } else { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } - /**************************************************************************/ /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */ - /**************************************************************************/ - if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION)) { memset(devpriv->ul_TTLPortConfiguration, 0, sizeof(devpriv->ul_TTLPortConfiguration)); - /*************************************/ /* Test the port direction selection */ - /*************************************/ - for (b_Cpt = 1; (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0); b_Cpt++) { - /**********************/ /* Test the direction */ - /**********************/ - if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF)) { - /************************/ - /* Port direction error */ - /************************/ - printk("\nPort %d direction selection error", (int) b_Cpt); i_ReturnValue = -(int) b_Cpt; } - /**************************/ /* Save the configuration */ - /**************************/ - devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] = devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] | (data[b_Cpt] << (8 * ((b_Cpt - @@ -212,27 +167,15 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, } } - /**************************/ /* Test if no error occur */ - /**************************/ - if (i_ReturnValue >= 0) { - /***********************************/ /* Test if TTL port initilaisation */ - /***********************************/ - if ((b_Command == APCI16XX_TTL_INIT) || (b_Command == APCI16XX_TTL_INITDIRECTION)) { - /******************************/ /* Set all port configuration */ - /******************************/ - for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt++) { if ((b_Cpt % 4) == 0) { - /*************************/ /* Set the configuration */ - /*************************/ - outl(devpriv-> ul_TTLPortConfiguration[b_Cpt / 4], @@ -242,10 +185,7 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, } } - /************************************************/ /* Test if output memory initialisation command */ - /************************************************/ - if (b_Command == APCI16XX_TTL_OUTPUTMEMORY) { if (data[1]) { devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; @@ -259,12 +199,6 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, /* +----------------------------------------------------------------------------+ -| INPUT FUNCTIONS | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ | Function Name : int i_APCI16XX_InsnBitsReadTTLIO | | (struct comedi_device *dev, | | struct comedi_subdevice *s, | @@ -297,7 +231,6 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, | -103 : The selected TTL digital input is wrong | +----------------------------------------------------------------------------+ */ - static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -314,32 +247,17 @@ static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, unsigned char *pb_Status; unsigned int dw_Status; - /************************/ /* Test the buffer size */ - /************************/ - if (insn->n >= 1) { - /*******************/ /* Get the command */ - /* **************** */ - b_Command = (unsigned char) data[0]; - /********************/ /* Test the command */ - /********************/ - if ((b_Command == APCI16XX_TTL_READCHANNEL) || (b_Command == APCI16XX_TTL_READPORT)) { - /**************************/ /* Test the selected port */ - /**************************/ - if (b_SelectedPort < b_NumberOfPort) { - /**********************/ /* Test if input port */ - /**********************/ - if (((devpriv->ul_TTLPortConfiguration [b_SelectedPort / 4] >> (8 * @@ -347,78 +265,43 @@ static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, % 4))) & 0xFF) == 0) { - /***************************/ /* Test the channel number */ - /***************************/ - if ((b_Command == APCI16XX_TTL_READCHANNEL) && (b_InputChannel > 7)) { - /*******************************************/ - /* The selected TTL digital input is wrong */ - /*******************************************/ - printk("\nChannel selection error"); i_ReturnValue = -103; } } else { - /****************************************/ - /* The selected TTL input port is wrong */ - /****************************************/ - printk("\nPort selection error"); i_ReturnValue = -102; } } else { - /****************************************/ - /* The selected TTL input port is wrong */ - /****************************************/ - printk("\nPort selection error"); i_ReturnValue = -102; } } else { - /************************/ - /* Config command error */ - /************************/ - printk("\nCommand selection error"); i_ReturnValue = -100; } } else { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } - /**************************/ /* Test if no error occur */ - /**************************/ - if (i_ReturnValue >= 0) { pb_Status = (unsigned char *) &data[0]; - /*******************************/ /* Get the digital inpu status */ - /*******************************/ - dw_Status = inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4)); dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF; - /***********************/ /* Save the port value */ - /***********************/ - *pb_Status = (unsigned char) dw_Status; - /***************************************/ /* Test if read channel status command */ - /***************************************/ - if (b_Command == APCI16XX_TTL_READCHANNEL) { *pb_Status = (*pb_Status >> b_InputChannel) & 1; } @@ -448,7 +331,6 @@ static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, | -101 : Data size error | +----------------------------------------------------------------------------+ */ - static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -462,16 +344,10 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, unsigned char b_NumberOfPort = 0; unsigned int *pls_ReadData = data; - /********************/ /* Test the command */ - /********************/ - if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) { - /**********************************/ /* Get the number of 32-Bit ports */ - /**********************************/ - b_NumberOfPort = (unsigned char) (this_board->i_NbrTTLChannel / 32); if ((b_NumberOfPort * 32) < @@ -479,70 +355,41 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, b_NumberOfPort = b_NumberOfPort + 1; } - /************************/ /* Test the buffer size */ - /************************/ - if (insn->n >= b_NumberOfPort) { if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS) { - /**************************/ /* Read all digital input */ - /**************************/ - for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { - /************************/ /* Read the 32-Bit port */ - /************************/ - pls_ReadData[b_Cpt] = inl(devpriv->iobase + 8 + (b_Cpt * 4)); - /**************************************/ /* Mask all channels used als outputs */ - /**************************************/ - pls_ReadData[b_Cpt] = pls_ReadData[b_Cpt] & (~devpriv-> ul_TTLPortConfiguration[b_Cpt]); } } else { - /****************************/ /* Read all digital outputs */ - /****************************/ - for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { - /************************/ /* Read the 32-Bit port */ - /************************/ - pls_ReadData[b_Cpt] = inl(devpriv->iobase + 20 + (b_Cpt * 4)); - /**************************************/ /* Mask all channels used als outputs */ - /**************************************/ - pls_ReadData[b_Cpt] = pls_ReadData[b_Cpt] & devpriv-> ul_TTLPortConfiguration[b_Cpt]; } } } else { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } } else { - /*****************/ - /* Command error */ - /*****************/ - printk("\nCommand selection error"); i_ReturnValue = -100; } @@ -552,12 +399,6 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, /* +----------------------------------------------------------------------------+ -| OUTPUT FUNCTIONS | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ | Function Name : int i_APCI16XX_InsnBitsWriteTTLIO | | (struct comedi_device *dev, | | struct comedi_subdevice *s, | @@ -592,7 +433,6 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, | -104 : Output memory disabled | +----------------------------------------------------------------------------+ */ - static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -608,34 +448,19 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, unsigned char b_OutputChannel = CR_CHAN(insn->chanspec); unsigned int dw_Status = 0; - /************************/ /* Test the buffer size */ - /************************/ - if (insn->n >= 1) { - /*******************/ /* Get the command */ - /* **************** */ - b_Command = (unsigned char) data[0]; - /********************/ /* Test the command */ - /********************/ - if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || (b_Command == APCI16XX_TTL_WRITEPORT_ON) || (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) { - /**************************/ /* Test the selected port */ - /**************************/ - if (b_SelectedPort < b_NumberOfPort) { - /***********************/ /* Test if output port */ - /***********************/ - if (((devpriv->ul_TTLPortConfiguration [b_SelectedPort / 4] >> (8 * @@ -643,126 +468,71 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, % 4))) & 0xFF) == 0xFF) { - /***************************/ /* Test the channel number */ - /***************************/ - if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7)) { - /********************************************/ - /* The selected TTL digital output is wrong */ - /********************************************/ - printk("\nChannel selection error"); i_ReturnValue = -103; } if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)) { - /********************************************/ - /* The selected TTL digital output is wrong */ - /********************************************/ - printk("\nOutput memory disabled"); i_ReturnValue = -104; } - /************************/ /* Test the buffer size */ - /************************/ - if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2)) { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } } else { - /*****************************************/ - /* The selected TTL output port is wrong */ - /*****************************************/ - printk("\nPort selection error %lX", (unsigned long)devpriv-> ul_TTLPortConfiguration[0]); i_ReturnValue = -102; } } else { - /****************************************/ - /* The selected TTL output port is wrong */ - /****************************************/ - printk("\nPort selection error %d %d", b_SelectedPort, b_NumberOfPort); i_ReturnValue = -102; } } else { - /************************/ - /* Config command error */ - /************************/ - printk("\nCommand selection error"); i_ReturnValue = -100; } } else { - /*******************/ - /* Data size error */ - /*******************/ - printk("\nBuffer size error"); i_ReturnValue = -101; } - /**************************/ /* Test if no error occur */ - /**************************/ - if (i_ReturnValue >= 0) { - /********************************/ /* Get the digital output state */ - /********************************/ - dw_Status = inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); - /**********************************/ /* Test if output memory not used */ - /**********************************/ - if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) { - /*********************************/ /* Clear the selected port value */ - /*********************************/ - dw_Status = dw_Status & (0xFFFFFFFFUL - (0xFFUL << (8 * (b_SelectedPort % 4)))); } - /******************************/ /* Test if setting channel ON */ - /******************************/ - if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON) { dw_Status = dw_Status | (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel)); } - /***************************/ /* Test if setting port ON */ - /***************************/ - if (b_Command == APCI16XX_TTL_WRITEPORT_ON) { dw_Status = dw_Status | ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4))); } - /*******************************/ /* Test if setting channel OFF */ - /*******************************/ - if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) { dw_Status = dw_Status & (0xFFFFFFFFUL - @@ -770,10 +540,7 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, b_OutputChannel))); } - /****************************/ /* Test if setting port OFF */ - /****************************/ - if (b_Command == APCI16XX_TTL_WRITEPORT_OFF) { dw_Status = dw_Status & (0xFFFFFFFFUL - -- cgit v0.10.2 From 6b9633b4c70a405fe0ffad6f5bbb59f0ad1eb5d9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:45:34 -0700 Subject: staging: comedi: addi_apci_16xx: remove devpriv->iobase usage The iobase address stored in devpriv->iobase is also stored in dev->iobase. Use that instead. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c index ec39b6f..da4f03b 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c @@ -179,7 +179,7 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, outl(devpriv-> ul_TTLPortConfiguration[b_Cpt / 4], - devpriv->iobase + 32 + b_Cpt); + dev->iobase + 32 + b_Cpt); } } } @@ -295,7 +295,7 @@ static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, /* Get the digital inpu status */ dw_Status = - inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4)); + inl(dev->iobase + 8 + ((b_SelectedPort / 4) * 4)); dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF; /* Save the port value */ @@ -362,7 +362,7 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { /* Read the 32-Bit port */ pls_ReadData[b_Cpt] = - inl(devpriv->iobase + 8 + + inl(dev->iobase + 8 + (b_Cpt * 4)); /* Mask all channels used als outputs */ @@ -376,7 +376,7 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { /* Read the 32-Bit port */ pls_ReadData[b_Cpt] = - inl(devpriv->iobase + 20 + + inl(dev->iobase + 20 + (b_Cpt * 4)); /* Mask all channels used als outputs */ @@ -508,7 +508,7 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, if (i_ReturnValue >= 0) { /* Get the digital output state */ dw_Status = - inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); + inl(dev->iobase + 20 + ((b_SelectedPort / 4) * 4)); /* Test if output memory not used */ if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) { @@ -549,7 +549,7 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, } outl(dw_Status, - devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); + dev->iobase + 20 + ((b_SelectedPort / 4) * 4)); } return i_ReturnValue; diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index e87ae35..2784a8a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -73,7 +73,6 @@ static int apci16xx_auto_attach(struct comedi_device *dev, return ret; dev->iobase = pci_resource_start(pcidev, 0); - devpriv->iobase = dev->iobase; /* Initialize parameters that can be overridden in EEPROM */ devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; -- cgit v0.10.2 From a6c2f99ec6a10eb5d6730087d79eb68b51af3c4e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:45:55 -0700 Subject: staging: comedi: addi_apci_16xx: remove devpriv->s_EeParameters usage This information is not used in the driver. Just remove it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 2784a8a..8078457 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -74,21 +74,6 @@ static int apci16xx_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 0); - /* Initialize parameters that can be overridden in EEPROM */ - devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; - devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; - devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; - devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; - devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; - devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; - devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; - devpriv->s_EeParameters.i_Dma = this_board->i_Dma; - devpriv->s_EeParameters.i_Timer = this_board->i_Timer; - devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = - this_board->ui_MinAcquisitiontimeNs; - devpriv->s_EeParameters.ui_MinDelaytimeNs = - this_board->ui_MinDelaytimeNs; - n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) -- cgit v0.10.2 From b6e7714cc261ef478f95449a32565d41378c9a87 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:46:17 -0700 Subject: staging: comedi: addi_apci_16xx: only allocate needed subdevices The addi-data "common" code always allocated 7 subdevices. This driver only uses 1. Change the allocation and remove the unused subdevices. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 8078457..5f1de01 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -55,7 +55,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, const struct addi_board *this_board; struct addi_private *devpriv; struct comedi_subdevice *s; - int ret, n_subdevices; + int ret; this_board = addi_find_boardinfo(dev, pcidev); if (!this_board) @@ -74,53 +74,24 @@ static int apci16xx_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 0); - n_subdevices = 7; - ret = comedi_alloc_subdevices(dev, n_subdevices); + ret = comedi_alloc_subdevices(dev, 1); if (ret) return ret; - /* Allocate and Initialise AI Subdevice Structures */ + /* Initialize the TTL digital i/o */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise AO Subdevice Structures */ - s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise DI Subdevice Structures */ - s = &dev->subdevices[2]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise DO Subdevice Structures */ - s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise Timer Subdevice Structures */ - s = &dev->subdevices[4]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise TTL */ - s = &dev->subdevices[5]; - if (this_board->i_NbrTTLChannel) { - s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = - SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrTTLChannel; - s->maxdata = 1; - s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; - s->range_table = &range_digital; - s->insn_config = this_board->ttl_config; - s->insn_bits = this_board->ttl_bits; - s->insn_read = this_board->ttl_read; - s->insn_write = this_board->ttl_write; - } else { - s->type = COMEDI_SUBD_UNUSED; - } - - /* EEPROM */ - s = &dev->subdevices[6]; - s->type = COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_TTLIO; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrTTLChannel; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->len_chanlist = this_board->i_NbrTTLChannel; + s->range_table = &range_digital; + s->insn_config = this_board->ttl_config; + s->insn_bits = this_board->ttl_bits; + s->insn_read = this_board->ttl_read; + s->insn_write = this_board->ttl_write; return 0; } -- cgit v0.10.2 From 8d5a19db72f72a730f3a1938044f12d9e1cf25a5 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:46:49 -0700 Subject: staging: comedi: addi_apci_16xx: cleanup subdevice initialization The comedi subdevice in this driver is a simple digital i/o device. Currently, the code abuses the comedi API by redefining the COMEDI_SUBD_SERIAL type as COMEDI_SUBD_TTLIO and using that for the 's->type'. Remove the defines and use the proper type, COMEDI_SUBD_DIO. The current code also sets the subdev_flags SDF_GROUND and SDF_COMMON for the subdevice. These flags really only have meaning for analog subdevices. Remove them. All the boards supported by this driver use the same functions for the subdevice 'insn_*' operations. Remove this information from the boardinfo and set the s->insn_* operations directly in the init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c index da4f03b..97f7441 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c @@ -47,10 +47,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour +-----------------------------------------------------------------------+ */ -#ifndef COMEDI_SUBD_TTLIO -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#endif - #define APCI16XX_TTL_INIT 0 #define APCI16XX_TTL_INITDIRECTION 1 #define APCI16XX_TTL_OUTPUTMEMORY 2 diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 5f1de01..3ad3fec 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -3,10 +3,6 @@ #include "addi-data/addi_common.h" -#ifndef COMEDI_SUBD_TTLIO -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#endif - #include "addi-data/hwdrv_apci16xx.c" static const struct addi_board apci16xx_boardtypes[] = { @@ -15,19 +11,11 @@ static const struct addi_board apci16xx_boardtypes[] = { .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x1009, .i_NbrTTLChannel = 48, - .ttl_config = i_APCI16XX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO, - .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue, - .ttl_write = i_APCI16XX_InsnBitsWriteTTLIO, }, { .pc_DriverName = "apci1696", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x100A, .i_NbrTTLChannel = 96, - .ttl_config = i_APCI16XX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO, - .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue, - .ttl_write = i_APCI16XX_InsnBitsWriteTTLIO, }, }; @@ -80,18 +68,17 @@ static int apci16xx_auto_attach(struct comedi_device *dev, /* Initialize the TTL digital i/o */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = - SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrTTLChannel; - s->maxdata = 1; - s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; - s->range_table = &range_digital; - s->insn_config = this_board->ttl_config; - s->insn_bits = this_board->ttl_bits; - s->insn_read = this_board->ttl_read; - s->insn_write = this_board->ttl_write; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITEABLE | SDF_READABLE; + s->n_chan = this_board->i_NbrTTLChannel; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->len_chanlist = this_board->i_NbrTTLChannel; + s->range_table = &range_digital; + s->insn_config = i_APCI16XX_InsnConfigInitTTLIO; + s->insn_bits = i_APCI16XX_InsnBitsReadTTLIO; + s->insn_read = i_APCI16XX_InsnReadTTLIOAllPortValue; + s->insn_write = i_APCI16XX_InsnBitsWriteTTLIO; return 0; } -- cgit v0.10.2 From 875a9cb1bd8153688ec76be746d620ff6f604f86 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:47:19 -0700 Subject: staging: comedi: addi_apci_16xx: remove need for comedi_board() Currently this driver uses the total number of channels, stored in the boardinfo, in a number of the subdevice insn_* functions. This information is already available in the subdevice as 's->n_chan'. Use that instead of needing to get the board pointer first. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c index 97f7441..098ea59 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c @@ -101,13 +101,11 @@ static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - const struct addi_board *this_board = comedi_board(dev); struct addi_private *devpriv = dev->private; int i_ReturnValue = insn->n; unsigned char b_Command = 0; unsigned char b_Cpt = 0; - unsigned char b_NumberOfPort = - (unsigned char) (this_board->i_NbrTTLChannel / 8); + unsigned char b_NumberOfPort = s->n_chan / 8; /* Test the buffer size */ if (insn->n >= 1) { @@ -232,12 +230,10 @@ static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - const struct addi_board *this_board = comedi_board(dev); struct addi_private *devpriv = dev->private; int i_ReturnValue = insn->n; unsigned char b_Command = 0; - unsigned char b_NumberOfPort = - (unsigned char) (this_board->i_NbrTTLChannel / 8); + unsigned char b_NumberOfPort = s->n_chan / 8; unsigned char b_SelectedPort = CR_RANGE(insn->chanspec); unsigned char b_InputChannel = CR_CHAN(insn->chanspec); unsigned char *pb_Status; @@ -332,7 +328,6 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - const struct addi_board *this_board = comedi_board(dev); struct addi_private *devpriv = dev->private; unsigned char b_Command = (unsigned char) CR_AREF(insn->chanspec); int i_ReturnValue = insn->n; @@ -344,12 +339,9 @@ static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) { /* Get the number of 32-Bit ports */ - b_NumberOfPort = - (unsigned char) (this_board->i_NbrTTLChannel / 32); - if ((b_NumberOfPort * 32) < - this_board->i_NbrTTLChannel) { + b_NumberOfPort = s->n_chan / 32; + if ((b_NumberOfPort * 32) < s->n_chan) b_NumberOfPort = b_NumberOfPort + 1; - } /* Test the buffer size */ if (insn->n >= b_NumberOfPort) { @@ -434,12 +426,10 @@ static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - const struct addi_board *this_board = comedi_board(dev); struct addi_private *devpriv = dev->private; int i_ReturnValue = insn->n; unsigned char b_Command = 0; - unsigned char b_NumberOfPort = - (unsigned char) (this_board->i_NbrTTLChannel / 8); + unsigned char b_NumberOfPort = s->n_chan / 8; unsigned char b_SelectedPort = CR_RANGE(insn->chanspec); unsigned char b_OutputChannel = CR_CHAN(insn->chanspec); unsigned int dw_Status = 0; -- cgit v0.10.2 From 2a2e63dd98ff5310b4677e177939dd2232e0c1c3 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:47:48 -0700 Subject: staging: comedi: addi_apci_16xx: redefine the boardinfo Currently this driver uses the struct addi_board from the addi-data "common" code to define the boardinfo. This struct contains a lot of information that is not used in this driver. Introduce a private struct in the driver that just contains the needed information. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 3ad3fec..23aafe2 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -5,17 +5,24 @@ #include "addi-data/hwdrv_apci16xx.c" -static const struct addi_board apci16xx_boardtypes[] = { +struct apci16xx_boardinfo { + const char *name; + unsigned short vendor; + unsigned short device; + int n_chan; +}; + +static const struct apci16xx_boardinfo apci16xx_boardtypes[] = { { - .pc_DriverName = "apci1648", - .i_VendorId = PCI_VENDOR_ID_ADDIDATA, - .i_DeviceId = 0x1009, - .i_NbrTTLChannel = 48, + .name = "apci1648", + .vendor = PCI_VENDOR_ID_ADDIDATA, + .device = 0x1009, + .n_chan = 48, }, { - .pc_DriverName = "apci1696", - .i_VendorId = PCI_VENDOR_ID_ADDIDATA, - .i_DeviceId = 0x100A, - .i_NbrTTLChannel = 96, + .name = "apci1696", + .vendor = PCI_VENDOR_ID_ADDIDATA, + .device = 0x100A, + .n_chan = 96, }, }; @@ -23,13 +30,13 @@ static const void *addi_find_boardinfo(struct comedi_device *dev, struct pci_dev *pcidev) { const void *p = dev->driver->board_name; - const struct addi_board *this_board; + const struct apci16xx_boardinfo *this_board; int i; for (i = 0; i < dev->driver->num_names; i++) { this_board = p; - if (this_board->i_VendorId == pcidev->vendor && - this_board->i_DeviceId == pcidev->device) + if (this_board->vendor == pcidev->vendor && + this_board->device == pcidev->device) return this_board; p += dev->driver->offset; } @@ -40,7 +47,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct addi_board *this_board; + const struct apci16xx_boardinfo *this_board; struct addi_private *devpriv; struct comedi_subdevice *s; int ret; @@ -49,7 +56,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev, if (!this_board) return -ENODEV; dev->board_ptr = this_board; - dev->board_name = this_board->pc_DriverName; + dev->board_name = this_board->name; devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); if (!devpriv) @@ -70,10 +77,10 @@ static int apci16xx_auto_attach(struct comedi_device *dev, s = &dev->subdevices[0]; s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_WRITEABLE | SDF_READABLE; - s->n_chan = this_board->i_NbrTTLChannel; + s->n_chan = this_board->n_chan; s->maxdata = 1; s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; + s->len_chanlist = this_board->n_chan; s->range_table = &range_digital; s->insn_config = i_APCI16XX_InsnConfigInitTTLIO; s->insn_bits = i_APCI16XX_InsnBitsReadTTLIO; @@ -99,8 +106,8 @@ static struct comedi_driver apci16xx_driver = { .auto_attach = apci16xx_auto_attach, .detach = apci16xx_detach, .num_names = ARRAY_SIZE(apci16xx_boardtypes), - .board_name = &apci16xx_boardtypes[0].pc_DriverName, - .offset = sizeof(struct addi_board), + .board_name = &apci16xx_boardtypes[0].name, + .offset = sizeof(struct apci16xx_boardinfo), }; static int apci16xx_pci_probe(struct pci_dev *dev, -- cgit v0.10.2 From 0e2bd50b393084a338a6a21063ef012c5a2720fb Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 18 Jan 2013 10:48:25 -0700 Subject: staging: comedi: addi_apci_16xx: cleanup addi_find_boardinfo() This function was originally in the addi-data "common" code and required using pointer math to access the boardinfo data using the void * 'dev->driver->board_name'. Now that the function is local to this driver we can access the boardinfo directly and remove the pointer math. Rename the function so it has namespace associated with this driver. Also, for aesthetic reasons, globally rename the local variable used for the boardinfo pointer from 'this_board' to 'board', Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 23aafe2..899dae1 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -26,19 +26,17 @@ static const struct apci16xx_boardinfo apci16xx_boardtypes[] = { }, }; -static const void *addi_find_boardinfo(struct comedi_device *dev, - struct pci_dev *pcidev) +static const void *apci16xx_find_boardinfo(struct comedi_device *dev, + struct pci_dev *pcidev) { - const void *p = dev->driver->board_name; - const struct apci16xx_boardinfo *this_board; + const struct apci16xx_boardinfo *board; int i; - for (i = 0; i < dev->driver->num_names; i++) { - this_board = p; - if (this_board->vendor == pcidev->vendor && - this_board->device == pcidev->device) - return this_board; - p += dev->driver->offset; + for (i = 0; i < ARRAY_SIZE(apci16xx_boardtypes); i++) { + board = &apci16xx_boardtypes[i]; + if (board->vendor == pcidev->vendor && + board->device == pcidev->device) + return board; } return NULL; } @@ -47,16 +45,16 @@ static int apci16xx_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct apci16xx_boardinfo *this_board; + const struct apci16xx_boardinfo *board; struct addi_private *devpriv; struct comedi_subdevice *s; int ret; - this_board = addi_find_boardinfo(dev, pcidev); - if (!this_board) + board = apci16xx_find_boardinfo(dev, pcidev); + if (!board) return -ENODEV; - dev->board_ptr = this_board; - dev->board_name = this_board->name; + dev->board_ptr = board; + dev->board_name = board->name; devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); if (!devpriv) @@ -77,10 +75,10 @@ static int apci16xx_auto_attach(struct comedi_device *dev, s = &dev->subdevices[0]; s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_WRITEABLE | SDF_READABLE; - s->n_chan = this_board->n_chan; + s->n_chan = board->n_chan; s->maxdata = 1; s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->n_chan; + s->len_chanlist = board->n_chan; s->range_table = &range_digital; s->insn_config = i_APCI16XX_InsnConfigInitTTLIO; s->insn_bits = i_APCI16XX_InsnBitsReadTTLIO; -- cgit v0.10.2 From 14c43aca244d009d33e7f187aa2c08e2133c9ffc Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Fri, 18 Jan 2013 13:24:23 -0800 Subject: staging: ramster: disable build in anticipation of renaming [V2: no code changes, patchset now generated via git format-patch -M] In staging, disable ramster build in anticipation of renaming to zcache Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index db8a512..eb61455 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -126,8 +126,6 @@ source "drivers/staging/csr/Kconfig" source "drivers/staging/omap-thermal/Kconfig" -source "drivers/staging/ramster/Kconfig" - source "drivers/staging/silicom/Kconfig" source "drivers/staging/ced1401/Kconfig" diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index a9d5479..18420b8 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -55,7 +55,6 @@ obj-$(CONFIG_USB_G_CCG) += ccg/ obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/ obj-$(CONFIG_CSR_WIFI) += csr/ obj-$(CONFIG_OMAP_BANDGAP) += omap-thermal/ -obj-$(CONFIG_ZCACHE2) += ramster/ obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/ obj-$(CONFIG_CED1401) += ced1401/ obj-$(CONFIG_DRM_IMX) += imx-drm/ -- cgit v0.10.2 From 703ba7fe5e085f2c85eeb451c2ac13cf275c7cb2 Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Fri, 18 Jan 2013 13:24:24 -0800 Subject: staging: zcache: rename ramster to zcache [V2: no code changes, patchset now generated via git format-patch -M] In staging, rename ramster to zcache The original zcache in staging was a "demo" version, and this new zcache is a significant rewrite. While certain disagreements were being resolved, both "old zcache" and "new zcache" needed to reside in the staging tree simultaneously. In order to minimize code change and churn, the newer version of zcache was temporarily merged into the "ramster" staging driver which, prior to that, had at one time heavily leveraged the older version of zcache. So, recently, "new zcache" resided in the ramster directory. Got that? No? Sorry, temporary political compromises are rarely pretty. The older version of zcache is no longer being maintained and has now been removed from the staging tree. So now the newer version of zcache can rightfully reclaim sole possession of the name "zcache". FYI, this [PATCH 2/5] is simply a "git mv" generated by "git format-patch -M". Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ramster/Kconfig b/drivers/staging/ramster/Kconfig deleted file mode 100644 index 3abf661..0000000 --- a/drivers/staging/ramster/Kconfig +++ /dev/null @@ -1,31 +0,0 @@ -config ZCACHE2 - bool "Dynamic compression of swap pages and clean pagecache pages" - depends on CRYPTO=y && SWAP=y && CLEANCACHE && FRONTSWAP && !ZCACHE - select CRYPTO_LZO - default n - help - Zcache2 doubles RAM efficiency while providing a significant - performance boosts on many workloads. Zcache2 uses - compression and an in-kernel implementation of transcendent - memory to store clean page cache pages and swap in RAM, - providing a noticeable reduction in disk I/O. Zcache2 - is a complete rewrite of the older zcache; it was intended to - be a merge but that has been blocked due to political and - technical disagreements. It is intended that they will merge - again in the future. Until then, zcache2 is a single-node - version of ramster. - -config RAMSTER - bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem" - depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE2=y - depends on NET - # must ensure struct page is 8-byte aligned - select HAVE_ALIGNED_STRUCT_PAGE if !64_BIT - default n - help - RAMster allows RAM on other machines in a cluster to be utilized - dynamically and symmetrically instead of swapping to a local swap - disk, thus improving performance on memory-constrained workloads - while minimizing total RAM across the cluster. RAMster, like - zcache2, compresses swap pages into local RAM, but then remotifies - the compressed pages to another node in the RAMster cluster. diff --git a/drivers/staging/ramster/Makefile b/drivers/staging/ramster/Makefile deleted file mode 100644 index 2d8b9d0..0000000 --- a/drivers/staging/ramster/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -zcache-y := zcache-main.o tmem.o zbud.o -zcache-$(CONFIG_RAMSTER) += ramster/ramster.o ramster/r2net.o -zcache-$(CONFIG_RAMSTER) += ramster/nodemanager.o ramster/tcp.o -zcache-$(CONFIG_RAMSTER) += ramster/heartbeat.o ramster/masklog.o - -obj-$(CONFIG_ZCACHE2) += zcache.o diff --git a/drivers/staging/ramster/ramster.h b/drivers/staging/ramster/ramster.h deleted file mode 100644 index 1b71aea..0000000 --- a/drivers/staging/ramster/ramster.h +++ /dev/null @@ -1,59 +0,0 @@ - -/* - * zcache/ramster.h - * - * Placeholder to resolve ramster references when !CONFIG_RAMSTER - * Real ramster.h lives in ramster subdirectory. - * - * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. - */ - -#ifndef _ZCACHE_RAMSTER_H_ -#define _ZCACHE_RAMSTER_H_ - -#ifdef CONFIG_RAMSTER -#include "ramster/ramster.h" -#else -static inline void ramster_init(bool x, bool y, bool z) -{ -} - -static inline void ramster_register_pamops(struct tmem_pamops *p) -{ -} - -static inline int ramster_remotify_pageframe(bool b) -{ - return 0; -} - -static inline void *ramster_pampd_free(void *v, struct tmem_pool *p, - struct tmem_oid *o, uint32_t u, bool b) -{ - return NULL; -} - -static inline int ramster_do_preload_flnode(struct tmem_pool *p) -{ - return -1; -} - -static inline bool pampd_is_remote(void *v) -{ - return false; -} - -static inline void ramster_count_foreign_pages(bool b, int i) -{ -} - -static inline void ramster_cpu_up(int cpu) -{ -} - -static inline void ramster_cpu_down(int cpu) -{ -} -#endif - -#endif /* _ZCACHE_RAMSTER_H */ diff --git a/drivers/staging/ramster/ramster/heartbeat.c b/drivers/staging/ramster/ramster/heartbeat.c deleted file mode 100644 index 75d3fe8..0000000 --- a/drivers/staging/ramster/ramster/heartbeat.c +++ /dev/null @@ -1,462 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * Copyright (C) 2004, 2005, 2012 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#include -#include -#include - -#include "heartbeat.h" -#include "tcp.h" -#include "nodemanager.h" - -#include "masklog.h" - -/* - * The first heartbeat pass had one global thread that would serialize all hb - * callback calls. This global serializing sem should only be removed once - * we've made sure that all callees can deal with being called concurrently - * from multiple hb region threads. - */ -static DECLARE_RWSEM(r2hb_callback_sem); - -/* - * multiple hb threads are watching multiple regions. A node is live - * whenever any of the threads sees activity from the node in its region. - */ -static DEFINE_SPINLOCK(r2hb_live_lock); -static unsigned long r2hb_live_node_bitmap[BITS_TO_LONGS(R2NM_MAX_NODES)]; - -static struct r2hb_callback { - struct list_head list; -} r2hb_callbacks[R2HB_NUM_CB]; - -enum r2hb_heartbeat_modes { - R2HB_HEARTBEAT_LOCAL = 0, - R2HB_HEARTBEAT_GLOBAL, - R2HB_HEARTBEAT_NUM_MODES, -}; - -char *r2hb_heartbeat_mode_desc[R2HB_HEARTBEAT_NUM_MODES] = { - "local", /* R2HB_HEARTBEAT_LOCAL */ - "global", /* R2HB_HEARTBEAT_GLOBAL */ -}; - -unsigned int r2hb_dead_threshold = R2HB_DEFAULT_DEAD_THRESHOLD; -unsigned int r2hb_heartbeat_mode = R2HB_HEARTBEAT_LOCAL; - -/* Only sets a new threshold if there are no active regions. - * - * No locking or otherwise interesting code is required for reading - * r2hb_dead_threshold as it can't change once regions are active and - * it's not interesting to anyone until then anyway. */ -static void r2hb_dead_threshold_set(unsigned int threshold) -{ - if (threshold > R2HB_MIN_DEAD_THRESHOLD) { - spin_lock(&r2hb_live_lock); - r2hb_dead_threshold = threshold; - spin_unlock(&r2hb_live_lock); - } -} - -static int r2hb_global_hearbeat_mode_set(unsigned int hb_mode) -{ - int ret = -1; - - if (hb_mode < R2HB_HEARTBEAT_NUM_MODES) { - spin_lock(&r2hb_live_lock); - r2hb_heartbeat_mode = hb_mode; - ret = 0; - spin_unlock(&r2hb_live_lock); - } - - return ret; -} - -void r2hb_exit(void) -{ -} - -int r2hb_init(void) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(r2hb_callbacks); i++) - INIT_LIST_HEAD(&r2hb_callbacks[i].list); - - memset(r2hb_live_node_bitmap, 0, sizeof(r2hb_live_node_bitmap)); - - return 0; -} - -/* if we're already in a callback then we're already serialized by the sem */ -static void r2hb_fill_node_map_from_callback(unsigned long *map, - unsigned bytes) -{ - BUG_ON(bytes < (BITS_TO_LONGS(R2NM_MAX_NODES) * sizeof(unsigned long))); - - memcpy(map, &r2hb_live_node_bitmap, bytes); -} - -/* - * get a map of all nodes that are heartbeating in any regions - */ -void r2hb_fill_node_map(unsigned long *map, unsigned bytes) -{ - /* callers want to serialize this map and callbacks so that they - * can trust that they don't miss nodes coming to the party */ - down_read(&r2hb_callback_sem); - spin_lock(&r2hb_live_lock); - r2hb_fill_node_map_from_callback(map, bytes); - spin_unlock(&r2hb_live_lock); - up_read(&r2hb_callback_sem); -} -EXPORT_SYMBOL_GPL(r2hb_fill_node_map); - -/* - * heartbeat configfs bits. The heartbeat set is a default set under - * the cluster set in nodemanager.c. - */ - -/* heartbeat set */ - -struct r2hb_hb_group { - struct config_group hs_group; - /* some stuff? */ -}; - -static struct r2hb_hb_group *to_r2hb_hb_group(struct config_group *group) -{ - return group ? - container_of(group, struct r2hb_hb_group, hs_group) - : NULL; -} - -static struct config_item r2hb_config_item; - -static struct config_item *r2hb_hb_group_make_item(struct config_group *group, - const char *name) -{ - int ret; - - if (strlen(name) > R2HB_MAX_REGION_NAME_LEN) { - ret = -ENAMETOOLONG; - goto free; - } - - config_item_put(&r2hb_config_item); - - return &r2hb_config_item; -free: - return ERR_PTR(ret); -} - -static void r2hb_hb_group_drop_item(struct config_group *group, - struct config_item *item) -{ - if (r2hb_global_heartbeat_active()) { - pr_notice("ramster: Heartbeat %s on region %s (%s)\n", - "stopped/aborted", config_item_name(item), - "no region"); - } - - config_item_put(item); -} - -struct r2hb_hb_group_attribute { - struct configfs_attribute attr; - ssize_t (*show)(struct r2hb_hb_group *, char *); - ssize_t (*store)(struct r2hb_hb_group *, const char *, size_t); -}; - -static ssize_t r2hb_hb_group_show(struct config_item *item, - struct configfs_attribute *attr, - char *page) -{ - struct r2hb_hb_group *reg = to_r2hb_hb_group(to_config_group(item)); - struct r2hb_hb_group_attribute *r2hb_hb_group_attr = - container_of(attr, struct r2hb_hb_group_attribute, attr); - ssize_t ret = 0; - - if (r2hb_hb_group_attr->show) - ret = r2hb_hb_group_attr->show(reg, page); - return ret; -} - -static ssize_t r2hb_hb_group_store(struct config_item *item, - struct configfs_attribute *attr, - const char *page, size_t count) -{ - struct r2hb_hb_group *reg = to_r2hb_hb_group(to_config_group(item)); - struct r2hb_hb_group_attribute *r2hb_hb_group_attr = - container_of(attr, struct r2hb_hb_group_attribute, attr); - ssize_t ret = -EINVAL; - - if (r2hb_hb_group_attr->store) - ret = r2hb_hb_group_attr->store(reg, page, count); - return ret; -} - -static ssize_t r2hb_hb_group_threshold_show(struct r2hb_hb_group *group, - char *page) -{ - return sprintf(page, "%u\n", r2hb_dead_threshold); -} - -static ssize_t r2hb_hb_group_threshold_store(struct r2hb_hb_group *group, - const char *page, - size_t count) -{ - unsigned long tmp; - char *p = (char *)page; - int err; - - err = kstrtoul(p, 10, &tmp); - if (err) - return err; - - /* this will validate ranges for us. */ - r2hb_dead_threshold_set((unsigned int) tmp); - - return count; -} - -static -ssize_t r2hb_hb_group_mode_show(struct r2hb_hb_group *group, - char *page) -{ - return sprintf(page, "%s\n", - r2hb_heartbeat_mode_desc[r2hb_heartbeat_mode]); -} - -static -ssize_t r2hb_hb_group_mode_store(struct r2hb_hb_group *group, - const char *page, size_t count) -{ - unsigned int i; - int ret; - size_t len; - - len = (page[count - 1] == '\n') ? count - 1 : count; - if (!len) - return -EINVAL; - - for (i = 0; i < R2HB_HEARTBEAT_NUM_MODES; ++i) { - if (strnicmp(page, r2hb_heartbeat_mode_desc[i], len)) - continue; - - ret = r2hb_global_hearbeat_mode_set(i); - if (!ret) - pr_notice("ramster: Heartbeat mode set to %s\n", - r2hb_heartbeat_mode_desc[i]); - return count; - } - - return -EINVAL; - -} - -static struct r2hb_hb_group_attribute r2hb_hb_group_attr_threshold = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "dead_threshold", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2hb_hb_group_threshold_show, - .store = r2hb_hb_group_threshold_store, -}; - -static struct r2hb_hb_group_attribute r2hb_hb_group_attr_mode = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "mode", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2hb_hb_group_mode_show, - .store = r2hb_hb_group_mode_store, -}; - -static struct configfs_attribute *r2hb_hb_group_attrs[] = { - &r2hb_hb_group_attr_threshold.attr, - &r2hb_hb_group_attr_mode.attr, - NULL, -}; - -static struct configfs_item_operations r2hb_hearbeat_group_item_ops = { - .show_attribute = r2hb_hb_group_show, - .store_attribute = r2hb_hb_group_store, -}; - -static struct configfs_group_operations r2hb_hb_group_group_ops = { - .make_item = r2hb_hb_group_make_item, - .drop_item = r2hb_hb_group_drop_item, -}; - -static struct config_item_type r2hb_hb_group_type = { - .ct_group_ops = &r2hb_hb_group_group_ops, - .ct_item_ops = &r2hb_hearbeat_group_item_ops, - .ct_attrs = r2hb_hb_group_attrs, - .ct_owner = THIS_MODULE, -}; - -/* this is just here to avoid touching group in heartbeat.h which the - * entire damn world #includes */ -struct config_group *r2hb_alloc_hb_set(void) -{ - struct r2hb_hb_group *hs = NULL; - struct config_group *ret = NULL; - - hs = kzalloc(sizeof(struct r2hb_hb_group), GFP_KERNEL); - if (hs == NULL) - goto out; - - config_group_init_type_name(&hs->hs_group, "heartbeat", - &r2hb_hb_group_type); - - ret = &hs->hs_group; -out: - if (ret == NULL) - kfree(hs); - return ret; -} - -void r2hb_free_hb_set(struct config_group *group) -{ - struct r2hb_hb_group *hs = to_r2hb_hb_group(group); - kfree(hs); -} - -/* hb callback registration and issuing */ - -static struct r2hb_callback *hbcall_from_type(enum r2hb_callback_type type) -{ - if (type == R2HB_NUM_CB) - return ERR_PTR(-EINVAL); - - return &r2hb_callbacks[type]; -} - -void r2hb_setup_callback(struct r2hb_callback_func *hc, - enum r2hb_callback_type type, - r2hb_cb_func *func, - void *data, - int priority) -{ - INIT_LIST_HEAD(&hc->hc_item); - hc->hc_func = func; - hc->hc_data = data; - hc->hc_priority = priority; - hc->hc_type = type; - hc->hc_magic = R2HB_CB_MAGIC; -} -EXPORT_SYMBOL_GPL(r2hb_setup_callback); - -int r2hb_register_callback(const char *region_uuid, - struct r2hb_callback_func *hc) -{ - struct r2hb_callback_func *tmp; - struct list_head *iter; - struct r2hb_callback *hbcall; - int ret; - - BUG_ON(hc->hc_magic != R2HB_CB_MAGIC); - BUG_ON(!list_empty(&hc->hc_item)); - - hbcall = hbcall_from_type(hc->hc_type); - if (IS_ERR(hbcall)) { - ret = PTR_ERR(hbcall); - goto out; - } - - down_write(&r2hb_callback_sem); - - list_for_each(iter, &hbcall->list) { - tmp = list_entry(iter, struct r2hb_callback_func, hc_item); - if (hc->hc_priority < tmp->hc_priority) { - list_add_tail(&hc->hc_item, iter); - break; - } - } - if (list_empty(&hc->hc_item)) - list_add_tail(&hc->hc_item, &hbcall->list); - - up_write(&r2hb_callback_sem); - ret = 0; -out: - mlog(ML_CLUSTER, "returning %d on behalf of %p for funcs %p\n", - ret, __builtin_return_address(0), hc); - return ret; -} -EXPORT_SYMBOL_GPL(r2hb_register_callback); - -void r2hb_unregister_callback(const char *region_uuid, - struct r2hb_callback_func *hc) -{ - BUG_ON(hc->hc_magic != R2HB_CB_MAGIC); - - mlog(ML_CLUSTER, "on behalf of %p for funcs %p\n", - __builtin_return_address(0), hc); - - /* XXX Can this happen _with_ a region reference? */ - if (list_empty(&hc->hc_item)) - return; - - down_write(&r2hb_callback_sem); - - list_del_init(&hc->hc_item); - - up_write(&r2hb_callback_sem); -} -EXPORT_SYMBOL_GPL(r2hb_unregister_callback); - -int r2hb_check_node_heartbeating_from_callback(u8 node_num) -{ - unsigned long testing_map[BITS_TO_LONGS(R2NM_MAX_NODES)]; - - r2hb_fill_node_map_from_callback(testing_map, sizeof(testing_map)); - if (!test_bit(node_num, testing_map)) { - mlog(ML_HEARTBEAT, - "node (%u) does not have heartbeating enabled.\n", - node_num); - return 0; - } - - return 1; -} -EXPORT_SYMBOL_GPL(r2hb_check_node_heartbeating_from_callback); - -void r2hb_stop_all_regions(void) -{ -} -EXPORT_SYMBOL_GPL(r2hb_stop_all_regions); - -/* - * this is just a hack until we get the plumbing which flips file systems - * read only and drops the hb ref instead of killing the node dead. - */ -int r2hb_global_heartbeat_active(void) -{ - return (r2hb_heartbeat_mode == R2HB_HEARTBEAT_GLOBAL); -} -EXPORT_SYMBOL(r2hb_global_heartbeat_active); - -/* added for RAMster */ -void r2hb_manual_set_node_heartbeating(int node_num) -{ - if (node_num < R2NM_MAX_NODES) - set_bit(node_num, r2hb_live_node_bitmap); -} -EXPORT_SYMBOL(r2hb_manual_set_node_heartbeating); diff --git a/drivers/staging/ramster/ramster/heartbeat.h b/drivers/staging/ramster/ramster/heartbeat.h deleted file mode 100644 index 6cbc775..0000000 --- a/drivers/staging/ramster/ramster/heartbeat.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * heartbeat.h - * - * Function prototypes - * - * Copyright (C) 2004 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - * - */ - -#ifndef R2CLUSTER_HEARTBEAT_H -#define R2CLUSTER_HEARTBEAT_H - -#define R2HB_REGION_TIMEOUT_MS 2000 - -#define R2HB_MAX_REGION_NAME_LEN 32 - -/* number of changes to be seen as live */ -#define R2HB_LIVE_THRESHOLD 2 -/* number of equal samples to be seen as dead */ -extern unsigned int r2hb_dead_threshold; -#define R2HB_DEFAULT_DEAD_THRESHOLD 31 -/* Otherwise MAX_WRITE_TIMEOUT will be zero... */ -#define R2HB_MIN_DEAD_THRESHOLD 2 -#define R2HB_MAX_WRITE_TIMEOUT_MS \ - (R2HB_REGION_TIMEOUT_MS * (r2hb_dead_threshold - 1)) - -#define R2HB_CB_MAGIC 0x51d1e4ec - -/* callback stuff */ -enum r2hb_callback_type { - R2HB_NODE_DOWN_CB = 0, - R2HB_NODE_UP_CB, - R2HB_NUM_CB -}; - -struct r2nm_node; -typedef void (r2hb_cb_func)(struct r2nm_node *, int, void *); - -struct r2hb_callback_func { - u32 hc_magic; - struct list_head hc_item; - r2hb_cb_func *hc_func; - void *hc_data; - int hc_priority; - enum r2hb_callback_type hc_type; -}; - -struct config_group *r2hb_alloc_hb_set(void); -void r2hb_free_hb_set(struct config_group *group); - -void r2hb_setup_callback(struct r2hb_callback_func *hc, - enum r2hb_callback_type type, - r2hb_cb_func *func, - void *data, - int priority); -int r2hb_register_callback(const char *region_uuid, - struct r2hb_callback_func *hc); -void r2hb_unregister_callback(const char *region_uuid, - struct r2hb_callback_func *hc); -void r2hb_fill_node_map(unsigned long *map, - unsigned bytes); -void r2hb_exit(void); -int r2hb_init(void); -int r2hb_check_node_heartbeating_from_callback(u8 node_num); -void r2hb_stop_all_regions(void); -int r2hb_get_all_regions(char *region_uuids, u8 numregions); -int r2hb_global_heartbeat_active(void); -void r2hb_manual_set_node_heartbeating(int); - -#endif /* R2CLUSTER_HEARTBEAT_H */ diff --git a/drivers/staging/ramster/ramster/masklog.c b/drivers/staging/ramster/ramster/masklog.c deleted file mode 100644 index 1261d85..0000000 --- a/drivers/staging/ramster/ramster/masklog.c +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * Copyright (C) 2004, 2005, 2012 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#include -#include -#include -#include -#include -#include - -#include "masklog.h" - -struct mlog_bits r2_mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK); -EXPORT_SYMBOL_GPL(r2_mlog_and_bits); -struct mlog_bits r2_mlog_not_bits = MLOG_BITS_RHS(0); -EXPORT_SYMBOL_GPL(r2_mlog_not_bits); - -static ssize_t mlog_mask_show(u64 mask, char *buf) -{ - char *state; - - if (__mlog_test_u64(mask, r2_mlog_and_bits)) - state = "allow"; - else if (__mlog_test_u64(mask, r2_mlog_not_bits)) - state = "deny"; - else - state = "off"; - - return snprintf(buf, PAGE_SIZE, "%s\n", state); -} - -static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count) -{ - if (!strnicmp(buf, "allow", 5)) { - __mlog_set_u64(mask, r2_mlog_and_bits); - __mlog_clear_u64(mask, r2_mlog_not_bits); - } else if (!strnicmp(buf, "deny", 4)) { - __mlog_set_u64(mask, r2_mlog_not_bits); - __mlog_clear_u64(mask, r2_mlog_and_bits); - } else if (!strnicmp(buf, "off", 3)) { - __mlog_clear_u64(mask, r2_mlog_not_bits); - __mlog_clear_u64(mask, r2_mlog_and_bits); - } else - return -EINVAL; - - return count; -} - -struct mlog_attribute { - struct attribute attr; - u64 mask; -}; - -#define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr) - -#define define_mask(_name) { \ - .attr = { \ - .name = #_name, \ - .mode = S_IRUGO | S_IWUSR, \ - }, \ - .mask = ML_##_name, \ -} - -static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = { - define_mask(TCP), - define_mask(MSG), - define_mask(SOCKET), - define_mask(HEARTBEAT), - define_mask(HB_BIO), - define_mask(DLMFS), - define_mask(DLM), - define_mask(DLM_DOMAIN), - define_mask(DLM_THREAD), - define_mask(DLM_MASTER), - define_mask(DLM_RECOVERY), - define_mask(DLM_GLUE), - define_mask(VOTE), - define_mask(CONN), - define_mask(QUORUM), - define_mask(BASTS), - define_mask(CLUSTER), - define_mask(ERROR), - define_mask(NOTICE), - define_mask(KTHREAD), -}; - -static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, }; - -static ssize_t mlog_show(struct kobject *obj, struct attribute *attr, - char *buf) -{ - struct mlog_attribute *mlog_attr = to_mlog_attr(attr); - - return mlog_mask_show(mlog_attr->mask, buf); -} - -static ssize_t mlog_store(struct kobject *obj, struct attribute *attr, - const char *buf, size_t count) -{ - struct mlog_attribute *mlog_attr = to_mlog_attr(attr); - - return mlog_mask_store(mlog_attr->mask, buf, count); -} - -static const struct sysfs_ops mlog_attr_ops = { - .show = mlog_show, - .store = mlog_store, -}; - -static struct kobj_type mlog_ktype = { - .default_attrs = mlog_attr_ptrs, - .sysfs_ops = &mlog_attr_ops, -}; - -static struct kset mlog_kset = { - .kobj = {.ktype = &mlog_ktype}, -}; - -int r2_mlog_sys_init(struct kset *r2cb_kset) -{ - int i = 0; - - while (mlog_attrs[i].attr.mode) { - mlog_attr_ptrs[i] = &mlog_attrs[i].attr; - i++; - } - mlog_attr_ptrs[i] = NULL; - - kobject_set_name(&mlog_kset.kobj, "logmask"); - mlog_kset.kobj.kset = r2cb_kset; - return kset_register(&mlog_kset); -} - -void r2_mlog_sys_shutdown(void) -{ - kset_unregister(&mlog_kset); -} diff --git a/drivers/staging/ramster/ramster/masklog.h b/drivers/staging/ramster/ramster/masklog.h deleted file mode 100644 index 918ae11..0000000 --- a/drivers/staging/ramster/ramster/masklog.h +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * Copyright (C) 2005, 2012 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#ifndef R2CLUSTER_MASKLOG_H -#define R2CLUSTER_MASKLOG_H - -/* - * For now this is a trivial wrapper around printk() that gives the critical - * ability to enable sets of debugging output at run-time. In the future this - * will almost certainly be redirected to relayfs so that it can pay a - * substantially lower heisenberg tax. - * - * Callers associate the message with a bitmask and a global bitmask is - * maintained with help from /proc. If any of the bits match the message is - * output. - * - * We must have efficient bit tests on i386 and it seems gcc still emits crazy - * code for the 64bit compare. It emits very good code for the dual unsigned - * long tests, though, completely avoiding tests that can never pass if the - * caller gives a constant bitmask that fills one of the longs with all 0s. So - * the desire is to have almost all of the calls decided on by comparing just - * one of the longs. This leads to having infrequently given bits that are - * frequently matched in the high bits. - * - * _ERROR and _NOTICE are used for messages that always go to the console and - * have appropriate KERN_ prefixes. We wrap these in our function instead of - * just calling printk() so that this can eventually make its way through - * relayfs along with the debugging messages. Everything else gets KERN_DEBUG. - * The inline tests and macro dance give GCC the opportunity to quite cleverly - * only emit the appropriage printk() when the caller passes in a constant - * mask, as is almost always the case. - * - * All this bitmask nonsense is managed from the files under - * /sys/fs/r2cb/logmask/. Reading the files gives a straightforward - * indication of which bits are allowed (allow) or denied (off/deny). - * ENTRY deny - * EXIT deny - * TCP off - * MSG off - * SOCKET off - * ERROR allow - * NOTICE allow - * - * Writing changes the state of a given bit and requires a strictly formatted - * single write() call: - * - * write(fd, "allow", 5); - * - * Echoing allow/deny/off string into the logmask files can flip the bits - * on or off as expected; here is the bash script for example: - * - * log_mask="/sys/fs/r2cb/log_mask" - * for node in ENTRY EXIT TCP MSG SOCKET ERROR NOTICE; do - * echo allow >"$log_mask"/"$node" - * done - * - * The debugfs.ramster tool can also flip the bits with the -l option: - * - * debugfs.ramster -l TCP allow - */ - -/* for task_struct */ -#include - -/* bits that are frequently given and infrequently matched in the low word */ -/* NOTE: If you add a flag, you need to also update masklog.c! */ -#define ML_TCP 0x0000000000000001ULL /* net cluster/tcp.c */ -#define ML_MSG 0x0000000000000002ULL /* net network messages */ -#define ML_SOCKET 0x0000000000000004ULL /* net socket lifetime */ -#define ML_HEARTBEAT 0x0000000000000008ULL /* hb all heartbeat tracking */ -#define ML_HB_BIO 0x0000000000000010ULL /* hb io tracing */ -#define ML_DLMFS 0x0000000000000020ULL /* dlm user dlmfs */ -#define ML_DLM 0x0000000000000040ULL /* dlm general debugging */ -#define ML_DLM_DOMAIN 0x0000000000000080ULL /* dlm domain debugging */ -#define ML_DLM_THREAD 0x0000000000000100ULL /* dlm domain thread */ -#define ML_DLM_MASTER 0x0000000000000200ULL /* dlm master functions */ -#define ML_DLM_RECOVERY 0x0000000000000400ULL /* dlm master functions */ -#define ML_DLM_GLUE 0x0000000000000800ULL /* ramster dlm glue layer */ -#define ML_VOTE 0x0000000000001000ULL /* ramster node messaging */ -#define ML_CONN 0x0000000000002000ULL /* net connection management */ -#define ML_QUORUM 0x0000000000004000ULL /* net connection quorum */ -#define ML_BASTS 0x0000000000008000ULL /* dlmglue asts and basts */ -#define ML_CLUSTER 0x0000000000010000ULL /* cluster stack */ - -/* bits that are infrequently given and frequently matched in the high word */ -#define ML_ERROR 0x1000000000000000ULL /* sent to KERN_ERR */ -#define ML_NOTICE 0x2000000000000000ULL /* setn to KERN_NOTICE */ -#define ML_KTHREAD 0x4000000000000000ULL /* kernel thread activity */ - -#define MLOG_INITIAL_AND_MASK (ML_ERROR|ML_NOTICE) -#ifndef MLOG_MASK_PREFIX -#define MLOG_MASK_PREFIX 0 -#endif - -/* - * When logging is disabled, force the bit test to 0 for anything other - * than errors and notices, allowing gcc to remove the code completely. - * When enabled, allow all masks. - */ -#if defined(CONFIG_RAMSTER_DEBUG_MASKLOG) -#define ML_ALLOWED_BITS (~0) -#else -#define ML_ALLOWED_BITS (ML_ERROR|ML_NOTICE) -#endif - -#define MLOG_MAX_BITS 64 - -struct mlog_bits { - unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG]; -}; - -extern struct mlog_bits r2_mlog_and_bits, r2_mlog_not_bits; - -#if BITS_PER_LONG == 32 - -#define __mlog_test_u64(mask, bits) \ - ((u32)(mask & 0xffffffff) & bits.words[0] || \ - ((u64)(mask) >> 32) & bits.words[1]) -#define __mlog_set_u64(mask, bits) do { \ - bits.words[0] |= (u32)(mask & 0xffffffff); \ - bits.words[1] |= (u64)(mask) >> 32; \ -} while (0) -#define __mlog_clear_u64(mask, bits) do { \ - bits.words[0] &= ~((u32)(mask & 0xffffffff)); \ - bits.words[1] &= ~((u64)(mask) >> 32); \ -} while (0) -#define MLOG_BITS_RHS(mask) { \ - { \ - [0] = (u32)(mask & 0xffffffff), \ - [1] = (u64)(mask) >> 32, \ - } \ -} - -#else /* 32bit long above, 64bit long below */ - -#define __mlog_test_u64(mask, bits) ((mask) & bits.words[0]) -#define __mlog_set_u64(mask, bits) do { \ - bits.words[0] |= (mask); \ -} while (0) -#define __mlog_clear_u64(mask, bits) do { \ - bits.words[0] &= ~(mask); \ -} while (0) -#define MLOG_BITS_RHS(mask) { { (mask) } } - -#endif - -/* - * smp_processor_id() "helpfully" screams when called outside preemptible - * regions in current kernels. sles doesn't have the variants that don't - * scream. just do this instead of trying to guess which we're building - * against.. *sigh*. - */ -#define __mlog_cpu_guess ({ \ - unsigned long _cpu = get_cpu(); \ - put_cpu(); \ - _cpu; \ -}) - -/* In the following two macros, the whitespace after the ',' just - * before ##args is intentional. Otherwise, gcc 2.95 will eat the - * previous token if args expands to nothing. - */ -#define __mlog_printk(level, fmt, args...) \ - printk(level "(%s,%u,%lu):%s:%d " fmt, current->comm, \ - task_pid_nr(current), __mlog_cpu_guess, \ - __PRETTY_FUNCTION__, __LINE__ , ##args) - -#define mlog(mask, fmt, args...) do { \ - u64 __m = MLOG_MASK_PREFIX | (mask); \ - if ((__m & ML_ALLOWED_BITS) && \ - __mlog_test_u64(__m, r2_mlog_and_bits) && \ - !__mlog_test_u64(__m, r2_mlog_not_bits)) { \ - if (__m & ML_ERROR) \ - __mlog_printk(KERN_ERR, "ERROR: "fmt , ##args); \ - else if (__m & ML_NOTICE) \ - __mlog_printk(KERN_NOTICE, fmt , ##args); \ - else \ - __mlog_printk(KERN_INFO, fmt , ##args); \ - } \ -} while (0) - -#define mlog_errno(st) do { \ - int _st = (st); \ - if (_st != -ERESTARTSYS && _st != -EINTR && \ - _st != AOP_TRUNCATED_PAGE && _st != -ENOSPC) \ - mlog(ML_ERROR, "status = %lld\n", (long long)_st); \ -} while (0) - -#define mlog_bug_on_msg(cond, fmt, args...) do { \ - if (cond) { \ - mlog(ML_ERROR, "bug expression: " #cond "\n"); \ - mlog(ML_ERROR, fmt, ##args); \ - BUG(); \ - } \ -} while (0) - -#include -#include -int r2_mlog_sys_init(struct kset *r2cb_subsys); -void r2_mlog_sys_shutdown(void); - -#endif /* R2CLUSTER_MASKLOG_H */ diff --git a/drivers/staging/ramster/ramster/nodemanager.c b/drivers/staging/ramster/ramster/nodemanager.c deleted file mode 100644 index c0f4815..0000000 --- a/drivers/staging/ramster/ramster/nodemanager.c +++ /dev/null @@ -1,995 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * Copyright (C) 2004, 2005, 2012 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#include -#include -#include -#include - -#include "tcp.h" -#include "nodemanager.h" -#include "heartbeat.h" -#include "masklog.h" - -/* for now we operate under the assertion that there can be only one - * cluster active at a time. Changing this will require trickling - * cluster references throughout where nodes are looked up */ -struct r2nm_cluster *r2nm_single_cluster; - -char *r2nm_fence_method_desc[R2NM_FENCE_METHODS] = { - "reset", /* R2NM_FENCE_RESET */ - "panic", /* R2NM_FENCE_PANIC */ -}; - -struct r2nm_node *r2nm_get_node_by_num(u8 node_num) -{ - struct r2nm_node *node = NULL; - - if (node_num >= R2NM_MAX_NODES || r2nm_single_cluster == NULL) - goto out; - - read_lock(&r2nm_single_cluster->cl_nodes_lock); - node = r2nm_single_cluster->cl_nodes[node_num]; - if (node) - config_item_get(&node->nd_item); - read_unlock(&r2nm_single_cluster->cl_nodes_lock); -out: - return node; -} -EXPORT_SYMBOL_GPL(r2nm_get_node_by_num); - -int r2nm_configured_node_map(unsigned long *map, unsigned bytes) -{ - struct r2nm_cluster *cluster = r2nm_single_cluster; - - BUG_ON(bytes < (sizeof(cluster->cl_nodes_bitmap))); - - if (cluster == NULL) - return -EINVAL; - - read_lock(&cluster->cl_nodes_lock); - memcpy(map, cluster->cl_nodes_bitmap, sizeof(cluster->cl_nodes_bitmap)); - read_unlock(&cluster->cl_nodes_lock); - - return 0; -} -EXPORT_SYMBOL_GPL(r2nm_configured_node_map); - -static struct r2nm_node *r2nm_node_ip_tree_lookup(struct r2nm_cluster *cluster, - __be32 ip_needle, - struct rb_node ***ret_p, - struct rb_node **ret_parent) -{ - struct rb_node **p = &cluster->cl_node_ip_tree.rb_node; - struct rb_node *parent = NULL; - struct r2nm_node *node, *ret = NULL; - - while (*p) { - int cmp; - - parent = *p; - node = rb_entry(parent, struct r2nm_node, nd_ip_node); - - cmp = memcmp(&ip_needle, &node->nd_ipv4_address, - sizeof(ip_needle)); - if (cmp < 0) - p = &(*p)->rb_left; - else if (cmp > 0) - p = &(*p)->rb_right; - else { - ret = node; - break; - } - } - - if (ret_p != NULL) - *ret_p = p; - if (ret_parent != NULL) - *ret_parent = parent; - - return ret; -} - -struct r2nm_node *r2nm_get_node_by_ip(__be32 addr) -{ - struct r2nm_node *node = NULL; - struct r2nm_cluster *cluster = r2nm_single_cluster; - - if (cluster == NULL) - goto out; - - read_lock(&cluster->cl_nodes_lock); - node = r2nm_node_ip_tree_lookup(cluster, addr, NULL, NULL); - if (node) - config_item_get(&node->nd_item); - read_unlock(&cluster->cl_nodes_lock); - -out: - return node; -} -EXPORT_SYMBOL_GPL(r2nm_get_node_by_ip); - -void r2nm_node_put(struct r2nm_node *node) -{ - config_item_put(&node->nd_item); -} -EXPORT_SYMBOL_GPL(r2nm_node_put); - -void r2nm_node_get(struct r2nm_node *node) -{ - config_item_get(&node->nd_item); -} -EXPORT_SYMBOL_GPL(r2nm_node_get); - -u8 r2nm_this_node(void) -{ - u8 node_num = R2NM_MAX_NODES; - - if (r2nm_single_cluster && r2nm_single_cluster->cl_has_local) - node_num = r2nm_single_cluster->cl_local_node; - - return node_num; -} -EXPORT_SYMBOL_GPL(r2nm_this_node); - -/* node configfs bits */ - -static struct r2nm_cluster *to_r2nm_cluster(struct config_item *item) -{ - return item ? - container_of(to_config_group(item), struct r2nm_cluster, - cl_group) - : NULL; -} - -static struct r2nm_node *to_r2nm_node(struct config_item *item) -{ - return item ? container_of(item, struct r2nm_node, nd_item) : NULL; -} - -static void r2nm_node_release(struct config_item *item) -{ - struct r2nm_node *node = to_r2nm_node(item); - kfree(node); -} - -static ssize_t r2nm_node_num_read(struct r2nm_node *node, char *page) -{ - return sprintf(page, "%d\n", node->nd_num); -} - -static struct r2nm_cluster *to_r2nm_cluster_from_node(struct r2nm_node *node) -{ - /* through the first node_set .parent - * mycluster/nodes/mynode == r2nm_cluster->r2nm_node_group->r2nm_node */ - return to_r2nm_cluster(node->nd_item.ci_parent->ci_parent); -} - -enum { - R2NM_NODE_ATTR_NUM = 0, - R2NM_NODE_ATTR_PORT, - R2NM_NODE_ATTR_ADDRESS, - R2NM_NODE_ATTR_LOCAL, -}; - -static ssize_t r2nm_node_num_write(struct r2nm_node *node, const char *page, - size_t count) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster_from_node(node); - unsigned long tmp; - char *p = (char *)page; - int err; - - err = kstrtoul(p, 10, &tmp); - if (err) - return err; - - if (tmp >= R2NM_MAX_NODES) - return -ERANGE; - - /* once we're in the cl_nodes tree networking can look us up by - * node number and try to use our address and port attributes - * to connect to this node.. make sure that they've been set - * before writing the node attribute? */ - if (!test_bit(R2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) || - !test_bit(R2NM_NODE_ATTR_PORT, &node->nd_set_attributes)) - return -EINVAL; /* XXX */ - - write_lock(&cluster->cl_nodes_lock); - if (cluster->cl_nodes[tmp]) - p = NULL; - else { - cluster->cl_nodes[tmp] = node; - node->nd_num = tmp; - set_bit(tmp, cluster->cl_nodes_bitmap); - } - write_unlock(&cluster->cl_nodes_lock); - if (p == NULL) - return -EEXIST; - - return count; -} -static ssize_t r2nm_node_ipv4_port_read(struct r2nm_node *node, char *page) -{ - return sprintf(page, "%u\n", ntohs(node->nd_ipv4_port)); -} - -static ssize_t r2nm_node_ipv4_port_write(struct r2nm_node *node, - const char *page, size_t count) -{ - unsigned long tmp; - char *p = (char *)page; - int err; - - err = kstrtoul(p, 10, &tmp); - if (err) - return err; - - if (tmp == 0) - return -EINVAL; - if (tmp >= (u16)-1) - return -ERANGE; - - node->nd_ipv4_port = htons(tmp); - - return count; -} - -static ssize_t r2nm_node_ipv4_address_read(struct r2nm_node *node, char *page) -{ - return sprintf(page, "%pI4\n", &node->nd_ipv4_address); -} - -static ssize_t r2nm_node_ipv4_address_write(struct r2nm_node *node, - const char *page, - size_t count) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster_from_node(node); - int ret, i; - struct rb_node **p, *parent; - unsigned int octets[4]; - __be32 ipv4_addr = 0; - - ret = sscanf(page, "%3u.%3u.%3u.%3u", &octets[3], &octets[2], - &octets[1], &octets[0]); - if (ret != 4) - return -EINVAL; - - for (i = 0; i < ARRAY_SIZE(octets); i++) { - if (octets[i] > 255) - return -ERANGE; - be32_add_cpu(&ipv4_addr, octets[i] << (i * 8)); - } - - ret = 0; - write_lock(&cluster->cl_nodes_lock); - if (r2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent)) - ret = -EEXIST; - else { - rb_link_node(&node->nd_ip_node, parent, p); - rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree); - } - write_unlock(&cluster->cl_nodes_lock); - if (ret) - return ret; - - memcpy(&node->nd_ipv4_address, &ipv4_addr, sizeof(ipv4_addr)); - - return count; -} - -static ssize_t r2nm_node_local_read(struct r2nm_node *node, char *page) -{ - return sprintf(page, "%d\n", node->nd_local); -} - -static ssize_t r2nm_node_local_write(struct r2nm_node *node, const char *page, - size_t count) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster_from_node(node); - unsigned long tmp; - char *p = (char *)page; - ssize_t ret; - int err; - - err = kstrtoul(p, 10, &tmp); - if (err) - return err; - - tmp = !!tmp; /* boolean of whether this node wants to be local */ - - /* setting local turns on networking rx for now so we require having - * set everything else first */ - if (!test_bit(R2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) || - !test_bit(R2NM_NODE_ATTR_NUM, &node->nd_set_attributes) || - !test_bit(R2NM_NODE_ATTR_PORT, &node->nd_set_attributes)) - return -EINVAL; /* XXX */ - - /* the only failure case is trying to set a new local node - * when a different one is already set */ - if (tmp && tmp == cluster->cl_has_local && - cluster->cl_local_node != node->nd_num) - return -EBUSY; - - /* bring up the rx thread if we're setting the new local node. */ - if (tmp && !cluster->cl_has_local) { - ret = r2net_start_listening(node); - if (ret) - return ret; - } - - if (!tmp && cluster->cl_has_local && - cluster->cl_local_node == node->nd_num) { - r2net_stop_listening(node); - cluster->cl_local_node = R2NM_INVALID_NODE_NUM; - } - - node->nd_local = tmp; - if (node->nd_local) { - cluster->cl_has_local = tmp; - cluster->cl_local_node = node->nd_num; - } - - return count; -} - -struct r2nm_node_attribute { - struct configfs_attribute attr; - ssize_t (*show)(struct r2nm_node *, char *); - ssize_t (*store)(struct r2nm_node *, const char *, size_t); -}; - -static struct r2nm_node_attribute r2nm_node_attr_num = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "num", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_node_num_read, - .store = r2nm_node_num_write, -}; - -static struct r2nm_node_attribute r2nm_node_attr_ipv4_port = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "ipv4_port", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_node_ipv4_port_read, - .store = r2nm_node_ipv4_port_write, -}; - -static struct r2nm_node_attribute r2nm_node_attr_ipv4_address = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "ipv4_address", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_node_ipv4_address_read, - .store = r2nm_node_ipv4_address_write, -}; - -static struct r2nm_node_attribute r2nm_node_attr_local = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "local", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_node_local_read, - .store = r2nm_node_local_write, -}; - -static struct configfs_attribute *r2nm_node_attrs[] = { - [R2NM_NODE_ATTR_NUM] = &r2nm_node_attr_num.attr, - [R2NM_NODE_ATTR_PORT] = &r2nm_node_attr_ipv4_port.attr, - [R2NM_NODE_ATTR_ADDRESS] = &r2nm_node_attr_ipv4_address.attr, - [R2NM_NODE_ATTR_LOCAL] = &r2nm_node_attr_local.attr, - NULL, -}; - -static int r2nm_attr_index(struct configfs_attribute *attr) -{ - int i; - for (i = 0; i < ARRAY_SIZE(r2nm_node_attrs); i++) { - if (attr == r2nm_node_attrs[i]) - return i; - } - BUG(); - return 0; -} - -static ssize_t r2nm_node_show(struct config_item *item, - struct configfs_attribute *attr, - char *page) -{ - struct r2nm_node *node = to_r2nm_node(item); - struct r2nm_node_attribute *r2nm_node_attr = - container_of(attr, struct r2nm_node_attribute, attr); - ssize_t ret = 0; - - if (r2nm_node_attr->show) - ret = r2nm_node_attr->show(node, page); - return ret; -} - -static ssize_t r2nm_node_store(struct config_item *item, - struct configfs_attribute *attr, - const char *page, size_t count) -{ - struct r2nm_node *node = to_r2nm_node(item); - struct r2nm_node_attribute *r2nm_node_attr = - container_of(attr, struct r2nm_node_attribute, attr); - ssize_t ret; - int attr_index = r2nm_attr_index(attr); - - if (r2nm_node_attr->store == NULL) { - ret = -EINVAL; - goto out; - } - - if (test_bit(attr_index, &node->nd_set_attributes)) - return -EBUSY; - - ret = r2nm_node_attr->store(node, page, count); - if (ret < count) - goto out; - - set_bit(attr_index, &node->nd_set_attributes); -out: - return ret; -} - -static struct configfs_item_operations r2nm_node_item_ops = { - .release = r2nm_node_release, - .show_attribute = r2nm_node_show, - .store_attribute = r2nm_node_store, -}; - -static struct config_item_type r2nm_node_type = { - .ct_item_ops = &r2nm_node_item_ops, - .ct_attrs = r2nm_node_attrs, - .ct_owner = THIS_MODULE, -}; - -/* node set */ - -struct r2nm_node_group { - struct config_group ns_group; - /* some stuff? */ -}; - -#if 0 -static struct r2nm_node_group *to_r2nm_node_group(struct config_group *group) -{ - return group ? - container_of(group, struct r2nm_node_group, ns_group) - : NULL; -} -#endif - -struct r2nm_cluster_attribute { - struct configfs_attribute attr; - ssize_t (*show)(struct r2nm_cluster *, char *); - ssize_t (*store)(struct r2nm_cluster *, const char *, size_t); -}; - -static ssize_t r2nm_cluster_attr_write(const char *page, ssize_t count, - unsigned int *val) -{ - unsigned long tmp; - char *p = (char *)page; - int err; - - err = kstrtoul(p, 10, &tmp); - if (err) - return err; - - if (tmp == 0) - return -EINVAL; - if (tmp >= (u32)-1) - return -ERANGE; - - *val = tmp; - - return count; -} - -static ssize_t r2nm_cluster_attr_idle_timeout_ms_read( - struct r2nm_cluster *cluster, char *page) -{ - return sprintf(page, "%u\n", cluster->cl_idle_timeout_ms); -} - -static ssize_t r2nm_cluster_attr_idle_timeout_ms_write( - struct r2nm_cluster *cluster, const char *page, size_t count) -{ - ssize_t ret; - unsigned int val = 0; - - ret = r2nm_cluster_attr_write(page, count, &val); - - if (ret > 0) { - if (cluster->cl_idle_timeout_ms != val - && r2net_num_connected_peers()) { - mlog(ML_NOTICE, - "r2net: cannot change idle timeout after " - "the first peer has agreed to it." - " %d connected peers\n", - r2net_num_connected_peers()); - ret = -EINVAL; - } else if (val <= cluster->cl_keepalive_delay_ms) { - mlog(ML_NOTICE, - "r2net: idle timeout must be larger " - "than keepalive delay\n"); - ret = -EINVAL; - } else { - cluster->cl_idle_timeout_ms = val; - } - } - - return ret; -} - -static ssize_t r2nm_cluster_attr_keepalive_delay_ms_read( - struct r2nm_cluster *cluster, char *page) -{ - return sprintf(page, "%u\n", cluster->cl_keepalive_delay_ms); -} - -static ssize_t r2nm_cluster_attr_keepalive_delay_ms_write( - struct r2nm_cluster *cluster, const char *page, size_t count) -{ - ssize_t ret; - unsigned int val = 0; - - ret = r2nm_cluster_attr_write(page, count, &val); - - if (ret > 0) { - if (cluster->cl_keepalive_delay_ms != val - && r2net_num_connected_peers()) { - mlog(ML_NOTICE, - "r2net: cannot change keepalive delay after" - " the first peer has agreed to it." - " %d connected peers\n", - r2net_num_connected_peers()); - ret = -EINVAL; - } else if (val >= cluster->cl_idle_timeout_ms) { - mlog(ML_NOTICE, - "r2net: keepalive delay must be " - "smaller than idle timeout\n"); - ret = -EINVAL; - } else { - cluster->cl_keepalive_delay_ms = val; - } - } - - return ret; -} - -static ssize_t r2nm_cluster_attr_reconnect_delay_ms_read( - struct r2nm_cluster *cluster, char *page) -{ - return sprintf(page, "%u\n", cluster->cl_reconnect_delay_ms); -} - -static ssize_t r2nm_cluster_attr_reconnect_delay_ms_write( - struct r2nm_cluster *cluster, const char *page, size_t count) -{ - return r2nm_cluster_attr_write(page, count, - &cluster->cl_reconnect_delay_ms); -} - -static ssize_t r2nm_cluster_attr_fence_method_read( - struct r2nm_cluster *cluster, char *page) -{ - ssize_t ret = 0; - - if (cluster) - ret = sprintf(page, "%s\n", - r2nm_fence_method_desc[cluster->cl_fence_method]); - return ret; -} - -static ssize_t r2nm_cluster_attr_fence_method_write( - struct r2nm_cluster *cluster, const char *page, size_t count) -{ - unsigned int i; - - if (page[count - 1] != '\n') - goto bail; - - for (i = 0; i < R2NM_FENCE_METHODS; ++i) { - if (count != strlen(r2nm_fence_method_desc[i]) + 1) - continue; - if (strncasecmp(page, r2nm_fence_method_desc[i], count - 1)) - continue; - if (cluster->cl_fence_method != i) { - pr_info("ramster: Changing fence method to %s\n", - r2nm_fence_method_desc[i]); - cluster->cl_fence_method = i; - } - return count; - } - -bail: - return -EINVAL; -} - -static struct r2nm_cluster_attribute r2nm_cluster_attr_idle_timeout_ms = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "idle_timeout_ms", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_cluster_attr_idle_timeout_ms_read, - .store = r2nm_cluster_attr_idle_timeout_ms_write, -}; - -static struct r2nm_cluster_attribute r2nm_cluster_attr_keepalive_delay_ms = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "keepalive_delay_ms", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_cluster_attr_keepalive_delay_ms_read, - .store = r2nm_cluster_attr_keepalive_delay_ms_write, -}; - -static struct r2nm_cluster_attribute r2nm_cluster_attr_reconnect_delay_ms = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "reconnect_delay_ms", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_cluster_attr_reconnect_delay_ms_read, - .store = r2nm_cluster_attr_reconnect_delay_ms_write, -}; - -static struct r2nm_cluster_attribute r2nm_cluster_attr_fence_method = { - .attr = { .ca_owner = THIS_MODULE, - .ca_name = "fence_method", - .ca_mode = S_IRUGO | S_IWUSR }, - .show = r2nm_cluster_attr_fence_method_read, - .store = r2nm_cluster_attr_fence_method_write, -}; - -static struct configfs_attribute *r2nm_cluster_attrs[] = { - &r2nm_cluster_attr_idle_timeout_ms.attr, - &r2nm_cluster_attr_keepalive_delay_ms.attr, - &r2nm_cluster_attr_reconnect_delay_ms.attr, - &r2nm_cluster_attr_fence_method.attr, - NULL, -}; -static ssize_t r2nm_cluster_show(struct config_item *item, - struct configfs_attribute *attr, - char *page) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster(item); - struct r2nm_cluster_attribute *r2nm_cluster_attr = - container_of(attr, struct r2nm_cluster_attribute, attr); - ssize_t ret = 0; - - if (r2nm_cluster_attr->show) - ret = r2nm_cluster_attr->show(cluster, page); - return ret; -} - -static ssize_t r2nm_cluster_store(struct config_item *item, - struct configfs_attribute *attr, - const char *page, size_t count) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster(item); - struct r2nm_cluster_attribute *r2nm_cluster_attr = - container_of(attr, struct r2nm_cluster_attribute, attr); - ssize_t ret; - - if (r2nm_cluster_attr->store == NULL) { - ret = -EINVAL; - goto out; - } - - ret = r2nm_cluster_attr->store(cluster, page, count); - if (ret < count) - goto out; -out: - return ret; -} - -static struct config_item *r2nm_node_group_make_item(struct config_group *group, - const char *name) -{ - struct r2nm_node *node = NULL; - - if (strlen(name) > R2NM_MAX_NAME_LEN) - return ERR_PTR(-ENAMETOOLONG); - - node = kzalloc(sizeof(struct r2nm_node), GFP_KERNEL); - if (node == NULL) - return ERR_PTR(-ENOMEM); - - strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */ - config_item_init_type_name(&node->nd_item, name, &r2nm_node_type); - spin_lock_init(&node->nd_lock); - - mlog(ML_CLUSTER, "r2nm: Registering node %s\n", name); - - return &node->nd_item; -} - -static void r2nm_node_group_drop_item(struct config_group *group, - struct config_item *item) -{ - struct r2nm_node *node = to_r2nm_node(item); - struct r2nm_cluster *cluster = - to_r2nm_cluster(group->cg_item.ci_parent); - - r2net_disconnect_node(node); - - if (cluster->cl_has_local && - (cluster->cl_local_node == node->nd_num)) { - cluster->cl_has_local = 0; - cluster->cl_local_node = R2NM_INVALID_NODE_NUM; - r2net_stop_listening(node); - } - - /* XXX call into net to stop this node from trading messages */ - - write_lock(&cluster->cl_nodes_lock); - - /* XXX sloppy */ - if (node->nd_ipv4_address) - rb_erase(&node->nd_ip_node, &cluster->cl_node_ip_tree); - - /* nd_num might be 0 if the node number hasn't been set.. */ - if (cluster->cl_nodes[node->nd_num] == node) { - cluster->cl_nodes[node->nd_num] = NULL; - clear_bit(node->nd_num, cluster->cl_nodes_bitmap); - } - write_unlock(&cluster->cl_nodes_lock); - - mlog(ML_CLUSTER, "r2nm: Unregistered node %s\n", - config_item_name(&node->nd_item)); - - config_item_put(item); -} - -static struct configfs_group_operations r2nm_node_group_group_ops = { - .make_item = r2nm_node_group_make_item, - .drop_item = r2nm_node_group_drop_item, -}; - -static struct config_item_type r2nm_node_group_type = { - .ct_group_ops = &r2nm_node_group_group_ops, - .ct_owner = THIS_MODULE, -}; - -/* cluster */ - -static void r2nm_cluster_release(struct config_item *item) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster(item); - - kfree(cluster->cl_group.default_groups); - kfree(cluster); -} - -static struct configfs_item_operations r2nm_cluster_item_ops = { - .release = r2nm_cluster_release, - .show_attribute = r2nm_cluster_show, - .store_attribute = r2nm_cluster_store, -}; - -static struct config_item_type r2nm_cluster_type = { - .ct_item_ops = &r2nm_cluster_item_ops, - .ct_attrs = r2nm_cluster_attrs, - .ct_owner = THIS_MODULE, -}; - -/* cluster set */ - -struct r2nm_cluster_group { - struct configfs_subsystem cs_subsys; - /* some stuff? */ -}; - -#if 0 -static struct r2nm_cluster_group * -to_r2nm_cluster_group(struct config_group *group) -{ - return group ? - container_of(to_configfs_subsystem(group), - struct r2nm_cluster_group, cs_subsys) - : NULL; -} -#endif - -static struct config_group * -r2nm_cluster_group_make_group(struct config_group *group, - const char *name) -{ - struct r2nm_cluster *cluster = NULL; - struct r2nm_node_group *ns = NULL; - struct config_group *r2hb_group = NULL, *ret = NULL; - void *defs = NULL; - - /* this runs under the parent dir's i_mutex; there can be only - * one caller in here at a time */ - if (r2nm_single_cluster) - return ERR_PTR(-ENOSPC); - - cluster = kzalloc(sizeof(struct r2nm_cluster), GFP_KERNEL); - ns = kzalloc(sizeof(struct r2nm_node_group), GFP_KERNEL); - defs = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL); - r2hb_group = r2hb_alloc_hb_set(); - if (cluster == NULL || ns == NULL || r2hb_group == NULL || defs == NULL) - goto out; - - config_group_init_type_name(&cluster->cl_group, name, - &r2nm_cluster_type); - config_group_init_type_name(&ns->ns_group, "node", - &r2nm_node_group_type); - - cluster->cl_group.default_groups = defs; - cluster->cl_group.default_groups[0] = &ns->ns_group; - cluster->cl_group.default_groups[1] = r2hb_group; - cluster->cl_group.default_groups[2] = NULL; - rwlock_init(&cluster->cl_nodes_lock); - cluster->cl_node_ip_tree = RB_ROOT; - cluster->cl_reconnect_delay_ms = R2NET_RECONNECT_DELAY_MS_DEFAULT; - cluster->cl_idle_timeout_ms = R2NET_IDLE_TIMEOUT_MS_DEFAULT; - cluster->cl_keepalive_delay_ms = R2NET_KEEPALIVE_DELAY_MS_DEFAULT; - cluster->cl_fence_method = R2NM_FENCE_RESET; - - ret = &cluster->cl_group; - r2nm_single_cluster = cluster; - -out: - if (ret == NULL) { - kfree(cluster); - kfree(ns); - r2hb_free_hb_set(r2hb_group); - kfree(defs); - ret = ERR_PTR(-ENOMEM); - } - - return ret; -} - -static void r2nm_cluster_group_drop_item(struct config_group *group, - struct config_item *item) -{ - struct r2nm_cluster *cluster = to_r2nm_cluster(item); - int i; - struct config_item *killme; - - BUG_ON(r2nm_single_cluster != cluster); - r2nm_single_cluster = NULL; - - for (i = 0; cluster->cl_group.default_groups[i]; i++) { - killme = &cluster->cl_group.default_groups[i]->cg_item; - cluster->cl_group.default_groups[i] = NULL; - config_item_put(killme); - } - - config_item_put(item); -} - -static struct configfs_group_operations r2nm_cluster_group_group_ops = { - .make_group = r2nm_cluster_group_make_group, - .drop_item = r2nm_cluster_group_drop_item, -}; - -static struct config_item_type r2nm_cluster_group_type = { - .ct_group_ops = &r2nm_cluster_group_group_ops, - .ct_owner = THIS_MODULE, -}; - -static struct r2nm_cluster_group r2nm_cluster_group = { - .cs_subsys = { - .su_group = { - .cg_item = { - .ci_namebuf = "cluster", - .ci_type = &r2nm_cluster_group_type, - }, - }, - }, -}; - -int r2nm_depend_item(struct config_item *item) -{ - return configfs_depend_item(&r2nm_cluster_group.cs_subsys, item); -} - -void r2nm_undepend_item(struct config_item *item) -{ - configfs_undepend_item(&r2nm_cluster_group.cs_subsys, item); -} - -int r2nm_depend_this_node(void) -{ - int ret = 0; - struct r2nm_node *local_node; - - local_node = r2nm_get_node_by_num(r2nm_this_node()); - if (!local_node) { - ret = -EINVAL; - goto out; - } - - ret = r2nm_depend_item(&local_node->nd_item); - r2nm_node_put(local_node); - -out: - return ret; -} - -void r2nm_undepend_this_node(void) -{ - struct r2nm_node *local_node; - - local_node = r2nm_get_node_by_num(r2nm_this_node()); - BUG_ON(!local_node); - - r2nm_undepend_item(&local_node->nd_item); - r2nm_node_put(local_node); -} - - -static void __exit exit_r2nm(void) -{ - /* XXX sync with hb callbacks and shut down hb? */ - r2net_unregister_hb_callbacks(); - configfs_unregister_subsystem(&r2nm_cluster_group.cs_subsys); - - r2net_exit(); - r2hb_exit(); -} - -static int __init init_r2nm(void) -{ - int ret = -1; - - ret = r2hb_init(); - if (ret) - goto out; - - ret = r2net_init(); - if (ret) - goto out_r2hb; - - ret = r2net_register_hb_callbacks(); - if (ret) - goto out_r2net; - - config_group_init(&r2nm_cluster_group.cs_subsys.su_group); - mutex_init(&r2nm_cluster_group.cs_subsys.su_mutex); - ret = configfs_register_subsystem(&r2nm_cluster_group.cs_subsys); - if (ret) { - pr_err("nodemanager: Registration returned %d\n", ret); - goto out_callbacks; - } - - if (!ret) - goto out; - - configfs_unregister_subsystem(&r2nm_cluster_group.cs_subsys); -out_callbacks: - r2net_unregister_hb_callbacks(); -out_r2net: - r2net_exit(); -out_r2hb: - r2hb_exit(); -out: - return ret; -} - -MODULE_AUTHOR("Oracle"); -MODULE_LICENSE("GPL"); - -/* module_init(init_r2nm) */ -late_initcall(init_r2nm); -/* module_exit(exit_r2nm) */ diff --git a/drivers/staging/ramster/ramster/nodemanager.h b/drivers/staging/ramster/ramster/nodemanager.h deleted file mode 100644 index 41a04df..0000000 --- a/drivers/staging/ramster/ramster/nodemanager.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * nodemanager.h - * - * Function prototypes - * - * Copyright (C) 2004 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - * - */ - -#ifndef R2CLUSTER_NODEMANAGER_H -#define R2CLUSTER_NODEMANAGER_H - -#include "ramster_nodemanager.h" - -/* This totally doesn't belong here. */ -#include -#include - -enum r2nm_fence_method { - R2NM_FENCE_RESET = 0, - R2NM_FENCE_PANIC, - R2NM_FENCE_METHODS, /* Number of fence methods */ -}; - -struct r2nm_node { - spinlock_t nd_lock; - struct config_item nd_item; - char nd_name[R2NM_MAX_NAME_LEN+1]; /* replace? */ - __u8 nd_num; - /* only one address per node, as attributes, for now. */ - __be32 nd_ipv4_address; - __be16 nd_ipv4_port; - struct rb_node nd_ip_node; - /* there can be only one local node for now */ - int nd_local; - - unsigned long nd_set_attributes; -}; - -struct r2nm_cluster { - struct config_group cl_group; - unsigned cl_has_local:1; - u8 cl_local_node; - rwlock_t cl_nodes_lock; - struct r2nm_node *cl_nodes[R2NM_MAX_NODES]; - struct rb_root cl_node_ip_tree; - unsigned int cl_idle_timeout_ms; - unsigned int cl_keepalive_delay_ms; - unsigned int cl_reconnect_delay_ms; - enum r2nm_fence_method cl_fence_method; - - /* part of a hack for disk bitmap.. will go eventually. - zab */ - unsigned long cl_nodes_bitmap[BITS_TO_LONGS(R2NM_MAX_NODES)]; -}; - -extern struct r2nm_cluster *r2nm_single_cluster; - -u8 r2nm_this_node(void); - -int r2nm_configured_node_map(unsigned long *map, unsigned bytes); -struct r2nm_node *r2nm_get_node_by_num(u8 node_num); -struct r2nm_node *r2nm_get_node_by_ip(__be32 addr); -void r2nm_node_get(struct r2nm_node *node); -void r2nm_node_put(struct r2nm_node *node); - -int r2nm_depend_item(struct config_item *item); -void r2nm_undepend_item(struct config_item *item); -int r2nm_depend_this_node(void); -void r2nm_undepend_this_node(void); - -#endif /* R2CLUSTER_NODEMANAGER_H */ diff --git a/drivers/staging/ramster/ramster/r2net.c b/drivers/staging/ramster/ramster/r2net.c deleted file mode 100644 index 34818dc..0000000 --- a/drivers/staging/ramster/ramster/r2net.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * r2net.c - * - * Copyright (c) 2011-2012, Dan Magenheimer, Oracle Corp. - * - * Ramster_r2net provides an interface between zcache and r2net. - * - * FIXME: support more than two nodes - */ - -#include -#include "tcp.h" -#include "nodemanager.h" -#include "../tmem.h" -#include "../zcache.h" -#include "ramster.h" - -#define RAMSTER_TESTING - -#define RMSTR_KEY 0x77347734 - -enum { - RMSTR_TMEM_PUT_EPH = 100, - RMSTR_TMEM_PUT_PERS, - RMSTR_TMEM_ASYNC_GET_REQUEST, - RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST, - RMSTR_TMEM_ASYNC_GET_REPLY, - RMSTR_TMEM_FLUSH, - RMSTR_TMEM_FLOBJ, - RMSTR_TMEM_DESTROY_POOL, -}; - -#define RMSTR_R2NET_MAX_LEN \ - (R2NET_MAX_PAYLOAD_BYTES - sizeof(struct tmem_xhandle)) - -#include "tcp_internal.h" - -static struct r2nm_node *r2net_target_node; -static int r2net_target_nodenum; - -int r2net_remote_target_node_set(int node_num) -{ - int ret = -1; - - r2net_target_node = r2nm_get_node_by_num(node_num); - if (r2net_target_node != NULL) { - r2net_target_nodenum = node_num; - r2nm_node_put(r2net_target_node); - ret = 0; - } - return ret; -} - -/* FIXME following buffer should be per-cpu, protected by preempt_disable */ -static char ramster_async_get_buf[R2NET_MAX_PAYLOAD_BYTES]; - -static int ramster_remote_async_get_request_handler(struct r2net_msg *msg, - u32 len, void *data, void **ret_data) -{ - char *pdata; - struct tmem_xhandle xh; - int found; - size_t size = RMSTR_R2NET_MAX_LEN; - u16 msgtype = be16_to_cpu(msg->msg_type); - bool get_and_free = (msgtype == RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST); - unsigned long flags; - - xh = *(struct tmem_xhandle *)msg->buf; - if (xh.xh_data_size > RMSTR_R2NET_MAX_LEN) - BUG(); - pdata = ramster_async_get_buf; - *(struct tmem_xhandle *)pdata = xh; - pdata += sizeof(struct tmem_xhandle); - local_irq_save(flags); - found = zcache_get_page(xh.client_id, xh.pool_id, &xh.oid, xh.index, - pdata, &size, true, get_and_free ? 1 : -1); - local_irq_restore(flags); - if (found < 0) { - /* a zero size indicates the get failed */ - size = 0; - } - if (size > RMSTR_R2NET_MAX_LEN) - BUG(); - *ret_data = pdata - sizeof(struct tmem_xhandle); - /* now make caller (r2net_process_message) handle specially */ - r2net_force_data_magic(msg, RMSTR_TMEM_ASYNC_GET_REPLY, RMSTR_KEY); - return size + sizeof(struct tmem_xhandle); -} - -static int ramster_remote_async_get_reply_handler(struct r2net_msg *msg, - u32 len, void *data, void **ret_data) -{ - char *in = (char *)msg->buf; - int datalen = len - sizeof(struct r2net_msg); - int ret = -1; - struct tmem_xhandle *xh = (struct tmem_xhandle *)in; - - in += sizeof(struct tmem_xhandle); - datalen -= sizeof(struct tmem_xhandle); - BUG_ON(datalen < 0 || datalen > PAGE_SIZE); - ret = ramster_localify(xh->pool_id, &xh->oid, xh->index, - in, datalen, xh->extra); -#ifdef RAMSTER_TESTING - if (ret == -EEXIST) - pr_err("TESTING ArrgREP, aborted overwrite on racy put\n"); -#endif - return ret; -} - -int ramster_remote_put_handler(struct r2net_msg *msg, - u32 len, void *data, void **ret_data) -{ - struct tmem_xhandle *xh; - char *p = (char *)msg->buf; - int datalen = len - sizeof(struct r2net_msg) - - sizeof(struct tmem_xhandle); - u16 msgtype = be16_to_cpu(msg->msg_type); - bool ephemeral = (msgtype == RMSTR_TMEM_PUT_EPH); - unsigned long flags; - int ret; - - xh = (struct tmem_xhandle *)p; - p += sizeof(struct tmem_xhandle); - zcache_autocreate_pool(xh->client_id, xh->pool_id, ephemeral); - local_irq_save(flags); - ret = zcache_put_page(xh->client_id, xh->pool_id, &xh->oid, xh->index, - p, datalen, true, ephemeral); - local_irq_restore(flags); - return ret; -} - -int ramster_remote_flush_handler(struct r2net_msg *msg, - u32 len, void *data, void **ret_data) -{ - struct tmem_xhandle *xh; - char *p = (char *)msg->buf; - - xh = (struct tmem_xhandle *)p; - p += sizeof(struct tmem_xhandle); - (void)zcache_flush_page(xh->client_id, xh->pool_id, - &xh->oid, xh->index); - return 0; -} - -int ramster_remote_flobj_handler(struct r2net_msg *msg, - u32 len, void *data, void **ret_data) -{ - struct tmem_xhandle *xh; - char *p = (char *)msg->buf; - - xh = (struct tmem_xhandle *)p; - p += sizeof(struct tmem_xhandle); - (void)zcache_flush_object(xh->client_id, xh->pool_id, &xh->oid); - return 0; -} - -int r2net_remote_async_get(struct tmem_xhandle *xh, bool free, int remotenode, - size_t expect_size, uint8_t expect_cksum, - void *extra) -{ - int nodenum, ret = -1, status; - struct r2nm_node *node = NULL; - struct kvec vec[1]; - size_t veclen = 1; - u32 msg_type; - struct r2net_node *nn; - - node = r2nm_get_node_by_num(remotenode); - if (node == NULL) - goto out; - xh->client_id = r2nm_this_node(); /* which node is getting */ - xh->xh_data_cksum = expect_cksum; - xh->xh_data_size = expect_size; - xh->extra = extra; - vec[0].iov_len = sizeof(*xh); - vec[0].iov_base = xh; - - node = r2net_target_node; - if (!node) - goto out; - - nodenum = r2net_target_nodenum; - - r2nm_node_get(node); - nn = r2net_nn_from_num(nodenum); - if (nn->nn_persistent_error || !nn->nn_sc_valid) { - ret = -ENOTCONN; - r2nm_node_put(node); - goto out; - } - - if (free) - msg_type = RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST; - else - msg_type = RMSTR_TMEM_ASYNC_GET_REQUEST; - ret = r2net_send_message_vec(msg_type, RMSTR_KEY, - vec, veclen, remotenode, &status); - r2nm_node_put(node); - if (ret < 0) { - if (ret == -ENOTCONN || ret == -EHOSTDOWN) - goto out; - if (ret == -EAGAIN) - goto out; - /* FIXME handle bad message possibilities here? */ - pr_err("UNTESTED ret<0 in ramster_remote_async_get: ret=%d\n", - ret); - } - ret = status; -out: - return ret; -} - -#ifdef RAMSTER_TESTING -/* leave me here to see if it catches a weird crash */ -static void ramster_check_irq_counts(void) -{ - static int last_hardirq_cnt, last_softirq_cnt, last_preempt_cnt; - int cur_hardirq_cnt, cur_softirq_cnt, cur_preempt_cnt; - - cur_hardirq_cnt = hardirq_count() >> HARDIRQ_SHIFT; - if (cur_hardirq_cnt > last_hardirq_cnt) { - last_hardirq_cnt = cur_hardirq_cnt; - if (!(last_hardirq_cnt&(last_hardirq_cnt-1))) - pr_err("RAMSTER TESTING RRP hardirq_count=%d\n", - last_hardirq_cnt); - } - cur_softirq_cnt = softirq_count() >> SOFTIRQ_SHIFT; - if (cur_softirq_cnt > last_softirq_cnt) { - last_softirq_cnt = cur_softirq_cnt; - if (!(last_softirq_cnt&(last_softirq_cnt-1))) - pr_err("RAMSTER TESTING RRP softirq_count=%d\n", - last_softirq_cnt); - } - cur_preempt_cnt = preempt_count() & PREEMPT_MASK; - if (cur_preempt_cnt > last_preempt_cnt) { - last_preempt_cnt = cur_preempt_cnt; - if (!(last_preempt_cnt&(last_preempt_cnt-1))) - pr_err("RAMSTER TESTING RRP preempt_count=%d\n", - last_preempt_cnt); - } -} -#endif - -int r2net_remote_put(struct tmem_xhandle *xh, char *data, size_t size, - bool ephemeral, int *remotenode) -{ - int nodenum, ret = -1, status; - struct r2nm_node *node = NULL; - struct kvec vec[2]; - size_t veclen = 2; - u32 msg_type; - struct r2net_node *nn; - - BUG_ON(size > RMSTR_R2NET_MAX_LEN); - xh->client_id = r2nm_this_node(); /* which node is putting */ - vec[0].iov_len = sizeof(*xh); - vec[0].iov_base = xh; - vec[1].iov_len = size; - vec[1].iov_base = data; - - node = r2net_target_node; - if (!node) - goto out; - - nodenum = r2net_target_nodenum; - - r2nm_node_get(node); - - nn = r2net_nn_from_num(nodenum); - if (nn->nn_persistent_error || !nn->nn_sc_valid) { - ret = -ENOTCONN; - r2nm_node_put(node); - goto out; - } - - if (ephemeral) - msg_type = RMSTR_TMEM_PUT_EPH; - else - msg_type = RMSTR_TMEM_PUT_PERS; -#ifdef RAMSTER_TESTING - /* leave me here to see if it catches a weird crash */ - ramster_check_irq_counts(); -#endif - - ret = r2net_send_message_vec(msg_type, RMSTR_KEY, vec, veclen, - nodenum, &status); - if (ret < 0) - ret = -1; - else { - ret = status; - *remotenode = nodenum; - } - - r2nm_node_put(node); -out: - return ret; -} - -int r2net_remote_flush(struct tmem_xhandle *xh, int remotenode) -{ - int ret = -1, status; - struct r2nm_node *node = NULL; - struct kvec vec[1]; - size_t veclen = 1; - - node = r2nm_get_node_by_num(remotenode); - BUG_ON(node == NULL); - xh->client_id = r2nm_this_node(); /* which node is flushing */ - vec[0].iov_len = sizeof(*xh); - vec[0].iov_base = xh; - BUG_ON(irqs_disabled()); - BUG_ON(in_softirq()); - ret = r2net_send_message_vec(RMSTR_TMEM_FLUSH, RMSTR_KEY, - vec, veclen, remotenode, &status); - r2nm_node_put(node); - return ret; -} - -int r2net_remote_flush_object(struct tmem_xhandle *xh, int remotenode) -{ - int ret = -1, status; - struct r2nm_node *node = NULL; - struct kvec vec[1]; - size_t veclen = 1; - - node = r2nm_get_node_by_num(remotenode); - BUG_ON(node == NULL); - xh->client_id = r2nm_this_node(); /* which node is flobjing */ - vec[0].iov_len = sizeof(*xh); - vec[0].iov_base = xh; - ret = r2net_send_message_vec(RMSTR_TMEM_FLOBJ, RMSTR_KEY, - vec, veclen, remotenode, &status); - r2nm_node_put(node); - return ret; -} - -/* - * Handler registration - */ - -static LIST_HEAD(r2net_unreg_list); - -static void r2net_unregister_handlers(void) -{ - r2net_unregister_handler_list(&r2net_unreg_list); -} - -int r2net_register_handlers(void) -{ - int status; - - status = r2net_register_handler(RMSTR_TMEM_PUT_EPH, RMSTR_KEY, - RMSTR_R2NET_MAX_LEN, - ramster_remote_put_handler, - NULL, NULL, &r2net_unreg_list); - if (status) - goto bail; - - status = r2net_register_handler(RMSTR_TMEM_PUT_PERS, RMSTR_KEY, - RMSTR_R2NET_MAX_LEN, - ramster_remote_put_handler, - NULL, NULL, &r2net_unreg_list); - if (status) - goto bail; - - status = r2net_register_handler(RMSTR_TMEM_ASYNC_GET_REQUEST, RMSTR_KEY, - RMSTR_R2NET_MAX_LEN, - ramster_remote_async_get_request_handler, - NULL, NULL, - &r2net_unreg_list); - if (status) - goto bail; - - status = r2net_register_handler(RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST, - RMSTR_KEY, RMSTR_R2NET_MAX_LEN, - ramster_remote_async_get_request_handler, - NULL, NULL, - &r2net_unreg_list); - if (status) - goto bail; - - status = r2net_register_handler(RMSTR_TMEM_ASYNC_GET_REPLY, RMSTR_KEY, - RMSTR_R2NET_MAX_LEN, - ramster_remote_async_get_reply_handler, - NULL, NULL, - &r2net_unreg_list); - if (status) - goto bail; - - status = r2net_register_handler(RMSTR_TMEM_FLUSH, RMSTR_KEY, - RMSTR_R2NET_MAX_LEN, - ramster_remote_flush_handler, - NULL, NULL, - &r2net_unreg_list); - if (status) - goto bail; - - status = r2net_register_handler(RMSTR_TMEM_FLOBJ, RMSTR_KEY, - RMSTR_R2NET_MAX_LEN, - ramster_remote_flobj_handler, - NULL, NULL, - &r2net_unreg_list); - if (status) - goto bail; - - pr_info("ramster: r2net handlers registered\n"); - -bail: - if (status) { - r2net_unregister_handlers(); - pr_err("ramster: couldn't register r2net handlers\n"); - } - return status; -} diff --git a/drivers/staging/ramster/ramster/ramster.c b/drivers/staging/ramster/ramster/ramster.c deleted file mode 100644 index c06709f..0000000 --- a/drivers/staging/ramster/ramster/ramster.c +++ /dev/null @@ -1,985 +0,0 @@ -/* - * ramster.c - * - * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. - * - * RAMster implements peer-to-peer transcendent memory, allowing a "cluster" of - * kernels to dynamically pool their RAM so that a RAM-hungry workload on one - * machine can temporarily and transparently utilize RAM on another machine - * which is presumably idle or running a non-RAM-hungry workload. - * - * RAMster combines a clustering and messaging foundation based on the ocfs2 - * cluster layer with the in-kernel compression implementation of zcache, and - * adds code to glue them together. When a page is "put" to RAMster, it is - * compressed and stored locally. Periodically, a thread will "remotify" these - * pages by sending them via messages to a remote machine. When the page is - * later needed as indicated by a page fault, a "get" is issued. If the data - * is local, it is uncompressed and the fault is resolved. If the data is - * remote, a message is sent to fetch the data and the faulting thread sleeps; - * when the data arrives, the thread awakens, the data is decompressed and - * the fault is resolved. - - * As of V5, clusters up to eight nodes are supported; each node can remotify - * pages to one specified node, so clusters can be configured as clients to - * a "memory server". Some simple policy is in place that will need to be - * refined over time. Larger clusters and fault-resistant protocols can also - * be added over time. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../tmem.h" -#include "../zcache.h" -#include "../zbud.h" -#include "ramster.h" -#include "ramster_nodemanager.h" -#include "tcp.h" - -#define RAMSTER_TESTING - -#ifndef CONFIG_SYSFS -#error "ramster needs sysfs to define cluster nodes to use" -#endif - -static bool use_cleancache __read_mostly; -static bool use_frontswap __read_mostly; -static bool use_frontswap_exclusive_gets __read_mostly; - -/* These must be sysfs not debugfs as they are checked/used by userland!! */ -static unsigned long ramster_interface_revision __read_mostly = - R2NM_API_VERSION; /* interface revision must match userspace! */ -static unsigned long ramster_pers_remotify_enable __read_mostly; -static unsigned long ramster_eph_remotify_enable __read_mostly; -static atomic_t ramster_remote_pers_pages = ATOMIC_INIT(0); -#define MANUAL_NODES 8 -static bool ramster_nodes_manual_up[MANUAL_NODES] __read_mostly; -static int ramster_remote_target_nodenum __read_mostly = -1; - -/* these counters are made available via debugfs */ -static long ramster_flnodes; -static atomic_t ramster_flnodes_atomic = ATOMIC_INIT(0); -static unsigned long ramster_flnodes_max; -static long ramster_foreign_eph_pages; -static atomic_t ramster_foreign_eph_pages_atomic = ATOMIC_INIT(0); -static unsigned long ramster_foreign_eph_pages_max; -static long ramster_foreign_pers_pages; -static atomic_t ramster_foreign_pers_pages_atomic = ATOMIC_INIT(0); -static unsigned long ramster_foreign_pers_pages_max; -static unsigned long ramster_eph_pages_remoted; -static unsigned long ramster_pers_pages_remoted; -static unsigned long ramster_eph_pages_remote_failed; -static unsigned long ramster_pers_pages_remote_failed; -static unsigned long ramster_remote_eph_pages_succ_get; -static unsigned long ramster_remote_pers_pages_succ_get; -static unsigned long ramster_remote_eph_pages_unsucc_get; -static unsigned long ramster_remote_pers_pages_unsucc_get; -static unsigned long ramster_pers_pages_remote_nomem; -static unsigned long ramster_remote_objects_flushed; -static unsigned long ramster_remote_object_flushes_failed; -static unsigned long ramster_remote_pages_flushed; -static unsigned long ramster_remote_page_flushes_failed; -/* FIXME frontswap selfshrinking knobs in debugfs? */ - -#ifdef CONFIG_DEBUG_FS -#include -#define zdfs debugfs_create_size_t -#define zdfs64 debugfs_create_u64 -static int __init ramster_debugfs_init(void) -{ - struct dentry *root = debugfs_create_dir("ramster", NULL); - if (root == NULL) - return -ENXIO; - - zdfs("eph_pages_remoted", S_IRUGO, root, &ramster_eph_pages_remoted); - zdfs("pers_pages_remoted", S_IRUGO, root, &ramster_pers_pages_remoted); - zdfs("eph_pages_remote_failed", S_IRUGO, root, - &ramster_eph_pages_remote_failed); - zdfs("pers_pages_remote_failed", S_IRUGO, root, - &ramster_pers_pages_remote_failed); - zdfs("remote_eph_pages_succ_get", S_IRUGO, root, - &ramster_remote_eph_pages_succ_get); - zdfs("remote_pers_pages_succ_get", S_IRUGO, root, - &ramster_remote_pers_pages_succ_get); - zdfs("remote_eph_pages_unsucc_get", S_IRUGO, root, - &ramster_remote_eph_pages_unsucc_get); - zdfs("remote_pers_pages_unsucc_get", S_IRUGO, root, - &ramster_remote_pers_pages_unsucc_get); - zdfs("pers_pages_remote_nomem", S_IRUGO, root, - &ramster_pers_pages_remote_nomem); - zdfs("remote_objects_flushed", S_IRUGO, root, - &ramster_remote_objects_flushed); - zdfs("remote_pages_flushed", S_IRUGO, root, - &ramster_remote_pages_flushed); - zdfs("remote_object_flushes_failed", S_IRUGO, root, - &ramster_remote_object_flushes_failed); - zdfs("remote_page_flushes_failed", S_IRUGO, root, - &ramster_remote_page_flushes_failed); - zdfs("foreign_eph_pages", S_IRUGO, root, - &ramster_foreign_eph_pages); - zdfs("foreign_eph_pages_max", S_IRUGO, root, - &ramster_foreign_eph_pages_max); - zdfs("foreign_pers_pages", S_IRUGO, root, - &ramster_foreign_pers_pages); - zdfs("foreign_pers_pages_max", S_IRUGO, root, - &ramster_foreign_pers_pages_max); - return 0; -} -#undef zdebugfs -#undef zdfs64 -#endif - -static LIST_HEAD(ramster_rem_op_list); -static DEFINE_SPINLOCK(ramster_rem_op_list_lock); -static DEFINE_PER_CPU(struct ramster_preload, ramster_preloads); - -static DEFINE_PER_CPU(unsigned char *, ramster_remoteputmem1); -static DEFINE_PER_CPU(unsigned char *, ramster_remoteputmem2); - -static struct kmem_cache *ramster_flnode_cache __read_mostly; - -static struct flushlist_node *ramster_flnode_alloc(struct tmem_pool *pool) -{ - struct flushlist_node *flnode = NULL; - struct ramster_preload *kp; - - kp = &__get_cpu_var(ramster_preloads); - flnode = kp->flnode; - BUG_ON(flnode == NULL); - kp->flnode = NULL; - ramster_flnodes = atomic_inc_return(&ramster_flnodes_atomic); - if (ramster_flnodes > ramster_flnodes_max) - ramster_flnodes_max = ramster_flnodes; - return flnode; -} - -/* the "flush list" asynchronously collects pages to remotely flush */ -#define FLUSH_ENTIRE_OBJECT ((uint32_t)-1) -static void ramster_flnode_free(struct flushlist_node *flnode, - struct tmem_pool *pool) -{ - int flnodes; - - flnodes = atomic_dec_return(&ramster_flnodes_atomic); - BUG_ON(flnodes < 0); - kmem_cache_free(ramster_flnode_cache, flnode); -} - -int ramster_do_preload_flnode(struct tmem_pool *pool) -{ - struct ramster_preload *kp; - struct flushlist_node *flnode; - int ret = -ENOMEM; - - BUG_ON(!irqs_disabled()); - if (unlikely(ramster_flnode_cache == NULL)) - BUG(); - kp = &__get_cpu_var(ramster_preloads); - flnode = kmem_cache_alloc(ramster_flnode_cache, GFP_ATOMIC); - if (unlikely(flnode == NULL) && kp->flnode == NULL) - BUG(); /* FIXME handle more gracefully, but how??? */ - else if (kp->flnode == NULL) - kp->flnode = flnode; - else - kmem_cache_free(ramster_flnode_cache, flnode); - return ret; -} - -/* - * Called by the message handler after a (still compressed) page has been - * fetched from the remote machine in response to an "is_remote" tmem_get - * or persistent tmem_localify. For a tmem_get, "extra" is the address of - * the page that is to be filled to successfully resolve the tmem_get; for - * a (persistent) tmem_localify, "extra" is NULL (as the data is placed only - * in the local zcache). "data" points to "size" bytes of (compressed) data - * passed in the message. In the case of a persistent remote get, if - * pre-allocation was successful (see ramster_repatriate_preload), the page - * is placed into both local zcache and at "extra". - */ -int ramster_localify(int pool_id, struct tmem_oid *oidp, uint32_t index, - char *data, unsigned int size, void *extra) -{ - int ret = -ENOENT; - unsigned long flags; - struct tmem_pool *pool; - bool eph, delete = false; - void *pampd, *saved_hb; - struct tmem_obj *obj; - - pool = zcache_get_pool_by_id(LOCAL_CLIENT, pool_id); - if (unlikely(pool == NULL)) - /* pool doesn't exist anymore */ - goto out; - eph = is_ephemeral(pool); - local_irq_save(flags); /* FIXME: maybe only disable softirqs? */ - pampd = tmem_localify_get_pampd(pool, oidp, index, &obj, &saved_hb); - if (pampd == NULL) { - /* hmmm... must have been a flush while waiting */ -#ifdef RAMSTER_TESTING - pr_err("UNTESTED pampd==NULL in ramster_localify\n"); -#endif - if (eph) - ramster_remote_eph_pages_unsucc_get++; - else - ramster_remote_pers_pages_unsucc_get++; - obj = NULL; - goto finish; - } else if (unlikely(!pampd_is_remote(pampd))) { - /* hmmm... must have been a dup put while waiting */ -#ifdef RAMSTER_TESTING - pr_err("UNTESTED dup while waiting in ramster_localify\n"); -#endif - if (eph) - ramster_remote_eph_pages_unsucc_get++; - else - ramster_remote_pers_pages_unsucc_get++; - obj = NULL; - pampd = NULL; - ret = -EEXIST; - goto finish; - } else if (size == 0) { - /* no remote data, delete the local is_remote pampd */ - pampd = NULL; - if (eph) - ramster_remote_eph_pages_unsucc_get++; - else - BUG(); - delete = true; - goto finish; - } - if (pampd_is_intransit(pampd)) { - /* - * a pampd is marked intransit if it is remote and space has - * been allocated for it locally (note, only happens for - * persistent pages, in which case the remote copy is freed) - */ - BUG_ON(eph); - pampd = pampd_mask_intransit_and_remote(pampd); - zbud_copy_to_zbud(pampd, data, size); - } else { - /* - * setting pampd to NULL tells tmem_localify_finish to leave - * pampd alone... meaning it is left pointing to the - * remote copy - */ - pampd = NULL; - obj = NULL; - } - /* - * but in all cases, we decompress direct-to-memory to complete - * the remotify and return success - */ - BUG_ON(extra == NULL); - zcache_decompress_to_page(data, size, (struct page *)extra); - if (eph) - ramster_remote_eph_pages_succ_get++; - else - ramster_remote_pers_pages_succ_get++; - ret = 0; -finish: - tmem_localify_finish(obj, index, pampd, saved_hb, delete); - zcache_put_pool(pool); - local_irq_restore(flags); -out: - return ret; -} - -void ramster_pampd_new_obj(struct tmem_obj *obj) -{ - obj->extra = NULL; -} - -void ramster_pampd_free_obj(struct tmem_pool *pool, struct tmem_obj *obj, - bool pool_destroy) -{ - struct flushlist_node *flnode; - - BUG_ON(preemptible()); - if (obj->extra == NULL) - return; - if (pool_destroy && is_ephemeral(pool)) - /* FIXME don't bother with remote eph data for now */ - return; - BUG_ON(!pampd_is_remote(obj->extra)); - flnode = ramster_flnode_alloc(pool); - flnode->xh.client_id = pampd_remote_node(obj->extra); - flnode->xh.pool_id = pool->pool_id; - flnode->xh.oid = obj->oid; - flnode->xh.index = FLUSH_ENTIRE_OBJECT; - flnode->rem_op.op = RAMSTER_REMOTIFY_FLUSH_OBJ; - spin_lock(&ramster_rem_op_list_lock); - list_add(&flnode->rem_op.list, &ramster_rem_op_list); - spin_unlock(&ramster_rem_op_list_lock); -} - -/* - * Called on a remote persistent tmem_get to attempt to preallocate - * local storage for the data contained in the remote persistent page. - * If successfully preallocated, returns the pampd, marked as remote and - * in_transit. Else returns NULL. Note that the appropriate tmem data - * structure must be locked. - */ -void *ramster_pampd_repatriate_preload(void *pampd, struct tmem_pool *pool, - struct tmem_oid *oidp, uint32_t index, - bool *intransit) -{ - int clen = pampd_remote_size(pampd), c; - void *ret_pampd = NULL; - unsigned long flags; - struct tmem_handle th; - - BUG_ON(!pampd_is_remote(pampd)); - BUG_ON(is_ephemeral(pool)); - if (use_frontswap_exclusive_gets) - /* don't need local storage */ - goto out; - if (pampd_is_intransit(pampd)) { - /* - * to avoid multiple allocations (and maybe a memory leak) - * don't preallocate if already in the process of being - * repatriated - */ - *intransit = true; - goto out; - } - *intransit = false; - local_irq_save(flags); - th.client_id = pampd_remote_node(pampd); - th.pool_id = pool->pool_id; - th.oid = *oidp; - th.index = index; - ret_pampd = zcache_pampd_create(NULL, clen, true, false, &th); - if (ret_pampd != NULL) { - /* - * a pampd is marked intransit if it is remote and space has - * been allocated for it locally (note, only happens for - * persistent pages, in which case the remote copy is freed) - */ - ret_pampd = pampd_mark_intransit(ret_pampd); - c = atomic_dec_return(&ramster_remote_pers_pages); - WARN_ON_ONCE(c < 0); - } else { - ramster_pers_pages_remote_nomem++; - } - local_irq_restore(flags); -out: - return ret_pampd; -} - -/* - * Called on a remote tmem_get to invoke a message to fetch the page. - * Might sleep so no tmem locks can be held. "extra" is passed - * all the way through the round-trip messaging to ramster_localify. - */ -int ramster_pampd_repatriate(void *fake_pampd, void *real_pampd, - struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index, - bool free, void *extra) -{ - struct tmem_xhandle xh; - int ret; - - if (pampd_is_intransit(real_pampd)) - /* have local space pre-reserved, so free remote copy */ - free = true; - xh = tmem_xhandle_fill(LOCAL_CLIENT, pool, oid, index); - /* unreliable request/response for now */ - ret = r2net_remote_async_get(&xh, free, - pampd_remote_node(fake_pampd), - pampd_remote_size(fake_pampd), - pampd_remote_cksum(fake_pampd), - extra); - return ret; -} - -bool ramster_pampd_is_remote(void *pampd) -{ - return pampd_is_remote(pampd); -} - -int ramster_pampd_replace_in_obj(void *new_pampd, struct tmem_obj *obj) -{ - int ret = -1; - - if (new_pampd != NULL) { - if (obj->extra == NULL) - obj->extra = new_pampd; - /* enforce that all remote pages in an object reside - * in the same node! */ - else if (pampd_remote_node(new_pampd) != - pampd_remote_node((void *)(obj->extra))) - BUG(); - ret = 0; - } - return ret; -} - -void *ramster_pampd_free(void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index, bool acct) -{ - bool eph = is_ephemeral(pool); - void *local_pampd = NULL; - int c; - - BUG_ON(preemptible()); - BUG_ON(!pampd_is_remote(pampd)); - WARN_ON(acct == false); - if (oid == NULL) { - /* - * a NULL oid means to ignore this pampd free - * as the remote freeing will be handled elsewhere - */ - } else if (eph) { - /* FIXME remote flush optional but probably good idea */ - } else if (pampd_is_intransit(pampd)) { - /* did a pers remote get_and_free, so just free local */ - local_pampd = pampd_mask_intransit_and_remote(pampd); - } else { - struct flushlist_node *flnode = - ramster_flnode_alloc(pool); - - flnode->xh.client_id = pampd_remote_node(pampd); - flnode->xh.pool_id = pool->pool_id; - flnode->xh.oid = *oid; - flnode->xh.index = index; - flnode->rem_op.op = RAMSTER_REMOTIFY_FLUSH_PAGE; - spin_lock(&ramster_rem_op_list_lock); - list_add(&flnode->rem_op.list, &ramster_rem_op_list); - spin_unlock(&ramster_rem_op_list_lock); - c = atomic_dec_return(&ramster_remote_pers_pages); - WARN_ON_ONCE(c < 0); - } - return local_pampd; -} - -void ramster_count_foreign_pages(bool eph, int count) -{ - int c; - - BUG_ON(count != 1 && count != -1); - if (eph) { - if (count > 0) { - c = atomic_inc_return( - &ramster_foreign_eph_pages_atomic); - if (c > ramster_foreign_eph_pages_max) - ramster_foreign_eph_pages_max = c; - } else { - c = atomic_dec_return(&ramster_foreign_eph_pages_atomic); - WARN_ON_ONCE(c < 0); - } - ramster_foreign_eph_pages = c; - } else { - if (count > 0) { - c = atomic_inc_return( - &ramster_foreign_pers_pages_atomic); - if (c > ramster_foreign_pers_pages_max) - ramster_foreign_pers_pages_max = c; - } else { - c = atomic_dec_return( - &ramster_foreign_pers_pages_atomic); - WARN_ON_ONCE(c < 0); - } - ramster_foreign_pers_pages = c; - } -} - -/* - * For now, just push over a few pages every few seconds to - * ensure that it basically works - */ -static struct workqueue_struct *ramster_remotify_workqueue; -static void ramster_remotify_process(struct work_struct *work); -static DECLARE_DELAYED_WORK(ramster_remotify_worker, - ramster_remotify_process); - -static void ramster_remotify_queue_delayed_work(unsigned long delay) -{ - if (!queue_delayed_work(ramster_remotify_workqueue, - &ramster_remotify_worker, delay)) - pr_err("ramster_remotify: bad workqueue\n"); -} - -static void ramster_remote_flush_page(struct flushlist_node *flnode) -{ - struct tmem_xhandle *xh; - int remotenode, ret; - - preempt_disable(); - xh = &flnode->xh; - remotenode = flnode->xh.client_id; - ret = r2net_remote_flush(xh, remotenode); - if (ret >= 0) - ramster_remote_pages_flushed++; - else - ramster_remote_page_flushes_failed++; - preempt_enable_no_resched(); - ramster_flnode_free(flnode, NULL); -} - -static void ramster_remote_flush_object(struct flushlist_node *flnode) -{ - struct tmem_xhandle *xh; - int remotenode, ret; - - preempt_disable(); - xh = &flnode->xh; - remotenode = flnode->xh.client_id; - ret = r2net_remote_flush_object(xh, remotenode); - if (ret >= 0) - ramster_remote_objects_flushed++; - else - ramster_remote_object_flushes_failed++; - preempt_enable_no_resched(); - ramster_flnode_free(flnode, NULL); -} - -int ramster_remotify_pageframe(bool eph) -{ - struct tmem_xhandle xh; - unsigned int size; - int remotenode, ret, zbuds; - struct tmem_pool *pool; - unsigned long flags; - unsigned char cksum; - char *p; - int i, j; - unsigned char *tmpmem[2]; - struct tmem_handle th[2]; - unsigned int zsize[2]; - - tmpmem[0] = __get_cpu_var(ramster_remoteputmem1); - tmpmem[1] = __get_cpu_var(ramster_remoteputmem2); - local_bh_disable(); - zbuds = zbud_make_zombie_lru(&th[0], &tmpmem[0], &zsize[0], eph); - /* now OK to release lock set in caller */ - local_bh_enable(); - if (zbuds == 0) - goto out; - BUG_ON(zbuds > 2); - for (i = 0; i < zbuds; i++) { - xh.client_id = th[i].client_id; - xh.pool_id = th[i].pool_id; - xh.oid = th[i].oid; - xh.index = th[i].index; - size = zsize[i]; - BUG_ON(size == 0 || size > zbud_max_buddy_size()); - for (p = tmpmem[i], cksum = 0, j = 0; j < size; j++) - cksum += *p++; - ret = r2net_remote_put(&xh, tmpmem[i], size, eph, &remotenode); - if (ret != 0) { - /* - * This is some form of a memory leak... if the remote put - * fails, there will never be another attempt to remotify - * this page. But since we've dropped the zv pointer, - * the page may have been freed or the data replaced - * so we can't just "put it back" in the remote op list. - * Even if we could, not sure where to put it in the list - * because there may be flushes that must be strictly - * ordered vs the put. So leave this as a FIXME for now. - * But count them so we know if it becomes a problem. - */ - if (eph) - ramster_eph_pages_remote_failed++; - else - ramster_pers_pages_remote_failed++; - break; - } else { - if (!eph) - atomic_inc(&ramster_remote_pers_pages); - } - if (eph) - ramster_eph_pages_remoted++; - else - ramster_pers_pages_remoted++; - /* - * data was successfully remoted so change the local version to - * point to the remote node where it landed - */ - local_bh_disable(); - pool = zcache_get_pool_by_id(LOCAL_CLIENT, xh.pool_id); - local_irq_save(flags); - (void)tmem_replace(pool, &xh.oid, xh.index, - pampd_make_remote(remotenode, size, cksum)); - local_irq_restore(flags); - zcache_put_pool(pool); - local_bh_enable(); - } -out: - return zbuds; -} - -static void zcache_do_remotify_flushes(void) -{ - struct ramster_remotify_hdr *rem_op; - union remotify_list_node *u; - - while (1) { - spin_lock(&ramster_rem_op_list_lock); - if (list_empty(&ramster_rem_op_list)) { - spin_unlock(&ramster_rem_op_list_lock); - goto out; - } - rem_op = list_first_entry(&ramster_rem_op_list, - struct ramster_remotify_hdr, list); - list_del_init(&rem_op->list); - spin_unlock(&ramster_rem_op_list_lock); - u = (union remotify_list_node *)rem_op; - switch (rem_op->op) { - case RAMSTER_REMOTIFY_FLUSH_PAGE: - ramster_remote_flush_page((struct flushlist_node *)u); - break; - case RAMSTER_REMOTIFY_FLUSH_OBJ: - ramster_remote_flush_object((struct flushlist_node *)u); - break; - default: - BUG(); - } - } -out: - return; -} - -static void ramster_remotify_process(struct work_struct *work) -{ - static bool remotify_in_progress; - int i; - - BUG_ON(irqs_disabled()); - if (remotify_in_progress) - goto requeue; - if (ramster_remote_target_nodenum == -1) - goto requeue; - remotify_in_progress = true; - if (use_cleancache && ramster_eph_remotify_enable) { - for (i = 0; i < 100; i++) { - zcache_do_remotify_flushes(); - (void)ramster_remotify_pageframe(true); - } - } - if (use_frontswap && ramster_pers_remotify_enable) { - for (i = 0; i < 100; i++) { - zcache_do_remotify_flushes(); - (void)ramster_remotify_pageframe(false); - } - } - remotify_in_progress = false; -requeue: - ramster_remotify_queue_delayed_work(HZ); -} - -void __init ramster_remotify_init(void) -{ - unsigned long n = 60UL; - ramster_remotify_workqueue = - create_singlethread_workqueue("ramster_remotify"); - ramster_remotify_queue_delayed_work(n * HZ); -} - -static ssize_t ramster_manual_node_up_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - int i; - char *p = buf; - for (i = 0; i < MANUAL_NODES; i++) - if (ramster_nodes_manual_up[i]) - p += sprintf(p, "%d ", i); - p += sprintf(p, "\n"); - return p - buf; -} - -static ssize_t ramster_manual_node_up_store(struct kobject *kobj, - struct kobj_attribute *attr, const char *buf, size_t count) -{ - int err; - unsigned long node_num; - - err = kstrtoul(buf, 10, &node_num); - if (err) { - pr_err("ramster: bad strtoul?\n"); - return -EINVAL; - } - if (node_num >= MANUAL_NODES) { - pr_err("ramster: bad node_num=%lu?\n", node_num); - return -EINVAL; - } - if (ramster_nodes_manual_up[node_num]) { - pr_err("ramster: node %d already up, ignoring\n", - (int)node_num); - } else { - ramster_nodes_manual_up[node_num] = true; - r2net_hb_node_up_manual((int)node_num); - } - return count; -} - -static struct kobj_attribute ramster_manual_node_up_attr = { - .attr = { .name = "manual_node_up", .mode = 0644 }, - .show = ramster_manual_node_up_show, - .store = ramster_manual_node_up_store, -}; - -static ssize_t ramster_remote_target_nodenum_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - if (ramster_remote_target_nodenum == -1UL) - return sprintf(buf, "unset\n"); - else - return sprintf(buf, "%d\n", ramster_remote_target_nodenum); -} - -static ssize_t ramster_remote_target_nodenum_store(struct kobject *kobj, - struct kobj_attribute *attr, const char *buf, size_t count) -{ - int err; - unsigned long node_num; - - err = kstrtoul(buf, 10, &node_num); - if (err) { - pr_err("ramster: bad strtoul?\n"); - return -EINVAL; - } else if (node_num == -1UL) { - pr_err("ramster: disabling all remotification, " - "data may still reside on remote nodes however\n"); - return -EINVAL; - } else if (node_num >= MANUAL_NODES) { - pr_err("ramster: bad node_num=%lu?\n", node_num); - return -EINVAL; - } else if (!ramster_nodes_manual_up[node_num]) { - pr_err("ramster: node %d not up, ignoring setting " - "of remotification target\n", (int)node_num); - } else if (r2net_remote_target_node_set((int)node_num) >= 0) { - pr_info("ramster: node %d set as remotification target\n", - (int)node_num); - ramster_remote_target_nodenum = (int)node_num; - } else { - pr_err("ramster: bad num to node node_num=%d?\n", - (int)node_num); - return -EINVAL; - } - return count; -} - -static struct kobj_attribute ramster_remote_target_nodenum_attr = { - .attr = { .name = "remote_target_nodenum", .mode = 0644 }, - .show = ramster_remote_target_nodenum_show, - .store = ramster_remote_target_nodenum_store, -}; - -#define RAMSTER_SYSFS_RO(_name) \ - static ssize_t ramster_##_name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ - { \ - return sprintf(buf, "%lu\n", ramster_##_name); \ - } \ - static struct kobj_attribute ramster_##_name##_attr = { \ - .attr = { .name = __stringify(_name), .mode = 0444 }, \ - .show = ramster_##_name##_show, \ - } - -#define RAMSTER_SYSFS_RW(_name) \ - static ssize_t ramster_##_name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ - { \ - return sprintf(buf, "%lu\n", ramster_##_name); \ - } \ - static ssize_t ramster_##_name##_store(struct kobject *kobj, \ - struct kobj_attribute *attr, const char *buf, size_t count) \ - { \ - int err; \ - unsigned long enable; \ - err = kstrtoul(buf, 10, &enable); \ - if (err) \ - return -EINVAL; \ - ramster_##_name = enable; \ - return count; \ - } \ - static struct kobj_attribute ramster_##_name##_attr = { \ - .attr = { .name = __stringify(_name), .mode = 0644 }, \ - .show = ramster_##_name##_show, \ - .store = ramster_##_name##_store, \ - } - -#define RAMSTER_SYSFS_RO_ATOMIC(_name) \ - static ssize_t ramster_##_name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ - { \ - return sprintf(buf, "%d\n", atomic_read(&ramster_##_name)); \ - } \ - static struct kobj_attribute ramster_##_name##_attr = { \ - .attr = { .name = __stringify(_name), .mode = 0444 }, \ - .show = ramster_##_name##_show, \ - } - -RAMSTER_SYSFS_RO(interface_revision); -RAMSTER_SYSFS_RO_ATOMIC(remote_pers_pages); -RAMSTER_SYSFS_RW(pers_remotify_enable); -RAMSTER_SYSFS_RW(eph_remotify_enable); - -static struct attribute *ramster_attrs[] = { - &ramster_interface_revision_attr.attr, - &ramster_remote_pers_pages_attr.attr, - &ramster_manual_node_up_attr.attr, - &ramster_remote_target_nodenum_attr.attr, - &ramster_pers_remotify_enable_attr.attr, - &ramster_eph_remotify_enable_attr.attr, - NULL, -}; - -static struct attribute_group ramster_attr_group = { - .attrs = ramster_attrs, - .name = "ramster", -}; - -/* - * frontswap selfshrinking - */ - -/* In HZ, controls frequency of worker invocation. */ -static unsigned int selfshrink_interval __read_mostly = 5; -/* Enable/disable with sysfs. */ -static bool frontswap_selfshrinking __read_mostly; - -static void selfshrink_process(struct work_struct *work); -static DECLARE_DELAYED_WORK(selfshrink_worker, selfshrink_process); - -/* Enable/disable with kernel boot option. */ -static bool use_frontswap_selfshrink __initdata = true; - -/* - * The default values for the following parameters were deemed reasonable - * by experimentation, may be workload-dependent, and can all be - * adjusted via sysfs. - */ - -/* Control rate for frontswap shrinking. Higher hysteresis is slower. */ -static unsigned int frontswap_hysteresis __read_mostly = 20; - -/* - * Number of selfshrink worker invocations to wait before observing that - * frontswap selfshrinking should commence. Note that selfshrinking does - * not use a separate worker thread. - */ -static unsigned int frontswap_inertia __read_mostly = 3; - -/* Countdown to next invocation of frontswap_shrink() */ -static unsigned long frontswap_inertia_counter; - -/* - * Invoked by the selfshrink worker thread, uses current number of pages - * in frontswap (frontswap_curr_pages()), previous status, and control - * values (hysteresis and inertia) to determine if frontswap should be - * shrunk and what the new frontswap size should be. Note that - * frontswap_shrink is essentially a partial swapoff that immediately - * transfers pages from the "swap device" (frontswap) back into kernel - * RAM; despite the name, frontswap "shrinking" is very different from - * the "shrinker" interface used by the kernel MM subsystem to reclaim - * memory. - */ -static void frontswap_selfshrink(void) -{ - static unsigned long cur_frontswap_pages; - static unsigned long last_frontswap_pages; - static unsigned long tgt_frontswap_pages; - - last_frontswap_pages = cur_frontswap_pages; - cur_frontswap_pages = frontswap_curr_pages(); - if (!cur_frontswap_pages || - (cur_frontswap_pages > last_frontswap_pages)) { - frontswap_inertia_counter = frontswap_inertia; - return; - } - if (frontswap_inertia_counter && --frontswap_inertia_counter) - return; - if (cur_frontswap_pages <= frontswap_hysteresis) - tgt_frontswap_pages = 0; - else - tgt_frontswap_pages = cur_frontswap_pages - - (cur_frontswap_pages / frontswap_hysteresis); - frontswap_shrink(tgt_frontswap_pages); -} - -static int __init ramster_nofrontswap_selfshrink_setup(char *s) -{ - use_frontswap_selfshrink = false; - return 1; -} - -__setup("noselfshrink", ramster_nofrontswap_selfshrink_setup); - -static void selfshrink_process(struct work_struct *work) -{ - if (frontswap_selfshrinking && frontswap_enabled) { - frontswap_selfshrink(); - schedule_delayed_work(&selfshrink_worker, - selfshrink_interval * HZ); - } -} - -void ramster_cpu_up(int cpu) -{ - unsigned char *p1 = kzalloc(PAGE_SIZE, GFP_KERNEL | __GFP_REPEAT); - unsigned char *p2 = kzalloc(PAGE_SIZE, GFP_KERNEL | __GFP_REPEAT); - BUG_ON(!p1 || !p2); - per_cpu(ramster_remoteputmem1, cpu) = p1; - per_cpu(ramster_remoteputmem2, cpu) = p2; -} - -void ramster_cpu_down(int cpu) -{ - struct ramster_preload *kp; - - kfree(per_cpu(ramster_remoteputmem1, cpu)); - per_cpu(ramster_remoteputmem1, cpu) = NULL; - kfree(per_cpu(ramster_remoteputmem2, cpu)); - per_cpu(ramster_remoteputmem2, cpu) = NULL; - kp = &per_cpu(ramster_preloads, cpu); - if (kp->flnode) { - kmem_cache_free(ramster_flnode_cache, kp->flnode); - kp->flnode = NULL; - } -} - -void ramster_register_pamops(struct tmem_pamops *pamops) -{ - pamops->free_obj = ramster_pampd_free_obj; - pamops->new_obj = ramster_pampd_new_obj; - pamops->replace_in_obj = ramster_pampd_replace_in_obj; - pamops->is_remote = ramster_pampd_is_remote; - pamops->repatriate = ramster_pampd_repatriate; - pamops->repatriate_preload = ramster_pampd_repatriate_preload; -} - -void __init ramster_init(bool cleancache, bool frontswap, - bool frontswap_exclusive_gets) -{ - int ret = 0; - - if (cleancache) - use_cleancache = true; - if (frontswap) - use_frontswap = true; - if (frontswap_exclusive_gets) - use_frontswap_exclusive_gets = true; - ramster_debugfs_init(); - ret = sysfs_create_group(mm_kobj, &ramster_attr_group); - if (ret) - pr_err("ramster: can't create sysfs for ramster\n"); - (void)r2net_register_handlers(); - INIT_LIST_HEAD(&ramster_rem_op_list); - ramster_flnode_cache = kmem_cache_create("ramster_flnode", - sizeof(struct flushlist_node), 0, 0, NULL); - frontswap_selfshrinking = use_frontswap_selfshrink; - if (frontswap_selfshrinking) { - pr_info("ramster: Initializing frontswap selfshrink driver.\n"); - schedule_delayed_work(&selfshrink_worker, - selfshrink_interval * HZ); - } - ramster_remotify_init(); -} diff --git a/drivers/staging/ramster/ramster/ramster.h b/drivers/staging/ramster/ramster/ramster.h deleted file mode 100644 index 12ae56f..0000000 --- a/drivers/staging/ramster/ramster/ramster.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * ramster.h - * - * Peer-to-peer transcendent memory - * - * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. - */ - -#ifndef _RAMSTER_RAMSTER_H_ -#define _RAMSTER_RAMSTER_H_ - -#include "../tmem.h" - -enum ramster_remotify_op { - RAMSTER_REMOTIFY_FLUSH_PAGE, - RAMSTER_REMOTIFY_FLUSH_OBJ, -}; - -struct ramster_remotify_hdr { - enum ramster_remotify_op op; - struct list_head list; -}; - -struct flushlist_node { - struct ramster_remotify_hdr rem_op; - struct tmem_xhandle xh; -}; - -struct ramster_preload { - struct flushlist_node *flnode; -}; - -union remotify_list_node { - struct ramster_remotify_hdr rem_op; - struct { - struct ramster_remotify_hdr rem_op; - struct tmem_handle th; - } zbud_hdr; - struct flushlist_node flist; -}; - -/* - * format of remote pampd: - * bit 0 is reserved for zbud (in-page buddy selection) - * bit 1 == intransit - * bit 2 == is_remote... if this bit is set, then - * bit 3-10 == remotenode - * bit 11-23 == size - * bit 24-31 == cksum - */ -#define FAKE_PAMPD_INTRANSIT_BITS 1 -#define FAKE_PAMPD_ISREMOTE_BITS 1 -#define FAKE_PAMPD_REMOTENODE_BITS 8 -#define FAKE_PAMPD_REMOTESIZE_BITS 13 -#define FAKE_PAMPD_CHECKSUM_BITS 8 - -#define FAKE_PAMPD_INTRANSIT_SHIFT 1 -#define FAKE_PAMPD_ISREMOTE_SHIFT (FAKE_PAMPD_INTRANSIT_SHIFT + \ - FAKE_PAMPD_INTRANSIT_BITS) -#define FAKE_PAMPD_REMOTENODE_SHIFT (FAKE_PAMPD_ISREMOTE_SHIFT + \ - FAKE_PAMPD_ISREMOTE_BITS) -#define FAKE_PAMPD_REMOTESIZE_SHIFT (FAKE_PAMPD_REMOTENODE_SHIFT + \ - FAKE_PAMPD_REMOTENODE_BITS) -#define FAKE_PAMPD_CHECKSUM_SHIFT (FAKE_PAMPD_REMOTESIZE_SHIFT + \ - FAKE_PAMPD_REMOTESIZE_BITS) - -#define FAKE_PAMPD_MASK(x) ((1UL << (x)) - 1) - -static inline void *pampd_make_remote(int remotenode, size_t size, - unsigned char cksum) -{ - unsigned long fake_pampd = 0; - fake_pampd |= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT; - fake_pampd |= ((unsigned long)remotenode & - FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS)) << - FAKE_PAMPD_REMOTENODE_SHIFT; - fake_pampd |= ((unsigned long)size & - FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS)) << - FAKE_PAMPD_REMOTESIZE_SHIFT; - fake_pampd |= ((unsigned long)cksum & - FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS)) << - FAKE_PAMPD_CHECKSUM_SHIFT; - return (void *)fake_pampd; -} - -static inline unsigned int pampd_remote_node(void *pampd) -{ - unsigned long fake_pampd = (unsigned long)pampd; - return (fake_pampd >> FAKE_PAMPD_REMOTENODE_SHIFT) & - FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS); -} - -static inline unsigned int pampd_remote_size(void *pampd) -{ - unsigned long fake_pampd = (unsigned long)pampd; - return (fake_pampd >> FAKE_PAMPD_REMOTESIZE_SHIFT) & - FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS); -} - -static inline unsigned char pampd_remote_cksum(void *pampd) -{ - unsigned long fake_pampd = (unsigned long)pampd; - return (fake_pampd >> FAKE_PAMPD_CHECKSUM_SHIFT) & - FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS); -} - -static inline bool pampd_is_remote(void *pampd) -{ - unsigned long fake_pampd = (unsigned long)pampd; - return (fake_pampd >> FAKE_PAMPD_ISREMOTE_SHIFT) & - FAKE_PAMPD_MASK(FAKE_PAMPD_ISREMOTE_BITS); -} - -static inline bool pampd_is_intransit(void *pampd) -{ - unsigned long fake_pampd = (unsigned long)pampd; - return (fake_pampd >> FAKE_PAMPD_INTRANSIT_SHIFT) & - FAKE_PAMPD_MASK(FAKE_PAMPD_INTRANSIT_BITS); -} - -/* note that it is a BUG for intransit to be set without isremote also set */ -static inline void *pampd_mark_intransit(void *pampd) -{ - unsigned long fake_pampd = (unsigned long)pampd; - - fake_pampd |= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT; - fake_pampd |= 1UL << FAKE_PAMPD_INTRANSIT_SHIFT; - return (void *)fake_pampd; -} - -static inline void *pampd_mask_intransit_and_remote(void *marked_pampd) -{ - unsigned long pampd = (unsigned long)marked_pampd; - - pampd &= ~(1UL << FAKE_PAMPD_INTRANSIT_SHIFT); - pampd &= ~(1UL << FAKE_PAMPD_ISREMOTE_SHIFT); - return (void *)pampd; -} - -extern int r2net_remote_async_get(struct tmem_xhandle *, - bool, int, size_t, uint8_t, void *extra); -extern int r2net_remote_put(struct tmem_xhandle *, char *, size_t, - bool, int *); -extern int r2net_remote_flush(struct tmem_xhandle *, int); -extern int r2net_remote_flush_object(struct tmem_xhandle *, int); -extern int r2net_register_handlers(void); -extern int r2net_remote_target_node_set(int); - -extern int ramster_remotify_pageframe(bool); -extern void ramster_init(bool, bool, bool); -extern void ramster_register_pamops(struct tmem_pamops *); -extern int ramster_localify(int, struct tmem_oid *oidp, uint32_t, char *, - unsigned int, void *); -extern void *ramster_pampd_free(void *, struct tmem_pool *, struct tmem_oid *, - uint32_t, bool); -extern void ramster_count_foreign_pages(bool, int); -extern int ramster_do_preload_flnode(struct tmem_pool *); -extern void ramster_cpu_up(int); -extern void ramster_cpu_down(int); - -#endif /* _RAMSTER_RAMSTER_H */ diff --git a/drivers/staging/ramster/ramster/ramster_nodemanager.h b/drivers/staging/ramster/ramster/ramster_nodemanager.h deleted file mode 100644 index 49f879d..0000000 --- a/drivers/staging/ramster/ramster/ramster_nodemanager.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * ramster_nodemanager.h - * - * Header describing the interface between userspace and the kernel - * for the ramster_nodemanager module. - * - * Copyright (C) 2002, 2004, 2012 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - * - */ - -#ifndef _RAMSTER_NODEMANAGER_H -#define _RAMSTER_NODEMANAGER_H - -#define R2NM_API_VERSION 5 - -#define R2NM_MAX_NODES 255 -#define R2NM_INVALID_NODE_NUM 255 - -/* host name, group name, cluster name all 64 bytes */ -#define R2NM_MAX_NAME_LEN 64 /* __NEW_UTS_LEN */ - -#endif /* _RAMSTER_NODEMANAGER_H */ diff --git a/drivers/staging/ramster/ramster/tcp.c b/drivers/staging/ramster/ramster/tcp.c deleted file mode 100644 index aa2a1a7..0000000 --- a/drivers/staging/ramster/ramster/tcp.c +++ /dev/null @@ -1,2253 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * Copyright (C) 2004 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - * - * ---- - * - * Callers for this were originally written against a very simple synchronus - * API. This implementation reflects those simple callers. Some day I'm sure - * we'll need to move to a more robust posting/callback mechanism. - * - * Transmit calls pass in kernel virtual addresses and block copying this into - * the socket's tx buffers via a usual blocking sendmsg. They'll block waiting - * for a failed socket to timeout. TX callers can also pass in a poniter to an - * 'int' which gets filled with an errno off the wire in response to the - * message they send. - * - * Handlers for unsolicited messages are registered. Each socket has a page - * that incoming data is copied into. First the header, then the data. - * Handlers are called from only one thread with a reference to this per-socket - * page. This page is destroyed after the handler call, so it can't be - * referenced beyond the call. Handlers may block but are discouraged from - * doing so. - * - * Any framing errors (bad magic, large payload lengths) close a connection. - * - * Our sock_container holds the state we associate with a socket. It's current - * framing state is held there as well as the refcounting we do around when it - * is safe to tear down the socket. The socket is only finally torn down from - * the container when the container loses all of its references -- so as long - * as you hold a ref on the container you can trust that the socket is valid - * for use with kernel socket APIs. - * - * Connections are initiated between a pair of nodes when the node with the - * higher node number gets a heartbeat callback which indicates that the lower - * numbered node has started heartbeating. The lower numbered node is passive - * and only accepts the connection if the higher numbered node is heartbeating. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "heartbeat.h" -#include "tcp.h" -#include "nodemanager.h" -#define MLOG_MASK_PREFIX ML_TCP -#include "masklog.h" - -#include "tcp_internal.h" - -#define SC_NODEF_FMT "node %s (num %u) at %pI4:%u" - -/* - * In the following two log macros, the whitespace after the ',' just - * before ##args is intentional. Otherwise, gcc 2.95 will eat the - * previous token if args expands to nothing. - */ -#define msglog(hdr, fmt, args...) do { \ - typeof(hdr) __hdr = (hdr); \ - mlog(ML_MSG, "[mag %u len %u typ %u stat %d sys_stat %d " \ - "key %08x num %u] " fmt, \ - be16_to_cpu(__hdr->magic), be16_to_cpu(__hdr->data_len), \ - be16_to_cpu(__hdr->msg_type), be32_to_cpu(__hdr->status), \ - be32_to_cpu(__hdr->sys_status), be32_to_cpu(__hdr->key), \ - be32_to_cpu(__hdr->msg_num) , ##args); \ -} while (0) - -#define sclog(sc, fmt, args...) do { \ - typeof(sc) __sc = (sc); \ - mlog(ML_SOCKET, "[sc %p refs %d sock %p node %u page %p " \ - "pg_off %zu] " fmt, __sc, \ - atomic_read(&__sc->sc_kref.refcount), __sc->sc_sock, \ - __sc->sc_node->nd_num, __sc->sc_page, __sc->sc_page_off , \ - ##args); \ -} while (0) - -static DEFINE_RWLOCK(r2net_handler_lock); -static struct rb_root r2net_handler_tree = RB_ROOT; - -static struct r2net_node r2net_nodes[R2NM_MAX_NODES]; - -/* XXX someday we'll need better accounting */ -static struct socket *r2net_listen_sock; - -/* - * listen work is only queued by the listening socket callbacks on the - * r2net_wq. teardown detaches the callbacks before destroying the workqueue. - * quorum work is queued as sock containers are shutdown.. stop_listening - * tears down all the node's sock containers, preventing future shutdowns - * and queued quorum work, before canceling delayed quorum work and - * destroying the work queue. - */ -static struct workqueue_struct *r2net_wq; -static struct work_struct r2net_listen_work; - -static struct r2hb_callback_func r2net_hb_up, r2net_hb_down; -#define R2NET_HB_PRI 0x1 - -static struct r2net_handshake *r2net_hand; -static struct r2net_msg *r2net_keep_req, *r2net_keep_resp; - -static int r2net_sys_err_translations[R2NET_ERR_MAX] = { - [R2NET_ERR_NONE] = 0, - [R2NET_ERR_NO_HNDLR] = -ENOPROTOOPT, - [R2NET_ERR_OVERFLOW] = -EOVERFLOW, - [R2NET_ERR_DIED] = -EHOSTDOWN,}; - -/* can't quite avoid *all* internal declarations :/ */ -static void r2net_sc_connect_completed(struct work_struct *work); -static void r2net_rx_until_empty(struct work_struct *work); -static void r2net_shutdown_sc(struct work_struct *work); -static void r2net_listen_data_ready(struct sock *sk, int bytes); -static void r2net_sc_send_keep_req(struct work_struct *work); -static void r2net_idle_timer(unsigned long data); -static void r2net_sc_postpone_idle(struct r2net_sock_container *sc); -static void r2net_sc_reset_idle_timer(struct r2net_sock_container *sc); - -#ifdef CONFIG_DEBUG_FS -static void r2net_init_nst(struct r2net_send_tracking *nst, u32 msgtype, - u32 msgkey, struct task_struct *task, u8 node) -{ - INIT_LIST_HEAD(&nst->st_net_debug_item); - nst->st_task = task; - nst->st_msg_type = msgtype; - nst->st_msg_key = msgkey; - nst->st_node = node; -} - -static inline void r2net_set_nst_sock_time(struct r2net_send_tracking *nst) -{ - nst->st_sock_time = ktime_get(); -} - -static inline void r2net_set_nst_send_time(struct r2net_send_tracking *nst) -{ - nst->st_send_time = ktime_get(); -} - -static inline void r2net_set_nst_status_time(struct r2net_send_tracking *nst) -{ - nst->st_status_time = ktime_get(); -} - -static inline void r2net_set_nst_sock_container(struct r2net_send_tracking *nst, - struct r2net_sock_container *sc) -{ - nst->st_sc = sc; -} - -static inline void r2net_set_nst_msg_id(struct r2net_send_tracking *nst, - u32 msg_id) -{ - nst->st_id = msg_id; -} - -static inline void r2net_set_sock_timer(struct r2net_sock_container *sc) -{ - sc->sc_tv_timer = ktime_get(); -} - -static inline void r2net_set_data_ready_time(struct r2net_sock_container *sc) -{ - sc->sc_tv_data_ready = ktime_get(); -} - -static inline void r2net_set_advance_start_time(struct r2net_sock_container *sc) -{ - sc->sc_tv_advance_start = ktime_get(); -} - -static inline void r2net_set_advance_stop_time(struct r2net_sock_container *sc) -{ - sc->sc_tv_advance_stop = ktime_get(); -} - -static inline void r2net_set_func_start_time(struct r2net_sock_container *sc) -{ - sc->sc_tv_func_start = ktime_get(); -} - -static inline void r2net_set_func_stop_time(struct r2net_sock_container *sc) -{ - sc->sc_tv_func_stop = ktime_get(); -} - -#else /* CONFIG_DEBUG_FS */ -# define r2net_init_nst(a, b, c, d, e) -# define r2net_set_nst_sock_time(a) -# define r2net_set_nst_send_time(a) -# define r2net_set_nst_status_time(a) -# define r2net_set_nst_sock_container(a, b) -# define r2net_set_nst_msg_id(a, b) -# define r2net_set_sock_timer(a) -# define r2net_set_data_ready_time(a) -# define r2net_set_advance_start_time(a) -# define r2net_set_advance_stop_time(a) -# define r2net_set_func_start_time(a) -# define r2net_set_func_stop_time(a) -#endif /* CONFIG_DEBUG_FS */ - -#ifdef CONFIG_RAMSTER_FS_STATS -static ktime_t r2net_get_func_run_time(struct r2net_sock_container *sc) -{ - return ktime_sub(sc->sc_tv_func_stop, sc->sc_tv_func_start); -} - -static void r2net_update_send_stats(struct r2net_send_tracking *nst, - struct r2net_sock_container *sc) -{ - sc->sc_tv_status_total = ktime_add(sc->sc_tv_status_total, - ktime_sub(ktime_get(), - nst->st_status_time)); - sc->sc_tv_send_total = ktime_add(sc->sc_tv_send_total, - ktime_sub(nst->st_status_time, - nst->st_send_time)); - sc->sc_tv_acquiry_total = ktime_add(sc->sc_tv_acquiry_total, - ktime_sub(nst->st_send_time, - nst->st_sock_time)); - sc->sc_send_count++; -} - -static void r2net_update_recv_stats(struct r2net_sock_container *sc) -{ - sc->sc_tv_process_total = ktime_add(sc->sc_tv_process_total, - r2net_get_func_run_time(sc)); - sc->sc_recv_count++; -} - -#else - -# define r2net_update_send_stats(a, b) - -# define r2net_update_recv_stats(sc) - -#endif /* CONFIG_RAMSTER_FS_STATS */ - -static inline int r2net_reconnect_delay(void) -{ - return r2nm_single_cluster->cl_reconnect_delay_ms; -} - -static inline int r2net_keepalive_delay(void) -{ - return r2nm_single_cluster->cl_keepalive_delay_ms; -} - -static inline int r2net_idle_timeout(void) -{ - return r2nm_single_cluster->cl_idle_timeout_ms; -} - -static inline int r2net_sys_err_to_errno(enum r2net_system_error err) -{ - int trans; - BUG_ON(err >= R2NET_ERR_MAX); - trans = r2net_sys_err_translations[err]; - - /* Just in case we mess up the translation table above */ - BUG_ON(err != R2NET_ERR_NONE && trans == 0); - return trans; -} - -struct r2net_node *r2net_nn_from_num(u8 node_num) -{ - BUG_ON(node_num >= ARRAY_SIZE(r2net_nodes)); - return &r2net_nodes[node_num]; -} - -static u8 r2net_num_from_nn(struct r2net_node *nn) -{ - BUG_ON(nn == NULL); - return nn - r2net_nodes; -} - -/* ------------------------------------------------------------ */ - -static int r2net_prep_nsw(struct r2net_node *nn, struct r2net_status_wait *nsw) -{ - int ret = 0; - - do { - if (!idr_pre_get(&nn->nn_status_idr, GFP_ATOMIC)) { - ret = -EAGAIN; - break; - } - spin_lock(&nn->nn_lock); - ret = idr_get_new(&nn->nn_status_idr, nsw, &nsw->ns_id); - if (ret == 0) - list_add_tail(&nsw->ns_node_item, - &nn->nn_status_list); - spin_unlock(&nn->nn_lock); - } while (ret == -EAGAIN); - - if (ret == 0) { - init_waitqueue_head(&nsw->ns_wq); - nsw->ns_sys_status = R2NET_ERR_NONE; - nsw->ns_status = 0; - } - - return ret; -} - -static void r2net_complete_nsw_locked(struct r2net_node *nn, - struct r2net_status_wait *nsw, - enum r2net_system_error sys_status, - s32 status) -{ - assert_spin_locked(&nn->nn_lock); - - if (!list_empty(&nsw->ns_node_item)) { - list_del_init(&nsw->ns_node_item); - nsw->ns_sys_status = sys_status; - nsw->ns_status = status; - idr_remove(&nn->nn_status_idr, nsw->ns_id); - wake_up(&nsw->ns_wq); - } -} - -static void r2net_complete_nsw(struct r2net_node *nn, - struct r2net_status_wait *nsw, - u64 id, enum r2net_system_error sys_status, - s32 status) -{ - spin_lock(&nn->nn_lock); - if (nsw == NULL) { - if (id > INT_MAX) - goto out; - - nsw = idr_find(&nn->nn_status_idr, id); - if (nsw == NULL) - goto out; - } - - r2net_complete_nsw_locked(nn, nsw, sys_status, status); - -out: - spin_unlock(&nn->nn_lock); - return; -} - -static void r2net_complete_nodes_nsw(struct r2net_node *nn) -{ - struct r2net_status_wait *nsw, *tmp; - unsigned int num_kills = 0; - - assert_spin_locked(&nn->nn_lock); - - list_for_each_entry_safe(nsw, tmp, &nn->nn_status_list, ns_node_item) { - r2net_complete_nsw_locked(nn, nsw, R2NET_ERR_DIED, 0); - num_kills++; - } - - mlog(0, "completed %d messages for node %u\n", num_kills, - r2net_num_from_nn(nn)); -} - -static int r2net_nsw_completed(struct r2net_node *nn, - struct r2net_status_wait *nsw) -{ - int completed; - spin_lock(&nn->nn_lock); - completed = list_empty(&nsw->ns_node_item); - spin_unlock(&nn->nn_lock); - return completed; -} - -/* ------------------------------------------------------------ */ - -static void sc_kref_release(struct kref *kref) -{ - struct r2net_sock_container *sc = container_of(kref, - struct r2net_sock_container, sc_kref); - BUG_ON(timer_pending(&sc->sc_idle_timeout)); - - sclog(sc, "releasing\n"); - - if (sc->sc_sock) { - sock_release(sc->sc_sock); - sc->sc_sock = NULL; - } - - r2nm_undepend_item(&sc->sc_node->nd_item); - r2nm_node_put(sc->sc_node); - sc->sc_node = NULL; - - r2net_debug_del_sc(sc); - kfree(sc); -} - -static void sc_put(struct r2net_sock_container *sc) -{ - sclog(sc, "put\n"); - kref_put(&sc->sc_kref, sc_kref_release); -} -static void sc_get(struct r2net_sock_container *sc) -{ - sclog(sc, "get\n"); - kref_get(&sc->sc_kref); -} -static struct r2net_sock_container *sc_alloc(struct r2nm_node *node) -{ - struct r2net_sock_container *sc, *ret = NULL; - struct page *page = NULL; - int status = 0; - - page = alloc_page(GFP_NOFS); - sc = kzalloc(sizeof(*sc), GFP_NOFS); - if (sc == NULL || page == NULL) - goto out; - - kref_init(&sc->sc_kref); - r2nm_node_get(node); - sc->sc_node = node; - - /* pin the node item of the remote node */ - status = r2nm_depend_item(&node->nd_item); - if (status) { - mlog_errno(status); - r2nm_node_put(node); - goto out; - } - INIT_WORK(&sc->sc_connect_work, r2net_sc_connect_completed); - INIT_WORK(&sc->sc_rx_work, r2net_rx_until_empty); - INIT_WORK(&sc->sc_shutdown_work, r2net_shutdown_sc); - INIT_DELAYED_WORK(&sc->sc_keepalive_work, r2net_sc_send_keep_req); - - init_timer(&sc->sc_idle_timeout); - sc->sc_idle_timeout.function = r2net_idle_timer; - sc->sc_idle_timeout.data = (unsigned long)sc; - - sclog(sc, "alloced\n"); - - ret = sc; - sc->sc_page = page; - r2net_debug_add_sc(sc); - sc = NULL; - page = NULL; - -out: - if (page) - __free_page(page); - kfree(sc); - - return ret; -} - -/* ------------------------------------------------------------ */ - -static void r2net_sc_queue_work(struct r2net_sock_container *sc, - struct work_struct *work) -{ - sc_get(sc); - if (!queue_work(r2net_wq, work)) - sc_put(sc); -} -static void r2net_sc_queue_delayed_work(struct r2net_sock_container *sc, - struct delayed_work *work, - int delay) -{ - sc_get(sc); - if (!queue_delayed_work(r2net_wq, work, delay)) - sc_put(sc); -} -static void r2net_sc_cancel_delayed_work(struct r2net_sock_container *sc, - struct delayed_work *work) -{ - if (cancel_delayed_work(work)) - sc_put(sc); -} - -static atomic_t r2net_connected_peers = ATOMIC_INIT(0); - -int r2net_num_connected_peers(void) -{ - return atomic_read(&r2net_connected_peers); -} - -static void r2net_set_nn_state(struct r2net_node *nn, - struct r2net_sock_container *sc, - unsigned valid, int err) -{ - int was_valid = nn->nn_sc_valid; - int was_err = nn->nn_persistent_error; - struct r2net_sock_container *old_sc = nn->nn_sc; - - assert_spin_locked(&nn->nn_lock); - - if (old_sc && !sc) - atomic_dec(&r2net_connected_peers); - else if (!old_sc && sc) - atomic_inc(&r2net_connected_peers); - - /* the node num comparison and single connect/accept path should stop - * an non-null sc from being overwritten with another */ - BUG_ON(sc && nn->nn_sc && nn->nn_sc != sc); - mlog_bug_on_msg(err && valid, "err %d valid %u\n", err, valid); - mlog_bug_on_msg(valid && !sc, "valid %u sc %p\n", valid, sc); - - if (was_valid && !valid && err == 0) - err = -ENOTCONN; - - mlog(ML_CONN, "node %u sc: %p -> %p, valid %u -> %u, err %d -> %d\n", - r2net_num_from_nn(nn), nn->nn_sc, sc, nn->nn_sc_valid, valid, - nn->nn_persistent_error, err); - - nn->nn_sc = sc; - nn->nn_sc_valid = valid ? 1 : 0; - nn->nn_persistent_error = err; - - /* mirrors r2net_tx_can_proceed() */ - if (nn->nn_persistent_error || nn->nn_sc_valid) - wake_up(&nn->nn_sc_wq); - - if (!was_err && nn->nn_persistent_error) { - queue_delayed_work(r2net_wq, &nn->nn_still_up, - msecs_to_jiffies(R2NET_QUORUM_DELAY_MS)); - } - - if (was_valid && !valid) { - pr_notice("ramster: No longer connected to " SC_NODEF_FMT "\n", - old_sc->sc_node->nd_name, old_sc->sc_node->nd_num, - &old_sc->sc_node->nd_ipv4_address, - ntohs(old_sc->sc_node->nd_ipv4_port)); - r2net_complete_nodes_nsw(nn); - } - - if (!was_valid && valid) { - cancel_delayed_work(&nn->nn_connect_expired); - pr_notice("ramster: %s " SC_NODEF_FMT "\n", - r2nm_this_node() > sc->sc_node->nd_num ? - "Connected to" : "Accepted connection from", - sc->sc_node->nd_name, sc->sc_node->nd_num, - &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port)); - } - - /* trigger the connecting worker func as long as we're not valid, - * it will back off if it shouldn't connect. This can be called - * from node config teardown and so needs to be careful about - * the work queue actually being up. */ - if (!valid && r2net_wq) { - unsigned long delay; - /* delay if we're within a RECONNECT_DELAY of the - * last attempt */ - delay = (nn->nn_last_connect_attempt + - msecs_to_jiffies(r2net_reconnect_delay())) - - jiffies; - if (delay > msecs_to_jiffies(r2net_reconnect_delay())) - delay = 0; - mlog(ML_CONN, "queueing conn attempt in %lu jiffies\n", delay); - queue_delayed_work(r2net_wq, &nn->nn_connect_work, delay); - - /* - * Delay the expired work after idle timeout. - * - * We might have lots of failed connection attempts that run - * through here but we only cancel the connect_expired work when - * a connection attempt succeeds. So only the first enqueue of - * the connect_expired work will do anything. The rest will see - * that it's already queued and do nothing. - */ - delay += msecs_to_jiffies(r2net_idle_timeout()); - queue_delayed_work(r2net_wq, &nn->nn_connect_expired, delay); - } - - /* keep track of the nn's sc ref for the caller */ - if ((old_sc == NULL) && sc) - sc_get(sc); - if (old_sc && (old_sc != sc)) { - r2net_sc_queue_work(old_sc, &old_sc->sc_shutdown_work); - sc_put(old_sc); - } -} - -/* see r2net_register_callbacks() */ -static void r2net_data_ready(struct sock *sk, int bytes) -{ - void (*ready)(struct sock *sk, int bytes); - - read_lock(&sk->sk_callback_lock); - if (sk->sk_user_data) { - struct r2net_sock_container *sc = sk->sk_user_data; - sclog(sc, "data_ready hit\n"); - r2net_set_data_ready_time(sc); - r2net_sc_queue_work(sc, &sc->sc_rx_work); - ready = sc->sc_data_ready; - } else { - ready = sk->sk_data_ready; - } - read_unlock(&sk->sk_callback_lock); - - ready(sk, bytes); -} - -/* see r2net_register_callbacks() */ -static void r2net_state_change(struct sock *sk) -{ - void (*state_change)(struct sock *sk); - struct r2net_sock_container *sc; - - read_lock(&sk->sk_callback_lock); - sc = sk->sk_user_data; - if (sc == NULL) { - state_change = sk->sk_state_change; - goto out; - } - - sclog(sc, "state_change to %d\n", sk->sk_state); - - state_change = sc->sc_state_change; - - switch (sk->sk_state) { - - /* ignore connecting sockets as they make progress */ - case TCP_SYN_SENT: - case TCP_SYN_RECV: - break; - case TCP_ESTABLISHED: - r2net_sc_queue_work(sc, &sc->sc_connect_work); - break; - default: - pr_info("ramster: Connection to " - SC_NODEF_FMT " shutdown, state %d\n", - sc->sc_node->nd_name, sc->sc_node->nd_num, - &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), sk->sk_state); - r2net_sc_queue_work(sc, &sc->sc_shutdown_work); - break; - - } -out: - read_unlock(&sk->sk_callback_lock); - state_change(sk); -} - -/* - * we register callbacks so we can queue work on events before calling - * the original callbacks. our callbacks are careful to test user_data - * to discover when they've reaced with r2net_unregister_callbacks(). - */ -static void r2net_register_callbacks(struct sock *sk, - struct r2net_sock_container *sc) -{ - write_lock_bh(&sk->sk_callback_lock); - - /* accepted sockets inherit the old listen socket data ready */ - if (sk->sk_data_ready == r2net_listen_data_ready) { - sk->sk_data_ready = sk->sk_user_data; - sk->sk_user_data = NULL; - } - - BUG_ON(sk->sk_user_data != NULL); - sk->sk_user_data = sc; - sc_get(sc); - - sc->sc_data_ready = sk->sk_data_ready; - sc->sc_state_change = sk->sk_state_change; - sk->sk_data_ready = r2net_data_ready; - sk->sk_state_change = r2net_state_change; - - mutex_init(&sc->sc_send_lock); - - write_unlock_bh(&sk->sk_callback_lock); -} - -static int r2net_unregister_callbacks(struct sock *sk, - struct r2net_sock_container *sc) -{ - int ret = 0; - - write_lock_bh(&sk->sk_callback_lock); - if (sk->sk_user_data == sc) { - ret = 1; - sk->sk_user_data = NULL; - sk->sk_data_ready = sc->sc_data_ready; - sk->sk_state_change = sc->sc_state_change; - } - write_unlock_bh(&sk->sk_callback_lock); - - return ret; -} - -/* - * this is a little helper that is called by callers who have seen a problem - * with an sc and want to detach it from the nn if someone already hasn't beat - * them to it. if an error is given then the shutdown will be persistent - * and pending transmits will be canceled. - */ -static void r2net_ensure_shutdown(struct r2net_node *nn, - struct r2net_sock_container *sc, - int err) -{ - spin_lock(&nn->nn_lock); - if (nn->nn_sc == sc) - r2net_set_nn_state(nn, NULL, 0, err); - spin_unlock(&nn->nn_lock); -} - -/* - * This work queue function performs the blocking parts of socket shutdown. A - * few paths lead here. set_nn_state will trigger this callback if it sees an - * sc detached from the nn. state_change will also trigger this callback - * directly when it sees errors. In that case we need to call set_nn_state - * ourselves as state_change couldn't get the nn_lock and call set_nn_state - * itself. - */ -static void r2net_shutdown_sc(struct work_struct *work) -{ - struct r2net_sock_container *sc = - container_of(work, struct r2net_sock_container, - sc_shutdown_work); - struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); - - sclog(sc, "shutting down\n"); - - /* drop the callbacks ref and call shutdown only once */ - if (r2net_unregister_callbacks(sc->sc_sock->sk, sc)) { - /* we shouldn't flush as we're in the thread, the - * races with pending sc work structs are harmless */ - del_timer_sync(&sc->sc_idle_timeout); - r2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); - sc_put(sc); - kernel_sock_shutdown(sc->sc_sock, SHUT_RDWR); - } - - /* not fatal so failed connects before the other guy has our - * heartbeat can be retried */ - r2net_ensure_shutdown(nn, sc, 0); - sc_put(sc); -} - -/* ------------------------------------------------------------ */ - -static int r2net_handler_cmp(struct r2net_msg_handler *nmh, u32 msg_type, - u32 key) -{ - int ret = memcmp(&nmh->nh_key, &key, sizeof(key)); - - if (ret == 0) - ret = memcmp(&nmh->nh_msg_type, &msg_type, sizeof(msg_type)); - - return ret; -} - -static struct r2net_msg_handler * -r2net_handler_tree_lookup(u32 msg_type, u32 key, struct rb_node ***ret_p, - struct rb_node **ret_parent) -{ - struct rb_node **p = &r2net_handler_tree.rb_node; - struct rb_node *parent = NULL; - struct r2net_msg_handler *nmh, *ret = NULL; - int cmp; - - while (*p) { - parent = *p; - nmh = rb_entry(parent, struct r2net_msg_handler, nh_node); - cmp = r2net_handler_cmp(nmh, msg_type, key); - - if (cmp < 0) - p = &(*p)->rb_left; - else if (cmp > 0) - p = &(*p)->rb_right; - else { - ret = nmh; - break; - } - } - - if (ret_p != NULL) - *ret_p = p; - if (ret_parent != NULL) - *ret_parent = parent; - - return ret; -} - -static void r2net_handler_kref_release(struct kref *kref) -{ - struct r2net_msg_handler *nmh; - nmh = container_of(kref, struct r2net_msg_handler, nh_kref); - - kfree(nmh); -} - -static void r2net_handler_put(struct r2net_msg_handler *nmh) -{ - kref_put(&nmh->nh_kref, r2net_handler_kref_release); -} - -/* max_len is protection for the handler func. incoming messages won't - * be given to the handler if their payload is longer than the max. */ -int r2net_register_handler(u32 msg_type, u32 key, u32 max_len, - r2net_msg_handler_func *func, void *data, - r2net_post_msg_handler_func *post_func, - struct list_head *unreg_list) -{ - struct r2net_msg_handler *nmh = NULL; - struct rb_node **p, *parent; - int ret = 0; - - if (max_len > R2NET_MAX_PAYLOAD_BYTES) { - mlog(0, "max_len for message handler out of range: %u\n", - max_len); - ret = -EINVAL; - goto out; - } - - if (!msg_type) { - mlog(0, "no message type provided: %u, %p\n", msg_type, func); - ret = -EINVAL; - goto out; - - } - if (!func) { - mlog(0, "no message handler provided: %u, %p\n", - msg_type, func); - ret = -EINVAL; - goto out; - } - - nmh = kzalloc(sizeof(struct r2net_msg_handler), GFP_NOFS); - if (nmh == NULL) { - ret = -ENOMEM; - goto out; - } - - nmh->nh_func = func; - nmh->nh_func_data = data; - nmh->nh_post_func = post_func; - nmh->nh_msg_type = msg_type; - nmh->nh_max_len = max_len; - nmh->nh_key = key; - /* the tree and list get this ref.. they're both removed in - * unregister when this ref is dropped */ - kref_init(&nmh->nh_kref); - INIT_LIST_HEAD(&nmh->nh_unregister_item); - - write_lock(&r2net_handler_lock); - if (r2net_handler_tree_lookup(msg_type, key, &p, &parent)) - ret = -EEXIST; - else { - rb_link_node(&nmh->nh_node, parent, p); - rb_insert_color(&nmh->nh_node, &r2net_handler_tree); - list_add_tail(&nmh->nh_unregister_item, unreg_list); - - mlog(ML_TCP, "registered handler func %p type %u key %08x\n", - func, msg_type, key); - /* we've had some trouble with handlers seemingly vanishing. */ - mlog_bug_on_msg(r2net_handler_tree_lookup(msg_type, key, &p, - &parent) == NULL, - "couldn't find handler we *just* registered " - "for type %u key %08x\n", msg_type, key); - } - write_unlock(&r2net_handler_lock); - if (ret) - goto out; - -out: - if (ret) - kfree(nmh); - - return ret; -} -EXPORT_SYMBOL_GPL(r2net_register_handler); - -void r2net_unregister_handler_list(struct list_head *list) -{ - struct r2net_msg_handler *nmh, *n; - - write_lock(&r2net_handler_lock); - list_for_each_entry_safe(nmh, n, list, nh_unregister_item) { - mlog(ML_TCP, "unregistering handler func %p type %u key %08x\n", - nmh->nh_func, nmh->nh_msg_type, nmh->nh_key); - rb_erase(&nmh->nh_node, &r2net_handler_tree); - list_del_init(&nmh->nh_unregister_item); - kref_put(&nmh->nh_kref, r2net_handler_kref_release); - } - write_unlock(&r2net_handler_lock); -} -EXPORT_SYMBOL_GPL(r2net_unregister_handler_list); - -static struct r2net_msg_handler *r2net_handler_get(u32 msg_type, u32 key) -{ - struct r2net_msg_handler *nmh; - - read_lock(&r2net_handler_lock); - nmh = r2net_handler_tree_lookup(msg_type, key, NULL, NULL); - if (nmh) - kref_get(&nmh->nh_kref); - read_unlock(&r2net_handler_lock); - - return nmh; -} - -/* ------------------------------------------------------------ */ - -static int r2net_recv_tcp_msg(struct socket *sock, void *data, size_t len) -{ - int ret; - mm_segment_t oldfs; - struct kvec vec = { - .iov_len = len, - .iov_base = data, - }; - struct msghdr msg = { - .msg_iovlen = 1, - .msg_iov = (struct iovec *)&vec, - .msg_flags = MSG_DONTWAIT, - }; - - oldfs = get_fs(); - set_fs(get_ds()); - ret = sock_recvmsg(sock, &msg, len, msg.msg_flags); - set_fs(oldfs); - - return ret; -} - -static int r2net_send_tcp_msg(struct socket *sock, struct kvec *vec, - size_t veclen, size_t total) -{ - int ret; - mm_segment_t oldfs; - struct msghdr msg = { - .msg_iov = (struct iovec *)vec, - .msg_iovlen = veclen, - }; - - if (sock == NULL) { - ret = -EINVAL; - goto out; - } - - oldfs = get_fs(); - set_fs(get_ds()); - ret = sock_sendmsg(sock, &msg, total); - set_fs(oldfs); - if (ret != total) { - mlog(ML_ERROR, "sendmsg returned %d instead of %zu\n", ret, - total); - if (ret >= 0) - ret = -EPIPE; /* should be smarter, I bet */ - goto out; - } - - ret = 0; -out: - if (ret < 0) - mlog(0, "returning error: %d\n", ret); - return ret; -} - -static void r2net_sendpage(struct r2net_sock_container *sc, - void *kmalloced_virt, - size_t size) -{ - struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); - ssize_t ret; - - while (1) { - mutex_lock(&sc->sc_send_lock); - ret = sc->sc_sock->ops->sendpage(sc->sc_sock, - virt_to_page(kmalloced_virt), - (long)kmalloced_virt & ~PAGE_MASK, - size, MSG_DONTWAIT); - mutex_unlock(&sc->sc_send_lock); - if (ret == size) - break; - if (ret == (ssize_t)-EAGAIN) { - mlog(0, "sendpage of size %zu to " SC_NODEF_FMT - " returned EAGAIN\n", size, sc->sc_node->nd_name, - sc->sc_node->nd_num, - &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port)); - cond_resched(); - continue; - } - mlog(ML_ERROR, "sendpage of size %zu to " SC_NODEF_FMT - " failed with %zd\n", size, sc->sc_node->nd_name, - sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), ret); - r2net_ensure_shutdown(nn, sc, 0); - break; - } -} - -static void r2net_init_msg(struct r2net_msg *msg, u16 data_len, - u16 msg_type, u32 key) -{ - memset(msg, 0, sizeof(struct r2net_msg)); - msg->magic = cpu_to_be16(R2NET_MSG_MAGIC); - msg->data_len = cpu_to_be16(data_len); - msg->msg_type = cpu_to_be16(msg_type); - msg->sys_status = cpu_to_be32(R2NET_ERR_NONE); - msg->status = 0; - msg->key = cpu_to_be32(key); -} - -static int r2net_tx_can_proceed(struct r2net_node *nn, - struct r2net_sock_container **sc_ret, - int *error) -{ - int ret = 0; - - spin_lock(&nn->nn_lock); - if (nn->nn_persistent_error) { - ret = 1; - *sc_ret = NULL; - *error = nn->nn_persistent_error; - } else if (nn->nn_sc_valid) { - kref_get(&nn->nn_sc->sc_kref); - - ret = 1; - *sc_ret = nn->nn_sc; - *error = 0; - } - spin_unlock(&nn->nn_lock); - - return ret; -} - -/* Get a map of all nodes to which this node is currently connected to */ -void r2net_fill_node_map(unsigned long *map, unsigned bytes) -{ - struct r2net_sock_container *sc; - int node, ret; - - BUG_ON(bytes < (BITS_TO_LONGS(R2NM_MAX_NODES) * sizeof(unsigned long))); - - memset(map, 0, bytes); - for (node = 0; node < R2NM_MAX_NODES; ++node) { - r2net_tx_can_proceed(r2net_nn_from_num(node), &sc, &ret); - if (!ret) { - set_bit(node, map); - sc_put(sc); - } - } -} -EXPORT_SYMBOL_GPL(r2net_fill_node_map); - -int r2net_send_message_vec(u32 msg_type, u32 key, struct kvec *caller_vec, - size_t caller_veclen, u8 target_node, int *status) -{ - int ret = 0; - struct r2net_msg *msg = NULL; - size_t veclen, caller_bytes = 0; - struct kvec *vec = NULL; - struct r2net_sock_container *sc = NULL; - struct r2net_node *nn = r2net_nn_from_num(target_node); - struct r2net_status_wait nsw = { - .ns_node_item = LIST_HEAD_INIT(nsw.ns_node_item), - }; - struct r2net_send_tracking nst; - - /* this may be a general bug fix */ - init_waitqueue_head(&nsw.ns_wq); - - r2net_init_nst(&nst, msg_type, key, current, target_node); - - if (r2net_wq == NULL) { - mlog(0, "attempt to tx without r2netd running\n"); - ret = -ESRCH; - goto out; - } - - if (caller_veclen == 0) { - mlog(0, "bad kvec array length\n"); - ret = -EINVAL; - goto out; - } - - caller_bytes = iov_length((struct iovec *)caller_vec, caller_veclen); - if (caller_bytes > R2NET_MAX_PAYLOAD_BYTES) { - mlog(0, "total payload len %zu too large\n", caller_bytes); - ret = -EINVAL; - goto out; - } - - if (target_node == r2nm_this_node()) { - ret = -ELOOP; - goto out; - } - - r2net_debug_add_nst(&nst); - - r2net_set_nst_sock_time(&nst); - - wait_event(nn->nn_sc_wq, r2net_tx_can_proceed(nn, &sc, &ret)); - if (ret) - goto out; - - r2net_set_nst_sock_container(&nst, sc); - - veclen = caller_veclen + 1; - vec = kmalloc(sizeof(struct kvec) * veclen, GFP_ATOMIC); - if (vec == NULL) { - mlog(0, "failed to %zu element kvec!\n", veclen); - ret = -ENOMEM; - goto out; - } - - msg = kmalloc(sizeof(struct r2net_msg), GFP_ATOMIC); - if (!msg) { - mlog(0, "failed to allocate a r2net_msg!\n"); - ret = -ENOMEM; - goto out; - } - - r2net_init_msg(msg, caller_bytes, msg_type, key); - - vec[0].iov_len = sizeof(struct r2net_msg); - vec[0].iov_base = msg; - memcpy(&vec[1], caller_vec, caller_veclen * sizeof(struct kvec)); - - ret = r2net_prep_nsw(nn, &nsw); - if (ret) - goto out; - - msg->msg_num = cpu_to_be32(nsw.ns_id); - r2net_set_nst_msg_id(&nst, nsw.ns_id); - - r2net_set_nst_send_time(&nst); - - /* finally, convert the message header to network byte-order - * and send */ - mutex_lock(&sc->sc_send_lock); - ret = r2net_send_tcp_msg(sc->sc_sock, vec, veclen, - sizeof(struct r2net_msg) + caller_bytes); - mutex_unlock(&sc->sc_send_lock); - msglog(msg, "sending returned %d\n", ret); - if (ret < 0) { - mlog(0, "error returned from r2net_send_tcp_msg=%d\n", ret); - goto out; - } - - /* wait on other node's handler */ - r2net_set_nst_status_time(&nst); - wait_event(nsw.ns_wq, r2net_nsw_completed(nn, &nsw) || - nn->nn_persistent_error || !nn->nn_sc_valid); - - r2net_update_send_stats(&nst, sc); - - /* Note that we avoid overwriting the callers status return - * variable if a system error was reported on the other - * side. Callers beware. */ - ret = r2net_sys_err_to_errno(nsw.ns_sys_status); - if (status && !ret) - *status = nsw.ns_status; - - mlog(0, "woken, returning system status %d, user status %d\n", - ret, nsw.ns_status); -out: - r2net_debug_del_nst(&nst); /* must be before dropping sc and node */ - if (sc) - sc_put(sc); - kfree(vec); - kfree(msg); - r2net_complete_nsw(nn, &nsw, 0, 0, 0); - return ret; -} -EXPORT_SYMBOL_GPL(r2net_send_message_vec); - -int r2net_send_message(u32 msg_type, u32 key, void *data, u32 len, - u8 target_node, int *status) -{ - struct kvec vec = { - .iov_base = data, - .iov_len = len, - }; - return r2net_send_message_vec(msg_type, key, &vec, 1, - target_node, status); -} -EXPORT_SYMBOL_GPL(r2net_send_message); - -static int r2net_send_status_magic(struct socket *sock, struct r2net_msg *hdr, - enum r2net_system_error syserr, int err) -{ - struct kvec vec = { - .iov_base = hdr, - .iov_len = sizeof(struct r2net_msg), - }; - - BUG_ON(syserr >= R2NET_ERR_MAX); - - /* leave other fields intact from the incoming message, msg_num - * in particular */ - hdr->sys_status = cpu_to_be32(syserr); - hdr->status = cpu_to_be32(err); - /* twiddle the magic */ - hdr->magic = cpu_to_be16(R2NET_MSG_STATUS_MAGIC); - hdr->data_len = 0; - - msglog(hdr, "about to send status magic %d\n", err); - /* hdr has been in host byteorder this whole time */ - return r2net_send_tcp_msg(sock, &vec, 1, sizeof(struct r2net_msg)); -} - -/* - * "data magic" is a long version of "status magic" where the message - * payload actually contains data to be passed in reply to certain messages - */ -static int r2net_send_data_magic(struct r2net_sock_container *sc, - struct r2net_msg *hdr, - void *data, size_t data_len, - enum r2net_system_error syserr, int err) -{ - struct kvec vec[2]; - int ret; - - vec[0].iov_base = hdr; - vec[0].iov_len = sizeof(struct r2net_msg); - vec[1].iov_base = data; - vec[1].iov_len = data_len; - - BUG_ON(syserr >= R2NET_ERR_MAX); - - /* leave other fields intact from the incoming message, msg_num - * in particular */ - hdr->sys_status = cpu_to_be32(syserr); - hdr->status = cpu_to_be32(err); - hdr->magic = cpu_to_be16(R2NET_MSG_DATA_MAGIC); /* twiddle magic */ - hdr->data_len = cpu_to_be16(data_len); - - msglog(hdr, "about to send data magic %d\n", err); - /* hdr has been in host byteorder this whole time */ - ret = r2net_send_tcp_msg(sc->sc_sock, vec, 2, - sizeof(struct r2net_msg) + data_len); - return ret; -} - -/* - * called by a message handler to convert an otherwise normal reply - * message into a "data magic" message - */ -void r2net_force_data_magic(struct r2net_msg *hdr, u16 msgtype, u32 msgkey) -{ - hdr->magic = cpu_to_be16(R2NET_MSG_DATA_MAGIC); - hdr->msg_type = cpu_to_be16(msgtype); - hdr->key = cpu_to_be32(msgkey); -} - -/* this returns -errno if the header was unknown or too large, etc. - * after this is called the buffer us reused for the next message */ -static int r2net_process_message(struct r2net_sock_container *sc, - struct r2net_msg *hdr) -{ - struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); - int ret = 0, handler_status; - enum r2net_system_error syserr; - struct r2net_msg_handler *nmh = NULL; - void *ret_data = NULL; - int data_magic = 0; - - msglog(hdr, "processing message\n"); - - r2net_sc_postpone_idle(sc); - - switch (be16_to_cpu(hdr->magic)) { - - case R2NET_MSG_STATUS_MAGIC: - /* special type for returning message status */ - r2net_complete_nsw(nn, NULL, be32_to_cpu(hdr->msg_num), - be32_to_cpu(hdr->sys_status), - be32_to_cpu(hdr->status)); - goto out; - case R2NET_MSG_KEEP_REQ_MAGIC: - r2net_sendpage(sc, r2net_keep_resp, sizeof(*r2net_keep_resp)); - goto out; - case R2NET_MSG_KEEP_RESP_MAGIC: - goto out; - case R2NET_MSG_MAGIC: - break; - case R2NET_MSG_DATA_MAGIC: - /* - * unlike a normal status magic, a data magic DOES - * (MUST) have a handler, so the control flow is - * a little funky here as a result - */ - data_magic = 1; - break; - default: - msglog(hdr, "bad magic\n"); - ret = -EINVAL; - goto out; - break; - } - - /* find a handler for it */ - handler_status = 0; - nmh = r2net_handler_get(be16_to_cpu(hdr->msg_type), - be32_to_cpu(hdr->key)); - if (!nmh) { - mlog(ML_TCP, "couldn't find handler for type %u key %08x\n", - be16_to_cpu(hdr->msg_type), be32_to_cpu(hdr->key)); - syserr = R2NET_ERR_NO_HNDLR; - goto out_respond; - } - - syserr = R2NET_ERR_NONE; - - if (be16_to_cpu(hdr->data_len) > nmh->nh_max_len) - syserr = R2NET_ERR_OVERFLOW; - - if (syserr != R2NET_ERR_NONE) { - pr_err("ramster_r2net, message length problem\n"); - goto out_respond; - } - - r2net_set_func_start_time(sc); - sc->sc_msg_key = be32_to_cpu(hdr->key); - sc->sc_msg_type = be16_to_cpu(hdr->msg_type); - handler_status = (nmh->nh_func)(hdr, sizeof(struct r2net_msg) + - be16_to_cpu(hdr->data_len), - nmh->nh_func_data, &ret_data); - if (data_magic) { - /* - * handler handled data sent in reply to request - * so complete the transaction - */ - r2net_complete_nsw(nn, NULL, be32_to_cpu(hdr->msg_num), - be32_to_cpu(hdr->sys_status), handler_status); - goto out; - } - /* - * handler changed magic to DATA_MAGIC to reply to request for data, - * implies ret_data points to data to return and handler_status - * is the number of bytes of data - */ - if (be16_to_cpu(hdr->magic) == R2NET_MSG_DATA_MAGIC) { - ret = r2net_send_data_magic(sc, hdr, - ret_data, handler_status, - syserr, 0); - hdr = NULL; - mlog(0, "sending data reply %d, syserr %d returned %d\n", - handler_status, syserr, ret); - r2net_set_func_stop_time(sc); - - r2net_update_recv_stats(sc); - goto out; - } - r2net_set_func_stop_time(sc); - - r2net_update_recv_stats(sc); - -out_respond: - /* this destroys the hdr, so don't use it after this */ - mutex_lock(&sc->sc_send_lock); - ret = r2net_send_status_magic(sc->sc_sock, hdr, syserr, - handler_status); - mutex_unlock(&sc->sc_send_lock); - hdr = NULL; - mlog(0, "sending handler status %d, syserr %d returned %d\n", - handler_status, syserr, ret); - - if (nmh) { - BUG_ON(ret_data != NULL && nmh->nh_post_func == NULL); - if (nmh->nh_post_func) - (nmh->nh_post_func)(handler_status, nmh->nh_func_data, - ret_data); - } - -out: - if (nmh) - r2net_handler_put(nmh); - return ret; -} - -static int r2net_check_handshake(struct r2net_sock_container *sc) -{ - struct r2net_handshake *hand = page_address(sc->sc_page); - struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); - - if (hand->protocol_version != cpu_to_be64(R2NET_PROTOCOL_VERSION)) { - pr_notice("ramster: " SC_NODEF_FMT " Advertised net " - "protocol version %llu but %llu is required. " - "Disconnecting.\n", sc->sc_node->nd_name, - sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), - (unsigned long long)be64_to_cpu(hand->protocol_version), - R2NET_PROTOCOL_VERSION); - - /* don't bother reconnecting if its the wrong version. */ - r2net_ensure_shutdown(nn, sc, -ENOTCONN); - return -1; - } - - /* - * Ensure timeouts are consistent with other nodes, otherwise - * we can end up with one node thinking that the other must be down, - * but isn't. This can ultimately cause corruption. - */ - if (be32_to_cpu(hand->r2net_idle_timeout_ms) != - r2net_idle_timeout()) { - pr_notice("ramster: " SC_NODEF_FMT " uses a network " - "idle timeout of %u ms, but we use %u ms locally. " - "Disconnecting.\n", sc->sc_node->nd_name, - sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), - be32_to_cpu(hand->r2net_idle_timeout_ms), - r2net_idle_timeout()); - r2net_ensure_shutdown(nn, sc, -ENOTCONN); - return -1; - } - - if (be32_to_cpu(hand->r2net_keepalive_delay_ms) != - r2net_keepalive_delay()) { - pr_notice("ramster: " SC_NODEF_FMT " uses a keepalive " - "delay of %u ms, but we use %u ms locally. " - "Disconnecting.\n", sc->sc_node->nd_name, - sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), - be32_to_cpu(hand->r2net_keepalive_delay_ms), - r2net_keepalive_delay()); - r2net_ensure_shutdown(nn, sc, -ENOTCONN); - return -1; - } - - if (be32_to_cpu(hand->r2hb_heartbeat_timeout_ms) != - R2HB_MAX_WRITE_TIMEOUT_MS) { - pr_notice("ramster: " SC_NODEF_FMT " uses a heartbeat " - "timeout of %u ms, but we use %u ms locally. " - "Disconnecting.\n", sc->sc_node->nd_name, - sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), - be32_to_cpu(hand->r2hb_heartbeat_timeout_ms), - R2HB_MAX_WRITE_TIMEOUT_MS); - r2net_ensure_shutdown(nn, sc, -ENOTCONN); - return -1; - } - - sc->sc_handshake_ok = 1; - - spin_lock(&nn->nn_lock); - /* set valid and queue the idle timers only if it hasn't been - * shut down already */ - if (nn->nn_sc == sc) { - r2net_sc_reset_idle_timer(sc); - atomic_set(&nn->nn_timeout, 0); - r2net_set_nn_state(nn, sc, 1, 0); - } - spin_unlock(&nn->nn_lock); - - /* shift everything up as though it wasn't there */ - sc->sc_page_off -= sizeof(struct r2net_handshake); - if (sc->sc_page_off) - memmove(hand, hand + 1, sc->sc_page_off); - - return 0; -} - -/* this demuxes the queued rx bytes into header or payload bits and calls - * handlers as each full message is read off the socket. it returns -error, - * == 0 eof, or > 0 for progress made.*/ -static int r2net_advance_rx(struct r2net_sock_container *sc) -{ - struct r2net_msg *hdr; - int ret = 0; - void *data; - size_t datalen; - - sclog(sc, "receiving\n"); - r2net_set_advance_start_time(sc); - - if (unlikely(sc->sc_handshake_ok == 0)) { - if (sc->sc_page_off < sizeof(struct r2net_handshake)) { - data = page_address(sc->sc_page) + sc->sc_page_off; - datalen = sizeof(struct r2net_handshake) - - sc->sc_page_off; - ret = r2net_recv_tcp_msg(sc->sc_sock, data, datalen); - if (ret > 0) - sc->sc_page_off += ret; - } - - if (sc->sc_page_off == sizeof(struct r2net_handshake)) { - r2net_check_handshake(sc); - if (unlikely(sc->sc_handshake_ok == 0)) - ret = -EPROTO; - } - goto out; - } - - /* do we need more header? */ - if (sc->sc_page_off < sizeof(struct r2net_msg)) { - data = page_address(sc->sc_page) + sc->sc_page_off; - datalen = sizeof(struct r2net_msg) - sc->sc_page_off; - ret = r2net_recv_tcp_msg(sc->sc_sock, data, datalen); - if (ret > 0) { - sc->sc_page_off += ret; - /* only swab incoming here.. we can - * only get here once as we cross from - * being under to over */ - if (sc->sc_page_off == sizeof(struct r2net_msg)) { - hdr = page_address(sc->sc_page); - if (be16_to_cpu(hdr->data_len) > - R2NET_MAX_PAYLOAD_BYTES) - ret = -EOVERFLOW; - WARN_ON_ONCE(ret == -EOVERFLOW); - } - } - if (ret <= 0) - goto out; - } - - if (sc->sc_page_off < sizeof(struct r2net_msg)) { - /* oof, still don't have a header */ - goto out; - } - - /* this was swabbed above when we first read it */ - hdr = page_address(sc->sc_page); - - msglog(hdr, "at page_off %zu\n", sc->sc_page_off); - - /* do we need more payload? */ - if (sc->sc_page_off - sizeof(struct r2net_msg) < - be16_to_cpu(hdr->data_len)) { - /* need more payload */ - data = page_address(sc->sc_page) + sc->sc_page_off; - datalen = (sizeof(struct r2net_msg) + - be16_to_cpu(hdr->data_len)) - - sc->sc_page_off; - ret = r2net_recv_tcp_msg(sc->sc_sock, data, datalen); - if (ret > 0) - sc->sc_page_off += ret; - if (ret <= 0) - goto out; - } - - if (sc->sc_page_off - sizeof(struct r2net_msg) == - be16_to_cpu(hdr->data_len)) { - /* we can only get here once, the first time we read - * the payload.. so set ret to progress if the handler - * works out. after calling this the message is toast */ - ret = r2net_process_message(sc, hdr); - if (ret == 0) - ret = 1; - sc->sc_page_off = 0; - } - -out: - sclog(sc, "ret = %d\n", ret); - r2net_set_advance_stop_time(sc); - return ret; -} - -/* this work func is triggerd by data ready. it reads until it can read no - * more. it interprets 0, eof, as fatal. if data_ready hits while we're doing - * our work the work struct will be marked and we'll be called again. */ -static void r2net_rx_until_empty(struct work_struct *work) -{ - struct r2net_sock_container *sc = - container_of(work, struct r2net_sock_container, sc_rx_work); - int ret; - - do { - ret = r2net_advance_rx(sc); - } while (ret > 0); - - if (ret <= 0 && ret != -EAGAIN) { - struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); - sclog(sc, "saw error %d, closing\n", ret); - /* not permanent so read failed handshake can retry */ - r2net_ensure_shutdown(nn, sc, 0); - } - sc_put(sc); -} - -static int r2net_set_nodelay(struct socket *sock) -{ - int ret, val = 1; - mm_segment_t oldfs; - - oldfs = get_fs(); - set_fs(KERNEL_DS); - - /* - * Dear unsuspecting programmer, - * - * Don't use sock_setsockopt() for SOL_TCP. It doesn't check its level - * argument and assumes SOL_SOCKET so, say, your TCP_NODELAY will - * silently turn into SO_DEBUG. - * - * Yours, - * Keeper of hilariously fragile interfaces. - */ - ret = sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, - (char __user *)&val, sizeof(val)); - - set_fs(oldfs); - return ret; -} - -static void r2net_initialize_handshake(void) -{ - r2net_hand->r2hb_heartbeat_timeout_ms = cpu_to_be32( - R2HB_MAX_WRITE_TIMEOUT_MS); - r2net_hand->r2net_idle_timeout_ms = cpu_to_be32(r2net_idle_timeout()); - r2net_hand->r2net_keepalive_delay_ms = cpu_to_be32( - r2net_keepalive_delay()); - r2net_hand->r2net_reconnect_delay_ms = cpu_to_be32( - r2net_reconnect_delay()); -} - -/* ------------------------------------------------------------ */ - -/* called when a connect completes and after a sock is accepted. the - * rx path will see the response and mark the sc valid */ -static void r2net_sc_connect_completed(struct work_struct *work) -{ - struct r2net_sock_container *sc = - container_of(work, struct r2net_sock_container, - sc_connect_work); - - mlog(ML_MSG, "sc sending handshake with ver %llu id %llx\n", - (unsigned long long)R2NET_PROTOCOL_VERSION, - (unsigned long long)be64_to_cpu(r2net_hand->connector_id)); - - r2net_initialize_handshake(); - r2net_sendpage(sc, r2net_hand, sizeof(*r2net_hand)); - sc_put(sc); -} - -/* this is called as a work_struct func. */ -static void r2net_sc_send_keep_req(struct work_struct *work) -{ - struct r2net_sock_container *sc = - container_of(work, struct r2net_sock_container, - sc_keepalive_work.work); - - r2net_sendpage(sc, r2net_keep_req, sizeof(*r2net_keep_req)); - sc_put(sc); -} - -/* socket shutdown does a del_timer_sync against this as it tears down. - * we can't start this timer until we've got to the point in sc buildup - * where shutdown is going to be involved */ -static void r2net_idle_timer(unsigned long data) -{ - struct r2net_sock_container *sc = (struct r2net_sock_container *)data; - struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); -#ifdef CONFIG_DEBUG_FS - unsigned long msecs = ktime_to_ms(ktime_get()) - - ktime_to_ms(sc->sc_tv_timer); -#else - unsigned long msecs = r2net_idle_timeout(); -#endif - - pr_notice("ramster: Connection to " SC_NODEF_FMT " has been " - "idle for %lu.%lu secs, shutting it down.\n", - sc->sc_node->nd_name, sc->sc_node->nd_num, - &sc->sc_node->nd_ipv4_address, ntohs(sc->sc_node->nd_ipv4_port), - msecs / 1000, msecs % 1000); - - /* - * Initialize the nn_timeout so that the next connection attempt - * will continue in r2net_start_connect. - */ - atomic_set(&nn->nn_timeout, 1); - r2net_sc_queue_work(sc, &sc->sc_shutdown_work); -} - -static void r2net_sc_reset_idle_timer(struct r2net_sock_container *sc) -{ - r2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); - r2net_sc_queue_delayed_work(sc, &sc->sc_keepalive_work, - msecs_to_jiffies(r2net_keepalive_delay())); - r2net_set_sock_timer(sc); - mod_timer(&sc->sc_idle_timeout, - jiffies + msecs_to_jiffies(r2net_idle_timeout())); -} - -static void r2net_sc_postpone_idle(struct r2net_sock_container *sc) -{ - /* Only push out an existing timer */ - if (timer_pending(&sc->sc_idle_timeout)) - r2net_sc_reset_idle_timer(sc); -} - -/* this work func is kicked whenever a path sets the nn state which doesn't - * have valid set. This includes seeing hb come up, losing a connection, - * having a connect attempt fail, etc. This centralizes the logic which decides - * if a connect attempt should be made or if we should give up and all future - * transmit attempts should fail */ -static void r2net_start_connect(struct work_struct *work) -{ - struct r2net_node *nn = - container_of(work, struct r2net_node, nn_connect_work.work); - struct r2net_sock_container *sc = NULL; - struct r2nm_node *node = NULL, *mynode = NULL; - struct socket *sock = NULL; - struct sockaddr_in myaddr = {0, }, remoteaddr = {0, }; - int ret = 0, stop; - unsigned int timeout; - - /* if we're greater we initiate tx, otherwise we accept */ - if (r2nm_this_node() <= r2net_num_from_nn(nn)) - goto out; - - /* watch for racing with tearing a node down */ - node = r2nm_get_node_by_num(r2net_num_from_nn(nn)); - if (node == NULL) { - ret = 0; - goto out; - } - - mynode = r2nm_get_node_by_num(r2nm_this_node()); - if (mynode == NULL) { - ret = 0; - goto out; - } - - spin_lock(&nn->nn_lock); - /* - * see if we already have one pending or have given up. - * For nn_timeout, it is set when we close the connection - * because of the idle time out. So it means that we have - * at least connected to that node successfully once, - * now try to connect to it again. - */ - timeout = atomic_read(&nn->nn_timeout); - stop = (nn->nn_sc || - (nn->nn_persistent_error && - (nn->nn_persistent_error != -ENOTCONN || timeout == 0))); - spin_unlock(&nn->nn_lock); - if (stop) - goto out; - - nn->nn_last_connect_attempt = jiffies; - - sc = sc_alloc(node); - if (sc == NULL) { - mlog(0, "couldn't allocate sc\n"); - ret = -ENOMEM; - goto out; - } - - ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); - if (ret < 0) { - mlog(0, "can't create socket: %d\n", ret); - goto out; - } - sc->sc_sock = sock; /* freed by sc_kref_release */ - - sock->sk->sk_allocation = GFP_ATOMIC; - - myaddr.sin_family = AF_INET; - myaddr.sin_addr.s_addr = mynode->nd_ipv4_address; - myaddr.sin_port = htons(0); /* any port */ - - ret = sock->ops->bind(sock, (struct sockaddr *)&myaddr, - sizeof(myaddr)); - if (ret) { - mlog(ML_ERROR, "bind failed with %d at address %pI4\n", - ret, &mynode->nd_ipv4_address); - goto out; - } - - ret = r2net_set_nodelay(sc->sc_sock); - if (ret) { - mlog(ML_ERROR, "setting TCP_NODELAY failed with %d\n", ret); - goto out; - } - - r2net_register_callbacks(sc->sc_sock->sk, sc); - - spin_lock(&nn->nn_lock); - /* handshake completion will set nn->nn_sc_valid */ - r2net_set_nn_state(nn, sc, 0, 0); - spin_unlock(&nn->nn_lock); - - remoteaddr.sin_family = AF_INET; - remoteaddr.sin_addr.s_addr = node->nd_ipv4_address; - remoteaddr.sin_port = node->nd_ipv4_port; - - ret = sc->sc_sock->ops->connect(sc->sc_sock, - (struct sockaddr *)&remoteaddr, - sizeof(remoteaddr), - O_NONBLOCK); - if (ret == -EINPROGRESS) - ret = 0; - -out: - if (ret) { - pr_notice("ramster: Connect attempt to " SC_NODEF_FMT - " failed with errno %d\n", sc->sc_node->nd_name, - sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, - ntohs(sc->sc_node->nd_ipv4_port), ret); - /* 0 err so that another will be queued and attempted - * from set_nn_state */ - if (sc) - r2net_ensure_shutdown(nn, sc, 0); - } - if (sc) - sc_put(sc); - if (node) - r2nm_node_put(node); - if (mynode) - r2nm_node_put(mynode); - - return; -} - -static void r2net_connect_expired(struct work_struct *work) -{ - struct r2net_node *nn = - container_of(work, struct r2net_node, nn_connect_expired.work); - - spin_lock(&nn->nn_lock); - if (!nn->nn_sc_valid) { - pr_notice("ramster: No connection established with " - "node %u after %u.%u seconds, giving up.\n", - r2net_num_from_nn(nn), - r2net_idle_timeout() / 1000, - r2net_idle_timeout() % 1000); - - r2net_set_nn_state(nn, NULL, 0, -ENOTCONN); - } - spin_unlock(&nn->nn_lock); -} - -static void r2net_still_up(struct work_struct *work) -{ -} - -/* ------------------------------------------------------------ */ - -void r2net_disconnect_node(struct r2nm_node *node) -{ - struct r2net_node *nn = r2net_nn_from_num(node->nd_num); - - /* don't reconnect until it's heartbeating again */ - spin_lock(&nn->nn_lock); - atomic_set(&nn->nn_timeout, 0); - r2net_set_nn_state(nn, NULL, 0, -ENOTCONN); - spin_unlock(&nn->nn_lock); - - if (r2net_wq) { - cancel_delayed_work(&nn->nn_connect_expired); - cancel_delayed_work(&nn->nn_connect_work); - cancel_delayed_work(&nn->nn_still_up); - flush_workqueue(r2net_wq); - } -} - -static void r2net_hb_node_down_cb(struct r2nm_node *node, int node_num, - void *data) -{ - if (!node) - return; - - if (node_num != r2nm_this_node()) - r2net_disconnect_node(node); - - BUG_ON(atomic_read(&r2net_connected_peers) < 0); -} - -static void r2net_hb_node_up_cb(struct r2nm_node *node, int node_num, - void *data) -{ - struct r2net_node *nn = r2net_nn_from_num(node_num); - - BUG_ON(!node); - - /* ensure an immediate connect attempt */ - nn->nn_last_connect_attempt = jiffies - - (msecs_to_jiffies(r2net_reconnect_delay()) + 1); - - if (node_num != r2nm_this_node()) { - /* believe it or not, accept and node hearbeating testing - * can succeed for this node before we got here.. so - * only use set_nn_state to clear the persistent error - * if that hasn't already happened */ - spin_lock(&nn->nn_lock); - atomic_set(&nn->nn_timeout, 0); - if (nn->nn_persistent_error) - r2net_set_nn_state(nn, NULL, 0, 0); - spin_unlock(&nn->nn_lock); - } -} - -void r2net_unregister_hb_callbacks(void) -{ - r2hb_unregister_callback(NULL, &r2net_hb_up); - r2hb_unregister_callback(NULL, &r2net_hb_down); -} - -int r2net_register_hb_callbacks(void) -{ - int ret; - - r2hb_setup_callback(&r2net_hb_down, R2HB_NODE_DOWN_CB, - r2net_hb_node_down_cb, NULL, R2NET_HB_PRI); - r2hb_setup_callback(&r2net_hb_up, R2HB_NODE_UP_CB, - r2net_hb_node_up_cb, NULL, R2NET_HB_PRI); - - ret = r2hb_register_callback(NULL, &r2net_hb_up); - if (ret == 0) - ret = r2hb_register_callback(NULL, &r2net_hb_down); - - if (ret) - r2net_unregister_hb_callbacks(); - - return ret; -} - -/* ------------------------------------------------------------ */ - -static int r2net_accept_one(struct socket *sock) -{ - int ret, slen; - struct sockaddr_in sin; - struct socket *new_sock = NULL; - struct r2nm_node *node = NULL; - struct r2nm_node *local_node = NULL; - struct r2net_sock_container *sc = NULL; - struct r2net_node *nn; - - BUG_ON(sock == NULL); - ret = sock_create_lite(sock->sk->sk_family, sock->sk->sk_type, - sock->sk->sk_protocol, &new_sock); - if (ret) - goto out; - - new_sock->type = sock->type; - new_sock->ops = sock->ops; - ret = sock->ops->accept(sock, new_sock, O_NONBLOCK); - if (ret < 0) - goto out; - - new_sock->sk->sk_allocation = GFP_ATOMIC; - - ret = r2net_set_nodelay(new_sock); - if (ret) { - mlog(ML_ERROR, "setting TCP_NODELAY failed with %d\n", ret); - goto out; - } - - slen = sizeof(sin); - ret = new_sock->ops->getname(new_sock, (struct sockaddr *) &sin, - &slen, 1); - if (ret < 0) - goto out; - - node = r2nm_get_node_by_ip(sin.sin_addr.s_addr); - if (node == NULL) { - pr_notice("ramster: Attempt to connect from unknown " - "node at %pI4:%d\n", &sin.sin_addr.s_addr, - ntohs(sin.sin_port)); - ret = -EINVAL; - goto out; - } - - if (r2nm_this_node() >= node->nd_num) { - local_node = r2nm_get_node_by_num(r2nm_this_node()); - pr_notice("ramster: Unexpected connect attempt seen " - "at node '%s' (%u, %pI4:%d) from node '%s' (%u, " - "%pI4:%d)\n", local_node->nd_name, local_node->nd_num, - &(local_node->nd_ipv4_address), - ntohs(local_node->nd_ipv4_port), node->nd_name, - node->nd_num, &sin.sin_addr.s_addr, ntohs(sin.sin_port)); - ret = -EINVAL; - goto out; - } - - /* this happens all the time when the other node sees our heartbeat - * and tries to connect before we see their heartbeat */ - if (!r2hb_check_node_heartbeating_from_callback(node->nd_num)) { - mlog(ML_CONN, "attempt to connect from node '%s' at " - "%pI4:%d but it isn't heartbeating\n", - node->nd_name, &sin.sin_addr.s_addr, - ntohs(sin.sin_port)); - ret = -EINVAL; - goto out; - } - - nn = r2net_nn_from_num(node->nd_num); - - spin_lock(&nn->nn_lock); - if (nn->nn_sc) - ret = -EBUSY; - else - ret = 0; - spin_unlock(&nn->nn_lock); - if (ret) { - pr_notice("ramster: Attempt to connect from node '%s' " - "at %pI4:%d but it already has an open connection\n", - node->nd_name, &sin.sin_addr.s_addr, - ntohs(sin.sin_port)); - goto out; - } - - sc = sc_alloc(node); - if (sc == NULL) { - ret = -ENOMEM; - goto out; - } - - sc->sc_sock = new_sock; - new_sock = NULL; - - spin_lock(&nn->nn_lock); - atomic_set(&nn->nn_timeout, 0); - r2net_set_nn_state(nn, sc, 0, 0); - spin_unlock(&nn->nn_lock); - - r2net_register_callbacks(sc->sc_sock->sk, sc); - r2net_sc_queue_work(sc, &sc->sc_rx_work); - - r2net_initialize_handshake(); - r2net_sendpage(sc, r2net_hand, sizeof(*r2net_hand)); - -out: - if (new_sock) - sock_release(new_sock); - if (node) - r2nm_node_put(node); - if (local_node) - r2nm_node_put(local_node); - if (sc) - sc_put(sc); - return ret; -} - -static void r2net_accept_many(struct work_struct *work) -{ - struct socket *sock = r2net_listen_sock; - while (r2net_accept_one(sock) == 0) - cond_resched(); -} - -static void r2net_listen_data_ready(struct sock *sk, int bytes) -{ - void (*ready)(struct sock *sk, int bytes); - - read_lock(&sk->sk_callback_lock); - ready = sk->sk_user_data; - if (ready == NULL) { /* check for teardown race */ - ready = sk->sk_data_ready; - goto out; - } - - /* ->sk_data_ready is also called for a newly established child socket - * before it has been accepted and the acceptor has set up their - * data_ready.. we only want to queue listen work for our listening - * socket */ - if (sk->sk_state == TCP_LISTEN) { - mlog(ML_TCP, "bytes: %d\n", bytes); - queue_work(r2net_wq, &r2net_listen_work); - } - -out: - read_unlock(&sk->sk_callback_lock); - ready(sk, bytes); -} - -static int r2net_open_listening_sock(__be32 addr, __be16 port) -{ - struct socket *sock = NULL; - int ret; - struct sockaddr_in sin = { - .sin_family = PF_INET, - .sin_addr = { .s_addr = addr }, - .sin_port = port, - }; - - ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); - if (ret < 0) { - pr_err("ramster: Error %d while creating socket\n", ret); - goto out; - } - - sock->sk->sk_allocation = GFP_ATOMIC; - - write_lock_bh(&sock->sk->sk_callback_lock); - sock->sk->sk_user_data = sock->sk->sk_data_ready; - sock->sk->sk_data_ready = r2net_listen_data_ready; - write_unlock_bh(&sock->sk->sk_callback_lock); - - r2net_listen_sock = sock; - INIT_WORK(&r2net_listen_work, r2net_accept_many); - - sock->sk->sk_reuse = /* SK_CAN_REUSE FIXME FOR 3.4 */ 1; - ret = sock->ops->bind(sock, (struct sockaddr *)&sin, sizeof(sin)); - if (ret < 0) { - pr_err("ramster: Error %d while binding socket at %pI4:%u\n", - ret, &addr, ntohs(port)); - goto out; - } - - ret = sock->ops->listen(sock, 64); - if (ret < 0) - pr_err("ramster: Error %d while listening on %pI4:%u\n", - ret, &addr, ntohs(port)); - -out: - if (ret) { - r2net_listen_sock = NULL; - if (sock) - sock_release(sock); - } - return ret; -} - -/* - * called from node manager when we should bring up our network listening - * socket. node manager handles all the serialization to only call this - * once and to match it with r2net_stop_listening(). note, - * r2nm_this_node() doesn't work yet as we're being called while it - * is being set up. - */ -int r2net_start_listening(struct r2nm_node *node) -{ - int ret = 0; - - BUG_ON(r2net_wq != NULL); - BUG_ON(r2net_listen_sock != NULL); - - mlog(ML_KTHREAD, "starting r2net thread...\n"); - r2net_wq = create_singlethread_workqueue("r2net"); - if (r2net_wq == NULL) { - mlog(ML_ERROR, "unable to launch r2net thread\n"); - return -ENOMEM; /* ? */ - } - - ret = r2net_open_listening_sock(node->nd_ipv4_address, - node->nd_ipv4_port); - if (ret) { - destroy_workqueue(r2net_wq); - r2net_wq = NULL; - } - - return ret; -} - -/* again, r2nm_this_node() doesn't work here as we're involved in - * tearing it down */ -void r2net_stop_listening(struct r2nm_node *node) -{ - struct socket *sock = r2net_listen_sock; - size_t i; - - BUG_ON(r2net_wq == NULL); - BUG_ON(r2net_listen_sock == NULL); - - /* stop the listening socket from generating work */ - write_lock_bh(&sock->sk->sk_callback_lock); - sock->sk->sk_data_ready = sock->sk->sk_user_data; - sock->sk->sk_user_data = NULL; - write_unlock_bh(&sock->sk->sk_callback_lock); - - for (i = 0; i < ARRAY_SIZE(r2net_nodes); i++) { - struct r2nm_node *node = r2nm_get_node_by_num(i); - if (node) { - r2net_disconnect_node(node); - r2nm_node_put(node); - } - } - - /* finish all work and tear down the work queue */ - mlog(ML_KTHREAD, "waiting for r2net thread to exit....\n"); - destroy_workqueue(r2net_wq); - r2net_wq = NULL; - - sock_release(r2net_listen_sock); - r2net_listen_sock = NULL; -} - -void r2net_hb_node_up_manual(int node_num) -{ - struct r2nm_node dummy; - if (r2nm_single_cluster == NULL) - pr_err("ramster: cluster not alive, node_up_manual ignored\n"); - else { - r2hb_manual_set_node_heartbeating(node_num); - r2net_hb_node_up_cb(&dummy, node_num, NULL); - } -} - -/* ------------------------------------------------------------ */ - -int r2net_init(void) -{ - unsigned long i; - - if (r2net_debugfs_init()) - return -ENOMEM; - - r2net_hand = kzalloc(sizeof(struct r2net_handshake), GFP_KERNEL); - r2net_keep_req = kzalloc(sizeof(struct r2net_msg), GFP_KERNEL); - r2net_keep_resp = kzalloc(sizeof(struct r2net_msg), GFP_KERNEL); - if (!r2net_hand || !r2net_keep_req || !r2net_keep_resp) { - kfree(r2net_hand); - kfree(r2net_keep_req); - kfree(r2net_keep_resp); - return -ENOMEM; - } - - r2net_hand->protocol_version = cpu_to_be64(R2NET_PROTOCOL_VERSION); - r2net_hand->connector_id = cpu_to_be64(1); - - r2net_keep_req->magic = cpu_to_be16(R2NET_MSG_KEEP_REQ_MAGIC); - r2net_keep_resp->magic = cpu_to_be16(R2NET_MSG_KEEP_RESP_MAGIC); - - for (i = 0; i < ARRAY_SIZE(r2net_nodes); i++) { - struct r2net_node *nn = r2net_nn_from_num(i); - - atomic_set(&nn->nn_timeout, 0); - spin_lock_init(&nn->nn_lock); - INIT_DELAYED_WORK(&nn->nn_connect_work, r2net_start_connect); - INIT_DELAYED_WORK(&nn->nn_connect_expired, - r2net_connect_expired); - INIT_DELAYED_WORK(&nn->nn_still_up, r2net_still_up); - /* until we see hb from a node we'll return einval */ - nn->nn_persistent_error = -ENOTCONN; - init_waitqueue_head(&nn->nn_sc_wq); - idr_init(&nn->nn_status_idr); - INIT_LIST_HEAD(&nn->nn_status_list); - } - - return 0; -} - -void r2net_exit(void) -{ - kfree(r2net_hand); - kfree(r2net_keep_req); - kfree(r2net_keep_resp); - r2net_debugfs_exit(); -} diff --git a/drivers/staging/ramster/ramster/tcp.h b/drivers/staging/ramster/ramster/tcp.h deleted file mode 100644 index 9d05833..0000000 --- a/drivers/staging/ramster/ramster/tcp.h +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * tcp.h - * - * Function prototypes - * - * Copyright (C) 2004 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - * - */ - -#ifndef R2CLUSTER_TCP_H -#define R2CLUSTER_TCP_H - -#include -#ifdef __KERNEL__ -#include -#include -#else -#include -#endif -#include -#include - -struct r2net_msg { - __be16 magic; - __be16 data_len; - __be16 msg_type; - __be16 pad1; - __be32 sys_status; - __be32 status; - __be32 key; - __be32 msg_num; - __u8 buf[0]; -}; - -typedef int (r2net_msg_handler_func)(struct r2net_msg *msg, u32 len, void *data, - void **ret_data); -typedef void (r2net_post_msg_handler_func)(int status, void *data, - void *ret_data); - -#define R2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct r2net_msg)) - -/* same as hb delay, we're waiting for another node to recognize our hb */ -#define R2NET_RECONNECT_DELAY_MS_DEFAULT 2000 - -#define R2NET_KEEPALIVE_DELAY_MS_DEFAULT 2000 -#define R2NET_IDLE_TIMEOUT_MS_DEFAULT 30000 - - -/* TODO: figure this out.... */ -static inline int r2net_link_down(int err, struct socket *sock) -{ - if (sock) { - if (sock->sk->sk_state != TCP_ESTABLISHED && - sock->sk->sk_state != TCP_CLOSE_WAIT) - return 1; - } - - if (err >= 0) - return 0; - switch (err) { - - /* ????????????????????????? */ - case -ERESTARTSYS: - case -EBADF: - /* When the server has died, an ICMP port unreachable - * message prompts ECONNREFUSED. */ - case -ECONNREFUSED: - case -ENOTCONN: - case -ECONNRESET: - case -EPIPE: - return 1; - - } - return 0; -} - -enum { - R2NET_DRIVER_UNINITED, - R2NET_DRIVER_READY, -}; - -int r2net_send_message(u32 msg_type, u32 key, void *data, u32 len, - u8 target_node, int *status); -int r2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec, - size_t veclen, u8 target_node, int *status); - -int r2net_register_handler(u32 msg_type, u32 key, u32 max_len, - r2net_msg_handler_func *func, void *data, - r2net_post_msg_handler_func *post_func, - struct list_head *unreg_list); -void r2net_unregister_handler_list(struct list_head *list); - -void r2net_fill_node_map(unsigned long *map, unsigned bytes); - -void r2net_force_data_magic(struct r2net_msg *, u16, u32); -void r2net_hb_node_up_manual(int); -struct r2net_node *r2net_nn_from_num(u8); - -struct r2nm_node; -int r2net_register_hb_callbacks(void); -void r2net_unregister_hb_callbacks(void); -int r2net_start_listening(struct r2nm_node *node); -void r2net_stop_listening(struct r2nm_node *node); -void r2net_disconnect_node(struct r2nm_node *node); -int r2net_num_connected_peers(void); - -int r2net_init(void); -void r2net_exit(void); - -struct r2net_send_tracking; -struct r2net_sock_container; - -#if 0 -int r2net_debugfs_init(void); -void r2net_debugfs_exit(void); -void r2net_debug_add_nst(struct r2net_send_tracking *nst); -void r2net_debug_del_nst(struct r2net_send_tracking *nst); -void r2net_debug_add_sc(struct r2net_sock_container *sc); -void r2net_debug_del_sc(struct r2net_sock_container *sc); -#else -static inline int r2net_debugfs_init(void) -{ - return 0; -} -static inline void r2net_debugfs_exit(void) -{ -} -static inline void r2net_debug_add_nst(struct r2net_send_tracking *nst) -{ -} -static inline void r2net_debug_del_nst(struct r2net_send_tracking *nst) -{ -} -static inline void r2net_debug_add_sc(struct r2net_sock_container *sc) -{ -} -static inline void r2net_debug_del_sc(struct r2net_sock_container *sc) -{ -} -#endif /* CONFIG_DEBUG_FS */ - -#endif /* R2CLUSTER_TCP_H */ diff --git a/drivers/staging/ramster/ramster/tcp_internal.h b/drivers/staging/ramster/ramster/tcp_internal.h deleted file mode 100644 index 4d8cc9f..0000000 --- a/drivers/staging/ramster/ramster/tcp_internal.h +++ /dev/null @@ -1,248 +0,0 @@ -/* -*- mode: c; c-basic-offset: 8; -*- - * vim: noexpandtab sw=8 ts=8 sts=0: - * - * Copyright (C) 2005 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#ifndef R2CLUSTER_TCP_INTERNAL_H -#define R2CLUSTER_TCP_INTERNAL_H - -#define R2NET_MSG_MAGIC ((u16)0xfa55) -#define R2NET_MSG_STATUS_MAGIC ((u16)0xfa56) -#define R2NET_MSG_KEEP_REQ_MAGIC ((u16)0xfa57) -#define R2NET_MSG_KEEP_RESP_MAGIC ((u16)0xfa58) -/* - * "data magic" is a long version of "status magic" where the message - * payload actually contains data to be passed in reply to certain messages - */ -#define R2NET_MSG_DATA_MAGIC ((u16)0xfa59) - -/* we're delaying our quorum decision so that heartbeat will have timed - * out truly dead nodes by the time we come around to making decisions - * on their number */ -#define R2NET_QUORUM_DELAY_MS \ - ((r2hb_dead_threshold + 2) * R2HB_REGION_TIMEOUT_MS) - -/* - * This version number represents quite a lot, unfortunately. It not - * only represents the raw network message protocol on the wire but also - * locking semantics of the file system using the protocol. It should - * be somewhere else, I'm sure, but right now it isn't. - * - * With version 11, we separate out the filesystem locking portion. The - * filesystem now has a major.minor version it negotiates. Version 11 - * introduces this negotiation to the r2dlm protocol, and as such the - * version here in tcp_internal.h should not need to be bumped for - * filesystem locking changes. - * - * New in version 11 - * - Negotiation of filesystem locking in the dlm join. - * - * New in version 10: - * - Meta/data locks combined - * - * New in version 9: - * - All votes removed - * - * New in version 8: - * - Replace delete inode votes with a cluster lock - * - * New in version 7: - * - DLM join domain includes the live nodemap - * - * New in version 6: - * - DLM lockres remote refcount fixes. - * - * New in version 5: - * - Network timeout checking protocol - * - * New in version 4: - * - Remove i_generation from lock names for better stat performance. - * - * New in version 3: - * - Replace dentry votes with a cluster lock - * - * New in version 2: - * - full 64 bit i_size in the metadata lock lvbs - * - introduction of "rw" lock and pushing meta/data locking down - */ -#define R2NET_PROTOCOL_VERSION 11ULL -struct r2net_handshake { - __be64 protocol_version; - __be64 connector_id; - __be32 r2hb_heartbeat_timeout_ms; - __be32 r2net_idle_timeout_ms; - __be32 r2net_keepalive_delay_ms; - __be32 r2net_reconnect_delay_ms; -}; - -struct r2net_node { - /* this is never called from int/bh */ - spinlock_t nn_lock; - - /* set the moment an sc is allocated and a connect is started */ - struct r2net_sock_container *nn_sc; - /* _valid is only set after the handshake passes and tx can happen */ - unsigned nn_sc_valid:1; - /* if this is set tx just returns it */ - int nn_persistent_error; - /* It is only set to 1 after the idle time out. */ - atomic_t nn_timeout; - - /* threads waiting for an sc to arrive wait on the wq for generation - * to increase. it is increased when a connecting socket succeeds - * or fails or when an accepted socket is attached. */ - wait_queue_head_t nn_sc_wq; - - struct idr nn_status_idr; - struct list_head nn_status_list; - - /* connects are attempted from when heartbeat comes up until either hb - * goes down, the node is unconfigured, no connect attempts succeed - * before R2NET_CONN_IDLE_DELAY, or a connect succeeds. connect_work - * is queued from set_nn_state both from hb up and from itself if a - * connect attempt fails and so can be self-arming. shutdown is - * careful to first mark the nn such that no connects will be attempted - * before canceling delayed connect work and flushing the queue. */ - struct delayed_work nn_connect_work; - unsigned long nn_last_connect_attempt; - - /* this is queued as nodes come up and is canceled when a connection is - * established. this expiring gives up on the node and errors out - * transmits */ - struct delayed_work nn_connect_expired; - - /* after we give up on a socket we wait a while before deciding - * that it is still heartbeating and that we should do some - * quorum work */ - struct delayed_work nn_still_up; -}; - -struct r2net_sock_container { - struct kref sc_kref; - /* the next two are valid for the life time of the sc */ - struct socket *sc_sock; - struct r2nm_node *sc_node; - - /* all of these sc work structs hold refs on the sc while they are - * queued. they should not be able to ref a freed sc. the teardown - * race is with r2net_wq destruction in r2net_stop_listening() */ - - /* rx and connect work are generated from socket callbacks. sc - * shutdown removes the callbacks and then flushes the work queue */ - struct work_struct sc_rx_work; - struct work_struct sc_connect_work; - /* shutdown work is triggered in two ways. the simple way is - * for a code path calls ensure_shutdown which gets a lock, removes - * the sc from the nn, and queues the work. in this case the - * work is single-shot. the work is also queued from a sock - * callback, though, and in this case the work will find the sc - * still on the nn and will call ensure_shutdown itself.. this - * ends up triggering the shutdown work again, though nothing - * will be done in that second iteration. so work queue teardown - * has to be careful to remove the sc from the nn before waiting - * on the work queue so that the shutdown work doesn't remove the - * sc and rearm itself. - */ - struct work_struct sc_shutdown_work; - - struct timer_list sc_idle_timeout; - struct delayed_work sc_keepalive_work; - - unsigned sc_handshake_ok:1; - - struct page *sc_page; - size_t sc_page_off; - - /* original handlers for the sockets */ - void (*sc_state_change)(struct sock *sk); - void (*sc_data_ready)(struct sock *sk, int bytes); - - u32 sc_msg_key; - u16 sc_msg_type; - -#ifdef CONFIG_DEBUG_FS - struct list_head sc_net_debug_item; - ktime_t sc_tv_timer; - ktime_t sc_tv_data_ready; - ktime_t sc_tv_advance_start; - ktime_t sc_tv_advance_stop; - ktime_t sc_tv_func_start; - ktime_t sc_tv_func_stop; -#endif -#ifdef CONFIG_RAMSTER_FS_STATS - ktime_t sc_tv_acquiry_total; - ktime_t sc_tv_send_total; - ktime_t sc_tv_status_total; - u32 sc_send_count; - u32 sc_recv_count; - ktime_t sc_tv_process_total; -#endif - struct mutex sc_send_lock; -}; - -struct r2net_msg_handler { - struct rb_node nh_node; - u32 nh_max_len; - u32 nh_msg_type; - u32 nh_key; - r2net_msg_handler_func *nh_func; - r2net_msg_handler_func *nh_func_data; - r2net_post_msg_handler_func - *nh_post_func; - struct kref nh_kref; - struct list_head nh_unregister_item; -}; - -enum r2net_system_error { - R2NET_ERR_NONE = 0, - R2NET_ERR_NO_HNDLR, - R2NET_ERR_OVERFLOW, - R2NET_ERR_DIED, - R2NET_ERR_MAX -}; - -struct r2net_status_wait { - enum r2net_system_error ns_sys_status; - s32 ns_status; - int ns_id; - wait_queue_head_t ns_wq; - struct list_head ns_node_item; -}; - -#ifdef CONFIG_DEBUG_FS -/* just for state dumps */ -struct r2net_send_tracking { - struct list_head st_net_debug_item; - struct task_struct *st_task; - struct r2net_sock_container *st_sc; - u32 st_id; - u32 st_msg_type; - u32 st_msg_key; - u8 st_node; - ktime_t st_sock_time; - ktime_t st_send_time; - ktime_t st_status_time; -}; -#else -struct r2net_send_tracking { - u32 dummy; -}; -#endif /* CONFIG_DEBUG_FS */ - -#endif /* R2CLUSTER_TCP_INTERNAL_H */ diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c deleted file mode 100644 index a2b7e03..0000000 --- a/drivers/staging/ramster/tmem.c +++ /dev/null @@ -1,894 +0,0 @@ -/* - * In-kernel transcendent memory (generic implementation) - * - * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. - * - * The primary purpose of Transcedent Memory ("tmem") is to map object-oriented - * "handles" (triples containing a pool id, and object id, and an index), to - * pages in a page-accessible memory (PAM). Tmem references the PAM pages via - * an abstract "pampd" (PAM page-descriptor), which can be operated on by a - * set of functions (pamops). Each pampd contains some representation of - * PAGE_SIZE bytes worth of data. For those familiar with key-value stores, - * the tmem handle is a three-level hierarchical key, and the value is always - * reconstituted (but not necessarily stored) as PAGE_SIZE bytes and is - * referenced in the datastore by the pampd. The hierarchy is required - * to ensure that certain invalidation functions can be performed efficiently - * (i.e. flush all indexes associated with this object_id, or - * flush all objects associated with this pool). - * - * Tmem must support potentially millions of pages and must be able to insert, - * find, and delete these pages at a potential frequency of thousands per - * second concurrently across many CPUs, (and, if used with KVM, across many - * vcpus across many guests). Tmem is tracked with a hierarchy of data - * structures, organized by the elements in the handle-tuple: pool_id, - * object_id, and page index. One or more "clients" (e.g. guests) each - * provide one or more tmem_pools. Each pool, contains a hash table of - * rb_trees of tmem_objs. Each tmem_obj contains a radix-tree-like tree - * of pointers, with intermediate nodes called tmem_objnodes. Each leaf - * pointer in this tree points to a pampd, which is accessible only through - * a small set of callbacks registered by the PAM implementation (see - * tmem_register_pamops). Tmem only needs to memory allocation for objs - * and objnodes and this is done via a set of callbacks that must be - * registered by the tmem host implementation (e.g. see tmem_register_hostops). - */ - -#include -#include -#include -#ifdef CONFIG_RAMSTER -#include -#endif - -#include "tmem.h" - -/* data structure sentinels used for debugging... see tmem.h */ -#define POOL_SENTINEL 0x87658765 -#define OBJ_SENTINEL 0x12345678 -#define OBJNODE_SENTINEL 0xfedcba09 - -/* - * A tmem host implementation must use this function to register callbacks - * for memory allocation. - */ -static struct tmem_hostops tmem_hostops; - -static void tmem_objnode_tree_init(void); - -void tmem_register_hostops(struct tmem_hostops *m) -{ - tmem_objnode_tree_init(); - tmem_hostops = *m; -} - -/* - * A tmem host implementation must use this function to register - * callbacks for a page-accessible memory (PAM) implementation. - */ -static struct tmem_pamops tmem_pamops; - -void tmem_register_pamops(struct tmem_pamops *m) -{ - tmem_pamops = *m; -} - -/* - * Oid's are potentially very sparse and tmem_objs may have an indeterminately - * short life, being added and deleted at a relatively high frequency. - * So an rb_tree is an ideal data structure to manage tmem_objs. But because - * of the potentially huge number of tmem_objs, each pool manages a hashtable - * of rb_trees to reduce search, insert, delete, and rebalancing time. - * Each hashbucket also has a lock to manage concurrent access and no - * searches, inserts, or deletions can be performed unless the lock is held. - * As a result, care must be taken to ensure tmem routines are not called - * recursively; the vast majority of the time, a recursive call may work - * but a deadlock will occur a small fraction of the time due to the - * hashbucket lock. - * - * The following routines manage tmem_objs. In all of these routines, - * the hashbucket lock is already held. - */ - -/* Search for object==oid in pool, returns object if found. */ -static struct tmem_obj *__tmem_obj_find(struct tmem_hashbucket *hb, - struct tmem_oid *oidp, - struct rb_node **parent, - struct rb_node ***link) -{ - struct rb_node *_parent = NULL, **rbnode; - struct tmem_obj *obj = NULL; - - rbnode = &hb->obj_rb_root.rb_node; - while (*rbnode) { - BUG_ON(RB_EMPTY_NODE(*rbnode)); - _parent = *rbnode; - obj = rb_entry(*rbnode, struct tmem_obj, - rb_tree_node); - switch (tmem_oid_compare(oidp, &obj->oid)) { - case 0: /* equal */ - goto out; - case -1: - rbnode = &(*rbnode)->rb_left; - break; - case 1: - rbnode = &(*rbnode)->rb_right; - break; - } - } - - if (parent) - *parent = _parent; - if (link) - *link = rbnode; - obj = NULL; -out: - return obj; -} - -static struct tmem_obj *tmem_obj_find(struct tmem_hashbucket *hb, - struct tmem_oid *oidp) -{ - return __tmem_obj_find(hb, oidp, NULL, NULL); -} - -static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *, bool); - -/* Free an object that has no more pampds in it. */ -static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb) -{ - struct tmem_pool *pool; - - BUG_ON(obj == NULL); - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pampd_count > 0); - pool = obj->pool; - BUG_ON(pool == NULL); - if (obj->objnode_tree_root != NULL) /* may be "stump" with no leaves */ - tmem_pampd_destroy_all_in_obj(obj, false); - BUG_ON(obj->objnode_tree_root != NULL); - BUG_ON((long)obj->objnode_count != 0); - atomic_dec(&pool->obj_count); - BUG_ON(atomic_read(&pool->obj_count) < 0); - INVERT_SENTINEL(obj, OBJ); - obj->pool = NULL; - tmem_oid_set_invalid(&obj->oid); - rb_erase(&obj->rb_tree_node, &hb->obj_rb_root); -} - -/* - * Initialize, and insert an tmem_object_root (called only if find failed). - */ -static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb, - struct tmem_pool *pool, - struct tmem_oid *oidp) -{ - struct rb_root *root = &hb->obj_rb_root; - struct rb_node **new = NULL, *parent = NULL; - - BUG_ON(pool == NULL); - atomic_inc(&pool->obj_count); - obj->objnode_tree_height = 0; - obj->objnode_tree_root = NULL; - obj->pool = pool; - obj->oid = *oidp; - obj->objnode_count = 0; - obj->pampd_count = 0; -#ifdef CONFIG_RAMSTER - if (tmem_pamops.new_obj != NULL) - (*tmem_pamops.new_obj)(obj); -#endif - SET_SENTINEL(obj, OBJ); - - if (__tmem_obj_find(hb, oidp, &parent, &new)) - BUG(); - - rb_link_node(&obj->rb_tree_node, parent, new); - rb_insert_color(&obj->rb_tree_node, root); -} - -/* - * Tmem is managed as a set of tmem_pools with certain attributes, such as - * "ephemeral" vs "persistent". These attributes apply to all tmem_objs - * and all pampds that belong to a tmem_pool. A tmem_pool is created - * or deleted relatively rarely (for example, when a filesystem is - * mounted or unmounted). - */ - -/* flush all data from a pool and, optionally, free it */ -static void tmem_pool_flush(struct tmem_pool *pool, bool destroy) -{ - struct rb_node *rbnode; - struct tmem_obj *obj; - struct tmem_hashbucket *hb = &pool->hashbucket[0]; - int i; - - BUG_ON(pool == NULL); - for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) { - spin_lock(&hb->lock); - rbnode = rb_first(&hb->obj_rb_root); - while (rbnode != NULL) { - obj = rb_entry(rbnode, struct tmem_obj, rb_tree_node); - rbnode = rb_next(rbnode); - tmem_pampd_destroy_all_in_obj(obj, true); - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - } - spin_unlock(&hb->lock); - } - if (destroy) - list_del(&pool->pool_list); -} - -/* - * A tmem_obj contains a radix-tree-like tree in which the intermediate - * nodes are called tmem_objnodes. (The kernel lib/radix-tree.c implementation - * is very specialized and tuned for specific uses and is not particularly - * suited for use from this code, though some code from the core algorithms has - * been reused, thus the copyright notices below). Each tmem_objnode contains - * a set of pointers which point to either a set of intermediate tmem_objnodes - * or a set of of pampds. - * - * Portions Copyright (C) 2001 Momchil Velikov - * Portions Copyright (C) 2001 Christoph Hellwig - * Portions Copyright (C) 2005 SGI, Christoph Lameter - */ - -struct tmem_objnode_tree_path { - struct tmem_objnode *objnode; - int offset; -}; - -/* objnode height_to_maxindex translation */ -static unsigned long tmem_objnode_tree_h2max[OBJNODE_TREE_MAX_PATH + 1]; - -static void tmem_objnode_tree_init(void) -{ - unsigned int ht, tmp; - - for (ht = 0; ht < ARRAY_SIZE(tmem_objnode_tree_h2max); ht++) { - tmp = ht * OBJNODE_TREE_MAP_SHIFT; - if (tmp >= OBJNODE_TREE_INDEX_BITS) - tmem_objnode_tree_h2max[ht] = ~0UL; - else - tmem_objnode_tree_h2max[ht] = - (~0UL >> (OBJNODE_TREE_INDEX_BITS - tmp - 1)) >> 1; - } -} - -static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj) -{ - struct tmem_objnode *objnode; - - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pool == NULL); - ASSERT_SENTINEL(obj->pool, POOL); - objnode = (*tmem_hostops.objnode_alloc)(obj->pool); - if (unlikely(objnode == NULL)) - goto out; - objnode->obj = obj; - SET_SENTINEL(objnode, OBJNODE); - memset(&objnode->slots, 0, sizeof(objnode->slots)); - objnode->slots_in_use = 0; - obj->objnode_count++; -out: - return objnode; -} - -static void tmem_objnode_free(struct tmem_objnode *objnode) -{ - struct tmem_pool *pool; - int i; - - BUG_ON(objnode == NULL); - for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) - BUG_ON(objnode->slots[i] != NULL); - ASSERT_SENTINEL(objnode, OBJNODE); - INVERT_SENTINEL(objnode, OBJNODE); - BUG_ON(objnode->obj == NULL); - ASSERT_SENTINEL(objnode->obj, OBJ); - pool = objnode->obj->pool; - BUG_ON(pool == NULL); - ASSERT_SENTINEL(pool, POOL); - objnode->obj->objnode_count--; - objnode->obj = NULL; - (*tmem_hostops.objnode_free)(objnode, pool); -} - -/* - * Lookup index in object and return associated pampd (or NULL if not found). - */ -static void **__tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) -{ - unsigned int height, shift; - struct tmem_objnode **slot = NULL; - - BUG_ON(obj == NULL); - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pool == NULL); - ASSERT_SENTINEL(obj->pool, POOL); - - height = obj->objnode_tree_height; - if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) - goto out; - if (height == 0 && obj->objnode_tree_root) { - slot = &obj->objnode_tree_root; - goto out; - } - shift = (height-1) * OBJNODE_TREE_MAP_SHIFT; - slot = &obj->objnode_tree_root; - while (height > 0) { - if (*slot == NULL) - goto out; - slot = (struct tmem_objnode **) - ((*slot)->slots + - ((index >> shift) & OBJNODE_TREE_MAP_MASK)); - shift -= OBJNODE_TREE_MAP_SHIFT; - height--; - } -out: - return slot != NULL ? (void **)slot : NULL; -} - -static void *tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) -{ - struct tmem_objnode **slot; - - slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index); - return slot != NULL ? *slot : NULL; -} - -#ifdef CONFIG_RAMSTER -static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index, - void *new_pampd, bool no_free) -{ - struct tmem_objnode **slot; - void *ret = NULL; - - slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index); - if ((slot != NULL) && (*slot != NULL)) { - void *old_pampd = *(void **)slot; - *(void **)slot = new_pampd; - if (!no_free) - (*tmem_pamops.free)(old_pampd, obj->pool, - NULL, 0, false); - ret = new_pampd; - } - return ret; -} -#endif - -static int tmem_pampd_add_to_obj(struct tmem_obj *obj, uint32_t index, - void *pampd) -{ - int ret = 0; - struct tmem_objnode *objnode = NULL, *newnode, *slot; - unsigned int height, shift; - int offset = 0; - - /* if necessary, extend the tree to be higher */ - if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) { - height = obj->objnode_tree_height + 1; - if (index > tmem_objnode_tree_h2max[height]) - while (index > tmem_objnode_tree_h2max[height]) - height++; - if (obj->objnode_tree_root == NULL) { - obj->objnode_tree_height = height; - goto insert; - } - do { - newnode = tmem_objnode_alloc(obj); - if (!newnode) { - ret = -ENOMEM; - goto out; - } - newnode->slots[0] = obj->objnode_tree_root; - newnode->slots_in_use = 1; - obj->objnode_tree_root = newnode; - obj->objnode_tree_height++; - } while (height > obj->objnode_tree_height); - } -insert: - slot = obj->objnode_tree_root; - height = obj->objnode_tree_height; - shift = (height-1) * OBJNODE_TREE_MAP_SHIFT; - while (height > 0) { - if (slot == NULL) { - /* add a child objnode. */ - slot = tmem_objnode_alloc(obj); - if (!slot) { - ret = -ENOMEM; - goto out; - } - if (objnode) { - - objnode->slots[offset] = slot; - objnode->slots_in_use++; - } else - obj->objnode_tree_root = slot; - } - /* go down a level */ - offset = (index >> shift) & OBJNODE_TREE_MAP_MASK; - objnode = slot; - slot = objnode->slots[offset]; - shift -= OBJNODE_TREE_MAP_SHIFT; - height--; - } - BUG_ON(slot != NULL); - if (objnode) { - objnode->slots_in_use++; - objnode->slots[offset] = pampd; - } else - obj->objnode_tree_root = pampd; - obj->pampd_count++; -out: - return ret; -} - -static void *tmem_pampd_delete_from_obj(struct tmem_obj *obj, uint32_t index) -{ - struct tmem_objnode_tree_path path[OBJNODE_TREE_MAX_PATH + 1]; - struct tmem_objnode_tree_path *pathp = path; - struct tmem_objnode *slot = NULL; - unsigned int height, shift; - int offset; - - BUG_ON(obj == NULL); - ASSERT_SENTINEL(obj, OBJ); - BUG_ON(obj->pool == NULL); - ASSERT_SENTINEL(obj->pool, POOL); - height = obj->objnode_tree_height; - if (index > tmem_objnode_tree_h2max[height]) - goto out; - slot = obj->objnode_tree_root; - if (height == 0 && obj->objnode_tree_root) { - obj->objnode_tree_root = NULL; - goto out; - } - shift = (height - 1) * OBJNODE_TREE_MAP_SHIFT; - pathp->objnode = NULL; - do { - if (slot == NULL) - goto out; - pathp++; - offset = (index >> shift) & OBJNODE_TREE_MAP_MASK; - pathp->offset = offset; - pathp->objnode = slot; - slot = slot->slots[offset]; - shift -= OBJNODE_TREE_MAP_SHIFT; - height--; - } while (height > 0); - if (slot == NULL) - goto out; - while (pathp->objnode) { - pathp->objnode->slots[pathp->offset] = NULL; - pathp->objnode->slots_in_use--; - if (pathp->objnode->slots_in_use) { - if (pathp->objnode == obj->objnode_tree_root) { - while (obj->objnode_tree_height > 0 && - obj->objnode_tree_root->slots_in_use == 1 && - obj->objnode_tree_root->slots[0]) { - struct tmem_objnode *to_free = - obj->objnode_tree_root; - - obj->objnode_tree_root = - to_free->slots[0]; - obj->objnode_tree_height--; - to_free->slots[0] = NULL; - to_free->slots_in_use = 0; - tmem_objnode_free(to_free); - } - } - goto out; - } - tmem_objnode_free(pathp->objnode); /* 0 slots used, free it */ - pathp--; - } - obj->objnode_tree_height = 0; - obj->objnode_tree_root = NULL; - -out: - if (slot != NULL) - obj->pampd_count--; - BUG_ON(obj->pampd_count < 0); - return slot; -} - -/* Recursively walk the objnode_tree destroying pampds and objnodes. */ -static void tmem_objnode_node_destroy(struct tmem_obj *obj, - struct tmem_objnode *objnode, - unsigned int ht) -{ - int i; - - if (ht == 0) - return; - for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) { - if (objnode->slots[i]) { - if (ht == 1) { - obj->pampd_count--; - (*tmem_pamops.free)(objnode->slots[i], - obj->pool, NULL, 0, true); - objnode->slots[i] = NULL; - continue; - } - tmem_objnode_node_destroy(obj, objnode->slots[i], ht-1); - tmem_objnode_free(objnode->slots[i]); - objnode->slots[i] = NULL; - } - } -} - -static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj, - bool pool_destroy) -{ - if (obj->objnode_tree_root == NULL) - return; - if (obj->objnode_tree_height == 0) { - obj->pampd_count--; - (*tmem_pamops.free)(obj->objnode_tree_root, - obj->pool, NULL, 0, true); - } else { - tmem_objnode_node_destroy(obj, obj->objnode_tree_root, - obj->objnode_tree_height); - tmem_objnode_free(obj->objnode_tree_root); - obj->objnode_tree_height = 0; - } - obj->objnode_tree_root = NULL; -#ifdef CONFIG_RAMSTER - if (tmem_pamops.free_obj != NULL) - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy); -#endif -} - -/* - * Tmem is operated on by a set of well-defined actions: - * "put", "get", "flush", "flush_object", "new pool" and "destroy pool". - * (The tmem ABI allows for subpages and exchanges but these operations - * are not included in this implementation.) - * - * These "tmem core" operations are implemented in the following functions. - */ - -/* - * "Put" a page, e.g. associate the passed pampd with the passed handle. - * Tmem_put is complicated by a corner case: What if a page with matching - * handle already exists in tmem? To guarantee coherency, one of two - * actions is necessary: Either the data for the page must be overwritten, - * or the page must be "flushed" so that the data is not accessible to a - * subsequent "get". Since these "duplicate puts" are relatively rare, - * this implementation always flushes for simplicity. - */ -int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, - bool raw, void *pampd_to_use) -{ - struct tmem_obj *obj = NULL, *objfound = NULL, *objnew = NULL; - void *pampd = NULL, *pampd_del = NULL; - int ret = -ENOMEM; - struct tmem_hashbucket *hb; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = objfound = tmem_obj_find(hb, oidp); - if (obj != NULL) { - pampd = tmem_pampd_lookup_in_obj(objfound, index); - if (pampd != NULL) { - /* if found, is a dup put, flush the old one */ - pampd_del = tmem_pampd_delete_from_obj(obj, index); - BUG_ON(pampd_del != pampd); - (*tmem_pamops.free)(pampd, pool, oidp, index, true); - if (obj->pampd_count == 0) { - objnew = obj; - objfound = NULL; - } - pampd = NULL; - } - } else { - obj = objnew = (*tmem_hostops.obj_alloc)(pool); - if (unlikely(obj == NULL)) { - ret = -ENOMEM; - goto out; - } - tmem_obj_init(obj, hb, pool, oidp); - } - BUG_ON(obj == NULL); - BUG_ON(((objnew != obj) && (objfound != obj)) || (objnew == objfound)); - pampd = pampd_to_use; - BUG_ON(pampd_to_use == NULL); - ret = tmem_pampd_add_to_obj(obj, index, pampd); - if (unlikely(ret == -ENOMEM)) - /* may have partially built objnode tree ("stump") */ - goto delete_and_free; - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool)); - goto out; - -delete_and_free: - (void)tmem_pampd_delete_from_obj(obj, index); - if (pampd) - (*tmem_pamops.free)(pampd, pool, NULL, 0, true); - if (objnew) { - tmem_obj_free(objnew, hb); - (*tmem_hostops.obj_free)(objnew, pool); - } -out: - spin_unlock(&hb->lock); - return ret; -} - -#ifdef CONFIG_RAMSTER -/* - * For ramster only: The following routines provide a two-step sequence - * to allow the caller to replace a pampd in the tmem data structures with - * another pampd. Here, we lookup the passed handle and, if found, return the - * associated pampd and object, leaving the hashbucket locked and returning - * a reference to it. The caller is expected to immediately call the - * matching tmem_localify_finish routine which will handles the replacement - * and unlocks the hashbucket. - */ -void *tmem_localify_get_pampd(struct tmem_pool *pool, struct tmem_oid *oidp, - uint32_t index, struct tmem_obj **ret_obj, - void **saved_hb) -{ - struct tmem_hashbucket *hb; - struct tmem_obj *obj = NULL; - void *pampd = NULL; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (likely(obj != NULL)) - pampd = tmem_pampd_lookup_in_obj(obj, index); - *ret_obj = obj; - *saved_hb = (void *)hb; - /* note, hashbucket remains locked */ - return pampd; -} - -void tmem_localify_finish(struct tmem_obj *obj, uint32_t index, - void *pampd, void *saved_hb, bool delete) -{ - struct tmem_hashbucket *hb = (struct tmem_hashbucket *)saved_hb; - - BUG_ON(!spin_is_locked(&hb->lock)); - if (pampd != NULL) { - BUG_ON(obj == NULL); - (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1); - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool)); - } else if (delete) { - BUG_ON(obj == NULL); - (void)tmem_pampd_delete_from_obj(obj, index); - } - spin_unlock(&hb->lock); -} - -/* - * For ramster only. Helper function to support asynchronous tmem_get. - */ -static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb, - struct tmem_pool *pool, struct tmem_oid *oidp, - uint32_t index, bool free, char *data) -{ - void *old_pampd = *ppampd, *new_pampd = NULL; - bool intransit = false; - int ret = 0; - - if (!is_ephemeral(pool)) - new_pampd = (*tmem_pamops.repatriate_preload)( - old_pampd, pool, oidp, index, &intransit); - if (intransit) - ret = -EAGAIN; - else if (new_pampd != NULL) - *ppampd = new_pampd; - /* must release the hb->lock else repatriate can't sleep */ - spin_unlock(&hb->lock); - if (!intransit) - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool, - oidp, index, free, data); - if (ret == -EAGAIN) { - /* rare I think, but should cond_resched()??? */ - usleep_range(10, 1000); - } else if (ret == -ENOTCONN || ret == -EHOSTDOWN) { - ret = -1; - } else if (ret != 0 && ret != -ENOENT) { - ret = -1; - } - /* note hb->lock has now been unlocked */ - return ret; -} - -/* - * For ramster only. If a page in tmem matches the handle, replace the - * page so that any subsequent "get" gets the new page. Returns 0 if - * there was a page to replace, else returns -1. - */ -int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp, - uint32_t index, void *new_pampd) -{ - struct tmem_obj *obj; - int ret = -1; - struct tmem_hashbucket *hb; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0); - /* if we bug here, pamops wasn't properly set up for ramster */ - BUG_ON(tmem_pamops.replace_in_obj == NULL); - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj); -out: - spin_unlock(&hb->lock); - return ret; -} -#endif - -/* - * "Get" a page, e.g. if a pampd can be found matching the passed handle, - * use a pamops callback to recreated the page from the pampd with the - * matching handle. By tmem definition, when a "get" is successful on - * an ephemeral page, the page is "flushed", and when a "get" is successful - * on a persistent page, the page is retained in tmem. Note that to preserve - * coherency, "get" can never be skipped if tmem contains the data. - * That is, if a get is done with a certain handle and fails, any - * subsequent "get" must also fail (unless of course there is a - * "put" done with the same handle). - */ -int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, - char *data, size_t *sizep, bool raw, int get_and_free) -{ - struct tmem_obj *obj; - void *pampd = NULL; - bool ephemeral = is_ephemeral(pool); - int ret = -1; - struct tmem_hashbucket *hb; - bool free = (get_and_free == 1) || ((get_and_free == 0) && ephemeral); - bool lock_held = false; - void **ppampd; - - do { - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - lock_held = true; - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - ppampd = __tmem_pampd_lookup_in_obj(obj, index); - if (ppampd == NULL) - goto out; -#ifdef CONFIG_RAMSTER - if ((tmem_pamops.is_remote != NULL) && - tmem_pamops.is_remote(*ppampd)) { - ret = tmem_repatriate(ppampd, hb, pool, oidp, - index, free, data); - /* tmem_repatriate releases hb->lock */ - lock_held = false; - *sizep = PAGE_SIZE; - if (ret != -EAGAIN) - goto out; - } -#endif - } while (ret == -EAGAIN); - if (free) - pampd = tmem_pampd_delete_from_obj(obj, index); - else - pampd = tmem_pampd_lookup_in_obj(obj, index); - if (pampd == NULL) - goto out; - if (free) { - if (obj->pampd_count == 0) { - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - obj = NULL; - } - } - if (free) - ret = (*tmem_pamops.get_data_and_free)( - data, sizep, raw, pampd, pool, oidp, index); - else - ret = (*tmem_pamops.get_data)( - data, sizep, raw, pampd, pool, oidp, index); - if (ret < 0) - goto out; - ret = 0; -out: - if (lock_held) - spin_unlock(&hb->lock); - return ret; -} - -/* - * If a page in tmem matches the handle, "flush" this page from tmem such - * that any subsequent "get" does not succeed (unless, of course, there - * was another "put" with the same handle). - */ -int tmem_flush_page(struct tmem_pool *pool, - struct tmem_oid *oidp, uint32_t index) -{ - struct tmem_obj *obj; - void *pampd; - int ret = -1; - struct tmem_hashbucket *hb; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - pampd = tmem_pampd_delete_from_obj(obj, index); - if (pampd == NULL) - goto out; - (*tmem_pamops.free)(pampd, pool, oidp, index, true); - if (obj->pampd_count == 0) { - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - } - ret = 0; - -out: - spin_unlock(&hb->lock); - return ret; -} - -/* - * "Flush" all pages in tmem matching this oid. - */ -int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp) -{ - struct tmem_obj *obj; - struct tmem_hashbucket *hb; - int ret = -1; - - hb = &pool->hashbucket[tmem_oid_hash(oidp)]; - spin_lock(&hb->lock); - obj = tmem_obj_find(hb, oidp); - if (obj == NULL) - goto out; - tmem_pampd_destroy_all_in_obj(obj, false); - tmem_obj_free(obj, hb); - (*tmem_hostops.obj_free)(obj, pool); - ret = 0; - -out: - spin_unlock(&hb->lock); - return ret; -} - -/* - * "Flush" all pages (and tmem_objs) from this tmem_pool and disable - * all subsequent access to this tmem_pool. - */ -int tmem_destroy_pool(struct tmem_pool *pool) -{ - int ret = -1; - - if (pool == NULL) - goto out; - tmem_pool_flush(pool, 1); - ret = 0; -out: - return ret; -} - -static LIST_HEAD(tmem_global_pool_list); - -/* - * Create a new tmem_pool with the provided flag and return - * a pool id provided by the tmem host implementation. - */ -void tmem_new_pool(struct tmem_pool *pool, uint32_t flags) -{ - int persistent = flags & TMEM_POOL_PERSIST; - int shared = flags & TMEM_POOL_SHARED; - struct tmem_hashbucket *hb = &pool->hashbucket[0]; - int i; - - for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) { - hb->obj_rb_root = RB_ROOT; - spin_lock_init(&hb->lock); - } - INIT_LIST_HEAD(&pool->pool_list); - atomic_set(&pool->obj_count, 0); - SET_SENTINEL(pool, POOL); - list_add_tail(&pool->pool_list, &tmem_global_pool_list); - pool->persistent = persistent; - pool->shared = shared; -} diff --git a/drivers/staging/ramster/tmem.h b/drivers/staging/ramster/tmem.h deleted file mode 100644 index adbe5a8..0000000 --- a/drivers/staging/ramster/tmem.h +++ /dev/null @@ -1,259 +0,0 @@ -/* - * tmem.h - * - * Transcendent memory - * - * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. - */ - -#ifndef _TMEM_H_ -#define _TMEM_H_ - -#include -#include -#include -#include - -/* - * These are defined by the Xen<->Linux ABI so should remain consistent - */ -#define TMEM_POOL_PERSIST 1 -#define TMEM_POOL_SHARED 2 -#define TMEM_POOL_PRECOMPRESSED 4 -#define TMEM_POOL_PAGESIZE_SHIFT 4 -#define TMEM_POOL_PAGESIZE_MASK 0xf -#define TMEM_POOL_RESERVED_BITS 0x00ffff00 - -/* - * sentinels have proven very useful for debugging but can be removed - * or disabled before final merge. - */ -#undef SENTINELS -#ifdef SENTINELS -#define DECL_SENTINEL uint32_t sentinel; -#define SET_SENTINEL(_x, _y) (_x->sentinel = _y##_SENTINEL) -#define INVERT_SENTINEL(_x, _y) (_x->sentinel = ~_y##_SENTINEL) -#define ASSERT_SENTINEL(_x, _y) WARN_ON(_x->sentinel != _y##_SENTINEL) -#define ASSERT_INVERTED_SENTINEL(_x, _y) WARN_ON(_x->sentinel != ~_y##_SENTINEL) -#else -#define DECL_SENTINEL -#define SET_SENTINEL(_x, _y) do { } while (0) -#define INVERT_SENTINEL(_x, _y) do { } while (0) -#define ASSERT_SENTINEL(_x, _y) do { } while (0) -#define ASSERT_INVERTED_SENTINEL(_x, _y) do { } while (0) -#endif - -#define ASSERT_SPINLOCK(_l) lockdep_assert_held(_l) - -/* - * A pool is the highest-level data structure managed by tmem and - * usually corresponds to a large independent set of pages such as - * a filesystem. Each pool has an id, and certain attributes and counters. - * It also contains a set of hash buckets, each of which contains an rbtree - * of objects and a lock to manage concurrency within the pool. - */ - -#define TMEM_HASH_BUCKET_BITS 8 -#define TMEM_HASH_BUCKETS (1<persistent) -#define is_ephemeral(_p) (!(_p->persistent)) - -/* - * An object id ("oid") is large: 192-bits (to ensure, for example, files - * in a modern filesystem can be uniquely identified). - */ - -struct tmem_oid { - uint64_t oid[3]; -}; - -static inline void tmem_oid_set_invalid(struct tmem_oid *oidp) -{ - oidp->oid[0] = oidp->oid[1] = oidp->oid[2] = -1UL; -} - -static inline bool tmem_oid_valid(struct tmem_oid *oidp) -{ - return oidp->oid[0] != -1UL || oidp->oid[1] != -1UL || - oidp->oid[2] != -1UL; -} - -static inline int tmem_oid_compare(struct tmem_oid *left, - struct tmem_oid *right) -{ - int ret; - - if (left->oid[2] == right->oid[2]) { - if (left->oid[1] == right->oid[1]) { - if (left->oid[0] == right->oid[0]) - ret = 0; - else if (left->oid[0] < right->oid[0]) - ret = -1; - else - return 1; - } else if (left->oid[1] < right->oid[1]) - ret = -1; - else - ret = 1; - } else if (left->oid[2] < right->oid[2]) - ret = -1; - else - ret = 1; - return ret; -} - -static inline unsigned tmem_oid_hash(struct tmem_oid *oidp) -{ - return hash_long(oidp->oid[0] ^ oidp->oid[1] ^ oidp->oid[2], - TMEM_HASH_BUCKET_BITS); -} - -#ifdef CONFIG_RAMSTER -struct tmem_xhandle { - uint8_t client_id; - uint8_t xh_data_cksum; - uint16_t xh_data_size; - uint16_t pool_id; - struct tmem_oid oid; - uint32_t index; - void *extra; -}; - -static inline struct tmem_xhandle tmem_xhandle_fill(uint16_t client_id, - struct tmem_pool *pool, - struct tmem_oid *oidp, - uint32_t index) -{ - struct tmem_xhandle xh; - xh.client_id = client_id; - xh.xh_data_cksum = (uint8_t)-1; - xh.xh_data_size = (uint16_t)-1; - xh.pool_id = pool->pool_id; - xh.oid = *oidp; - xh.index = index; - return xh; -} -#endif - - -/* - * A tmem_obj contains an identifier (oid), pointers to the parent - * pool and the rb_tree to which it belongs, counters, and an ordered - * set of pampds, structured in a radix-tree-like tree. The intermediate - * nodes of the tree are called tmem_objnodes. - */ - -struct tmem_objnode; - -struct tmem_obj { - struct tmem_oid oid; - struct tmem_pool *pool; - struct rb_node rb_tree_node; - struct tmem_objnode *objnode_tree_root; - unsigned int objnode_tree_height; - unsigned long objnode_count; - long pampd_count; -#ifdef CONFIG_RAMSTER - /* - * for current design of ramster, all pages belonging to - * an object reside on the same remotenode and extra is - * used to record the number of the remotenode so a - * flush-object operation can specify it - */ - void *extra; /* for private use by pampd implementation */ -#endif - DECL_SENTINEL -}; - -#define OBJNODE_TREE_MAP_SHIFT 6 -#define OBJNODE_TREE_MAP_SIZE (1UL << OBJNODE_TREE_MAP_SHIFT) -#define OBJNODE_TREE_MAP_MASK (OBJNODE_TREE_MAP_SIZE-1) -#define OBJNODE_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long)) -#define OBJNODE_TREE_MAX_PATH \ - (OBJNODE_TREE_INDEX_BITS/OBJNODE_TREE_MAP_SHIFT + 2) - -struct tmem_objnode { - struct tmem_obj *obj; - DECL_SENTINEL - void *slots[OBJNODE_TREE_MAP_SIZE]; - unsigned int slots_in_use; -}; - -struct tmem_handle { - struct tmem_oid oid; /* 24 bytes */ - uint32_t index; - uint16_t pool_id; - uint16_t client_id; -}; - - -/* pampd abstract datatype methods provided by the PAM implementation */ -struct tmem_pamops { - void (*create_finish)(void *, bool); - int (*get_data)(char *, size_t *, bool, void *, struct tmem_pool *, - struct tmem_oid *, uint32_t); - int (*get_data_and_free)(char *, size_t *, bool, void *, - struct tmem_pool *, struct tmem_oid *, - uint32_t); - void (*free)(void *, struct tmem_pool *, - struct tmem_oid *, uint32_t, bool); -#ifdef CONFIG_RAMSTER - void (*new_obj)(struct tmem_obj *); - void (*free_obj)(struct tmem_pool *, struct tmem_obj *, bool); - void *(*repatriate_preload)(void *, struct tmem_pool *, - struct tmem_oid *, uint32_t, bool *); - int (*repatriate)(void *, void *, struct tmem_pool *, - struct tmem_oid *, uint32_t, bool, void *); - bool (*is_remote)(void *); - int (*replace_in_obj)(void *, struct tmem_obj *); -#endif -}; -extern void tmem_register_pamops(struct tmem_pamops *m); - -/* memory allocation methods provided by the host implementation */ -struct tmem_hostops { - struct tmem_obj *(*obj_alloc)(struct tmem_pool *); - void (*obj_free)(struct tmem_obj *, struct tmem_pool *); - struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *); - void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *); -}; -extern void tmem_register_hostops(struct tmem_hostops *m); - -/* core tmem accessor functions */ -extern int tmem_put(struct tmem_pool *, struct tmem_oid *, uint32_t index, - bool, void *); -extern int tmem_get(struct tmem_pool *, struct tmem_oid *, uint32_t index, - char *, size_t *, bool, int); -extern int tmem_flush_page(struct tmem_pool *, struct tmem_oid *, - uint32_t index); -extern int tmem_flush_object(struct tmem_pool *, struct tmem_oid *); -extern int tmem_destroy_pool(struct tmem_pool *); -extern void tmem_new_pool(struct tmem_pool *, uint32_t); -#ifdef CONFIG_RAMSTER -extern int tmem_replace(struct tmem_pool *, struct tmem_oid *, uint32_t index, - void *); -extern void *tmem_localify_get_pampd(struct tmem_pool *, struct tmem_oid *, - uint32_t index, struct tmem_obj **, - void **); -extern void tmem_localify_finish(struct tmem_obj *, uint32_t index, - void *, void *, bool); -#endif -#endif /* _TMEM_H */ diff --git a/drivers/staging/ramster/zbud.c b/drivers/staging/ramster/zbud.c deleted file mode 100644 index a7c4361..0000000 --- a/drivers/staging/ramster/zbud.c +++ /dev/null @@ -1,1060 +0,0 @@ -/* - * zbud.c - Compression buddies allocator - * - * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. - * - * Compression buddies ("zbud") provides for efficiently packing two - * (or, possibly in the future, more) compressed pages ("zpages") into - * a single "raw" pageframe and for tracking both zpages and pageframes - * so that whole pageframes can be easily reclaimed in LRU-like order. - * It is designed to be used in conjunction with transcendent memory - * ("tmem"); for example separate LRU lists are maintained for persistent - * vs. ephemeral pages. - * - * A zbudpage is an overlay for a struct page and thus each zbudpage - * refers to a physical pageframe of RAM. When the caller passes a - * struct page from the kernel's page allocator, zbud "transforms" it - * to a zbudpage which sets/uses a different set of fields than the - * struct-page and thus must "untransform" it back by reinitializing - * certain fields before the struct-page can be freed. The fields - * of a zbudpage include a page lock for controlling access to the - * corresponding pageframe, and there is a size field for each zpage. - * Each zbudpage also lives on two linked lists: a "budlist" which is - * used to support efficient buddying of zpages; and an "lru" which - * is used for reclaiming pageframes in approximately least-recently-used - * order. - * - * A zbudpageframe is a pageframe divided up into aligned 64-byte "chunks" - * which contain the compressed data for zero, one, or two zbuds. Contained - * with the compressed data is a tmem_handle which is a key to allow - * the same data to be found via the tmem interface so the zpage can - * be invalidated (for ephemeral pages) or repatriated to the swap cache - * (for persistent pages). The contents of a zbudpageframe must never - * be accessed without holding the page lock for the corresponding - * zbudpage and, to accomodate highmem machines, the contents may - * only be examined or changes when kmapped. Thus, when in use, a - * kmapped zbudpageframe is referred to in the zbud code as "void *zbpg". - * - * Note that the term "zbud" refers to the combination of a zpage and - * a tmem_handle that is stored as one of possibly two "buddied" zpages; - * it also generically refers to this allocator... sorry for any confusion. - * - * A zbudref is a pointer to a struct zbudpage (which can be cast to a - * struct page), with the LSB either cleared or set to indicate, respectively, - * the first or second zpage in the zbudpageframe. Since a zbudref can be - * cast to a pointer, it is used as the tmem "pampd" pointer and uniquely - * references a stored tmem page and so is the only zbud data structure - * externally visible to zbud.c/zbud.h. - * - * Since we wish to reclaim entire pageframes but zpages may be randomly - * added and deleted to any given pageframe, we approximate LRU by - * promoting a pageframe to MRU when a zpage is added to it, but - * leaving it at the current place in the list when a zpage is deleted - * from it. As a side effect, zpages that are difficult to buddy (e.g. - * very large paages) will be reclaimed faster than average, which seems - * reasonable. - * - * In the current implementation, no more than two zpages may be stored in - * any pageframe and no zpage ever crosses a pageframe boundary. While - * other zpage allocation mechanisms may allow greater density, this two - * zpage-per-pageframe limit both ensures simple reclaim of pageframes - * (including garbage collection of references to the contents of those - * pageframes from tmem data structures) AND avoids the need for compaction. - * With additional complexity, zbud could be modified to support storing - * up to three zpages per pageframe or, to handle larger average zpages, - * up to three zpages per pair of pageframes, but it is not clear if the - * additional complexity would be worth it. So consider it an exercise - * for future developers. - * - * Note also that zbud does no page allocation or freeing. This is so - * that the caller has complete control over and, for accounting, visibility - * into if/when pages are allocated and freed. - * - * Finally, note that zbud limits the size of zpages it can store; the - * caller must check the zpage size with zbud_max_buddy_size before - * storing it, else BUGs will result. User beware. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "tmem.h" -#include "zcache.h" -#include "zbud.h" - -/* - * We need to ensure that a struct zbudpage is never larger than a - * struct page. This is checked with a BUG_ON in zbud_init. - * - * The unevictable field indicates that a zbud is being added to the - * zbudpage. Since this is a two-phase process (due to tmem locking), - * this field locks the zbudpage against eviction when a zbud match - * or creation is in process. Since this addition process may occur - * in parallel for two zbuds in one zbudpage, the field is a counter - * that must not exceed two. - */ -struct zbudpage { - union { - struct page page; - struct { - unsigned long space_for_flags; - struct { - unsigned zbud0_size:12; - unsigned zbud1_size:12; - unsigned unevictable:2; - }; - struct list_head budlist; - struct list_head lru; - }; - }; -}; - -struct zbudref { - union { - struct zbudpage *zbudpage; - unsigned long zbudref; - }; -}; - -#define CHUNK_SHIFT 6 -#define CHUNK_SIZE (1 << CHUNK_SHIFT) -#define CHUNK_MASK (~(CHUNK_SIZE-1)) -#define NCHUNKS (PAGE_SIZE >> CHUNK_SHIFT) -#define MAX_CHUNK (NCHUNKS-1) - -/* - * The following functions deal with the difference between struct - * page and struct zbudpage. Note the hack of using the pageflags - * from struct page; this is to avoid duplicating all the complex - * pageflag macros. - */ -static inline void zbudpage_spin_lock(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - while (unlikely(test_and_set_bit_lock(PG_locked, &page->flags))) { - do { - cpu_relax(); - } while (test_bit(PG_locked, &page->flags)); - } -} - -static inline void zbudpage_spin_unlock(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - clear_bit(PG_locked, &page->flags); -} - -static inline int zbudpage_spin_trylock(struct zbudpage *zbudpage) -{ - return trylock_page((struct page *)zbudpage); -} - -static inline int zbudpage_is_locked(struct zbudpage *zbudpage) -{ - return PageLocked((struct page *)zbudpage); -} - -static inline void *kmap_zbudpage_atomic(struct zbudpage *zbudpage) -{ - return kmap_atomic((struct page *)zbudpage); -} - -/* - * A dying zbudpage is an ephemeral page in the process of being evicted. - * Any data contained in the zbudpage is invalid and we are just waiting for - * the tmem pampds to be invalidated before freeing the page - */ -static inline int zbudpage_is_dying(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - return test_bit(PG_reclaim, &page->flags); -} - -static inline void zbudpage_set_dying(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - set_bit(PG_reclaim, &page->flags); -} - -static inline void zbudpage_clear_dying(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - clear_bit(PG_reclaim, &page->flags); -} - -/* - * A zombie zbudpage is a persistent page in the process of being evicted. - * The data contained in the zbudpage is valid and we are just waiting for - * the tmem pampds to be invalidated before freeing the page - */ -static inline int zbudpage_is_zombie(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - return test_bit(PG_dirty, &page->flags); -} - -static inline void zbudpage_set_zombie(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - set_bit(PG_dirty, &page->flags); -} - -static inline void zbudpage_clear_zombie(struct zbudpage *zbudpage) -{ - struct page *page = (struct page *)zbudpage; - - clear_bit(PG_dirty, &page->flags); -} - -static inline void kunmap_zbudpage_atomic(void *zbpg) -{ - kunmap_atomic(zbpg); -} - -/* - * zbud "translation" and helper functions - */ - -static inline struct zbudpage *zbudref_to_zbudpage(struct zbudref *zref) -{ - unsigned long zbud = (unsigned long)zref; - zbud &= ~1UL; - return (struct zbudpage *)zbud; -} - -static inline struct zbudref *zbudpage_to_zbudref(struct zbudpage *zbudpage, - unsigned budnum) -{ - unsigned long zbud = (unsigned long)zbudpage; - BUG_ON(budnum > 1); - zbud |= budnum; - return (struct zbudref *)zbud; -} - -static inline int zbudref_budnum(struct zbudref *zbudref) -{ - unsigned long zbud = (unsigned long)zbudref; - return zbud & 1UL; -} - -static inline unsigned zbud_max_size(void) -{ - return MAX_CHUNK << CHUNK_SHIFT; -} - -static inline unsigned zbud_size_to_chunks(unsigned size) -{ - BUG_ON(size == 0 || size > zbud_max_size()); - return (size + CHUNK_SIZE - 1) >> CHUNK_SHIFT; -} - -/* can only be used between kmap_zbudpage_atomic/kunmap_zbudpage_atomic! */ -static inline char *zbud_data(void *zbpg, - unsigned budnum, unsigned size) -{ - char *p; - - BUG_ON(size == 0 || size > zbud_max_size()); - p = (char *)zbpg; - if (budnum == 1) - p += PAGE_SIZE - ((size + CHUNK_SIZE - 1) & CHUNK_MASK); - return p; -} - -/* - * These are all informative and exposed through debugfs... except for - * the arrays... anyone know how to do that? To avoid confusion for - * debugfs viewers, some of these should also be atomic_long_t, but - * I don't know how to expose atomics via debugfs either... - */ -static unsigned long zbud_eph_pageframes; -static unsigned long zbud_pers_pageframes; -static unsigned long zbud_eph_zpages; -static unsigned long zbud_pers_zpages; -static u64 zbud_eph_zbytes; -static u64 zbud_pers_zbytes; -static unsigned long zbud_eph_evicted_pageframes; -static unsigned long zbud_pers_evicted_pageframes; -static unsigned long zbud_eph_cumul_zpages; -static unsigned long zbud_pers_cumul_zpages; -static u64 zbud_eph_cumul_zbytes; -static u64 zbud_pers_cumul_zbytes; -static unsigned long zbud_eph_cumul_chunk_counts[NCHUNKS]; -static unsigned long zbud_pers_cumul_chunk_counts[NCHUNKS]; -static unsigned long zbud_eph_buddied_count; -static unsigned long zbud_pers_buddied_count; -static unsigned long zbud_eph_unbuddied_count; -static unsigned long zbud_pers_unbuddied_count; -static unsigned long zbud_eph_zombie_count; -static unsigned long zbud_pers_zombie_count; -static atomic_t zbud_eph_zombie_atomic; -static atomic_t zbud_pers_zombie_atomic; - -#ifdef CONFIG_DEBUG_FS -#include -#define zdfs debugfs_create_size_t -#define zdfs64 debugfs_create_u64 -static int zbud_debugfs_init(void) -{ - struct dentry *root = debugfs_create_dir("zbud", NULL); - if (root == NULL) - return -ENXIO; - - /* - * would be nice to dump the sizes of the unbuddied - * arrays, like was done with sysfs, but it doesn't - * look like debugfs is flexible enough to do that - */ - zdfs64("eph_zbytes", S_IRUGO, root, &zbud_eph_zbytes); - zdfs64("eph_cumul_zbytes", S_IRUGO, root, &zbud_eph_cumul_zbytes); - zdfs64("pers_zbytes", S_IRUGO, root, &zbud_pers_zbytes); - zdfs64("pers_cumul_zbytes", S_IRUGO, root, &zbud_pers_cumul_zbytes); - zdfs("eph_cumul_zpages", S_IRUGO, root, &zbud_eph_cumul_zpages); - zdfs("eph_evicted_pageframes", S_IRUGO, root, - &zbud_eph_evicted_pageframes); - zdfs("eph_zpages", S_IRUGO, root, &zbud_eph_zpages); - zdfs("eph_pageframes", S_IRUGO, root, &zbud_eph_pageframes); - zdfs("eph_buddied_count", S_IRUGO, root, &zbud_eph_buddied_count); - zdfs("eph_unbuddied_count", S_IRUGO, root, &zbud_eph_unbuddied_count); - zdfs("pers_cumul_zpages", S_IRUGO, root, &zbud_pers_cumul_zpages); - zdfs("pers_evicted_pageframes", S_IRUGO, root, - &zbud_pers_evicted_pageframes); - zdfs("pers_zpages", S_IRUGO, root, &zbud_pers_zpages); - zdfs("pers_pageframes", S_IRUGO, root, &zbud_pers_pageframes); - zdfs("pers_buddied_count", S_IRUGO, root, &zbud_pers_buddied_count); - zdfs("pers_unbuddied_count", S_IRUGO, root, &zbud_pers_unbuddied_count); - zdfs("pers_zombie_count", S_IRUGO, root, &zbud_pers_zombie_count); - return 0; -} -#undef zdfs -#undef zdfs64 -#endif - -/* protects the buddied list and all unbuddied lists */ -static DEFINE_SPINLOCK(zbud_eph_lists_lock); -static DEFINE_SPINLOCK(zbud_pers_lists_lock); - -struct zbud_unbuddied { - struct list_head list; - unsigned count; -}; - -/* list N contains pages with N chunks USED and NCHUNKS-N unused */ -/* element 0 is never used but optimizing that isn't worth it */ -static struct zbud_unbuddied zbud_eph_unbuddied[NCHUNKS]; -static struct zbud_unbuddied zbud_pers_unbuddied[NCHUNKS]; -static LIST_HEAD(zbud_eph_lru_list); -static LIST_HEAD(zbud_pers_lru_list); -static LIST_HEAD(zbud_eph_buddied_list); -static LIST_HEAD(zbud_pers_buddied_list); -static LIST_HEAD(zbud_eph_zombie_list); -static LIST_HEAD(zbud_pers_zombie_list); - -/* - * Given a struct page, transform it to a zbudpage so that it can be - * used by zbud and initialize fields as necessary. - */ -static inline struct zbudpage *zbud_init_zbudpage(struct page *page, bool eph) -{ - struct zbudpage *zbudpage = (struct zbudpage *)page; - - BUG_ON(page == NULL); - INIT_LIST_HEAD(&zbudpage->budlist); - INIT_LIST_HEAD(&zbudpage->lru); - zbudpage->zbud0_size = 0; - zbudpage->zbud1_size = 0; - zbudpage->unevictable = 0; - if (eph) - zbud_eph_pageframes++; - else - zbud_pers_pageframes++; - return zbudpage; -} - -/* "Transform" a zbudpage back to a struct page suitable to free. */ -static inline struct page *zbud_unuse_zbudpage(struct zbudpage *zbudpage, - bool eph) -{ - struct page *page = (struct page *)zbudpage; - - BUG_ON(!list_empty(&zbudpage->budlist)); - BUG_ON(!list_empty(&zbudpage->lru)); - BUG_ON(zbudpage->zbud0_size != 0); - BUG_ON(zbudpage->zbud1_size != 0); - BUG_ON(!PageLocked(page)); - BUG_ON(zbudpage->unevictable != 0); - BUG_ON(zbudpage_is_dying(zbudpage)); - BUG_ON(zbudpage_is_zombie(zbudpage)); - if (eph) - zbud_eph_pageframes--; - else - zbud_pers_pageframes--; - zbudpage_spin_unlock(zbudpage); - reset_page_mapcount(page); - init_page_count(page); - page->index = 0; - return page; -} - -/* Mark a zbud as unused and do accounting */ -static inline void zbud_unuse_zbud(struct zbudpage *zbudpage, - int budnum, bool eph) -{ - unsigned size; - - BUG_ON(!zbudpage_is_locked(zbudpage)); - if (budnum == 0) { - size = zbudpage->zbud0_size; - zbudpage->zbud0_size = 0; - } else { - size = zbudpage->zbud1_size; - zbudpage->zbud1_size = 0; - } - if (eph) { - zbud_eph_zbytes -= size; - zbud_eph_zpages--; - } else { - zbud_pers_zbytes -= size; - zbud_pers_zpages--; - } -} - -/* - * Given a zbudpage/budnum/size, a tmem handle, and a kmapped pointer - * to some data, set up the zbud appropriately including data copying - * and accounting. Note that if cdata is NULL, the data copying is - * skipped. (This is useful for lazy writes such as for RAMster.) - */ -static void zbud_init_zbud(struct zbudpage *zbudpage, struct tmem_handle *th, - bool eph, void *cdata, - unsigned budnum, unsigned size) -{ - char *to; - void *zbpg; - struct tmem_handle *to_th; - unsigned nchunks = zbud_size_to_chunks(size); - - BUG_ON(!zbudpage_is_locked(zbudpage)); - zbpg = kmap_zbudpage_atomic(zbudpage); - to = zbud_data(zbpg, budnum, size); - to_th = (struct tmem_handle *)to; - to_th->index = th->index; - to_th->oid = th->oid; - to_th->pool_id = th->pool_id; - to_th->client_id = th->client_id; - to += sizeof(struct tmem_handle); - if (cdata != NULL) - memcpy(to, cdata, size - sizeof(struct tmem_handle)); - kunmap_zbudpage_atomic(zbpg); - if (budnum == 0) - zbudpage->zbud0_size = size; - else - zbudpage->zbud1_size = size; - if (eph) { - zbud_eph_cumul_chunk_counts[nchunks]++; - zbud_eph_zpages++; - zbud_eph_cumul_zpages++; - zbud_eph_zbytes += size; - zbud_eph_cumul_zbytes += size; - } else { - zbud_pers_cumul_chunk_counts[nchunks]++; - zbud_pers_zpages++; - zbud_pers_cumul_zpages++; - zbud_pers_zbytes += size; - zbud_pers_cumul_zbytes += size; - } -} - -/* - * Given a locked dying zbudpage, read out the tmem handles from the data, - * unlock the page, then use the handles to tell tmem to flush out its - * references - */ -static void zbud_evict_tmem(struct zbudpage *zbudpage) -{ - int i, j; - uint32_t pool_id[2], client_id[2]; - uint32_t index[2]; - struct tmem_oid oid[2]; - struct tmem_pool *pool; - void *zbpg; - struct tmem_handle *th; - unsigned size; - - /* read out the tmem handles from the data and set aside */ - zbpg = kmap_zbudpage_atomic(zbudpage); - for (i = 0, j = 0; i < 2; i++) { - size = (i == 0) ? zbudpage->zbud0_size : zbudpage->zbud1_size; - if (size) { - th = (struct tmem_handle *)zbud_data(zbpg, i, size); - client_id[j] = th->client_id; - pool_id[j] = th->pool_id; - oid[j] = th->oid; - index[j] = th->index; - j++; - zbud_unuse_zbud(zbudpage, i, true); - } - } - kunmap_zbudpage_atomic(zbpg); - zbudpage_spin_unlock(zbudpage); - /* zbudpage is now an unlocked dying... tell tmem to flush pointers */ - for (i = 0; i < j; i++) { - pool = zcache_get_pool_by_id(client_id[i], pool_id[i]); - if (pool != NULL) { - tmem_flush_page(pool, &oid[i], index[i]); - zcache_put_pool(pool); - } - } -} - -/* - * Externally callable zbud handling routines. - */ - -/* - * Return the maximum size compressed page that can be stored (secretly - * setting aside space for the tmem handle. - */ -unsigned int zbud_max_buddy_size(void) -{ - return zbud_max_size() - sizeof(struct tmem_handle); -} - -/* - * Given a zbud reference, free the corresponding zbud from all lists, - * mark it as unused, do accounting, and if the freeing of the zbud - * frees up an entire pageframe, return it to the caller (else NULL). - */ -struct page *zbud_free_and_delist(struct zbudref *zref, bool eph, - unsigned int *zsize, unsigned int *zpages) -{ - unsigned long budnum = zbudref_budnum(zref); - struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); - struct page *page = NULL; - unsigned chunks, bud_size, other_bud_size; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - struct zbud_unbuddied *unbud = - eph ? zbud_eph_unbuddied : zbud_pers_unbuddied; - - - spin_lock(lists_lock); - zbudpage_spin_lock(zbudpage); - if (zbudpage_is_dying(zbudpage)) { - /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); - *zpages = 0; - *zsize = 0; - goto out; - } - if (budnum == 0) { - bud_size = zbudpage->zbud0_size; - other_bud_size = zbudpage->zbud1_size; - } else { - bud_size = zbudpage->zbud1_size; - other_bud_size = zbudpage->zbud0_size; - } - *zsize = bud_size - sizeof(struct tmem_handle); - *zpages = 1; - zbud_unuse_zbud(zbudpage, budnum, eph); - if (other_bud_size == 0) { /* was unbuddied: unlist and free */ - chunks = zbud_size_to_chunks(bud_size) ; - if (zbudpage_is_zombie(zbudpage)) { - if (eph) - zbud_pers_zombie_count = - atomic_dec_return(&zbud_eph_zombie_atomic); - else - zbud_pers_zombie_count = - atomic_dec_return(&zbud_pers_zombie_atomic); - zbudpage_clear_zombie(zbudpage); - } else { - BUG_ON(list_empty(&unbud[chunks].list)); - list_del_init(&zbudpage->budlist); - unbud[chunks].count--; - } - list_del_init(&zbudpage->lru); - spin_unlock(lists_lock); - if (eph) - zbud_eph_unbuddied_count--; - else - zbud_pers_unbuddied_count--; - page = zbud_unuse_zbudpage(zbudpage, eph); - } else { /* was buddied: move remaining buddy to unbuddied list */ - chunks = zbud_size_to_chunks(other_bud_size) ; - if (!zbudpage_is_zombie(zbudpage)) { - list_del_init(&zbudpage->budlist); - list_add_tail(&zbudpage->budlist, &unbud[chunks].list); - unbud[chunks].count++; - } - if (eph) { - zbud_eph_buddied_count--; - zbud_eph_unbuddied_count++; - } else { - zbud_pers_unbuddied_count++; - zbud_pers_buddied_count--; - } - /* don't mess with lru, no need to move it */ - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); - } -out: - return page; -} - -/* - * Given a tmem handle, and a kmapped pointer to compressed data of - * the given size, try to find an unbuddied zbudpage in which to - * create a zbud. If found, put it there, mark the zbudpage unevictable, - * and return a zbudref to it. Else return NULL. - */ -struct zbudref *zbud_match_prep(struct tmem_handle *th, bool eph, - void *cdata, unsigned size) -{ - struct zbudpage *zbudpage = NULL, *zbudpage2; - unsigned long budnum = 0UL; - unsigned nchunks; - int i, found_good_buddy = 0; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - struct zbud_unbuddied *unbud = - eph ? zbud_eph_unbuddied : zbud_pers_unbuddied; - - size += sizeof(struct tmem_handle); - nchunks = zbud_size_to_chunks(size); - for (i = MAX_CHUNK - nchunks + 1; i > 0; i--) { - spin_lock(lists_lock); - if (!list_empty(&unbud[i].list)) { - list_for_each_entry_safe(zbudpage, zbudpage2, - &unbud[i].list, budlist) { - if (zbudpage_spin_trylock(zbudpage)) { - found_good_buddy = i; - goto found_unbuddied; - } - } - } - spin_unlock(lists_lock); - } - zbudpage = NULL; - goto out; - -found_unbuddied: - BUG_ON(!zbudpage_is_locked(zbudpage)); - BUG_ON(!((zbudpage->zbud0_size == 0) ^ (zbudpage->zbud1_size == 0))); - if (zbudpage->zbud0_size == 0) - budnum = 0UL; - else if (zbudpage->zbud1_size == 0) - budnum = 1UL; - list_del_init(&zbudpage->budlist); - if (eph) { - list_add_tail(&zbudpage->budlist, &zbud_eph_buddied_list); - unbud[found_good_buddy].count--; - zbud_eph_unbuddied_count--; - zbud_eph_buddied_count++; - /* "promote" raw zbudpage to most-recently-used */ - list_del_init(&zbudpage->lru); - list_add_tail(&zbudpage->lru, &zbud_eph_lru_list); - } else { - list_add_tail(&zbudpage->budlist, &zbud_pers_buddied_list); - unbud[found_good_buddy].count--; - zbud_pers_unbuddied_count--; - zbud_pers_buddied_count++; - /* "promote" raw zbudpage to most-recently-used */ - list_del_init(&zbudpage->lru); - list_add_tail(&zbudpage->lru, &zbud_pers_lru_list); - } - zbud_init_zbud(zbudpage, th, eph, cdata, budnum, size); - zbudpage->unevictable++; - BUG_ON(zbudpage->unevictable == 3); - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); -out: - return zbudpage_to_zbudref(zbudpage, budnum); - -} - -/* - * Given a tmem handle, and a kmapped pointer to compressed data of - * the given size, and a newly allocated struct page, create an unevictable - * zbud in that new page and return a zbudref to it. - */ -struct zbudref *zbud_create_prep(struct tmem_handle *th, bool eph, - void *cdata, unsigned size, - struct page *newpage) -{ - struct zbudpage *zbudpage; - unsigned long budnum = 0; - unsigned nchunks; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - struct zbud_unbuddied *unbud = - eph ? zbud_eph_unbuddied : zbud_pers_unbuddied; - -#if 0 - /* this may be worth it later to support decompress-in-place? */ - static unsigned long counter; - budnum = counter++ & 1; /* alternate using zbud0 and zbud1 */ -#endif - - if (size > zbud_max_buddy_size()) - return NULL; - if (newpage == NULL) - return NULL; - - size += sizeof(struct tmem_handle); - nchunks = zbud_size_to_chunks(size) ; - spin_lock(lists_lock); - zbudpage = zbud_init_zbudpage(newpage, eph); - zbudpage_spin_lock(zbudpage); - list_add_tail(&zbudpage->budlist, &unbud[nchunks].list); - if (eph) { - list_add_tail(&zbudpage->lru, &zbud_eph_lru_list); - zbud_eph_unbuddied_count++; - } else { - list_add_tail(&zbudpage->lru, &zbud_pers_lru_list); - zbud_pers_unbuddied_count++; - } - unbud[nchunks].count++; - zbud_init_zbud(zbudpage, th, eph, cdata, budnum, size); - zbudpage->unevictable++; - BUG_ON(zbudpage->unevictable == 3); - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); - return zbudpage_to_zbudref(zbudpage, budnum); -} - -/* - * Finish creation of a zbud by, assuming another zbud isn't being created - * in parallel, marking it evictable. - */ -void zbud_create_finish(struct zbudref *zref, bool eph) -{ - struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - - spin_lock(lists_lock); - zbudpage_spin_lock(zbudpage); - BUG_ON(zbudpage_is_dying(zbudpage)); - zbudpage->unevictable--; - BUG_ON((int)zbudpage->unevictable < 0); - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); -} - -/* - * Given a zbudref and a struct page, decompress the data from - * the zbud into the physical page represented by the struct page - * by upcalling to zcache_decompress - */ -int zbud_decompress(struct page *data_page, struct zbudref *zref, bool eph, - void (*decompress)(char *, unsigned int, char *)) -{ - struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); - unsigned long budnum = zbudref_budnum(zref); - void *zbpg; - char *to_va, *from_va; - unsigned size; - int ret = -1; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - - spin_lock(lists_lock); - zbudpage_spin_lock(zbudpage); - if (zbudpage_is_dying(zbudpage)) { - /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ - goto out; - } - zbpg = kmap_zbudpage_atomic(zbudpage); - to_va = kmap_atomic(data_page); - if (budnum == 0) - size = zbudpage->zbud0_size; - else - size = zbudpage->zbud1_size; - BUG_ON(size == 0 || size > zbud_max_size()); - from_va = zbud_data(zbpg, budnum, size); - from_va += sizeof(struct tmem_handle); - size -= sizeof(struct tmem_handle); - decompress(from_va, size, to_va); - kunmap_atomic(to_va); - kunmap_zbudpage_atomic(zbpg); - ret = 0; -out: - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); - return ret; -} - -/* - * Given a zbudref and a kernel pointer, copy the data from - * the zbud to the kernel pointer. - */ -int zbud_copy_from_zbud(char *to_va, struct zbudref *zref, - size_t *sizep, bool eph) -{ - struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); - unsigned long budnum = zbudref_budnum(zref); - void *zbpg; - char *from_va; - unsigned size; - int ret = -1; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - - spin_lock(lists_lock); - zbudpage_spin_lock(zbudpage); - if (zbudpage_is_dying(zbudpage)) { - /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ - goto out; - } - zbpg = kmap_zbudpage_atomic(zbudpage); - if (budnum == 0) - size = zbudpage->zbud0_size; - else - size = zbudpage->zbud1_size; - BUG_ON(size == 0 || size > zbud_max_size()); - from_va = zbud_data(zbpg, budnum, size); - from_va += sizeof(struct tmem_handle); - size -= sizeof(struct tmem_handle); - *sizep = size; - memcpy(to_va, from_va, size); - - kunmap_zbudpage_atomic(zbpg); - ret = 0; -out: - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); - return ret; -} - -/* - * Given a zbudref and a kernel pointer, copy the data from - * the kernel pointer to the zbud. - */ -int zbud_copy_to_zbud(struct zbudref *zref, char *from_va, bool eph) -{ - struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); - unsigned long budnum = zbudref_budnum(zref); - void *zbpg; - char *to_va; - unsigned size; - int ret = -1; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - - spin_lock(lists_lock); - zbudpage_spin_lock(zbudpage); - if (zbudpage_is_dying(zbudpage)) { - /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ - goto out; - } - zbpg = kmap_zbudpage_atomic(zbudpage); - if (budnum == 0) - size = zbudpage->zbud0_size; - else - size = zbudpage->zbud1_size; - BUG_ON(size == 0 || size > zbud_max_size()); - to_va = zbud_data(zbpg, budnum, size); - to_va += sizeof(struct tmem_handle); - size -= sizeof(struct tmem_handle); - memcpy(to_va, from_va, size); - - kunmap_zbudpage_atomic(zbpg); - ret = 0; -out: - zbudpage_spin_unlock(zbudpage); - spin_unlock(lists_lock); - return ret; -} - -/* - * Choose an ephemeral LRU zbudpage that is evictable (not locked), ensure - * there are no references to it remaining, and return the now unused - * (and re-init'ed) struct page and the total amount of compressed - * data that was evicted. - */ -struct page *zbud_evict_pageframe_lru(unsigned int *zsize, unsigned int *zpages) -{ - struct zbudpage *zbudpage = NULL, *zbudpage2; - struct zbud_unbuddied *unbud = zbud_eph_unbuddied; - struct page *page = NULL; - bool irqs_disabled = irqs_disabled(); - - /* - * Since this can be called indirectly from cleancache_put, which - * has interrupts disabled, as well as frontswap_put, which does not, - * we need to be able to handle both cases, even though it is ugly. - */ - if (irqs_disabled) - spin_lock(&zbud_eph_lists_lock); - else - spin_lock_bh(&zbud_eph_lists_lock); - *zsize = 0; - if (list_empty(&zbud_eph_lru_list)) - goto unlock_out; - list_for_each_entry_safe(zbudpage, zbudpage2, &zbud_eph_lru_list, lru) { - /* skip a locked zbudpage */ - if (unlikely(!zbudpage_spin_trylock(zbudpage))) - continue; - /* skip an unevictable zbudpage */ - if (unlikely(zbudpage->unevictable != 0)) { - zbudpage_spin_unlock(zbudpage); - continue; - } - /* got a locked evictable page */ - goto evict_page; - - } -unlock_out: - /* no unlocked evictable pages, give up */ - if (irqs_disabled) - spin_unlock(&zbud_eph_lists_lock); - else - spin_unlock_bh(&zbud_eph_lists_lock); - goto out; - -evict_page: - list_del_init(&zbudpage->budlist); - list_del_init(&zbudpage->lru); - zbudpage_set_dying(zbudpage); - /* - * the zbudpage is now "dying" and attempts to read, write, - * or delete data from it will be ignored - */ - if (zbudpage->zbud0_size != 0 && zbudpage->zbud1_size != 0) { - *zsize = zbudpage->zbud0_size + zbudpage->zbud1_size - - (2 * sizeof(struct tmem_handle)); - *zpages = 2; - } else if (zbudpage->zbud0_size != 0) { - unbud[zbud_size_to_chunks(zbudpage->zbud0_size)].count--; - *zsize = zbudpage->zbud0_size - sizeof(struct tmem_handle); - *zpages = 1; - } else if (zbudpage->zbud1_size != 0) { - unbud[zbud_size_to_chunks(zbudpage->zbud1_size)].count--; - *zsize = zbudpage->zbud1_size - sizeof(struct tmem_handle); - *zpages = 1; - } else { - BUG(); - } - spin_unlock(&zbud_eph_lists_lock); - zbud_eph_evicted_pageframes++; - if (*zpages == 1) - zbud_eph_unbuddied_count--; - else - zbud_eph_buddied_count--; - zbud_evict_tmem(zbudpage); - zbudpage_spin_lock(zbudpage); - zbudpage_clear_dying(zbudpage); - page = zbud_unuse_zbudpage(zbudpage, true); - if (!irqs_disabled) - local_bh_enable(); -out: - return page; -} - -/* - * Choose a persistent LRU zbudpage that is evictable (not locked), zombify it, - * read the tmem_handle(s) out of it into the passed array, and return the - * number of zbuds. Caller must perform necessary tmem functions and, - * indirectly, zbud functions to fetch any valid data and cause the - * now-zombified zbudpage to eventually be freed. We track the zombified - * zbudpage count so it is possible to observe if there is a leak. - FIXME: describe (ramster) case where data pointers are passed in for memcpy - */ -unsigned int zbud_make_zombie_lru(struct tmem_handle *th, unsigned char **data, - unsigned int *zsize, bool eph) -{ - struct zbudpage *zbudpage = NULL, *zbudpag2; - struct tmem_handle *thfrom; - char *from_va; - void *zbpg; - unsigned size; - int ret = 0, i; - spinlock_t *lists_lock = - eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; - struct list_head *lru_list = - eph ? &zbud_eph_lru_list : &zbud_pers_lru_list; - - spin_lock_bh(lists_lock); - if (list_empty(lru_list)) - goto out; - list_for_each_entry_safe(zbudpage, zbudpag2, lru_list, lru) { - /* skip a locked zbudpage */ - if (unlikely(!zbudpage_spin_trylock(zbudpage))) - continue; - /* skip an unevictable zbudpage */ - if (unlikely(zbudpage->unevictable != 0)) { - zbudpage_spin_unlock(zbudpage); - continue; - } - /* got a locked evictable page */ - goto zombify_page; - } - /* no unlocked evictable pages, give up */ - goto out; - -zombify_page: - /* got an unlocked evictable page, zombify it */ - list_del_init(&zbudpage->budlist); - zbudpage_set_zombie(zbudpage); - /* FIXME what accounting do I need to do here? */ - list_del_init(&zbudpage->lru); - if (eph) { - list_add_tail(&zbudpage->lru, &zbud_eph_zombie_list); - zbud_eph_zombie_count = - atomic_inc_return(&zbud_eph_zombie_atomic); - } else { - list_add_tail(&zbudpage->lru, &zbud_pers_zombie_list); - zbud_pers_zombie_count = - atomic_inc_return(&zbud_pers_zombie_atomic); - } - /* FIXME what accounting do I need to do here? */ - zbpg = kmap_zbudpage_atomic(zbudpage); - for (i = 0; i < 2; i++) { - size = (i == 0) ? zbudpage->zbud0_size : zbudpage->zbud1_size; - if (size) { - from_va = zbud_data(zbpg, i, size); - thfrom = (struct tmem_handle *)from_va; - from_va += sizeof(struct tmem_handle); - size -= sizeof(struct tmem_handle); - if (th != NULL) - th[ret] = *thfrom; - if (data != NULL) - memcpy(data[ret], from_va, size); - if (zsize != NULL) - *zsize++ = size; - ret++; - } - } - kunmap_zbudpage_atomic(zbpg); - zbudpage_spin_unlock(zbudpage); -out: - spin_unlock_bh(lists_lock); - return ret; -} - -void __init zbud_init(void) -{ - int i; - -#ifdef CONFIG_DEBUG_FS - zbud_debugfs_init(); -#endif - BUG_ON((sizeof(struct tmem_handle) * 2 > CHUNK_SIZE)); - BUG_ON(sizeof(struct zbudpage) > sizeof(struct page)); - for (i = 0; i < NCHUNKS; i++) { - INIT_LIST_HEAD(&zbud_eph_unbuddied[i].list); - INIT_LIST_HEAD(&zbud_pers_unbuddied[i].list); - } -} diff --git a/drivers/staging/ramster/zbud.h b/drivers/staging/ramster/zbud.h deleted file mode 100644 index 891e8a7..0000000 --- a/drivers/staging/ramster/zbud.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * zbud.h - * - * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. - * - */ - -#ifndef _ZBUD_H_ -#define _ZBUD_H_ - -#include "tmem.h" - -struct zbudref; - -extern unsigned int zbud_max_buddy_size(void); -extern struct zbudref *zbud_match_prep(struct tmem_handle *th, bool eph, - void *cdata, unsigned size); -extern struct zbudref *zbud_create_prep(struct tmem_handle *th, bool eph, - void *cdata, unsigned size, - struct page *newpage); -extern void zbud_create_finish(struct zbudref *, bool); -extern int zbud_decompress(struct page *, struct zbudref *, bool, - void (*func)(char *, unsigned int, char *)); -extern int zbud_copy_from_zbud(char *, struct zbudref *, size_t *, bool); -extern int zbud_copy_to_zbud(struct zbudref *, char *, bool); -extern struct page *zbud_free_and_delist(struct zbudref *, bool eph, - unsigned int *, unsigned int *); -extern struct page *zbud_evict_pageframe_lru(unsigned int *, unsigned int *); -extern unsigned int zbud_make_zombie_lru(struct tmem_handle *, unsigned char **, - unsigned int *, bool); -extern void zbud_init(void); - -#endif /* _ZBUD_H_ */ diff --git a/drivers/staging/ramster/zcache-main.c b/drivers/staging/ramster/zcache-main.c deleted file mode 100644 index a09dd5c..0000000 --- a/drivers/staging/ramster/zcache-main.c +++ /dev/null @@ -1,1820 +0,0 @@ -/* - * zcache.c - * - * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. - * Copyright (c) 2010,2011, Nitin Gupta - * - * Zcache provides an in-kernel "host implementation" for transcendent memory - * ("tmem") and, thus indirectly, for cleancache and frontswap. Zcache uses - * lzo1x compression to improve density and an embedded allocator called - * "zbud" which "buddies" two compressed pages semi-optimally in each physical - * pageframe. Zbud is integrally tied into tmem to allow pageframes to - * be "reclaimed" efficiently. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "tmem.h" -#include "zcache.h" -#include "zbud.h" -#include "ramster.h" -#ifdef CONFIG_RAMSTER -static int ramster_enabled; -#else -#define ramster_enabled 0 -#endif - -#ifndef __PG_WAS_ACTIVE -static inline bool PageWasActive(struct page *page) -{ - return true; -} - -static inline void SetPageWasActive(struct page *page) -{ -} -#endif - -#ifdef FRONTSWAP_HAS_EXCLUSIVE_GETS -static bool frontswap_has_exclusive_gets __read_mostly = true; -#else -static bool frontswap_has_exclusive_gets __read_mostly; -static inline void frontswap_tmem_exclusive_gets(bool b) -{ -} -#endif - -static int zcache_enabled __read_mostly; -static int disable_cleancache __read_mostly; -static int disable_frontswap __read_mostly; -static int disable_frontswap_ignore_nonactive __read_mostly; -static int disable_cleancache_ignore_nonactive __read_mostly; -static char *namestr __read_mostly = "zcache"; - -#define ZCACHE_GFP_MASK \ - (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC) - -MODULE_LICENSE("GPL"); - -/* crypto API for zcache */ -#define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME -static char zcache_comp_name[ZCACHE_COMP_NAME_SZ] __read_mostly; -static struct crypto_comp * __percpu *zcache_comp_pcpu_tfms __read_mostly; - -enum comp_op { - ZCACHE_COMPOP_COMPRESS, - ZCACHE_COMPOP_DECOMPRESS -}; - -static inline int zcache_comp_op(enum comp_op op, - const u8 *src, unsigned int slen, - u8 *dst, unsigned int *dlen) -{ - struct crypto_comp *tfm; - int ret = -1; - - BUG_ON(!zcache_comp_pcpu_tfms); - tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, get_cpu()); - BUG_ON(!tfm); - switch (op) { - case ZCACHE_COMPOP_COMPRESS: - ret = crypto_comp_compress(tfm, src, slen, dst, dlen); - break; - case ZCACHE_COMPOP_DECOMPRESS: - ret = crypto_comp_decompress(tfm, src, slen, dst, dlen); - break; - default: - ret = -EINVAL; - } - put_cpu(); - return ret; -} - -/* - * policy parameters - */ - -/* - * byte count defining poor compression; pages with greater zsize will be - * rejected - */ -static unsigned int zbud_max_zsize __read_mostly = (PAGE_SIZE / 8) * 7; -/* - * byte count defining poor *mean* compression; pages with greater zsize - * will be rejected until sufficient better-compressed pages are accepted - * driving the mean below this threshold - */ -static unsigned int zbud_max_mean_zsize __read_mostly = (PAGE_SIZE / 8) * 5; - -/* - * for now, used named slabs so can easily track usage; later can - * either just use kmalloc, or perhaps add a slab-like allocator - * to more carefully manage total memory utilization - */ -static struct kmem_cache *zcache_objnode_cache; -static struct kmem_cache *zcache_obj_cache; - -static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, }; - -/* we try to keep these statistics SMP-consistent */ -static long zcache_obj_count; -static atomic_t zcache_obj_atomic = ATOMIC_INIT(0); -static long zcache_obj_count_max; -static long zcache_objnode_count; -static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0); -static long zcache_objnode_count_max; -static u64 zcache_eph_zbytes; -static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0); -static u64 zcache_eph_zbytes_max; -static u64 zcache_pers_zbytes; -static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0); -static u64 zcache_pers_zbytes_max; -static long zcache_eph_pageframes; -static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0); -static long zcache_eph_pageframes_max; -static long zcache_pers_pageframes; -static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0); -static long zcache_pers_pageframes_max; -static long zcache_pageframes_alloced; -static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0); -static long zcache_pageframes_freed; -static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0); -static long zcache_eph_zpages; -static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0); -static long zcache_eph_zpages_max; -static long zcache_pers_zpages; -static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0); -static long zcache_pers_zpages_max; - -/* but for the rest of these, counting races are ok */ -static unsigned long zcache_flush_total; -static unsigned long zcache_flush_found; -static unsigned long zcache_flobj_total; -static unsigned long zcache_flobj_found; -static unsigned long zcache_failed_eph_puts; -static unsigned long zcache_failed_pers_puts; -static unsigned long zcache_failed_getfreepages; -static unsigned long zcache_failed_alloc; -static unsigned long zcache_put_to_flush; -static unsigned long zcache_compress_poor; -static unsigned long zcache_mean_compress_poor; -static unsigned long zcache_eph_ate_tail; -static unsigned long zcache_eph_ate_tail_failed; -static unsigned long zcache_pers_ate_eph; -static unsigned long zcache_pers_ate_eph_failed; -static unsigned long zcache_evicted_eph_zpages; -static unsigned long zcache_evicted_eph_pageframes; -static unsigned long zcache_last_active_file_pageframes; -static unsigned long zcache_last_inactive_file_pageframes; -static unsigned long zcache_last_active_anon_pageframes; -static unsigned long zcache_last_inactive_anon_pageframes; -static unsigned long zcache_eph_nonactive_puts_ignored; -static unsigned long zcache_pers_nonactive_puts_ignored; - -#ifdef CONFIG_DEBUG_FS -#include -#define zdfs debugfs_create_size_t -#define zdfs64 debugfs_create_u64 -static int zcache_debugfs_init(void) -{ - struct dentry *root = debugfs_create_dir("zcache", NULL); - if (root == NULL) - return -ENXIO; - - zdfs("obj_count", S_IRUGO, root, &zcache_obj_count); - zdfs("obj_count_max", S_IRUGO, root, &zcache_obj_count_max); - zdfs("objnode_count", S_IRUGO, root, &zcache_objnode_count); - zdfs("objnode_count_max", S_IRUGO, root, &zcache_objnode_count_max); - zdfs("flush_total", S_IRUGO, root, &zcache_flush_total); - zdfs("flush_found", S_IRUGO, root, &zcache_flush_found); - zdfs("flobj_total", S_IRUGO, root, &zcache_flobj_total); - zdfs("flobj_found", S_IRUGO, root, &zcache_flobj_found); - zdfs("failed_eph_puts", S_IRUGO, root, &zcache_failed_eph_puts); - zdfs("failed_pers_puts", S_IRUGO, root, &zcache_failed_pers_puts); - zdfs("failed_get_free_pages", S_IRUGO, root, - &zcache_failed_getfreepages); - zdfs("failed_alloc", S_IRUGO, root, &zcache_failed_alloc); - zdfs("put_to_flush", S_IRUGO, root, &zcache_put_to_flush); - zdfs("compress_poor", S_IRUGO, root, &zcache_compress_poor); - zdfs("mean_compress_poor", S_IRUGO, root, &zcache_mean_compress_poor); - zdfs("eph_ate_tail", S_IRUGO, root, &zcache_eph_ate_tail); - zdfs("eph_ate_tail_failed", S_IRUGO, root, &zcache_eph_ate_tail_failed); - zdfs("pers_ate_eph", S_IRUGO, root, &zcache_pers_ate_eph); - zdfs("pers_ate_eph_failed", S_IRUGO, root, &zcache_pers_ate_eph_failed); - zdfs("evicted_eph_zpages", S_IRUGO, root, &zcache_evicted_eph_zpages); - zdfs("evicted_eph_pageframes", S_IRUGO, root, - &zcache_evicted_eph_pageframes); - zdfs("eph_pageframes", S_IRUGO, root, &zcache_eph_pageframes); - zdfs("eph_pageframes_max", S_IRUGO, root, &zcache_eph_pageframes_max); - zdfs("pers_pageframes", S_IRUGO, root, &zcache_pers_pageframes); - zdfs("pers_pageframes_max", S_IRUGO, root, &zcache_pers_pageframes_max); - zdfs("eph_zpages", S_IRUGO, root, &zcache_eph_zpages); - zdfs("eph_zpages_max", S_IRUGO, root, &zcache_eph_zpages_max); - zdfs("pers_zpages", S_IRUGO, root, &zcache_pers_zpages); - zdfs("pers_zpages_max", S_IRUGO, root, &zcache_pers_zpages_max); - zdfs("last_active_file_pageframes", S_IRUGO, root, - &zcache_last_active_file_pageframes); - zdfs("last_inactive_file_pageframes", S_IRUGO, root, - &zcache_last_inactive_file_pageframes); - zdfs("last_active_anon_pageframes", S_IRUGO, root, - &zcache_last_active_anon_pageframes); - zdfs("last_inactive_anon_pageframes", S_IRUGO, root, - &zcache_last_inactive_anon_pageframes); - zdfs("eph_nonactive_puts_ignored", S_IRUGO, root, - &zcache_eph_nonactive_puts_ignored); - zdfs("pers_nonactive_puts_ignored", S_IRUGO, root, - &zcache_pers_nonactive_puts_ignored); - zdfs64("eph_zbytes", S_IRUGO, root, &zcache_eph_zbytes); - zdfs64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max); - zdfs64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes); - zdfs64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max); - return 0; -} -#undef zdebugfs -#undef zdfs64 -#endif - -#define ZCACHE_DEBUG -#ifdef ZCACHE_DEBUG -/* developers can call this in case of ooms, e.g. to find memory leaks */ -void zcache_dump(void) -{ - pr_info("zcache: obj_count=%lu\n", zcache_obj_count); - pr_info("zcache: obj_count_max=%lu\n", zcache_obj_count_max); - pr_info("zcache: objnode_count=%lu\n", zcache_objnode_count); - pr_info("zcache: objnode_count_max=%lu\n", zcache_objnode_count_max); - pr_info("zcache: flush_total=%lu\n", zcache_flush_total); - pr_info("zcache: flush_found=%lu\n", zcache_flush_found); - pr_info("zcache: flobj_total=%lu\n", zcache_flobj_total); - pr_info("zcache: flobj_found=%lu\n", zcache_flobj_found); - pr_info("zcache: failed_eph_puts=%lu\n", zcache_failed_eph_puts); - pr_info("zcache: failed_pers_puts=%lu\n", zcache_failed_pers_puts); - pr_info("zcache: failed_get_free_pages=%lu\n", - zcache_failed_getfreepages); - pr_info("zcache: failed_alloc=%lu\n", zcache_failed_alloc); - pr_info("zcache: put_to_flush=%lu\n", zcache_put_to_flush); - pr_info("zcache: compress_poor=%lu\n", zcache_compress_poor); - pr_info("zcache: mean_compress_poor=%lu\n", - zcache_mean_compress_poor); - pr_info("zcache: eph_ate_tail=%lu\n", zcache_eph_ate_tail); - pr_info("zcache: eph_ate_tail_failed=%lu\n", - zcache_eph_ate_tail_failed); - pr_info("zcache: pers_ate_eph=%lu\n", zcache_pers_ate_eph); - pr_info("zcache: pers_ate_eph_failed=%lu\n", - zcache_pers_ate_eph_failed); - pr_info("zcache: evicted_eph_zpages=%lu\n", zcache_evicted_eph_zpages); - pr_info("zcache: evicted_eph_pageframes=%lu\n", - zcache_evicted_eph_pageframes); - pr_info("zcache: eph_pageframes=%lu\n", zcache_eph_pageframes); - pr_info("zcache: eph_pageframes_max=%lu\n", zcache_eph_pageframes_max); - pr_info("zcache: pers_pageframes=%lu\n", zcache_pers_pageframes); - pr_info("zcache: pers_pageframes_max=%lu\n", - zcache_pers_pageframes_max); - pr_info("zcache: eph_zpages=%lu\n", zcache_eph_zpages); - pr_info("zcache: eph_zpages_max=%lu\n", zcache_eph_zpages_max); - pr_info("zcache: pers_zpages=%lu\n", zcache_pers_zpages); - pr_info("zcache: pers_zpages_max=%lu\n", zcache_pers_zpages_max); - pr_info("zcache: eph_zbytes=%llu\n", - (unsigned long long)zcache_eph_zbytes); - pr_info("zcache: eph_zbytes_max=%llu\n", - (unsigned long long)zcache_eph_zbytes_max); - pr_info("zcache: pers_zbytes=%llu\n", - (unsigned long long)zcache_pers_zbytes); - pr_info("zcache: pers_zbytes_max=%llu\n", - (unsigned long long)zcache_pers_zbytes_max); -} -#endif - -/* - * zcache core code starts here - */ - -static struct zcache_client zcache_host; -static struct zcache_client zcache_clients[MAX_CLIENTS]; - -static inline bool is_local_client(struct zcache_client *cli) -{ - return cli == &zcache_host; -} - -static struct zcache_client *zcache_get_client_by_id(uint16_t cli_id) -{ - struct zcache_client *cli = &zcache_host; - - if (cli_id != LOCAL_CLIENT) { - if (cli_id >= MAX_CLIENTS) - goto out; - cli = &zcache_clients[cli_id]; - } -out: - return cli; -} - -/* - * Tmem operations assume the poolid implies the invoking client. - * Zcache only has one client (the kernel itself): LOCAL_CLIENT. - * RAMster has each client numbered by cluster node, and a KVM version - * of zcache would have one client per guest and each client might - * have a poolid==N. - */ -struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid) -{ - struct tmem_pool *pool = NULL; - struct zcache_client *cli = NULL; - - cli = zcache_get_client_by_id(cli_id); - if (cli == NULL) - goto out; - if (!is_local_client(cli)) - atomic_inc(&cli->refcount); - if (poolid < MAX_POOLS_PER_CLIENT) { - pool = cli->tmem_pools[poolid]; - if (pool != NULL) - atomic_inc(&pool->refcount); - } -out: - return pool; -} - -void zcache_put_pool(struct tmem_pool *pool) -{ - struct zcache_client *cli = NULL; - - if (pool == NULL) - BUG(); - cli = pool->client; - atomic_dec(&pool->refcount); - if (!is_local_client(cli)) - atomic_dec(&cli->refcount); -} - -int zcache_new_client(uint16_t cli_id) -{ - struct zcache_client *cli; - int ret = -1; - - cli = zcache_get_client_by_id(cli_id); - if (cli == NULL) - goto out; - if (cli->allocated) - goto out; - cli->allocated = 1; - ret = 0; -out: - return ret; -} - -/* - * zcache implementation for tmem host ops - */ - -static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool) -{ - struct tmem_objnode *objnode = NULL; - struct zcache_preload *kp; - int i; - - kp = &__get_cpu_var(zcache_preloads); - for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) { - objnode = kp->objnodes[i]; - if (objnode != NULL) { - kp->objnodes[i] = NULL; - break; - } - } - BUG_ON(objnode == NULL); - zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic); - if (zcache_objnode_count > zcache_objnode_count_max) - zcache_objnode_count_max = zcache_objnode_count; - return objnode; -} - -static void zcache_objnode_free(struct tmem_objnode *objnode, - struct tmem_pool *pool) -{ - zcache_objnode_count = - atomic_dec_return(&zcache_objnode_atomic); - BUG_ON(zcache_objnode_count < 0); - kmem_cache_free(zcache_objnode_cache, objnode); -} - -static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool) -{ - struct tmem_obj *obj = NULL; - struct zcache_preload *kp; - - kp = &__get_cpu_var(zcache_preloads); - obj = kp->obj; - BUG_ON(obj == NULL); - kp->obj = NULL; - zcache_obj_count = atomic_inc_return(&zcache_obj_atomic); - if (zcache_obj_count > zcache_obj_count_max) - zcache_obj_count_max = zcache_obj_count; - return obj; -} - -static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) -{ - zcache_obj_count = - atomic_dec_return(&zcache_obj_atomic); - BUG_ON(zcache_obj_count < 0); - kmem_cache_free(zcache_obj_cache, obj); -} - -static struct tmem_hostops zcache_hostops = { - .obj_alloc = zcache_obj_alloc, - .obj_free = zcache_obj_free, - .objnode_alloc = zcache_objnode_alloc, - .objnode_free = zcache_objnode_free, -}; - -static struct page *zcache_alloc_page(void) -{ - struct page *page = alloc_page(ZCACHE_GFP_MASK); - - if (page != NULL) - zcache_pageframes_alloced = - atomic_inc_return(&zcache_pageframes_alloced_atomic); - return page; -} - -#ifdef FRONTSWAP_HAS_UNUSE -static void zcache_unacct_page(void) -{ - zcache_pageframes_freed = - atomic_inc_return(&zcache_pageframes_freed_atomic); -} -#endif - -static void zcache_free_page(struct page *page) -{ - long curr_pageframes; - static long max_pageframes, min_pageframes; - - if (page == NULL) - BUG(); - __free_page(page); - zcache_pageframes_freed = - atomic_inc_return(&zcache_pageframes_freed_atomic); - curr_pageframes = zcache_pageframes_alloced - - atomic_read(&zcache_pageframes_freed_atomic) - - atomic_read(&zcache_eph_pageframes_atomic) - - atomic_read(&zcache_pers_pageframes_atomic); - if (curr_pageframes > max_pageframes) - max_pageframes = curr_pageframes; - if (curr_pageframes < min_pageframes) - min_pageframes = curr_pageframes; -#ifdef ZCACHE_DEBUG - if (curr_pageframes > 2L || curr_pageframes < -2L) { - /* pr_info here */ - } -#endif -} - -/* - * zcache implementations for PAM page descriptor ops - */ - -/* forward reference */ -static void zcache_compress(struct page *from, - void **out_va, unsigned *out_len); - -static struct page *zcache_evict_eph_pageframe(void); - -static void *zcache_pampd_eph_create(char *data, size_t size, bool raw, - struct tmem_handle *th) -{ - void *pampd = NULL, *cdata = data; - unsigned clen = size; - struct page *page = (struct page *)(data), *newpage; - - if (!raw) { - zcache_compress(page, &cdata, &clen); - if (clen > zbud_max_buddy_size()) { - zcache_compress_poor++; - goto out; - } - } else { - BUG_ON(clen > zbud_max_buddy_size()); - } - - /* look for space via an existing match first */ - pampd = (void *)zbud_match_prep(th, true, cdata, clen); - if (pampd != NULL) - goto got_pampd; - - /* no match, now we need to find (or free up) a full page */ - newpage = zcache_alloc_page(); - if (newpage != NULL) - goto create_in_new_page; - - zcache_failed_getfreepages++; - /* can't allocate a page, evict an ephemeral page via LRU */ - newpage = zcache_evict_eph_pageframe(); - if (newpage == NULL) { - zcache_eph_ate_tail_failed++; - goto out; - } - zcache_eph_ate_tail++; - -create_in_new_page: - pampd = (void *)zbud_create_prep(th, true, cdata, clen, newpage); - BUG_ON(pampd == NULL); - zcache_eph_pageframes = - atomic_inc_return(&zcache_eph_pageframes_atomic); - if (zcache_eph_pageframes > zcache_eph_pageframes_max) - zcache_eph_pageframes_max = zcache_eph_pageframes; - -got_pampd: - zcache_eph_zbytes = - atomic_long_add_return(clen, &zcache_eph_zbytes_atomic); - if (zcache_eph_zbytes > zcache_eph_zbytes_max) - zcache_eph_zbytes_max = zcache_eph_zbytes; - zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic); - if (zcache_eph_zpages > zcache_eph_zpages_max) - zcache_eph_zpages_max = zcache_eph_zpages; - if (ramster_enabled && raw) - ramster_count_foreign_pages(true, 1); -out: - return pampd; -} - -static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, - struct tmem_handle *th) -{ - void *pampd = NULL, *cdata = data; - unsigned clen = size; - struct page *page = (struct page *)(data), *newpage; - unsigned long zbud_mean_zsize; - unsigned long curr_pers_zpages, total_zsize; - - if (data == NULL) { - BUG_ON(!ramster_enabled); - goto create_pampd; - } - curr_pers_zpages = zcache_pers_zpages; -/* FIXME CONFIG_RAMSTER... subtract atomic remote_pers_pages here? */ - if (!raw) - zcache_compress(page, &cdata, &clen); - /* reject if compression is too poor */ - if (clen > zbud_max_zsize) { - zcache_compress_poor++; - goto out; - } - /* reject if mean compression is too poor */ - if ((clen > zbud_max_mean_zsize) && (curr_pers_zpages > 0)) { - total_zsize = zcache_pers_zbytes; - if ((long)total_zsize < 0) - total_zsize = 0; - zbud_mean_zsize = div_u64(total_zsize, - curr_pers_zpages); - if (zbud_mean_zsize > zbud_max_mean_zsize) { - zcache_mean_compress_poor++; - goto out; - } - } - -create_pampd: - /* look for space via an existing match first */ - pampd = (void *)zbud_match_prep(th, false, cdata, clen); - if (pampd != NULL) - goto got_pampd; - - /* no match, now we need to find (or free up) a full page */ - newpage = zcache_alloc_page(); - if (newpage != NULL) - goto create_in_new_page; - /* - * FIXME do the following only if eph is oversized? - * if (zcache_eph_pageframes > - * (global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE) + - * global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE))) - */ - zcache_failed_getfreepages++; - /* can't allocate a page, evict an ephemeral page via LRU */ - newpage = zcache_evict_eph_pageframe(); - if (newpage == NULL) { - zcache_pers_ate_eph_failed++; - goto out; - } - zcache_pers_ate_eph++; - -create_in_new_page: - pampd = (void *)zbud_create_prep(th, false, cdata, clen, newpage); - BUG_ON(pampd == NULL); - zcache_pers_pageframes = - atomic_inc_return(&zcache_pers_pageframes_atomic); - if (zcache_pers_pageframes > zcache_pers_pageframes_max) - zcache_pers_pageframes_max = zcache_pers_pageframes; - -got_pampd: - zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic); - if (zcache_pers_zpages > zcache_pers_zpages_max) - zcache_pers_zpages_max = zcache_pers_zpages; - zcache_pers_zbytes = - atomic_long_add_return(clen, &zcache_pers_zbytes_atomic); - if (zcache_pers_zbytes > zcache_pers_zbytes_max) - zcache_pers_zbytes_max = zcache_pers_zbytes; - if (ramster_enabled && raw) - ramster_count_foreign_pages(false, 1); -out: - return pampd; -} - -/* - * This is called directly from zcache_put_page to pre-allocate space - * to store a zpage. - */ -void *zcache_pampd_create(char *data, unsigned int size, bool raw, - int eph, struct tmem_handle *th) -{ - void *pampd = NULL; - struct zcache_preload *kp; - struct tmem_objnode *objnode; - struct tmem_obj *obj; - int i; - - BUG_ON(!irqs_disabled()); - /* pre-allocate per-cpu metadata */ - BUG_ON(zcache_objnode_cache == NULL); - BUG_ON(zcache_obj_cache == NULL); - kp = &__get_cpu_var(zcache_preloads); - for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) { - objnode = kp->objnodes[i]; - if (objnode == NULL) { - objnode = kmem_cache_alloc(zcache_objnode_cache, - ZCACHE_GFP_MASK); - if (unlikely(objnode == NULL)) { - zcache_failed_alloc++; - goto out; - } - kp->objnodes[i] = objnode; - } - } - if (kp->obj == NULL) { - obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK); - kp->obj = obj; - } - if (unlikely(kp->obj == NULL)) { - zcache_failed_alloc++; - goto out; - } - /* - * ok, have all the metadata pre-allocated, now do the data - * but since how we allocate the data is dependent on ephemeral - * or persistent, we split the call here to different sub-functions - */ - if (eph) - pampd = zcache_pampd_eph_create(data, size, raw, th); - else - pampd = zcache_pampd_pers_create(data, size, raw, th); -out: - return pampd; -} - -/* - * This is a pamops called via tmem_put and is necessary to "finish" - * a pampd creation. - */ -void zcache_pampd_create_finish(void *pampd, bool eph) -{ - zbud_create_finish((struct zbudref *)pampd, eph); -} - -/* - * This is passed as a function parameter to zbud_decompress so that - * zbud need not be familiar with the details of crypto. It assumes that - * the bytes from_va and to_va through from_va+size-1 and to_va+size-1 are - * kmapped. It must be successful, else there is a logic bug somewhere. - */ -static void zcache_decompress(char *from_va, unsigned int size, char *to_va) -{ - int ret; - unsigned int outlen = PAGE_SIZE; - - ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, from_va, size, - to_va, &outlen); - BUG_ON(ret); - BUG_ON(outlen != PAGE_SIZE); -} - -/* - * Decompress from the kernel va to a pageframe - */ -void zcache_decompress_to_page(char *from_va, unsigned int size, - struct page *to_page) -{ - char *to_va = kmap_atomic(to_page); - zcache_decompress(from_va, size, to_va); - kunmap_atomic(to_va); -} - -/* - * fill the pageframe corresponding to the struct page with the data - * from the passed pampd - */ -static int zcache_pampd_get_data(char *data, size_t *sizep, bool raw, - void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index) -{ - int ret; - bool eph = !is_persistent(pool); - - BUG_ON(preemptible()); - BUG_ON(eph); /* fix later if shared pools get implemented */ - BUG_ON(pampd_is_remote(pampd)); - if (raw) - ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, - sizep, eph); - else { - ret = zbud_decompress((struct page *)(data), - (struct zbudref *)pampd, false, - zcache_decompress); - *sizep = PAGE_SIZE; - } - return ret; -} - -/* - * fill the pageframe corresponding to the struct page with the data - * from the passed pampd - */ -static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, - void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index) -{ - int ret; - bool eph = !is_persistent(pool); - struct page *page = NULL; - unsigned int zsize, zpages; - - BUG_ON(preemptible()); - BUG_ON(pampd_is_remote(pampd)); - if (raw) - ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, - sizep, eph); - else { - ret = zbud_decompress((struct page *)(data), - (struct zbudref *)pampd, eph, - zcache_decompress); - *sizep = PAGE_SIZE; - } - page = zbud_free_and_delist((struct zbudref *)pampd, eph, - &zsize, &zpages); - if (eph) { - if (page) - zcache_eph_pageframes = - atomic_dec_return(&zcache_eph_pageframes_atomic); - zcache_eph_zpages = - atomic_sub_return(zpages, &zcache_eph_zpages_atomic); - zcache_eph_zbytes = - atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic); - } else { - if (page) - zcache_pers_pageframes = - atomic_dec_return(&zcache_pers_pageframes_atomic); - zcache_pers_zpages = - atomic_sub_return(zpages, &zcache_pers_zpages_atomic); - zcache_pers_zbytes = - atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic); - } - if (!is_local_client(pool->client)) - ramster_count_foreign_pages(eph, -1); - if (page) - zcache_free_page(page); - return ret; -} - -/* - * free the pampd and remove it from any zcache lists - * pampd must no longer be pointed to from any tmem data structures! - */ -static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, - struct tmem_oid *oid, uint32_t index, bool acct) -{ - struct page *page = NULL; - unsigned int zsize, zpages; - - BUG_ON(preemptible()); - if (pampd_is_remote(pampd)) { - BUG_ON(!ramster_enabled); - pampd = ramster_pampd_free(pampd, pool, oid, index, acct); - if (pampd == NULL) - return; - } - if (is_ephemeral(pool)) { - page = zbud_free_and_delist((struct zbudref *)pampd, - true, &zsize, &zpages); - if (page) - zcache_eph_pageframes = - atomic_dec_return(&zcache_eph_pageframes_atomic); - zcache_eph_zpages = - atomic_sub_return(zpages, &zcache_eph_zpages_atomic); - zcache_eph_zbytes = - atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic); - /* FIXME CONFIG_RAMSTER... check acct parameter? */ - } else { - page = zbud_free_and_delist((struct zbudref *)pampd, - false, &zsize, &zpages); - if (page) - zcache_pers_pageframes = - atomic_dec_return(&zcache_pers_pageframes_atomic); - zcache_pers_zpages = - atomic_sub_return(zpages, &zcache_pers_zpages_atomic); - zcache_pers_zbytes = - atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic); - } - if (!is_local_client(pool->client)) - ramster_count_foreign_pages(is_ephemeral(pool), -1); - if (page) - zcache_free_page(page); -} - -static struct tmem_pamops zcache_pamops = { - .create_finish = zcache_pampd_create_finish, - .get_data = zcache_pampd_get_data, - .get_data_and_free = zcache_pampd_get_data_and_free, - .free = zcache_pampd_free, -}; - -/* - * zcache compression/decompression and related per-cpu stuff - */ - -static DEFINE_PER_CPU(unsigned char *, zcache_dstmem); -#define ZCACHE_DSTMEM_ORDER 1 - -static void zcache_compress(struct page *from, void **out_va, unsigned *out_len) -{ - int ret; - unsigned char *dmem = __get_cpu_var(zcache_dstmem); - char *from_va; - - BUG_ON(!irqs_disabled()); - /* no buffer or no compressor so can't compress */ - BUG_ON(dmem == NULL); - *out_len = PAGE_SIZE << ZCACHE_DSTMEM_ORDER; - from_va = kmap_atomic(from); - mb(); - ret = zcache_comp_op(ZCACHE_COMPOP_COMPRESS, from_va, PAGE_SIZE, dmem, - out_len); - BUG_ON(ret); - *out_va = dmem; - kunmap_atomic(from_va); -} - -static int zcache_comp_cpu_up(int cpu) -{ - struct crypto_comp *tfm; - - tfm = crypto_alloc_comp(zcache_comp_name, 0, 0); - if (IS_ERR(tfm)) - return NOTIFY_BAD; - *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = tfm; - return NOTIFY_OK; -} - -static void zcache_comp_cpu_down(int cpu) -{ - struct crypto_comp *tfm; - - tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu); - crypto_free_comp(tfm); - *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = NULL; -} - -static int zcache_cpu_notifier(struct notifier_block *nb, - unsigned long action, void *pcpu) -{ - int ret, i, cpu = (long)pcpu; - struct zcache_preload *kp; - - switch (action) { - case CPU_UP_PREPARE: - ret = zcache_comp_cpu_up(cpu); - if (ret != NOTIFY_OK) { - pr_err("%s: can't allocate compressor xform\n", - namestr); - return ret; - } - per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages( - GFP_KERNEL | __GFP_REPEAT, ZCACHE_DSTMEM_ORDER); - if (ramster_enabled) - ramster_cpu_up(cpu); - break; - case CPU_DEAD: - case CPU_UP_CANCELED: - zcache_comp_cpu_down(cpu); - free_pages((unsigned long)per_cpu(zcache_dstmem, cpu), - ZCACHE_DSTMEM_ORDER); - per_cpu(zcache_dstmem, cpu) = NULL; - kp = &per_cpu(zcache_preloads, cpu); - for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) { - if (kp->objnodes[i]) - kmem_cache_free(zcache_objnode_cache, - kp->objnodes[i]); - } - if (kp->obj) { - kmem_cache_free(zcache_obj_cache, kp->obj); - kp->obj = NULL; - } - if (ramster_enabled) - ramster_cpu_down(cpu); - break; - default: - break; - } - return NOTIFY_OK; -} - -static struct notifier_block zcache_cpu_notifier_block = { - .notifier_call = zcache_cpu_notifier -}; - -/* - * The following code interacts with the zbud eviction and zbud - * zombify code to access LRU pages - */ - -static struct page *zcache_evict_eph_pageframe(void) -{ - struct page *page; - unsigned int zsize = 0, zpages = 0; - - page = zbud_evict_pageframe_lru(&zsize, &zpages); - if (page == NULL) - goto out; - zcache_eph_zbytes = atomic_long_sub_return(zsize, - &zcache_eph_zbytes_atomic); - zcache_eph_zpages = atomic_sub_return(zpages, - &zcache_eph_zpages_atomic); - zcache_evicted_eph_zpages++; - zcache_eph_pageframes = - atomic_dec_return(&zcache_eph_pageframes_atomic); - zcache_evicted_eph_pageframes++; -out: - return page; -} - -#ifdef FRONTSWAP_HAS_UNUSE -static void unswiz(struct tmem_oid oid, u32 index, - unsigned *type, pgoff_t *offset); - -/* - * Choose an LRU persistent pageframe and attempt to "unuse" it by - * calling frontswap_unuse on both zpages. - * - * This is work-in-progress. - */ - -static int zcache_frontswap_unuse(void) -{ - struct tmem_handle th[2]; - int ret = -ENOMEM; - int nzbuds, unuse_ret; - unsigned type; - struct page *newpage1 = NULL, *newpage2 = NULL; - struct page *evictpage1 = NULL, *evictpage2 = NULL; - pgoff_t offset; - - newpage1 = alloc_page(ZCACHE_GFP_MASK); - newpage2 = alloc_page(ZCACHE_GFP_MASK); - if (newpage1 == NULL) - evictpage1 = zcache_evict_eph_pageframe(); - if (newpage2 == NULL) - evictpage2 = zcache_evict_eph_pageframe(); - if (evictpage1 == NULL || evictpage2 == NULL) - goto free_and_out; - /* ok, we have two pages pre-allocated */ - nzbuds = zbud_make_zombie_lru(&th[0], NULL, NULL, false); - if (nzbuds == 0) { - ret = -ENOENT; - goto free_and_out; - } - unswiz(th[0].oid, th[0].index, &type, &offset); - unuse_ret = frontswap_unuse(type, offset, - newpage1 != NULL ? newpage1 : evictpage1, - ZCACHE_GFP_MASK); - if (unuse_ret != 0) - goto free_and_out; - else if (evictpage1 != NULL) - zcache_unacct_page(); - newpage1 = NULL; - evictpage1 = NULL; - if (nzbuds == 2) { - unswiz(th[1].oid, th[1].index, &type, &offset); - unuse_ret = frontswap_unuse(type, offset, - newpage2 != NULL ? newpage2 : evictpage2, - ZCACHE_GFP_MASK); - if (unuse_ret != 0) { - goto free_and_out; - } else if (evictpage2 != NULL) { - zcache_unacct_page(); - } - } - ret = 0; - goto out; - -free_and_out: - if (newpage1 != NULL) - __free_page(newpage1); - if (newpage2 != NULL) - __free_page(newpage2); - if (evictpage1 != NULL) - zcache_free_page(evictpage1); - if (evictpage2 != NULL) - zcache_free_page(evictpage2); -out: - return ret; -} -#endif - -/* - * When zcache is disabled ("frozen"), pools can be created and destroyed, - * but all puts (and thus all other operations that require memory allocation) - * must fail. If zcache is unfrozen, accepts puts, then frozen again, - * data consistency requires all puts while frozen to be converted into - * flushes. - */ -static bool zcache_freeze; - -/* - * This zcache shrinker interface reduces the number of ephemeral pageframes - * used by zcache to approximately the same as the total number of LRU_FILE - * pageframes in use. - */ -static int shrink_zcache_memory(struct shrinker *shrink, - struct shrink_control *sc) -{ - static bool in_progress; - int ret = -1; - int nr = sc->nr_to_scan; - int nr_evict = 0; - int nr_unuse = 0; - struct page *page; -#ifdef FRONTSWAP_HAS_UNUSE - int unuse_ret; -#endif - - if (nr <= 0) - goto skip_evict; - - /* don't allow more than one eviction thread at a time */ - if (in_progress) - goto skip_evict; - - in_progress = true; - - /* we are going to ignore nr, and target a different value */ - zcache_last_active_file_pageframes = - global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); - zcache_last_inactive_file_pageframes = - global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); - nr_evict = zcache_eph_pageframes - zcache_last_active_file_pageframes + - zcache_last_inactive_file_pageframes; - while (nr_evict-- > 0) { - page = zcache_evict_eph_pageframe(); - if (page == NULL) - break; - zcache_free_page(page); - } - - zcache_last_active_anon_pageframes = - global_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON); - zcache_last_inactive_anon_pageframes = - global_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON); - nr_unuse = zcache_pers_pageframes - zcache_last_active_anon_pageframes + - zcache_last_inactive_anon_pageframes; -#ifdef FRONTSWAP_HAS_UNUSE - /* rate limit for testing */ - if (nr_unuse > 32) - nr_unuse = 32; - while (nr_unuse-- > 0) { - unuse_ret = zcache_frontswap_unuse(); - if (unuse_ret == -ENOMEM) - break; - } -#endif - in_progress = false; - -skip_evict: - /* resample: has changed, but maybe not all the way yet */ - zcache_last_active_file_pageframes = - global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); - zcache_last_inactive_file_pageframes = - global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); - ret = zcache_eph_pageframes - zcache_last_active_file_pageframes + - zcache_last_inactive_file_pageframes; - if (ret < 0) - ret = 0; - return ret; -} - -static struct shrinker zcache_shrinker = { - .shrink = shrink_zcache_memory, - .seeks = DEFAULT_SEEKS, -}; - -/* - * zcache shims between cleancache/frontswap ops and tmem - */ - -/* FIXME rename these core routines to zcache_tmemput etc? */ -int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp, - uint32_t index, void *page, - unsigned int size, bool raw, int ephemeral) -{ - struct tmem_pool *pool; - struct tmem_handle th; - int ret = -1; - void *pampd = NULL; - - BUG_ON(!irqs_disabled()); - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (unlikely(pool == NULL)) - goto out; - if (!zcache_freeze) { - ret = 0; - th.client_id = cli_id; - th.pool_id = pool_id; - th.oid = *oidp; - th.index = index; - pampd = zcache_pampd_create((char *)page, size, raw, - ephemeral, &th); - if (pampd == NULL) { - ret = -ENOMEM; - if (ephemeral) - zcache_failed_eph_puts++; - else - zcache_failed_pers_puts++; - } else { - if (ramster_enabled) - ramster_do_preload_flnode(pool); - ret = tmem_put(pool, oidp, index, 0, pampd); - if (ret < 0) - BUG(); - } - zcache_put_pool(pool); - } else { - zcache_put_to_flush++; - if (ramster_enabled) - ramster_do_preload_flnode(pool); - if (atomic_read(&pool->obj_count) > 0) - /* the put fails whether the flush succeeds or not */ - (void)tmem_flush_page(pool, oidp, index); - zcache_put_pool(pool); - } -out: - return ret; -} - -int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp, - uint32_t index, void *page, - size_t *sizep, bool raw, int get_and_free) -{ - struct tmem_pool *pool; - int ret = -1; - bool eph; - - if (!raw) { - BUG_ON(irqs_disabled()); - BUG_ON(in_softirq()); - } - pool = zcache_get_pool_by_id(cli_id, pool_id); - eph = is_ephemeral(pool); - if (likely(pool != NULL)) { - if (atomic_read(&pool->obj_count) > 0) - ret = tmem_get(pool, oidp, index, (char *)(page), - sizep, raw, get_and_free); - zcache_put_pool(pool); - } - WARN_ONCE((!is_ephemeral(pool) && (ret != 0)), - "zcache_get fails on persistent pool, " - "bad things are very likely to happen soon\n"); -#ifdef RAMSTER_TESTING - if (ret != 0 && ret != -1 && !(ret == -EINVAL && is_ephemeral(pool))) - pr_err("TESTING zcache_get tmem_get returns ret=%d\n", ret); -#endif - return ret; -} - -int zcache_flush_page(int cli_id, int pool_id, - struct tmem_oid *oidp, uint32_t index) -{ - struct tmem_pool *pool; - int ret = -1; - unsigned long flags; - - local_irq_save(flags); - zcache_flush_total++; - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (ramster_enabled) - ramster_do_preload_flnode(pool); - if (likely(pool != NULL)) { - if (atomic_read(&pool->obj_count) > 0) - ret = tmem_flush_page(pool, oidp, index); - zcache_put_pool(pool); - } - if (ret >= 0) - zcache_flush_found++; - local_irq_restore(flags); - return ret; -} - -int zcache_flush_object(int cli_id, int pool_id, - struct tmem_oid *oidp) -{ - struct tmem_pool *pool; - int ret = -1; - unsigned long flags; - - local_irq_save(flags); - zcache_flobj_total++; - pool = zcache_get_pool_by_id(cli_id, pool_id); - if (ramster_enabled) - ramster_do_preload_flnode(pool); - if (likely(pool != NULL)) { - if (atomic_read(&pool->obj_count) > 0) - ret = tmem_flush_object(pool, oidp); - zcache_put_pool(pool); - } - if (ret >= 0) - zcache_flobj_found++; - local_irq_restore(flags); - return ret; -} - -static int zcache_client_destroy_pool(int cli_id, int pool_id) -{ - struct tmem_pool *pool = NULL; - struct zcache_client *cli = NULL; - int ret = -1; - - if (pool_id < 0) - goto out; - if (cli_id == LOCAL_CLIENT) - cli = &zcache_host; - else if ((unsigned int)cli_id < MAX_CLIENTS) - cli = &zcache_clients[cli_id]; - if (cli == NULL) - goto out; - atomic_inc(&cli->refcount); - pool = cli->tmem_pools[pool_id]; - if (pool == NULL) - goto out; - cli->tmem_pools[pool_id] = NULL; - /* wait for pool activity on other cpus to quiesce */ - while (atomic_read(&pool->refcount) != 0) - ; - atomic_dec(&cli->refcount); - local_bh_disable(); - ret = tmem_destroy_pool(pool); - local_bh_enable(); - kfree(pool); - if (cli_id == LOCAL_CLIENT) - pr_info("%s: destroyed local pool id=%d\n", namestr, pool_id); - else - pr_info("%s: destroyed pool id=%d, client=%d\n", - namestr, pool_id, cli_id); -out: - return ret; -} - -int zcache_new_pool(uint16_t cli_id, uint32_t flags) -{ - int poolid = -1; - struct tmem_pool *pool; - struct zcache_client *cli = NULL; - - if (cli_id == LOCAL_CLIENT) - cli = &zcache_host; - else if ((unsigned int)cli_id < MAX_CLIENTS) - cli = &zcache_clients[cli_id]; - if (cli == NULL) - goto out; - atomic_inc(&cli->refcount); - pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC); - if (pool == NULL) { - pr_info("%s: pool creation failed: out of memory\n", namestr); - goto out; - } - - for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++) - if (cli->tmem_pools[poolid] == NULL) - break; - if (poolid >= MAX_POOLS_PER_CLIENT) { - pr_info("%s: pool creation failed: max exceeded\n", namestr); - kfree(pool); - poolid = -1; - goto out; - } - atomic_set(&pool->refcount, 0); - pool->client = cli; - pool->pool_id = poolid; - tmem_new_pool(pool, flags); - cli->tmem_pools[poolid] = pool; - if (cli_id == LOCAL_CLIENT) - pr_info("%s: created %s local tmem pool, id=%d\n", namestr, - flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", - poolid); - else - pr_info("%s: created %s tmem pool, id=%d, client=%d\n", namestr, - flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", - poolid, cli_id); -out: - if (cli != NULL) - atomic_dec(&cli->refcount); - return poolid; -} - -static int zcache_local_new_pool(uint32_t flags) -{ - return zcache_new_pool(LOCAL_CLIENT, flags); -} - -int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph) -{ - struct tmem_pool *pool; - struct zcache_client *cli; - uint32_t flags = eph ? 0 : TMEM_POOL_PERSIST; - int ret = -1; - - BUG_ON(!ramster_enabled); - if (cli_id == LOCAL_CLIENT) - goto out; - if (pool_id >= MAX_POOLS_PER_CLIENT) - goto out; - if (cli_id >= MAX_CLIENTS) - goto out; - - cli = &zcache_clients[cli_id]; - if ((eph && disable_cleancache) || (!eph && disable_frontswap)) { - pr_err("zcache_autocreate_pool: pool type disabled\n"); - goto out; - } - if (!cli->allocated) { - if (zcache_new_client(cli_id)) { - pr_err("zcache_autocreate_pool: can't create client\n"); - goto out; - } - cli = &zcache_clients[cli_id]; - } - atomic_inc(&cli->refcount); - pool = cli->tmem_pools[pool_id]; - if (pool != NULL) { - if (pool->persistent && eph) { - pr_err("zcache_autocreate_pool: type mismatch\n"); - goto out; - } - ret = 0; - goto out; - } - pool = kmalloc(sizeof(struct tmem_pool), GFP_KERNEL); - if (pool == NULL) { - pr_info("%s: pool creation failed: out of memory\n", namestr); - goto out; - } - atomic_set(&pool->refcount, 0); - pool->client = cli; - pool->pool_id = pool_id; - tmem_new_pool(pool, flags); - cli->tmem_pools[pool_id] = pool; - pr_info("%s: AUTOcreated %s tmem poolid=%d, for remote client=%d\n", - namestr, flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", - pool_id, cli_id); - ret = 0; -out: - if (cli != NULL) - atomic_dec(&cli->refcount); - return ret; -} - -/********** - * Two kernel functionalities currently can be layered on top of tmem. - * These are "cleancache" which is used as a second-chance cache for clean - * page cache pages; and "frontswap" which is used for swap pages - * to avoid writes to disk. A generic "shim" is provided here for each - * to translate in-kernel semantics to zcache semantics. - */ - -static void zcache_cleancache_put_page(int pool_id, - struct cleancache_filekey key, - pgoff_t index, struct page *page) -{ - u32 ind = (u32) index; - struct tmem_oid oid = *(struct tmem_oid *)&key; - - if (!disable_cleancache_ignore_nonactive && !PageWasActive(page)) { - zcache_eph_nonactive_puts_ignored++; - return; - } - if (likely(ind == index)) - (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index, - page, PAGE_SIZE, false, 1); -} - -static int zcache_cleancache_get_page(int pool_id, - struct cleancache_filekey key, - pgoff_t index, struct page *page) -{ - u32 ind = (u32) index; - struct tmem_oid oid = *(struct tmem_oid *)&key; - size_t size; - int ret = -1; - - if (likely(ind == index)) { - ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index, - page, &size, false, 0); - BUG_ON(ret >= 0 && size != PAGE_SIZE); - if (ret == 0) - SetPageWasActive(page); - } - return ret; -} - -static void zcache_cleancache_flush_page(int pool_id, - struct cleancache_filekey key, - pgoff_t index) -{ - u32 ind = (u32) index; - struct tmem_oid oid = *(struct tmem_oid *)&key; - - if (likely(ind == index)) - (void)zcache_flush_page(LOCAL_CLIENT, pool_id, &oid, ind); -} - -static void zcache_cleancache_flush_inode(int pool_id, - struct cleancache_filekey key) -{ - struct tmem_oid oid = *(struct tmem_oid *)&key; - - (void)zcache_flush_object(LOCAL_CLIENT, pool_id, &oid); -} - -static void zcache_cleancache_flush_fs(int pool_id) -{ - if (pool_id >= 0) - (void)zcache_client_destroy_pool(LOCAL_CLIENT, pool_id); -} - -static int zcache_cleancache_init_fs(size_t pagesize) -{ - BUG_ON(sizeof(struct cleancache_filekey) != - sizeof(struct tmem_oid)); - BUG_ON(pagesize != PAGE_SIZE); - return zcache_local_new_pool(0); -} - -static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize) -{ - /* shared pools are unsupported and map to private */ - BUG_ON(sizeof(struct cleancache_filekey) != - sizeof(struct tmem_oid)); - BUG_ON(pagesize != PAGE_SIZE); - return zcache_local_new_pool(0); -} - -static struct cleancache_ops zcache_cleancache_ops = { - .put_page = zcache_cleancache_put_page, - .get_page = zcache_cleancache_get_page, - .invalidate_page = zcache_cleancache_flush_page, - .invalidate_inode = zcache_cleancache_flush_inode, - .invalidate_fs = zcache_cleancache_flush_fs, - .init_shared_fs = zcache_cleancache_init_shared_fs, - .init_fs = zcache_cleancache_init_fs -}; - -struct cleancache_ops zcache_cleancache_register_ops(void) -{ - struct cleancache_ops old_ops = - cleancache_register_ops(&zcache_cleancache_ops); - - return old_ops; -} - -/* a single tmem poolid is used for all frontswap "types" (swapfiles) */ -static int zcache_frontswap_poolid __read_mostly = -1; - -/* - * Swizzling increases objects per swaptype, increasing tmem concurrency - * for heavy swaploads. Later, larger nr_cpus -> larger SWIZ_BITS - * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from - * frontswap_get_page(), but has side-effects. Hence using 8. - */ -#define SWIZ_BITS 8 -#define SWIZ_MASK ((1 << SWIZ_BITS) - 1) -#define _oswiz(_type, _ind) ((_type << SWIZ_BITS) | (_ind & SWIZ_MASK)) -#define iswiz(_ind) (_ind >> SWIZ_BITS) - -static inline struct tmem_oid oswiz(unsigned type, u32 ind) -{ - struct tmem_oid oid = { .oid = { 0 } }; - oid.oid[0] = _oswiz(type, ind); - return oid; -} - -#ifdef FRONTSWAP_HAS_UNUSE -static void unswiz(struct tmem_oid oid, u32 index, - unsigned *type, pgoff_t *offset) -{ - *type = (unsigned)(oid.oid[0] >> SWIZ_BITS); - *offset = (pgoff_t)((index << SWIZ_BITS) | - (oid.oid[0] & SWIZ_MASK)); -} -#endif - -static int zcache_frontswap_put_page(unsigned type, pgoff_t offset, - struct page *page) -{ - u64 ind64 = (u64)offset; - u32 ind = (u32)offset; - struct tmem_oid oid = oswiz(type, ind); - int ret = -1; - unsigned long flags; - - BUG_ON(!PageLocked(page)); - if (!disable_frontswap_ignore_nonactive && !PageWasActive(page)) { - zcache_pers_nonactive_puts_ignored++; - ret = -ERANGE; - goto out; - } - if (likely(ind64 == ind)) { - local_irq_save(flags); - ret = zcache_put_page(LOCAL_CLIENT, zcache_frontswap_poolid, - &oid, iswiz(ind), - page, PAGE_SIZE, false, 0); - local_irq_restore(flags); - } -out: - return ret; -} - -/* returns 0 if the page was successfully gotten from frontswap, -1 if - * was not present (should never happen!) */ -static int zcache_frontswap_get_page(unsigned type, pgoff_t offset, - struct page *page) -{ - u64 ind64 = (u64)offset; - u32 ind = (u32)offset; - struct tmem_oid oid = oswiz(type, ind); - size_t size; - int ret = -1, get_and_free; - - if (frontswap_has_exclusive_gets) - get_and_free = 1; - else - get_and_free = -1; - BUG_ON(!PageLocked(page)); - if (likely(ind64 == ind)) { - ret = zcache_get_page(LOCAL_CLIENT, zcache_frontswap_poolid, - &oid, iswiz(ind), - page, &size, false, get_and_free); - BUG_ON(ret >= 0 && size != PAGE_SIZE); - } - return ret; -} - -/* flush a single page from frontswap */ -static void zcache_frontswap_flush_page(unsigned type, pgoff_t offset) -{ - u64 ind64 = (u64)offset; - u32 ind = (u32)offset; - struct tmem_oid oid = oswiz(type, ind); - - if (likely(ind64 == ind)) - (void)zcache_flush_page(LOCAL_CLIENT, zcache_frontswap_poolid, - &oid, iswiz(ind)); -} - -/* flush all pages from the passed swaptype */ -static void zcache_frontswap_flush_area(unsigned type) -{ - struct tmem_oid oid; - int ind; - - for (ind = SWIZ_MASK; ind >= 0; ind--) { - oid = oswiz(type, ind); - (void)zcache_flush_object(LOCAL_CLIENT, - zcache_frontswap_poolid, &oid); - } -} - -static void zcache_frontswap_init(unsigned ignored) -{ - /* a single tmem poolid is used for all frontswap "types" (swapfiles) */ - if (zcache_frontswap_poolid < 0) - zcache_frontswap_poolid = - zcache_local_new_pool(TMEM_POOL_PERSIST); -} - -static struct frontswap_ops zcache_frontswap_ops = { - .store = zcache_frontswap_put_page, - .load = zcache_frontswap_get_page, - .invalidate_page = zcache_frontswap_flush_page, - .invalidate_area = zcache_frontswap_flush_area, - .init = zcache_frontswap_init -}; - -struct frontswap_ops zcache_frontswap_register_ops(void) -{ - struct frontswap_ops old_ops = - frontswap_register_ops(&zcache_frontswap_ops); - - return old_ops; -} - -/* - * zcache initialization - * NOTE FOR NOW zcache or ramster MUST BE PROVIDED AS A KERNEL BOOT PARAMETER - * OR NOTHING HAPPENS! - */ - -static int __init enable_zcache(char *s) -{ - zcache_enabled = 1; - return 1; -} -__setup("zcache", enable_zcache); - -static int __init enable_ramster(char *s) -{ - zcache_enabled = 1; -#ifdef CONFIG_RAMSTER - ramster_enabled = 1; -#endif - return 1; -} -__setup("ramster", enable_ramster); - -/* allow independent dynamic disabling of cleancache and frontswap */ - -static int __init no_cleancache(char *s) -{ - disable_cleancache = 1; - return 1; -} - -__setup("nocleancache", no_cleancache); - -static int __init no_frontswap(char *s) -{ - disable_frontswap = 1; - return 1; -} - -__setup("nofrontswap", no_frontswap); - -static int __init no_frontswap_exclusive_gets(char *s) -{ - frontswap_has_exclusive_gets = false; - return 1; -} - -__setup("nofrontswapexclusivegets", no_frontswap_exclusive_gets); - -static int __init no_frontswap_ignore_nonactive(char *s) -{ - disable_frontswap_ignore_nonactive = 1; - return 1; -} - -__setup("nofrontswapignorenonactive", no_frontswap_ignore_nonactive); - -static int __init no_cleancache_ignore_nonactive(char *s) -{ - disable_cleancache_ignore_nonactive = 1; - return 1; -} - -__setup("nocleancacheignorenonactive", no_cleancache_ignore_nonactive); - -static int __init enable_zcache_compressor(char *s) -{ - strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ); - zcache_enabled = 1; - return 1; -} -__setup("zcache=", enable_zcache_compressor); - - -static int __init zcache_comp_init(void) -{ - int ret = 0; - - /* check crypto algorithm */ - if (*zcache_comp_name != '\0') { - ret = crypto_has_comp(zcache_comp_name, 0, 0); - if (!ret) - pr_info("zcache: %s not supported\n", - zcache_comp_name); - } - if (!ret) - strcpy(zcache_comp_name, "lzo"); - ret = crypto_has_comp(zcache_comp_name, 0, 0); - if (!ret) { - ret = 1; - goto out; - } - pr_info("zcache: using %s compressor\n", zcache_comp_name); - - /* alloc percpu transforms */ - ret = 0; - zcache_comp_pcpu_tfms = alloc_percpu(struct crypto_comp *); - if (!zcache_comp_pcpu_tfms) - ret = 1; -out: - return ret; -} - -static int __init zcache_init(void) -{ - int ret = 0; - - if (ramster_enabled) { - namestr = "ramster"; - ramster_register_pamops(&zcache_pamops); - } -#ifdef CONFIG_DEBUG_FS - zcache_debugfs_init(); -#endif - if (zcache_enabled) { - unsigned int cpu; - - tmem_register_hostops(&zcache_hostops); - tmem_register_pamops(&zcache_pamops); - ret = register_cpu_notifier(&zcache_cpu_notifier_block); - if (ret) { - pr_err("%s: can't register cpu notifier\n", namestr); - goto out; - } - ret = zcache_comp_init(); - if (ret) { - pr_err("%s: compressor initialization failed\n", - namestr); - goto out; - } - for_each_online_cpu(cpu) { - void *pcpu = (void *)(long)cpu; - zcache_cpu_notifier(&zcache_cpu_notifier_block, - CPU_UP_PREPARE, pcpu); - } - } - zcache_objnode_cache = kmem_cache_create("zcache_objnode", - sizeof(struct tmem_objnode), 0, 0, NULL); - zcache_obj_cache = kmem_cache_create("zcache_obj", - sizeof(struct tmem_obj), 0, 0, NULL); - ret = zcache_new_client(LOCAL_CLIENT); - if (ret) { - pr_err("%s: can't create client\n", namestr); - goto out; - } - zbud_init(); - if (zcache_enabled && !disable_cleancache) { - struct cleancache_ops old_ops; - - register_shrinker(&zcache_shrinker); - old_ops = zcache_cleancache_register_ops(); - pr_info("%s: cleancache enabled using kernel transcendent " - "memory and compression buddies\n", namestr); -#ifdef ZCACHE_DEBUG - pr_info("%s: cleancache: ignorenonactive = %d\n", - namestr, !disable_cleancache_ignore_nonactive); -#endif - if (old_ops.init_fs != NULL) - pr_warn("%s: cleancache_ops overridden\n", namestr); - } - if (zcache_enabled && !disable_frontswap) { - struct frontswap_ops old_ops; - - old_ops = zcache_frontswap_register_ops(); - if (frontswap_has_exclusive_gets) - frontswap_tmem_exclusive_gets(true); - pr_info("%s: frontswap enabled using kernel transcendent " - "memory and compression buddies\n", namestr); -#ifdef ZCACHE_DEBUG - pr_info("%s: frontswap: excl gets = %d active only = %d\n", - namestr, frontswap_has_exclusive_gets, - !disable_frontswap_ignore_nonactive); -#endif - if (old_ops.init != NULL) - pr_warn("%s: frontswap_ops overridden\n", namestr); - } - if (ramster_enabled) - ramster_init(!disable_cleancache, !disable_frontswap, - frontswap_has_exclusive_gets); -out: - return ret; -} - -late_initcall(zcache_init); diff --git a/drivers/staging/ramster/zcache.h b/drivers/staging/ramster/zcache.h deleted file mode 100644 index 81722b3..0000000 --- a/drivers/staging/ramster/zcache.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* - * zcache.h - * - * Copyright (c) 2012, Dan Magenheimer, Oracle Corp. - */ - -#ifndef _ZCACHE_H_ -#define _ZCACHE_H_ - -struct zcache_preload { - struct tmem_obj *obj; - struct tmem_objnode *objnodes[OBJNODE_TREE_MAX_PATH]; -}; - -struct tmem_pool; - -#define MAX_POOLS_PER_CLIENT 16 - -#define MAX_CLIENTS 16 -#define LOCAL_CLIENT ((uint16_t)-1) - -struct zcache_client { - struct tmem_pool *tmem_pools[MAX_POOLS_PER_CLIENT]; - bool allocated; - atomic_t refcount; -}; - -extern struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, - uint16_t poolid); -extern void zcache_put_pool(struct tmem_pool *pool); - -extern int zcache_put_page(int, int, struct tmem_oid *, - uint32_t, void *, - unsigned int, bool, int); -extern int zcache_get_page(int, int, struct tmem_oid *, uint32_t, - void *, size_t *, bool, int); -extern int zcache_flush_page(int, int, struct tmem_oid *, uint32_t); -extern int zcache_flush_object(int, int, struct tmem_oid *); -extern void zcache_decompress_to_page(char *, unsigned int, struct page *); - -#ifdef CONFIG_RAMSTER -extern void *zcache_pampd_create(char *, unsigned int, bool, int, - struct tmem_handle *); -int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph); -#endif - -#define MAX_POOLS_PER_CLIENT 16 - -#define MAX_CLIENTS 16 -#define LOCAL_CLIENT ((uint16_t)-1) - -#endif /* _ZCACHE_H_ */ diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig new file mode 100644 index 0000000..3abf661 --- /dev/null +++ b/drivers/staging/zcache/Kconfig @@ -0,0 +1,31 @@ +config ZCACHE2 + bool "Dynamic compression of swap pages and clean pagecache pages" + depends on CRYPTO=y && SWAP=y && CLEANCACHE && FRONTSWAP && !ZCACHE + select CRYPTO_LZO + default n + help + Zcache2 doubles RAM efficiency while providing a significant + performance boosts on many workloads. Zcache2 uses + compression and an in-kernel implementation of transcendent + memory to store clean page cache pages and swap in RAM, + providing a noticeable reduction in disk I/O. Zcache2 + is a complete rewrite of the older zcache; it was intended to + be a merge but that has been blocked due to political and + technical disagreements. It is intended that they will merge + again in the future. Until then, zcache2 is a single-node + version of ramster. + +config RAMSTER + bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem" + depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE2=y + depends on NET + # must ensure struct page is 8-byte aligned + select HAVE_ALIGNED_STRUCT_PAGE if !64_BIT + default n + help + RAMster allows RAM on other machines in a cluster to be utilized + dynamically and symmetrically instead of swapping to a local swap + disk, thus improving performance on memory-constrained workloads + while minimizing total RAM across the cluster. RAMster, like + zcache2, compresses swap pages into local RAM, but then remotifies + the compressed pages to another node in the RAMster cluster. diff --git a/drivers/staging/zcache/Makefile b/drivers/staging/zcache/Makefile new file mode 100644 index 0000000..2d8b9d0 --- /dev/null +++ b/drivers/staging/zcache/Makefile @@ -0,0 +1,6 @@ +zcache-y := zcache-main.o tmem.o zbud.o +zcache-$(CONFIG_RAMSTER) += ramster/ramster.o ramster/r2net.o +zcache-$(CONFIG_RAMSTER) += ramster/nodemanager.o ramster/tcp.o +zcache-$(CONFIG_RAMSTER) += ramster/heartbeat.o ramster/masklog.o + +obj-$(CONFIG_ZCACHE2) += zcache.o diff --git a/drivers/staging/zcache/ramster.h b/drivers/staging/zcache/ramster.h new file mode 100644 index 0000000..1b71aea --- /dev/null +++ b/drivers/staging/zcache/ramster.h @@ -0,0 +1,59 @@ + +/* + * zcache/ramster.h + * + * Placeholder to resolve ramster references when !CONFIG_RAMSTER + * Real ramster.h lives in ramster subdirectory. + * + * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. + */ + +#ifndef _ZCACHE_RAMSTER_H_ +#define _ZCACHE_RAMSTER_H_ + +#ifdef CONFIG_RAMSTER +#include "ramster/ramster.h" +#else +static inline void ramster_init(bool x, bool y, bool z) +{ +} + +static inline void ramster_register_pamops(struct tmem_pamops *p) +{ +} + +static inline int ramster_remotify_pageframe(bool b) +{ + return 0; +} + +static inline void *ramster_pampd_free(void *v, struct tmem_pool *p, + struct tmem_oid *o, uint32_t u, bool b) +{ + return NULL; +} + +static inline int ramster_do_preload_flnode(struct tmem_pool *p) +{ + return -1; +} + +static inline bool pampd_is_remote(void *v) +{ + return false; +} + +static inline void ramster_count_foreign_pages(bool b, int i) +{ +} + +static inline void ramster_cpu_up(int cpu) +{ +} + +static inline void ramster_cpu_down(int cpu) +{ +} +#endif + +#endif /* _ZCACHE_RAMSTER_H */ diff --git a/drivers/staging/zcache/ramster/heartbeat.c b/drivers/staging/zcache/ramster/heartbeat.c new file mode 100644 index 0000000..75d3fe8 --- /dev/null +++ b/drivers/staging/zcache/ramster/heartbeat.c @@ -0,0 +1,462 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * Copyright (C) 2004, 2005, 2012 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include + +#include "heartbeat.h" +#include "tcp.h" +#include "nodemanager.h" + +#include "masklog.h" + +/* + * The first heartbeat pass had one global thread that would serialize all hb + * callback calls. This global serializing sem should only be removed once + * we've made sure that all callees can deal with being called concurrently + * from multiple hb region threads. + */ +static DECLARE_RWSEM(r2hb_callback_sem); + +/* + * multiple hb threads are watching multiple regions. A node is live + * whenever any of the threads sees activity from the node in its region. + */ +static DEFINE_SPINLOCK(r2hb_live_lock); +static unsigned long r2hb_live_node_bitmap[BITS_TO_LONGS(R2NM_MAX_NODES)]; + +static struct r2hb_callback { + struct list_head list; +} r2hb_callbacks[R2HB_NUM_CB]; + +enum r2hb_heartbeat_modes { + R2HB_HEARTBEAT_LOCAL = 0, + R2HB_HEARTBEAT_GLOBAL, + R2HB_HEARTBEAT_NUM_MODES, +}; + +char *r2hb_heartbeat_mode_desc[R2HB_HEARTBEAT_NUM_MODES] = { + "local", /* R2HB_HEARTBEAT_LOCAL */ + "global", /* R2HB_HEARTBEAT_GLOBAL */ +}; + +unsigned int r2hb_dead_threshold = R2HB_DEFAULT_DEAD_THRESHOLD; +unsigned int r2hb_heartbeat_mode = R2HB_HEARTBEAT_LOCAL; + +/* Only sets a new threshold if there are no active regions. + * + * No locking or otherwise interesting code is required for reading + * r2hb_dead_threshold as it can't change once regions are active and + * it's not interesting to anyone until then anyway. */ +static void r2hb_dead_threshold_set(unsigned int threshold) +{ + if (threshold > R2HB_MIN_DEAD_THRESHOLD) { + spin_lock(&r2hb_live_lock); + r2hb_dead_threshold = threshold; + spin_unlock(&r2hb_live_lock); + } +} + +static int r2hb_global_hearbeat_mode_set(unsigned int hb_mode) +{ + int ret = -1; + + if (hb_mode < R2HB_HEARTBEAT_NUM_MODES) { + spin_lock(&r2hb_live_lock); + r2hb_heartbeat_mode = hb_mode; + ret = 0; + spin_unlock(&r2hb_live_lock); + } + + return ret; +} + +void r2hb_exit(void) +{ +} + +int r2hb_init(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(r2hb_callbacks); i++) + INIT_LIST_HEAD(&r2hb_callbacks[i].list); + + memset(r2hb_live_node_bitmap, 0, sizeof(r2hb_live_node_bitmap)); + + return 0; +} + +/* if we're already in a callback then we're already serialized by the sem */ +static void r2hb_fill_node_map_from_callback(unsigned long *map, + unsigned bytes) +{ + BUG_ON(bytes < (BITS_TO_LONGS(R2NM_MAX_NODES) * sizeof(unsigned long))); + + memcpy(map, &r2hb_live_node_bitmap, bytes); +} + +/* + * get a map of all nodes that are heartbeating in any regions + */ +void r2hb_fill_node_map(unsigned long *map, unsigned bytes) +{ + /* callers want to serialize this map and callbacks so that they + * can trust that they don't miss nodes coming to the party */ + down_read(&r2hb_callback_sem); + spin_lock(&r2hb_live_lock); + r2hb_fill_node_map_from_callback(map, bytes); + spin_unlock(&r2hb_live_lock); + up_read(&r2hb_callback_sem); +} +EXPORT_SYMBOL_GPL(r2hb_fill_node_map); + +/* + * heartbeat configfs bits. The heartbeat set is a default set under + * the cluster set in nodemanager.c. + */ + +/* heartbeat set */ + +struct r2hb_hb_group { + struct config_group hs_group; + /* some stuff? */ +}; + +static struct r2hb_hb_group *to_r2hb_hb_group(struct config_group *group) +{ + return group ? + container_of(group, struct r2hb_hb_group, hs_group) + : NULL; +} + +static struct config_item r2hb_config_item; + +static struct config_item *r2hb_hb_group_make_item(struct config_group *group, + const char *name) +{ + int ret; + + if (strlen(name) > R2HB_MAX_REGION_NAME_LEN) { + ret = -ENAMETOOLONG; + goto free; + } + + config_item_put(&r2hb_config_item); + + return &r2hb_config_item; +free: + return ERR_PTR(ret); +} + +static void r2hb_hb_group_drop_item(struct config_group *group, + struct config_item *item) +{ + if (r2hb_global_heartbeat_active()) { + pr_notice("ramster: Heartbeat %s on region %s (%s)\n", + "stopped/aborted", config_item_name(item), + "no region"); + } + + config_item_put(item); +} + +struct r2hb_hb_group_attribute { + struct configfs_attribute attr; + ssize_t (*show)(struct r2hb_hb_group *, char *); + ssize_t (*store)(struct r2hb_hb_group *, const char *, size_t); +}; + +static ssize_t r2hb_hb_group_show(struct config_item *item, + struct configfs_attribute *attr, + char *page) +{ + struct r2hb_hb_group *reg = to_r2hb_hb_group(to_config_group(item)); + struct r2hb_hb_group_attribute *r2hb_hb_group_attr = + container_of(attr, struct r2hb_hb_group_attribute, attr); + ssize_t ret = 0; + + if (r2hb_hb_group_attr->show) + ret = r2hb_hb_group_attr->show(reg, page); + return ret; +} + +static ssize_t r2hb_hb_group_store(struct config_item *item, + struct configfs_attribute *attr, + const char *page, size_t count) +{ + struct r2hb_hb_group *reg = to_r2hb_hb_group(to_config_group(item)); + struct r2hb_hb_group_attribute *r2hb_hb_group_attr = + container_of(attr, struct r2hb_hb_group_attribute, attr); + ssize_t ret = -EINVAL; + + if (r2hb_hb_group_attr->store) + ret = r2hb_hb_group_attr->store(reg, page, count); + return ret; +} + +static ssize_t r2hb_hb_group_threshold_show(struct r2hb_hb_group *group, + char *page) +{ + return sprintf(page, "%u\n", r2hb_dead_threshold); +} + +static ssize_t r2hb_hb_group_threshold_store(struct r2hb_hb_group *group, + const char *page, + size_t count) +{ + unsigned long tmp; + char *p = (char *)page; + int err; + + err = kstrtoul(p, 10, &tmp); + if (err) + return err; + + /* this will validate ranges for us. */ + r2hb_dead_threshold_set((unsigned int) tmp); + + return count; +} + +static +ssize_t r2hb_hb_group_mode_show(struct r2hb_hb_group *group, + char *page) +{ + return sprintf(page, "%s\n", + r2hb_heartbeat_mode_desc[r2hb_heartbeat_mode]); +} + +static +ssize_t r2hb_hb_group_mode_store(struct r2hb_hb_group *group, + const char *page, size_t count) +{ + unsigned int i; + int ret; + size_t len; + + len = (page[count - 1] == '\n') ? count - 1 : count; + if (!len) + return -EINVAL; + + for (i = 0; i < R2HB_HEARTBEAT_NUM_MODES; ++i) { + if (strnicmp(page, r2hb_heartbeat_mode_desc[i], len)) + continue; + + ret = r2hb_global_hearbeat_mode_set(i); + if (!ret) + pr_notice("ramster: Heartbeat mode set to %s\n", + r2hb_heartbeat_mode_desc[i]); + return count; + } + + return -EINVAL; + +} + +static struct r2hb_hb_group_attribute r2hb_hb_group_attr_threshold = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "dead_threshold", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2hb_hb_group_threshold_show, + .store = r2hb_hb_group_threshold_store, +}; + +static struct r2hb_hb_group_attribute r2hb_hb_group_attr_mode = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "mode", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2hb_hb_group_mode_show, + .store = r2hb_hb_group_mode_store, +}; + +static struct configfs_attribute *r2hb_hb_group_attrs[] = { + &r2hb_hb_group_attr_threshold.attr, + &r2hb_hb_group_attr_mode.attr, + NULL, +}; + +static struct configfs_item_operations r2hb_hearbeat_group_item_ops = { + .show_attribute = r2hb_hb_group_show, + .store_attribute = r2hb_hb_group_store, +}; + +static struct configfs_group_operations r2hb_hb_group_group_ops = { + .make_item = r2hb_hb_group_make_item, + .drop_item = r2hb_hb_group_drop_item, +}; + +static struct config_item_type r2hb_hb_group_type = { + .ct_group_ops = &r2hb_hb_group_group_ops, + .ct_item_ops = &r2hb_hearbeat_group_item_ops, + .ct_attrs = r2hb_hb_group_attrs, + .ct_owner = THIS_MODULE, +}; + +/* this is just here to avoid touching group in heartbeat.h which the + * entire damn world #includes */ +struct config_group *r2hb_alloc_hb_set(void) +{ + struct r2hb_hb_group *hs = NULL; + struct config_group *ret = NULL; + + hs = kzalloc(sizeof(struct r2hb_hb_group), GFP_KERNEL); + if (hs == NULL) + goto out; + + config_group_init_type_name(&hs->hs_group, "heartbeat", + &r2hb_hb_group_type); + + ret = &hs->hs_group; +out: + if (ret == NULL) + kfree(hs); + return ret; +} + +void r2hb_free_hb_set(struct config_group *group) +{ + struct r2hb_hb_group *hs = to_r2hb_hb_group(group); + kfree(hs); +} + +/* hb callback registration and issuing */ + +static struct r2hb_callback *hbcall_from_type(enum r2hb_callback_type type) +{ + if (type == R2HB_NUM_CB) + return ERR_PTR(-EINVAL); + + return &r2hb_callbacks[type]; +} + +void r2hb_setup_callback(struct r2hb_callback_func *hc, + enum r2hb_callback_type type, + r2hb_cb_func *func, + void *data, + int priority) +{ + INIT_LIST_HEAD(&hc->hc_item); + hc->hc_func = func; + hc->hc_data = data; + hc->hc_priority = priority; + hc->hc_type = type; + hc->hc_magic = R2HB_CB_MAGIC; +} +EXPORT_SYMBOL_GPL(r2hb_setup_callback); + +int r2hb_register_callback(const char *region_uuid, + struct r2hb_callback_func *hc) +{ + struct r2hb_callback_func *tmp; + struct list_head *iter; + struct r2hb_callback *hbcall; + int ret; + + BUG_ON(hc->hc_magic != R2HB_CB_MAGIC); + BUG_ON(!list_empty(&hc->hc_item)); + + hbcall = hbcall_from_type(hc->hc_type); + if (IS_ERR(hbcall)) { + ret = PTR_ERR(hbcall); + goto out; + } + + down_write(&r2hb_callback_sem); + + list_for_each(iter, &hbcall->list) { + tmp = list_entry(iter, struct r2hb_callback_func, hc_item); + if (hc->hc_priority < tmp->hc_priority) { + list_add_tail(&hc->hc_item, iter); + break; + } + } + if (list_empty(&hc->hc_item)) + list_add_tail(&hc->hc_item, &hbcall->list); + + up_write(&r2hb_callback_sem); + ret = 0; +out: + mlog(ML_CLUSTER, "returning %d on behalf of %p for funcs %p\n", + ret, __builtin_return_address(0), hc); + return ret; +} +EXPORT_SYMBOL_GPL(r2hb_register_callback); + +void r2hb_unregister_callback(const char *region_uuid, + struct r2hb_callback_func *hc) +{ + BUG_ON(hc->hc_magic != R2HB_CB_MAGIC); + + mlog(ML_CLUSTER, "on behalf of %p for funcs %p\n", + __builtin_return_address(0), hc); + + /* XXX Can this happen _with_ a region reference? */ + if (list_empty(&hc->hc_item)) + return; + + down_write(&r2hb_callback_sem); + + list_del_init(&hc->hc_item); + + up_write(&r2hb_callback_sem); +} +EXPORT_SYMBOL_GPL(r2hb_unregister_callback); + +int r2hb_check_node_heartbeating_from_callback(u8 node_num) +{ + unsigned long testing_map[BITS_TO_LONGS(R2NM_MAX_NODES)]; + + r2hb_fill_node_map_from_callback(testing_map, sizeof(testing_map)); + if (!test_bit(node_num, testing_map)) { + mlog(ML_HEARTBEAT, + "node (%u) does not have heartbeating enabled.\n", + node_num); + return 0; + } + + return 1; +} +EXPORT_SYMBOL_GPL(r2hb_check_node_heartbeating_from_callback); + +void r2hb_stop_all_regions(void) +{ +} +EXPORT_SYMBOL_GPL(r2hb_stop_all_regions); + +/* + * this is just a hack until we get the plumbing which flips file systems + * read only and drops the hb ref instead of killing the node dead. + */ +int r2hb_global_heartbeat_active(void) +{ + return (r2hb_heartbeat_mode == R2HB_HEARTBEAT_GLOBAL); +} +EXPORT_SYMBOL(r2hb_global_heartbeat_active); + +/* added for RAMster */ +void r2hb_manual_set_node_heartbeating(int node_num) +{ + if (node_num < R2NM_MAX_NODES) + set_bit(node_num, r2hb_live_node_bitmap); +} +EXPORT_SYMBOL(r2hb_manual_set_node_heartbeating); diff --git a/drivers/staging/zcache/ramster/heartbeat.h b/drivers/staging/zcache/ramster/heartbeat.h new file mode 100644 index 0000000..6cbc775 --- /dev/null +++ b/drivers/staging/zcache/ramster/heartbeat.h @@ -0,0 +1,87 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * heartbeat.h + * + * Function prototypes + * + * Copyright (C) 2004 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + */ + +#ifndef R2CLUSTER_HEARTBEAT_H +#define R2CLUSTER_HEARTBEAT_H + +#define R2HB_REGION_TIMEOUT_MS 2000 + +#define R2HB_MAX_REGION_NAME_LEN 32 + +/* number of changes to be seen as live */ +#define R2HB_LIVE_THRESHOLD 2 +/* number of equal samples to be seen as dead */ +extern unsigned int r2hb_dead_threshold; +#define R2HB_DEFAULT_DEAD_THRESHOLD 31 +/* Otherwise MAX_WRITE_TIMEOUT will be zero... */ +#define R2HB_MIN_DEAD_THRESHOLD 2 +#define R2HB_MAX_WRITE_TIMEOUT_MS \ + (R2HB_REGION_TIMEOUT_MS * (r2hb_dead_threshold - 1)) + +#define R2HB_CB_MAGIC 0x51d1e4ec + +/* callback stuff */ +enum r2hb_callback_type { + R2HB_NODE_DOWN_CB = 0, + R2HB_NODE_UP_CB, + R2HB_NUM_CB +}; + +struct r2nm_node; +typedef void (r2hb_cb_func)(struct r2nm_node *, int, void *); + +struct r2hb_callback_func { + u32 hc_magic; + struct list_head hc_item; + r2hb_cb_func *hc_func; + void *hc_data; + int hc_priority; + enum r2hb_callback_type hc_type; +}; + +struct config_group *r2hb_alloc_hb_set(void); +void r2hb_free_hb_set(struct config_group *group); + +void r2hb_setup_callback(struct r2hb_callback_func *hc, + enum r2hb_callback_type type, + r2hb_cb_func *func, + void *data, + int priority); +int r2hb_register_callback(const char *region_uuid, + struct r2hb_callback_func *hc); +void r2hb_unregister_callback(const char *region_uuid, + struct r2hb_callback_func *hc); +void r2hb_fill_node_map(unsigned long *map, + unsigned bytes); +void r2hb_exit(void); +int r2hb_init(void); +int r2hb_check_node_heartbeating_from_callback(u8 node_num); +void r2hb_stop_all_regions(void); +int r2hb_get_all_regions(char *region_uuids, u8 numregions); +int r2hb_global_heartbeat_active(void); +void r2hb_manual_set_node_heartbeating(int); + +#endif /* R2CLUSTER_HEARTBEAT_H */ diff --git a/drivers/staging/zcache/ramster/masklog.c b/drivers/staging/zcache/ramster/masklog.c new file mode 100644 index 0000000..1261d85 --- /dev/null +++ b/drivers/staging/zcache/ramster/masklog.c @@ -0,0 +1,155 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * Copyright (C) 2004, 2005, 2012 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include +#include +#include +#include + +#include "masklog.h" + +struct mlog_bits r2_mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK); +EXPORT_SYMBOL_GPL(r2_mlog_and_bits); +struct mlog_bits r2_mlog_not_bits = MLOG_BITS_RHS(0); +EXPORT_SYMBOL_GPL(r2_mlog_not_bits); + +static ssize_t mlog_mask_show(u64 mask, char *buf) +{ + char *state; + + if (__mlog_test_u64(mask, r2_mlog_and_bits)) + state = "allow"; + else if (__mlog_test_u64(mask, r2_mlog_not_bits)) + state = "deny"; + else + state = "off"; + + return snprintf(buf, PAGE_SIZE, "%s\n", state); +} + +static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count) +{ + if (!strnicmp(buf, "allow", 5)) { + __mlog_set_u64(mask, r2_mlog_and_bits); + __mlog_clear_u64(mask, r2_mlog_not_bits); + } else if (!strnicmp(buf, "deny", 4)) { + __mlog_set_u64(mask, r2_mlog_not_bits); + __mlog_clear_u64(mask, r2_mlog_and_bits); + } else if (!strnicmp(buf, "off", 3)) { + __mlog_clear_u64(mask, r2_mlog_not_bits); + __mlog_clear_u64(mask, r2_mlog_and_bits); + } else + return -EINVAL; + + return count; +} + +struct mlog_attribute { + struct attribute attr; + u64 mask; +}; + +#define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr) + +#define define_mask(_name) { \ + .attr = { \ + .name = #_name, \ + .mode = S_IRUGO | S_IWUSR, \ + }, \ + .mask = ML_##_name, \ +} + +static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = { + define_mask(TCP), + define_mask(MSG), + define_mask(SOCKET), + define_mask(HEARTBEAT), + define_mask(HB_BIO), + define_mask(DLMFS), + define_mask(DLM), + define_mask(DLM_DOMAIN), + define_mask(DLM_THREAD), + define_mask(DLM_MASTER), + define_mask(DLM_RECOVERY), + define_mask(DLM_GLUE), + define_mask(VOTE), + define_mask(CONN), + define_mask(QUORUM), + define_mask(BASTS), + define_mask(CLUSTER), + define_mask(ERROR), + define_mask(NOTICE), + define_mask(KTHREAD), +}; + +static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, }; + +static ssize_t mlog_show(struct kobject *obj, struct attribute *attr, + char *buf) +{ + struct mlog_attribute *mlog_attr = to_mlog_attr(attr); + + return mlog_mask_show(mlog_attr->mask, buf); +} + +static ssize_t mlog_store(struct kobject *obj, struct attribute *attr, + const char *buf, size_t count) +{ + struct mlog_attribute *mlog_attr = to_mlog_attr(attr); + + return mlog_mask_store(mlog_attr->mask, buf, count); +} + +static const struct sysfs_ops mlog_attr_ops = { + .show = mlog_show, + .store = mlog_store, +}; + +static struct kobj_type mlog_ktype = { + .default_attrs = mlog_attr_ptrs, + .sysfs_ops = &mlog_attr_ops, +}; + +static struct kset mlog_kset = { + .kobj = {.ktype = &mlog_ktype}, +}; + +int r2_mlog_sys_init(struct kset *r2cb_kset) +{ + int i = 0; + + while (mlog_attrs[i].attr.mode) { + mlog_attr_ptrs[i] = &mlog_attrs[i].attr; + i++; + } + mlog_attr_ptrs[i] = NULL; + + kobject_set_name(&mlog_kset.kobj, "logmask"); + mlog_kset.kobj.kset = r2cb_kset; + return kset_register(&mlog_kset); +} + +void r2_mlog_sys_shutdown(void) +{ + kset_unregister(&mlog_kset); +} diff --git a/drivers/staging/zcache/ramster/masklog.h b/drivers/staging/zcache/ramster/masklog.h new file mode 100644 index 0000000..918ae11 --- /dev/null +++ b/drivers/staging/zcache/ramster/masklog.h @@ -0,0 +1,220 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * Copyright (C) 2005, 2012 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef R2CLUSTER_MASKLOG_H +#define R2CLUSTER_MASKLOG_H + +/* + * For now this is a trivial wrapper around printk() that gives the critical + * ability to enable sets of debugging output at run-time. In the future this + * will almost certainly be redirected to relayfs so that it can pay a + * substantially lower heisenberg tax. + * + * Callers associate the message with a bitmask and a global bitmask is + * maintained with help from /proc. If any of the bits match the message is + * output. + * + * We must have efficient bit tests on i386 and it seems gcc still emits crazy + * code for the 64bit compare. It emits very good code for the dual unsigned + * long tests, though, completely avoiding tests that can never pass if the + * caller gives a constant bitmask that fills one of the longs with all 0s. So + * the desire is to have almost all of the calls decided on by comparing just + * one of the longs. This leads to having infrequently given bits that are + * frequently matched in the high bits. + * + * _ERROR and _NOTICE are used for messages that always go to the console and + * have appropriate KERN_ prefixes. We wrap these in our function instead of + * just calling printk() so that this can eventually make its way through + * relayfs along with the debugging messages. Everything else gets KERN_DEBUG. + * The inline tests and macro dance give GCC the opportunity to quite cleverly + * only emit the appropriage printk() when the caller passes in a constant + * mask, as is almost always the case. + * + * All this bitmask nonsense is managed from the files under + * /sys/fs/r2cb/logmask/. Reading the files gives a straightforward + * indication of which bits are allowed (allow) or denied (off/deny). + * ENTRY deny + * EXIT deny + * TCP off + * MSG off + * SOCKET off + * ERROR allow + * NOTICE allow + * + * Writing changes the state of a given bit and requires a strictly formatted + * single write() call: + * + * write(fd, "allow", 5); + * + * Echoing allow/deny/off string into the logmask files can flip the bits + * on or off as expected; here is the bash script for example: + * + * log_mask="/sys/fs/r2cb/log_mask" + * for node in ENTRY EXIT TCP MSG SOCKET ERROR NOTICE; do + * echo allow >"$log_mask"/"$node" + * done + * + * The debugfs.ramster tool can also flip the bits with the -l option: + * + * debugfs.ramster -l TCP allow + */ + +/* for task_struct */ +#include + +/* bits that are frequently given and infrequently matched in the low word */ +/* NOTE: If you add a flag, you need to also update masklog.c! */ +#define ML_TCP 0x0000000000000001ULL /* net cluster/tcp.c */ +#define ML_MSG 0x0000000000000002ULL /* net network messages */ +#define ML_SOCKET 0x0000000000000004ULL /* net socket lifetime */ +#define ML_HEARTBEAT 0x0000000000000008ULL /* hb all heartbeat tracking */ +#define ML_HB_BIO 0x0000000000000010ULL /* hb io tracing */ +#define ML_DLMFS 0x0000000000000020ULL /* dlm user dlmfs */ +#define ML_DLM 0x0000000000000040ULL /* dlm general debugging */ +#define ML_DLM_DOMAIN 0x0000000000000080ULL /* dlm domain debugging */ +#define ML_DLM_THREAD 0x0000000000000100ULL /* dlm domain thread */ +#define ML_DLM_MASTER 0x0000000000000200ULL /* dlm master functions */ +#define ML_DLM_RECOVERY 0x0000000000000400ULL /* dlm master functions */ +#define ML_DLM_GLUE 0x0000000000000800ULL /* ramster dlm glue layer */ +#define ML_VOTE 0x0000000000001000ULL /* ramster node messaging */ +#define ML_CONN 0x0000000000002000ULL /* net connection management */ +#define ML_QUORUM 0x0000000000004000ULL /* net connection quorum */ +#define ML_BASTS 0x0000000000008000ULL /* dlmglue asts and basts */ +#define ML_CLUSTER 0x0000000000010000ULL /* cluster stack */ + +/* bits that are infrequently given and frequently matched in the high word */ +#define ML_ERROR 0x1000000000000000ULL /* sent to KERN_ERR */ +#define ML_NOTICE 0x2000000000000000ULL /* setn to KERN_NOTICE */ +#define ML_KTHREAD 0x4000000000000000ULL /* kernel thread activity */ + +#define MLOG_INITIAL_AND_MASK (ML_ERROR|ML_NOTICE) +#ifndef MLOG_MASK_PREFIX +#define MLOG_MASK_PREFIX 0 +#endif + +/* + * When logging is disabled, force the bit test to 0 for anything other + * than errors and notices, allowing gcc to remove the code completely. + * When enabled, allow all masks. + */ +#if defined(CONFIG_RAMSTER_DEBUG_MASKLOG) +#define ML_ALLOWED_BITS (~0) +#else +#define ML_ALLOWED_BITS (ML_ERROR|ML_NOTICE) +#endif + +#define MLOG_MAX_BITS 64 + +struct mlog_bits { + unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG]; +}; + +extern struct mlog_bits r2_mlog_and_bits, r2_mlog_not_bits; + +#if BITS_PER_LONG == 32 + +#define __mlog_test_u64(mask, bits) \ + ((u32)(mask & 0xffffffff) & bits.words[0] || \ + ((u64)(mask) >> 32) & bits.words[1]) +#define __mlog_set_u64(mask, bits) do { \ + bits.words[0] |= (u32)(mask & 0xffffffff); \ + bits.words[1] |= (u64)(mask) >> 32; \ +} while (0) +#define __mlog_clear_u64(mask, bits) do { \ + bits.words[0] &= ~((u32)(mask & 0xffffffff)); \ + bits.words[1] &= ~((u64)(mask) >> 32); \ +} while (0) +#define MLOG_BITS_RHS(mask) { \ + { \ + [0] = (u32)(mask & 0xffffffff), \ + [1] = (u64)(mask) >> 32, \ + } \ +} + +#else /* 32bit long above, 64bit long below */ + +#define __mlog_test_u64(mask, bits) ((mask) & bits.words[0]) +#define __mlog_set_u64(mask, bits) do { \ + bits.words[0] |= (mask); \ +} while (0) +#define __mlog_clear_u64(mask, bits) do { \ + bits.words[0] &= ~(mask); \ +} while (0) +#define MLOG_BITS_RHS(mask) { { (mask) } } + +#endif + +/* + * smp_processor_id() "helpfully" screams when called outside preemptible + * regions in current kernels. sles doesn't have the variants that don't + * scream. just do this instead of trying to guess which we're building + * against.. *sigh*. + */ +#define __mlog_cpu_guess ({ \ + unsigned long _cpu = get_cpu(); \ + put_cpu(); \ + _cpu; \ +}) + +/* In the following two macros, the whitespace after the ',' just + * before ##args is intentional. Otherwise, gcc 2.95 will eat the + * previous token if args expands to nothing. + */ +#define __mlog_printk(level, fmt, args...) \ + printk(level "(%s,%u,%lu):%s:%d " fmt, current->comm, \ + task_pid_nr(current), __mlog_cpu_guess, \ + __PRETTY_FUNCTION__, __LINE__ , ##args) + +#define mlog(mask, fmt, args...) do { \ + u64 __m = MLOG_MASK_PREFIX | (mask); \ + if ((__m & ML_ALLOWED_BITS) && \ + __mlog_test_u64(__m, r2_mlog_and_bits) && \ + !__mlog_test_u64(__m, r2_mlog_not_bits)) { \ + if (__m & ML_ERROR) \ + __mlog_printk(KERN_ERR, "ERROR: "fmt , ##args); \ + else if (__m & ML_NOTICE) \ + __mlog_printk(KERN_NOTICE, fmt , ##args); \ + else \ + __mlog_printk(KERN_INFO, fmt , ##args); \ + } \ +} while (0) + +#define mlog_errno(st) do { \ + int _st = (st); \ + if (_st != -ERESTARTSYS && _st != -EINTR && \ + _st != AOP_TRUNCATED_PAGE && _st != -ENOSPC) \ + mlog(ML_ERROR, "status = %lld\n", (long long)_st); \ +} while (0) + +#define mlog_bug_on_msg(cond, fmt, args...) do { \ + if (cond) { \ + mlog(ML_ERROR, "bug expression: " #cond "\n"); \ + mlog(ML_ERROR, fmt, ##args); \ + BUG(); \ + } \ +} while (0) + +#include +#include +int r2_mlog_sys_init(struct kset *r2cb_subsys); +void r2_mlog_sys_shutdown(void); + +#endif /* R2CLUSTER_MASKLOG_H */ diff --git a/drivers/staging/zcache/ramster/nodemanager.c b/drivers/staging/zcache/ramster/nodemanager.c new file mode 100644 index 0000000..c0f4815 --- /dev/null +++ b/drivers/staging/zcache/ramster/nodemanager.c @@ -0,0 +1,995 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * Copyright (C) 2004, 2005, 2012 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include +#include + +#include "tcp.h" +#include "nodemanager.h" +#include "heartbeat.h" +#include "masklog.h" + +/* for now we operate under the assertion that there can be only one + * cluster active at a time. Changing this will require trickling + * cluster references throughout where nodes are looked up */ +struct r2nm_cluster *r2nm_single_cluster; + +char *r2nm_fence_method_desc[R2NM_FENCE_METHODS] = { + "reset", /* R2NM_FENCE_RESET */ + "panic", /* R2NM_FENCE_PANIC */ +}; + +struct r2nm_node *r2nm_get_node_by_num(u8 node_num) +{ + struct r2nm_node *node = NULL; + + if (node_num >= R2NM_MAX_NODES || r2nm_single_cluster == NULL) + goto out; + + read_lock(&r2nm_single_cluster->cl_nodes_lock); + node = r2nm_single_cluster->cl_nodes[node_num]; + if (node) + config_item_get(&node->nd_item); + read_unlock(&r2nm_single_cluster->cl_nodes_lock); +out: + return node; +} +EXPORT_SYMBOL_GPL(r2nm_get_node_by_num); + +int r2nm_configured_node_map(unsigned long *map, unsigned bytes) +{ + struct r2nm_cluster *cluster = r2nm_single_cluster; + + BUG_ON(bytes < (sizeof(cluster->cl_nodes_bitmap))); + + if (cluster == NULL) + return -EINVAL; + + read_lock(&cluster->cl_nodes_lock); + memcpy(map, cluster->cl_nodes_bitmap, sizeof(cluster->cl_nodes_bitmap)); + read_unlock(&cluster->cl_nodes_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(r2nm_configured_node_map); + +static struct r2nm_node *r2nm_node_ip_tree_lookup(struct r2nm_cluster *cluster, + __be32 ip_needle, + struct rb_node ***ret_p, + struct rb_node **ret_parent) +{ + struct rb_node **p = &cluster->cl_node_ip_tree.rb_node; + struct rb_node *parent = NULL; + struct r2nm_node *node, *ret = NULL; + + while (*p) { + int cmp; + + parent = *p; + node = rb_entry(parent, struct r2nm_node, nd_ip_node); + + cmp = memcmp(&ip_needle, &node->nd_ipv4_address, + sizeof(ip_needle)); + if (cmp < 0) + p = &(*p)->rb_left; + else if (cmp > 0) + p = &(*p)->rb_right; + else { + ret = node; + break; + } + } + + if (ret_p != NULL) + *ret_p = p; + if (ret_parent != NULL) + *ret_parent = parent; + + return ret; +} + +struct r2nm_node *r2nm_get_node_by_ip(__be32 addr) +{ + struct r2nm_node *node = NULL; + struct r2nm_cluster *cluster = r2nm_single_cluster; + + if (cluster == NULL) + goto out; + + read_lock(&cluster->cl_nodes_lock); + node = r2nm_node_ip_tree_lookup(cluster, addr, NULL, NULL); + if (node) + config_item_get(&node->nd_item); + read_unlock(&cluster->cl_nodes_lock); + +out: + return node; +} +EXPORT_SYMBOL_GPL(r2nm_get_node_by_ip); + +void r2nm_node_put(struct r2nm_node *node) +{ + config_item_put(&node->nd_item); +} +EXPORT_SYMBOL_GPL(r2nm_node_put); + +void r2nm_node_get(struct r2nm_node *node) +{ + config_item_get(&node->nd_item); +} +EXPORT_SYMBOL_GPL(r2nm_node_get); + +u8 r2nm_this_node(void) +{ + u8 node_num = R2NM_MAX_NODES; + + if (r2nm_single_cluster && r2nm_single_cluster->cl_has_local) + node_num = r2nm_single_cluster->cl_local_node; + + return node_num; +} +EXPORT_SYMBOL_GPL(r2nm_this_node); + +/* node configfs bits */ + +static struct r2nm_cluster *to_r2nm_cluster(struct config_item *item) +{ + return item ? + container_of(to_config_group(item), struct r2nm_cluster, + cl_group) + : NULL; +} + +static struct r2nm_node *to_r2nm_node(struct config_item *item) +{ + return item ? container_of(item, struct r2nm_node, nd_item) : NULL; +} + +static void r2nm_node_release(struct config_item *item) +{ + struct r2nm_node *node = to_r2nm_node(item); + kfree(node); +} + +static ssize_t r2nm_node_num_read(struct r2nm_node *node, char *page) +{ + return sprintf(page, "%d\n", node->nd_num); +} + +static struct r2nm_cluster *to_r2nm_cluster_from_node(struct r2nm_node *node) +{ + /* through the first node_set .parent + * mycluster/nodes/mynode == r2nm_cluster->r2nm_node_group->r2nm_node */ + return to_r2nm_cluster(node->nd_item.ci_parent->ci_parent); +} + +enum { + R2NM_NODE_ATTR_NUM = 0, + R2NM_NODE_ATTR_PORT, + R2NM_NODE_ATTR_ADDRESS, + R2NM_NODE_ATTR_LOCAL, +}; + +static ssize_t r2nm_node_num_write(struct r2nm_node *node, const char *page, + size_t count) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster_from_node(node); + unsigned long tmp; + char *p = (char *)page; + int err; + + err = kstrtoul(p, 10, &tmp); + if (err) + return err; + + if (tmp >= R2NM_MAX_NODES) + return -ERANGE; + + /* once we're in the cl_nodes tree networking can look us up by + * node number and try to use our address and port attributes + * to connect to this node.. make sure that they've been set + * before writing the node attribute? */ + if (!test_bit(R2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) || + !test_bit(R2NM_NODE_ATTR_PORT, &node->nd_set_attributes)) + return -EINVAL; /* XXX */ + + write_lock(&cluster->cl_nodes_lock); + if (cluster->cl_nodes[tmp]) + p = NULL; + else { + cluster->cl_nodes[tmp] = node; + node->nd_num = tmp; + set_bit(tmp, cluster->cl_nodes_bitmap); + } + write_unlock(&cluster->cl_nodes_lock); + if (p == NULL) + return -EEXIST; + + return count; +} +static ssize_t r2nm_node_ipv4_port_read(struct r2nm_node *node, char *page) +{ + return sprintf(page, "%u\n", ntohs(node->nd_ipv4_port)); +} + +static ssize_t r2nm_node_ipv4_port_write(struct r2nm_node *node, + const char *page, size_t count) +{ + unsigned long tmp; + char *p = (char *)page; + int err; + + err = kstrtoul(p, 10, &tmp); + if (err) + return err; + + if (tmp == 0) + return -EINVAL; + if (tmp >= (u16)-1) + return -ERANGE; + + node->nd_ipv4_port = htons(tmp); + + return count; +} + +static ssize_t r2nm_node_ipv4_address_read(struct r2nm_node *node, char *page) +{ + return sprintf(page, "%pI4\n", &node->nd_ipv4_address); +} + +static ssize_t r2nm_node_ipv4_address_write(struct r2nm_node *node, + const char *page, + size_t count) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster_from_node(node); + int ret, i; + struct rb_node **p, *parent; + unsigned int octets[4]; + __be32 ipv4_addr = 0; + + ret = sscanf(page, "%3u.%3u.%3u.%3u", &octets[3], &octets[2], + &octets[1], &octets[0]); + if (ret != 4) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(octets); i++) { + if (octets[i] > 255) + return -ERANGE; + be32_add_cpu(&ipv4_addr, octets[i] << (i * 8)); + } + + ret = 0; + write_lock(&cluster->cl_nodes_lock); + if (r2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent)) + ret = -EEXIST; + else { + rb_link_node(&node->nd_ip_node, parent, p); + rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree); + } + write_unlock(&cluster->cl_nodes_lock); + if (ret) + return ret; + + memcpy(&node->nd_ipv4_address, &ipv4_addr, sizeof(ipv4_addr)); + + return count; +} + +static ssize_t r2nm_node_local_read(struct r2nm_node *node, char *page) +{ + return sprintf(page, "%d\n", node->nd_local); +} + +static ssize_t r2nm_node_local_write(struct r2nm_node *node, const char *page, + size_t count) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster_from_node(node); + unsigned long tmp; + char *p = (char *)page; + ssize_t ret; + int err; + + err = kstrtoul(p, 10, &tmp); + if (err) + return err; + + tmp = !!tmp; /* boolean of whether this node wants to be local */ + + /* setting local turns on networking rx for now so we require having + * set everything else first */ + if (!test_bit(R2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) || + !test_bit(R2NM_NODE_ATTR_NUM, &node->nd_set_attributes) || + !test_bit(R2NM_NODE_ATTR_PORT, &node->nd_set_attributes)) + return -EINVAL; /* XXX */ + + /* the only failure case is trying to set a new local node + * when a different one is already set */ + if (tmp && tmp == cluster->cl_has_local && + cluster->cl_local_node != node->nd_num) + return -EBUSY; + + /* bring up the rx thread if we're setting the new local node. */ + if (tmp && !cluster->cl_has_local) { + ret = r2net_start_listening(node); + if (ret) + return ret; + } + + if (!tmp && cluster->cl_has_local && + cluster->cl_local_node == node->nd_num) { + r2net_stop_listening(node); + cluster->cl_local_node = R2NM_INVALID_NODE_NUM; + } + + node->nd_local = tmp; + if (node->nd_local) { + cluster->cl_has_local = tmp; + cluster->cl_local_node = node->nd_num; + } + + return count; +} + +struct r2nm_node_attribute { + struct configfs_attribute attr; + ssize_t (*show)(struct r2nm_node *, char *); + ssize_t (*store)(struct r2nm_node *, const char *, size_t); +}; + +static struct r2nm_node_attribute r2nm_node_attr_num = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "num", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_node_num_read, + .store = r2nm_node_num_write, +}; + +static struct r2nm_node_attribute r2nm_node_attr_ipv4_port = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "ipv4_port", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_node_ipv4_port_read, + .store = r2nm_node_ipv4_port_write, +}; + +static struct r2nm_node_attribute r2nm_node_attr_ipv4_address = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "ipv4_address", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_node_ipv4_address_read, + .store = r2nm_node_ipv4_address_write, +}; + +static struct r2nm_node_attribute r2nm_node_attr_local = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "local", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_node_local_read, + .store = r2nm_node_local_write, +}; + +static struct configfs_attribute *r2nm_node_attrs[] = { + [R2NM_NODE_ATTR_NUM] = &r2nm_node_attr_num.attr, + [R2NM_NODE_ATTR_PORT] = &r2nm_node_attr_ipv4_port.attr, + [R2NM_NODE_ATTR_ADDRESS] = &r2nm_node_attr_ipv4_address.attr, + [R2NM_NODE_ATTR_LOCAL] = &r2nm_node_attr_local.attr, + NULL, +}; + +static int r2nm_attr_index(struct configfs_attribute *attr) +{ + int i; + for (i = 0; i < ARRAY_SIZE(r2nm_node_attrs); i++) { + if (attr == r2nm_node_attrs[i]) + return i; + } + BUG(); + return 0; +} + +static ssize_t r2nm_node_show(struct config_item *item, + struct configfs_attribute *attr, + char *page) +{ + struct r2nm_node *node = to_r2nm_node(item); + struct r2nm_node_attribute *r2nm_node_attr = + container_of(attr, struct r2nm_node_attribute, attr); + ssize_t ret = 0; + + if (r2nm_node_attr->show) + ret = r2nm_node_attr->show(node, page); + return ret; +} + +static ssize_t r2nm_node_store(struct config_item *item, + struct configfs_attribute *attr, + const char *page, size_t count) +{ + struct r2nm_node *node = to_r2nm_node(item); + struct r2nm_node_attribute *r2nm_node_attr = + container_of(attr, struct r2nm_node_attribute, attr); + ssize_t ret; + int attr_index = r2nm_attr_index(attr); + + if (r2nm_node_attr->store == NULL) { + ret = -EINVAL; + goto out; + } + + if (test_bit(attr_index, &node->nd_set_attributes)) + return -EBUSY; + + ret = r2nm_node_attr->store(node, page, count); + if (ret < count) + goto out; + + set_bit(attr_index, &node->nd_set_attributes); +out: + return ret; +} + +static struct configfs_item_operations r2nm_node_item_ops = { + .release = r2nm_node_release, + .show_attribute = r2nm_node_show, + .store_attribute = r2nm_node_store, +}; + +static struct config_item_type r2nm_node_type = { + .ct_item_ops = &r2nm_node_item_ops, + .ct_attrs = r2nm_node_attrs, + .ct_owner = THIS_MODULE, +}; + +/* node set */ + +struct r2nm_node_group { + struct config_group ns_group; + /* some stuff? */ +}; + +#if 0 +static struct r2nm_node_group *to_r2nm_node_group(struct config_group *group) +{ + return group ? + container_of(group, struct r2nm_node_group, ns_group) + : NULL; +} +#endif + +struct r2nm_cluster_attribute { + struct configfs_attribute attr; + ssize_t (*show)(struct r2nm_cluster *, char *); + ssize_t (*store)(struct r2nm_cluster *, const char *, size_t); +}; + +static ssize_t r2nm_cluster_attr_write(const char *page, ssize_t count, + unsigned int *val) +{ + unsigned long tmp; + char *p = (char *)page; + int err; + + err = kstrtoul(p, 10, &tmp); + if (err) + return err; + + if (tmp == 0) + return -EINVAL; + if (tmp >= (u32)-1) + return -ERANGE; + + *val = tmp; + + return count; +} + +static ssize_t r2nm_cluster_attr_idle_timeout_ms_read( + struct r2nm_cluster *cluster, char *page) +{ + return sprintf(page, "%u\n", cluster->cl_idle_timeout_ms); +} + +static ssize_t r2nm_cluster_attr_idle_timeout_ms_write( + struct r2nm_cluster *cluster, const char *page, size_t count) +{ + ssize_t ret; + unsigned int val = 0; + + ret = r2nm_cluster_attr_write(page, count, &val); + + if (ret > 0) { + if (cluster->cl_idle_timeout_ms != val + && r2net_num_connected_peers()) { + mlog(ML_NOTICE, + "r2net: cannot change idle timeout after " + "the first peer has agreed to it." + " %d connected peers\n", + r2net_num_connected_peers()); + ret = -EINVAL; + } else if (val <= cluster->cl_keepalive_delay_ms) { + mlog(ML_NOTICE, + "r2net: idle timeout must be larger " + "than keepalive delay\n"); + ret = -EINVAL; + } else { + cluster->cl_idle_timeout_ms = val; + } + } + + return ret; +} + +static ssize_t r2nm_cluster_attr_keepalive_delay_ms_read( + struct r2nm_cluster *cluster, char *page) +{ + return sprintf(page, "%u\n", cluster->cl_keepalive_delay_ms); +} + +static ssize_t r2nm_cluster_attr_keepalive_delay_ms_write( + struct r2nm_cluster *cluster, const char *page, size_t count) +{ + ssize_t ret; + unsigned int val = 0; + + ret = r2nm_cluster_attr_write(page, count, &val); + + if (ret > 0) { + if (cluster->cl_keepalive_delay_ms != val + && r2net_num_connected_peers()) { + mlog(ML_NOTICE, + "r2net: cannot change keepalive delay after" + " the first peer has agreed to it." + " %d connected peers\n", + r2net_num_connected_peers()); + ret = -EINVAL; + } else if (val >= cluster->cl_idle_timeout_ms) { + mlog(ML_NOTICE, + "r2net: keepalive delay must be " + "smaller than idle timeout\n"); + ret = -EINVAL; + } else { + cluster->cl_keepalive_delay_ms = val; + } + } + + return ret; +} + +static ssize_t r2nm_cluster_attr_reconnect_delay_ms_read( + struct r2nm_cluster *cluster, char *page) +{ + return sprintf(page, "%u\n", cluster->cl_reconnect_delay_ms); +} + +static ssize_t r2nm_cluster_attr_reconnect_delay_ms_write( + struct r2nm_cluster *cluster, const char *page, size_t count) +{ + return r2nm_cluster_attr_write(page, count, + &cluster->cl_reconnect_delay_ms); +} + +static ssize_t r2nm_cluster_attr_fence_method_read( + struct r2nm_cluster *cluster, char *page) +{ + ssize_t ret = 0; + + if (cluster) + ret = sprintf(page, "%s\n", + r2nm_fence_method_desc[cluster->cl_fence_method]); + return ret; +} + +static ssize_t r2nm_cluster_attr_fence_method_write( + struct r2nm_cluster *cluster, const char *page, size_t count) +{ + unsigned int i; + + if (page[count - 1] != '\n') + goto bail; + + for (i = 0; i < R2NM_FENCE_METHODS; ++i) { + if (count != strlen(r2nm_fence_method_desc[i]) + 1) + continue; + if (strncasecmp(page, r2nm_fence_method_desc[i], count - 1)) + continue; + if (cluster->cl_fence_method != i) { + pr_info("ramster: Changing fence method to %s\n", + r2nm_fence_method_desc[i]); + cluster->cl_fence_method = i; + } + return count; + } + +bail: + return -EINVAL; +} + +static struct r2nm_cluster_attribute r2nm_cluster_attr_idle_timeout_ms = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "idle_timeout_ms", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_cluster_attr_idle_timeout_ms_read, + .store = r2nm_cluster_attr_idle_timeout_ms_write, +}; + +static struct r2nm_cluster_attribute r2nm_cluster_attr_keepalive_delay_ms = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "keepalive_delay_ms", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_cluster_attr_keepalive_delay_ms_read, + .store = r2nm_cluster_attr_keepalive_delay_ms_write, +}; + +static struct r2nm_cluster_attribute r2nm_cluster_attr_reconnect_delay_ms = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "reconnect_delay_ms", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_cluster_attr_reconnect_delay_ms_read, + .store = r2nm_cluster_attr_reconnect_delay_ms_write, +}; + +static struct r2nm_cluster_attribute r2nm_cluster_attr_fence_method = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "fence_method", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = r2nm_cluster_attr_fence_method_read, + .store = r2nm_cluster_attr_fence_method_write, +}; + +static struct configfs_attribute *r2nm_cluster_attrs[] = { + &r2nm_cluster_attr_idle_timeout_ms.attr, + &r2nm_cluster_attr_keepalive_delay_ms.attr, + &r2nm_cluster_attr_reconnect_delay_ms.attr, + &r2nm_cluster_attr_fence_method.attr, + NULL, +}; +static ssize_t r2nm_cluster_show(struct config_item *item, + struct configfs_attribute *attr, + char *page) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster(item); + struct r2nm_cluster_attribute *r2nm_cluster_attr = + container_of(attr, struct r2nm_cluster_attribute, attr); + ssize_t ret = 0; + + if (r2nm_cluster_attr->show) + ret = r2nm_cluster_attr->show(cluster, page); + return ret; +} + +static ssize_t r2nm_cluster_store(struct config_item *item, + struct configfs_attribute *attr, + const char *page, size_t count) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster(item); + struct r2nm_cluster_attribute *r2nm_cluster_attr = + container_of(attr, struct r2nm_cluster_attribute, attr); + ssize_t ret; + + if (r2nm_cluster_attr->store == NULL) { + ret = -EINVAL; + goto out; + } + + ret = r2nm_cluster_attr->store(cluster, page, count); + if (ret < count) + goto out; +out: + return ret; +} + +static struct config_item *r2nm_node_group_make_item(struct config_group *group, + const char *name) +{ + struct r2nm_node *node = NULL; + + if (strlen(name) > R2NM_MAX_NAME_LEN) + return ERR_PTR(-ENAMETOOLONG); + + node = kzalloc(sizeof(struct r2nm_node), GFP_KERNEL); + if (node == NULL) + return ERR_PTR(-ENOMEM); + + strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */ + config_item_init_type_name(&node->nd_item, name, &r2nm_node_type); + spin_lock_init(&node->nd_lock); + + mlog(ML_CLUSTER, "r2nm: Registering node %s\n", name); + + return &node->nd_item; +} + +static void r2nm_node_group_drop_item(struct config_group *group, + struct config_item *item) +{ + struct r2nm_node *node = to_r2nm_node(item); + struct r2nm_cluster *cluster = + to_r2nm_cluster(group->cg_item.ci_parent); + + r2net_disconnect_node(node); + + if (cluster->cl_has_local && + (cluster->cl_local_node == node->nd_num)) { + cluster->cl_has_local = 0; + cluster->cl_local_node = R2NM_INVALID_NODE_NUM; + r2net_stop_listening(node); + } + + /* XXX call into net to stop this node from trading messages */ + + write_lock(&cluster->cl_nodes_lock); + + /* XXX sloppy */ + if (node->nd_ipv4_address) + rb_erase(&node->nd_ip_node, &cluster->cl_node_ip_tree); + + /* nd_num might be 0 if the node number hasn't been set.. */ + if (cluster->cl_nodes[node->nd_num] == node) { + cluster->cl_nodes[node->nd_num] = NULL; + clear_bit(node->nd_num, cluster->cl_nodes_bitmap); + } + write_unlock(&cluster->cl_nodes_lock); + + mlog(ML_CLUSTER, "r2nm: Unregistered node %s\n", + config_item_name(&node->nd_item)); + + config_item_put(item); +} + +static struct configfs_group_operations r2nm_node_group_group_ops = { + .make_item = r2nm_node_group_make_item, + .drop_item = r2nm_node_group_drop_item, +}; + +static struct config_item_type r2nm_node_group_type = { + .ct_group_ops = &r2nm_node_group_group_ops, + .ct_owner = THIS_MODULE, +}; + +/* cluster */ + +static void r2nm_cluster_release(struct config_item *item) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster(item); + + kfree(cluster->cl_group.default_groups); + kfree(cluster); +} + +static struct configfs_item_operations r2nm_cluster_item_ops = { + .release = r2nm_cluster_release, + .show_attribute = r2nm_cluster_show, + .store_attribute = r2nm_cluster_store, +}; + +static struct config_item_type r2nm_cluster_type = { + .ct_item_ops = &r2nm_cluster_item_ops, + .ct_attrs = r2nm_cluster_attrs, + .ct_owner = THIS_MODULE, +}; + +/* cluster set */ + +struct r2nm_cluster_group { + struct configfs_subsystem cs_subsys; + /* some stuff? */ +}; + +#if 0 +static struct r2nm_cluster_group * +to_r2nm_cluster_group(struct config_group *group) +{ + return group ? + container_of(to_configfs_subsystem(group), + struct r2nm_cluster_group, cs_subsys) + : NULL; +} +#endif + +static struct config_group * +r2nm_cluster_group_make_group(struct config_group *group, + const char *name) +{ + struct r2nm_cluster *cluster = NULL; + struct r2nm_node_group *ns = NULL; + struct config_group *r2hb_group = NULL, *ret = NULL; + void *defs = NULL; + + /* this runs under the parent dir's i_mutex; there can be only + * one caller in here at a time */ + if (r2nm_single_cluster) + return ERR_PTR(-ENOSPC); + + cluster = kzalloc(sizeof(struct r2nm_cluster), GFP_KERNEL); + ns = kzalloc(sizeof(struct r2nm_node_group), GFP_KERNEL); + defs = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL); + r2hb_group = r2hb_alloc_hb_set(); + if (cluster == NULL || ns == NULL || r2hb_group == NULL || defs == NULL) + goto out; + + config_group_init_type_name(&cluster->cl_group, name, + &r2nm_cluster_type); + config_group_init_type_name(&ns->ns_group, "node", + &r2nm_node_group_type); + + cluster->cl_group.default_groups = defs; + cluster->cl_group.default_groups[0] = &ns->ns_group; + cluster->cl_group.default_groups[1] = r2hb_group; + cluster->cl_group.default_groups[2] = NULL; + rwlock_init(&cluster->cl_nodes_lock); + cluster->cl_node_ip_tree = RB_ROOT; + cluster->cl_reconnect_delay_ms = R2NET_RECONNECT_DELAY_MS_DEFAULT; + cluster->cl_idle_timeout_ms = R2NET_IDLE_TIMEOUT_MS_DEFAULT; + cluster->cl_keepalive_delay_ms = R2NET_KEEPALIVE_DELAY_MS_DEFAULT; + cluster->cl_fence_method = R2NM_FENCE_RESET; + + ret = &cluster->cl_group; + r2nm_single_cluster = cluster; + +out: + if (ret == NULL) { + kfree(cluster); + kfree(ns); + r2hb_free_hb_set(r2hb_group); + kfree(defs); + ret = ERR_PTR(-ENOMEM); + } + + return ret; +} + +static void r2nm_cluster_group_drop_item(struct config_group *group, + struct config_item *item) +{ + struct r2nm_cluster *cluster = to_r2nm_cluster(item); + int i; + struct config_item *killme; + + BUG_ON(r2nm_single_cluster != cluster); + r2nm_single_cluster = NULL; + + for (i = 0; cluster->cl_group.default_groups[i]; i++) { + killme = &cluster->cl_group.default_groups[i]->cg_item; + cluster->cl_group.default_groups[i] = NULL; + config_item_put(killme); + } + + config_item_put(item); +} + +static struct configfs_group_operations r2nm_cluster_group_group_ops = { + .make_group = r2nm_cluster_group_make_group, + .drop_item = r2nm_cluster_group_drop_item, +}; + +static struct config_item_type r2nm_cluster_group_type = { + .ct_group_ops = &r2nm_cluster_group_group_ops, + .ct_owner = THIS_MODULE, +}; + +static struct r2nm_cluster_group r2nm_cluster_group = { + .cs_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf = "cluster", + .ci_type = &r2nm_cluster_group_type, + }, + }, + }, +}; + +int r2nm_depend_item(struct config_item *item) +{ + return configfs_depend_item(&r2nm_cluster_group.cs_subsys, item); +} + +void r2nm_undepend_item(struct config_item *item) +{ + configfs_undepend_item(&r2nm_cluster_group.cs_subsys, item); +} + +int r2nm_depend_this_node(void) +{ + int ret = 0; + struct r2nm_node *local_node; + + local_node = r2nm_get_node_by_num(r2nm_this_node()); + if (!local_node) { + ret = -EINVAL; + goto out; + } + + ret = r2nm_depend_item(&local_node->nd_item); + r2nm_node_put(local_node); + +out: + return ret; +} + +void r2nm_undepend_this_node(void) +{ + struct r2nm_node *local_node; + + local_node = r2nm_get_node_by_num(r2nm_this_node()); + BUG_ON(!local_node); + + r2nm_undepend_item(&local_node->nd_item); + r2nm_node_put(local_node); +} + + +static void __exit exit_r2nm(void) +{ + /* XXX sync with hb callbacks and shut down hb? */ + r2net_unregister_hb_callbacks(); + configfs_unregister_subsystem(&r2nm_cluster_group.cs_subsys); + + r2net_exit(); + r2hb_exit(); +} + +static int __init init_r2nm(void) +{ + int ret = -1; + + ret = r2hb_init(); + if (ret) + goto out; + + ret = r2net_init(); + if (ret) + goto out_r2hb; + + ret = r2net_register_hb_callbacks(); + if (ret) + goto out_r2net; + + config_group_init(&r2nm_cluster_group.cs_subsys.su_group); + mutex_init(&r2nm_cluster_group.cs_subsys.su_mutex); + ret = configfs_register_subsystem(&r2nm_cluster_group.cs_subsys); + if (ret) { + pr_err("nodemanager: Registration returned %d\n", ret); + goto out_callbacks; + } + + if (!ret) + goto out; + + configfs_unregister_subsystem(&r2nm_cluster_group.cs_subsys); +out_callbacks: + r2net_unregister_hb_callbacks(); +out_r2net: + r2net_exit(); +out_r2hb: + r2hb_exit(); +out: + return ret; +} + +MODULE_AUTHOR("Oracle"); +MODULE_LICENSE("GPL"); + +/* module_init(init_r2nm) */ +late_initcall(init_r2nm); +/* module_exit(exit_r2nm) */ diff --git a/drivers/staging/zcache/ramster/nodemanager.h b/drivers/staging/zcache/ramster/nodemanager.h new file mode 100644 index 0000000..41a04df --- /dev/null +++ b/drivers/staging/zcache/ramster/nodemanager.h @@ -0,0 +1,88 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * nodemanager.h + * + * Function prototypes + * + * Copyright (C) 2004 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + */ + +#ifndef R2CLUSTER_NODEMANAGER_H +#define R2CLUSTER_NODEMANAGER_H + +#include "ramster_nodemanager.h" + +/* This totally doesn't belong here. */ +#include +#include + +enum r2nm_fence_method { + R2NM_FENCE_RESET = 0, + R2NM_FENCE_PANIC, + R2NM_FENCE_METHODS, /* Number of fence methods */ +}; + +struct r2nm_node { + spinlock_t nd_lock; + struct config_item nd_item; + char nd_name[R2NM_MAX_NAME_LEN+1]; /* replace? */ + __u8 nd_num; + /* only one address per node, as attributes, for now. */ + __be32 nd_ipv4_address; + __be16 nd_ipv4_port; + struct rb_node nd_ip_node; + /* there can be only one local node for now */ + int nd_local; + + unsigned long nd_set_attributes; +}; + +struct r2nm_cluster { + struct config_group cl_group; + unsigned cl_has_local:1; + u8 cl_local_node; + rwlock_t cl_nodes_lock; + struct r2nm_node *cl_nodes[R2NM_MAX_NODES]; + struct rb_root cl_node_ip_tree; + unsigned int cl_idle_timeout_ms; + unsigned int cl_keepalive_delay_ms; + unsigned int cl_reconnect_delay_ms; + enum r2nm_fence_method cl_fence_method; + + /* part of a hack for disk bitmap.. will go eventually. - zab */ + unsigned long cl_nodes_bitmap[BITS_TO_LONGS(R2NM_MAX_NODES)]; +}; + +extern struct r2nm_cluster *r2nm_single_cluster; + +u8 r2nm_this_node(void); + +int r2nm_configured_node_map(unsigned long *map, unsigned bytes); +struct r2nm_node *r2nm_get_node_by_num(u8 node_num); +struct r2nm_node *r2nm_get_node_by_ip(__be32 addr); +void r2nm_node_get(struct r2nm_node *node); +void r2nm_node_put(struct r2nm_node *node); + +int r2nm_depend_item(struct config_item *item); +void r2nm_undepend_item(struct config_item *item); +int r2nm_depend_this_node(void); +void r2nm_undepend_this_node(void); + +#endif /* R2CLUSTER_NODEMANAGER_H */ diff --git a/drivers/staging/zcache/ramster/r2net.c b/drivers/staging/zcache/ramster/r2net.c new file mode 100644 index 0000000..34818dc --- /dev/null +++ b/drivers/staging/zcache/ramster/r2net.c @@ -0,0 +1,414 @@ +/* + * r2net.c + * + * Copyright (c) 2011-2012, Dan Magenheimer, Oracle Corp. + * + * Ramster_r2net provides an interface between zcache and r2net. + * + * FIXME: support more than two nodes + */ + +#include +#include "tcp.h" +#include "nodemanager.h" +#include "../tmem.h" +#include "../zcache.h" +#include "ramster.h" + +#define RAMSTER_TESTING + +#define RMSTR_KEY 0x77347734 + +enum { + RMSTR_TMEM_PUT_EPH = 100, + RMSTR_TMEM_PUT_PERS, + RMSTR_TMEM_ASYNC_GET_REQUEST, + RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST, + RMSTR_TMEM_ASYNC_GET_REPLY, + RMSTR_TMEM_FLUSH, + RMSTR_TMEM_FLOBJ, + RMSTR_TMEM_DESTROY_POOL, +}; + +#define RMSTR_R2NET_MAX_LEN \ + (R2NET_MAX_PAYLOAD_BYTES - sizeof(struct tmem_xhandle)) + +#include "tcp_internal.h" + +static struct r2nm_node *r2net_target_node; +static int r2net_target_nodenum; + +int r2net_remote_target_node_set(int node_num) +{ + int ret = -1; + + r2net_target_node = r2nm_get_node_by_num(node_num); + if (r2net_target_node != NULL) { + r2net_target_nodenum = node_num; + r2nm_node_put(r2net_target_node); + ret = 0; + } + return ret; +} + +/* FIXME following buffer should be per-cpu, protected by preempt_disable */ +static char ramster_async_get_buf[R2NET_MAX_PAYLOAD_BYTES]; + +static int ramster_remote_async_get_request_handler(struct r2net_msg *msg, + u32 len, void *data, void **ret_data) +{ + char *pdata; + struct tmem_xhandle xh; + int found; + size_t size = RMSTR_R2NET_MAX_LEN; + u16 msgtype = be16_to_cpu(msg->msg_type); + bool get_and_free = (msgtype == RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST); + unsigned long flags; + + xh = *(struct tmem_xhandle *)msg->buf; + if (xh.xh_data_size > RMSTR_R2NET_MAX_LEN) + BUG(); + pdata = ramster_async_get_buf; + *(struct tmem_xhandle *)pdata = xh; + pdata += sizeof(struct tmem_xhandle); + local_irq_save(flags); + found = zcache_get_page(xh.client_id, xh.pool_id, &xh.oid, xh.index, + pdata, &size, true, get_and_free ? 1 : -1); + local_irq_restore(flags); + if (found < 0) { + /* a zero size indicates the get failed */ + size = 0; + } + if (size > RMSTR_R2NET_MAX_LEN) + BUG(); + *ret_data = pdata - sizeof(struct tmem_xhandle); + /* now make caller (r2net_process_message) handle specially */ + r2net_force_data_magic(msg, RMSTR_TMEM_ASYNC_GET_REPLY, RMSTR_KEY); + return size + sizeof(struct tmem_xhandle); +} + +static int ramster_remote_async_get_reply_handler(struct r2net_msg *msg, + u32 len, void *data, void **ret_data) +{ + char *in = (char *)msg->buf; + int datalen = len - sizeof(struct r2net_msg); + int ret = -1; + struct tmem_xhandle *xh = (struct tmem_xhandle *)in; + + in += sizeof(struct tmem_xhandle); + datalen -= sizeof(struct tmem_xhandle); + BUG_ON(datalen < 0 || datalen > PAGE_SIZE); + ret = ramster_localify(xh->pool_id, &xh->oid, xh->index, + in, datalen, xh->extra); +#ifdef RAMSTER_TESTING + if (ret == -EEXIST) + pr_err("TESTING ArrgREP, aborted overwrite on racy put\n"); +#endif + return ret; +} + +int ramster_remote_put_handler(struct r2net_msg *msg, + u32 len, void *data, void **ret_data) +{ + struct tmem_xhandle *xh; + char *p = (char *)msg->buf; + int datalen = len - sizeof(struct r2net_msg) - + sizeof(struct tmem_xhandle); + u16 msgtype = be16_to_cpu(msg->msg_type); + bool ephemeral = (msgtype == RMSTR_TMEM_PUT_EPH); + unsigned long flags; + int ret; + + xh = (struct tmem_xhandle *)p; + p += sizeof(struct tmem_xhandle); + zcache_autocreate_pool(xh->client_id, xh->pool_id, ephemeral); + local_irq_save(flags); + ret = zcache_put_page(xh->client_id, xh->pool_id, &xh->oid, xh->index, + p, datalen, true, ephemeral); + local_irq_restore(flags); + return ret; +} + +int ramster_remote_flush_handler(struct r2net_msg *msg, + u32 len, void *data, void **ret_data) +{ + struct tmem_xhandle *xh; + char *p = (char *)msg->buf; + + xh = (struct tmem_xhandle *)p; + p += sizeof(struct tmem_xhandle); + (void)zcache_flush_page(xh->client_id, xh->pool_id, + &xh->oid, xh->index); + return 0; +} + +int ramster_remote_flobj_handler(struct r2net_msg *msg, + u32 len, void *data, void **ret_data) +{ + struct tmem_xhandle *xh; + char *p = (char *)msg->buf; + + xh = (struct tmem_xhandle *)p; + p += sizeof(struct tmem_xhandle); + (void)zcache_flush_object(xh->client_id, xh->pool_id, &xh->oid); + return 0; +} + +int r2net_remote_async_get(struct tmem_xhandle *xh, bool free, int remotenode, + size_t expect_size, uint8_t expect_cksum, + void *extra) +{ + int nodenum, ret = -1, status; + struct r2nm_node *node = NULL; + struct kvec vec[1]; + size_t veclen = 1; + u32 msg_type; + struct r2net_node *nn; + + node = r2nm_get_node_by_num(remotenode); + if (node == NULL) + goto out; + xh->client_id = r2nm_this_node(); /* which node is getting */ + xh->xh_data_cksum = expect_cksum; + xh->xh_data_size = expect_size; + xh->extra = extra; + vec[0].iov_len = sizeof(*xh); + vec[0].iov_base = xh; + + node = r2net_target_node; + if (!node) + goto out; + + nodenum = r2net_target_nodenum; + + r2nm_node_get(node); + nn = r2net_nn_from_num(nodenum); + if (nn->nn_persistent_error || !nn->nn_sc_valid) { + ret = -ENOTCONN; + r2nm_node_put(node); + goto out; + } + + if (free) + msg_type = RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST; + else + msg_type = RMSTR_TMEM_ASYNC_GET_REQUEST; + ret = r2net_send_message_vec(msg_type, RMSTR_KEY, + vec, veclen, remotenode, &status); + r2nm_node_put(node); + if (ret < 0) { + if (ret == -ENOTCONN || ret == -EHOSTDOWN) + goto out; + if (ret == -EAGAIN) + goto out; + /* FIXME handle bad message possibilities here? */ + pr_err("UNTESTED ret<0 in ramster_remote_async_get: ret=%d\n", + ret); + } + ret = status; +out: + return ret; +} + +#ifdef RAMSTER_TESTING +/* leave me here to see if it catches a weird crash */ +static void ramster_check_irq_counts(void) +{ + static int last_hardirq_cnt, last_softirq_cnt, last_preempt_cnt; + int cur_hardirq_cnt, cur_softirq_cnt, cur_preempt_cnt; + + cur_hardirq_cnt = hardirq_count() >> HARDIRQ_SHIFT; + if (cur_hardirq_cnt > last_hardirq_cnt) { + last_hardirq_cnt = cur_hardirq_cnt; + if (!(last_hardirq_cnt&(last_hardirq_cnt-1))) + pr_err("RAMSTER TESTING RRP hardirq_count=%d\n", + last_hardirq_cnt); + } + cur_softirq_cnt = softirq_count() >> SOFTIRQ_SHIFT; + if (cur_softirq_cnt > last_softirq_cnt) { + last_softirq_cnt = cur_softirq_cnt; + if (!(last_softirq_cnt&(last_softirq_cnt-1))) + pr_err("RAMSTER TESTING RRP softirq_count=%d\n", + last_softirq_cnt); + } + cur_preempt_cnt = preempt_count() & PREEMPT_MASK; + if (cur_preempt_cnt > last_preempt_cnt) { + last_preempt_cnt = cur_preempt_cnt; + if (!(last_preempt_cnt&(last_preempt_cnt-1))) + pr_err("RAMSTER TESTING RRP preempt_count=%d\n", + last_preempt_cnt); + } +} +#endif + +int r2net_remote_put(struct tmem_xhandle *xh, char *data, size_t size, + bool ephemeral, int *remotenode) +{ + int nodenum, ret = -1, status; + struct r2nm_node *node = NULL; + struct kvec vec[2]; + size_t veclen = 2; + u32 msg_type; + struct r2net_node *nn; + + BUG_ON(size > RMSTR_R2NET_MAX_LEN); + xh->client_id = r2nm_this_node(); /* which node is putting */ + vec[0].iov_len = sizeof(*xh); + vec[0].iov_base = xh; + vec[1].iov_len = size; + vec[1].iov_base = data; + + node = r2net_target_node; + if (!node) + goto out; + + nodenum = r2net_target_nodenum; + + r2nm_node_get(node); + + nn = r2net_nn_from_num(nodenum); + if (nn->nn_persistent_error || !nn->nn_sc_valid) { + ret = -ENOTCONN; + r2nm_node_put(node); + goto out; + } + + if (ephemeral) + msg_type = RMSTR_TMEM_PUT_EPH; + else + msg_type = RMSTR_TMEM_PUT_PERS; +#ifdef RAMSTER_TESTING + /* leave me here to see if it catches a weird crash */ + ramster_check_irq_counts(); +#endif + + ret = r2net_send_message_vec(msg_type, RMSTR_KEY, vec, veclen, + nodenum, &status); + if (ret < 0) + ret = -1; + else { + ret = status; + *remotenode = nodenum; + } + + r2nm_node_put(node); +out: + return ret; +} + +int r2net_remote_flush(struct tmem_xhandle *xh, int remotenode) +{ + int ret = -1, status; + struct r2nm_node *node = NULL; + struct kvec vec[1]; + size_t veclen = 1; + + node = r2nm_get_node_by_num(remotenode); + BUG_ON(node == NULL); + xh->client_id = r2nm_this_node(); /* which node is flushing */ + vec[0].iov_len = sizeof(*xh); + vec[0].iov_base = xh; + BUG_ON(irqs_disabled()); + BUG_ON(in_softirq()); + ret = r2net_send_message_vec(RMSTR_TMEM_FLUSH, RMSTR_KEY, + vec, veclen, remotenode, &status); + r2nm_node_put(node); + return ret; +} + +int r2net_remote_flush_object(struct tmem_xhandle *xh, int remotenode) +{ + int ret = -1, status; + struct r2nm_node *node = NULL; + struct kvec vec[1]; + size_t veclen = 1; + + node = r2nm_get_node_by_num(remotenode); + BUG_ON(node == NULL); + xh->client_id = r2nm_this_node(); /* which node is flobjing */ + vec[0].iov_len = sizeof(*xh); + vec[0].iov_base = xh; + ret = r2net_send_message_vec(RMSTR_TMEM_FLOBJ, RMSTR_KEY, + vec, veclen, remotenode, &status); + r2nm_node_put(node); + return ret; +} + +/* + * Handler registration + */ + +static LIST_HEAD(r2net_unreg_list); + +static void r2net_unregister_handlers(void) +{ + r2net_unregister_handler_list(&r2net_unreg_list); +} + +int r2net_register_handlers(void) +{ + int status; + + status = r2net_register_handler(RMSTR_TMEM_PUT_EPH, RMSTR_KEY, + RMSTR_R2NET_MAX_LEN, + ramster_remote_put_handler, + NULL, NULL, &r2net_unreg_list); + if (status) + goto bail; + + status = r2net_register_handler(RMSTR_TMEM_PUT_PERS, RMSTR_KEY, + RMSTR_R2NET_MAX_LEN, + ramster_remote_put_handler, + NULL, NULL, &r2net_unreg_list); + if (status) + goto bail; + + status = r2net_register_handler(RMSTR_TMEM_ASYNC_GET_REQUEST, RMSTR_KEY, + RMSTR_R2NET_MAX_LEN, + ramster_remote_async_get_request_handler, + NULL, NULL, + &r2net_unreg_list); + if (status) + goto bail; + + status = r2net_register_handler(RMSTR_TMEM_ASYNC_GET_AND_FREE_REQUEST, + RMSTR_KEY, RMSTR_R2NET_MAX_LEN, + ramster_remote_async_get_request_handler, + NULL, NULL, + &r2net_unreg_list); + if (status) + goto bail; + + status = r2net_register_handler(RMSTR_TMEM_ASYNC_GET_REPLY, RMSTR_KEY, + RMSTR_R2NET_MAX_LEN, + ramster_remote_async_get_reply_handler, + NULL, NULL, + &r2net_unreg_list); + if (status) + goto bail; + + status = r2net_register_handler(RMSTR_TMEM_FLUSH, RMSTR_KEY, + RMSTR_R2NET_MAX_LEN, + ramster_remote_flush_handler, + NULL, NULL, + &r2net_unreg_list); + if (status) + goto bail; + + status = r2net_register_handler(RMSTR_TMEM_FLOBJ, RMSTR_KEY, + RMSTR_R2NET_MAX_LEN, + ramster_remote_flobj_handler, + NULL, NULL, + &r2net_unreg_list); + if (status) + goto bail; + + pr_info("ramster: r2net handlers registered\n"); + +bail: + if (status) { + r2net_unregister_handlers(); + pr_err("ramster: couldn't register r2net handlers\n"); + } + return status; +} diff --git a/drivers/staging/zcache/ramster/ramster.c b/drivers/staging/zcache/ramster/ramster.c new file mode 100644 index 0000000..c06709f --- /dev/null +++ b/drivers/staging/zcache/ramster/ramster.c @@ -0,0 +1,985 @@ +/* + * ramster.c + * + * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. + * + * RAMster implements peer-to-peer transcendent memory, allowing a "cluster" of + * kernels to dynamically pool their RAM so that a RAM-hungry workload on one + * machine can temporarily and transparently utilize RAM on another machine + * which is presumably idle or running a non-RAM-hungry workload. + * + * RAMster combines a clustering and messaging foundation based on the ocfs2 + * cluster layer with the in-kernel compression implementation of zcache, and + * adds code to glue them together. When a page is "put" to RAMster, it is + * compressed and stored locally. Periodically, a thread will "remotify" these + * pages by sending them via messages to a remote machine. When the page is + * later needed as indicated by a page fault, a "get" is issued. If the data + * is local, it is uncompressed and the fault is resolved. If the data is + * remote, a message is sent to fetch the data and the faulting thread sleeps; + * when the data arrives, the thread awakens, the data is decompressed and + * the fault is resolved. + + * As of V5, clusters up to eight nodes are supported; each node can remotify + * pages to one specified node, so clusters can be configured as clients to + * a "memory server". Some simple policy is in place that will need to be + * refined over time. Larger clusters and fault-resistant protocols can also + * be added over time. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../tmem.h" +#include "../zcache.h" +#include "../zbud.h" +#include "ramster.h" +#include "ramster_nodemanager.h" +#include "tcp.h" + +#define RAMSTER_TESTING + +#ifndef CONFIG_SYSFS +#error "ramster needs sysfs to define cluster nodes to use" +#endif + +static bool use_cleancache __read_mostly; +static bool use_frontswap __read_mostly; +static bool use_frontswap_exclusive_gets __read_mostly; + +/* These must be sysfs not debugfs as they are checked/used by userland!! */ +static unsigned long ramster_interface_revision __read_mostly = + R2NM_API_VERSION; /* interface revision must match userspace! */ +static unsigned long ramster_pers_remotify_enable __read_mostly; +static unsigned long ramster_eph_remotify_enable __read_mostly; +static atomic_t ramster_remote_pers_pages = ATOMIC_INIT(0); +#define MANUAL_NODES 8 +static bool ramster_nodes_manual_up[MANUAL_NODES] __read_mostly; +static int ramster_remote_target_nodenum __read_mostly = -1; + +/* these counters are made available via debugfs */ +static long ramster_flnodes; +static atomic_t ramster_flnodes_atomic = ATOMIC_INIT(0); +static unsigned long ramster_flnodes_max; +static long ramster_foreign_eph_pages; +static atomic_t ramster_foreign_eph_pages_atomic = ATOMIC_INIT(0); +static unsigned long ramster_foreign_eph_pages_max; +static long ramster_foreign_pers_pages; +static atomic_t ramster_foreign_pers_pages_atomic = ATOMIC_INIT(0); +static unsigned long ramster_foreign_pers_pages_max; +static unsigned long ramster_eph_pages_remoted; +static unsigned long ramster_pers_pages_remoted; +static unsigned long ramster_eph_pages_remote_failed; +static unsigned long ramster_pers_pages_remote_failed; +static unsigned long ramster_remote_eph_pages_succ_get; +static unsigned long ramster_remote_pers_pages_succ_get; +static unsigned long ramster_remote_eph_pages_unsucc_get; +static unsigned long ramster_remote_pers_pages_unsucc_get; +static unsigned long ramster_pers_pages_remote_nomem; +static unsigned long ramster_remote_objects_flushed; +static unsigned long ramster_remote_object_flushes_failed; +static unsigned long ramster_remote_pages_flushed; +static unsigned long ramster_remote_page_flushes_failed; +/* FIXME frontswap selfshrinking knobs in debugfs? */ + +#ifdef CONFIG_DEBUG_FS +#include +#define zdfs debugfs_create_size_t +#define zdfs64 debugfs_create_u64 +static int __init ramster_debugfs_init(void) +{ + struct dentry *root = debugfs_create_dir("ramster", NULL); + if (root == NULL) + return -ENXIO; + + zdfs("eph_pages_remoted", S_IRUGO, root, &ramster_eph_pages_remoted); + zdfs("pers_pages_remoted", S_IRUGO, root, &ramster_pers_pages_remoted); + zdfs("eph_pages_remote_failed", S_IRUGO, root, + &ramster_eph_pages_remote_failed); + zdfs("pers_pages_remote_failed", S_IRUGO, root, + &ramster_pers_pages_remote_failed); + zdfs("remote_eph_pages_succ_get", S_IRUGO, root, + &ramster_remote_eph_pages_succ_get); + zdfs("remote_pers_pages_succ_get", S_IRUGO, root, + &ramster_remote_pers_pages_succ_get); + zdfs("remote_eph_pages_unsucc_get", S_IRUGO, root, + &ramster_remote_eph_pages_unsucc_get); + zdfs("remote_pers_pages_unsucc_get", S_IRUGO, root, + &ramster_remote_pers_pages_unsucc_get); + zdfs("pers_pages_remote_nomem", S_IRUGO, root, + &ramster_pers_pages_remote_nomem); + zdfs("remote_objects_flushed", S_IRUGO, root, + &ramster_remote_objects_flushed); + zdfs("remote_pages_flushed", S_IRUGO, root, + &ramster_remote_pages_flushed); + zdfs("remote_object_flushes_failed", S_IRUGO, root, + &ramster_remote_object_flushes_failed); + zdfs("remote_page_flushes_failed", S_IRUGO, root, + &ramster_remote_page_flushes_failed); + zdfs("foreign_eph_pages", S_IRUGO, root, + &ramster_foreign_eph_pages); + zdfs("foreign_eph_pages_max", S_IRUGO, root, + &ramster_foreign_eph_pages_max); + zdfs("foreign_pers_pages", S_IRUGO, root, + &ramster_foreign_pers_pages); + zdfs("foreign_pers_pages_max", S_IRUGO, root, + &ramster_foreign_pers_pages_max); + return 0; +} +#undef zdebugfs +#undef zdfs64 +#endif + +static LIST_HEAD(ramster_rem_op_list); +static DEFINE_SPINLOCK(ramster_rem_op_list_lock); +static DEFINE_PER_CPU(struct ramster_preload, ramster_preloads); + +static DEFINE_PER_CPU(unsigned char *, ramster_remoteputmem1); +static DEFINE_PER_CPU(unsigned char *, ramster_remoteputmem2); + +static struct kmem_cache *ramster_flnode_cache __read_mostly; + +static struct flushlist_node *ramster_flnode_alloc(struct tmem_pool *pool) +{ + struct flushlist_node *flnode = NULL; + struct ramster_preload *kp; + + kp = &__get_cpu_var(ramster_preloads); + flnode = kp->flnode; + BUG_ON(flnode == NULL); + kp->flnode = NULL; + ramster_flnodes = atomic_inc_return(&ramster_flnodes_atomic); + if (ramster_flnodes > ramster_flnodes_max) + ramster_flnodes_max = ramster_flnodes; + return flnode; +} + +/* the "flush list" asynchronously collects pages to remotely flush */ +#define FLUSH_ENTIRE_OBJECT ((uint32_t)-1) +static void ramster_flnode_free(struct flushlist_node *flnode, + struct tmem_pool *pool) +{ + int flnodes; + + flnodes = atomic_dec_return(&ramster_flnodes_atomic); + BUG_ON(flnodes < 0); + kmem_cache_free(ramster_flnode_cache, flnode); +} + +int ramster_do_preload_flnode(struct tmem_pool *pool) +{ + struct ramster_preload *kp; + struct flushlist_node *flnode; + int ret = -ENOMEM; + + BUG_ON(!irqs_disabled()); + if (unlikely(ramster_flnode_cache == NULL)) + BUG(); + kp = &__get_cpu_var(ramster_preloads); + flnode = kmem_cache_alloc(ramster_flnode_cache, GFP_ATOMIC); + if (unlikely(flnode == NULL) && kp->flnode == NULL) + BUG(); /* FIXME handle more gracefully, but how??? */ + else if (kp->flnode == NULL) + kp->flnode = flnode; + else + kmem_cache_free(ramster_flnode_cache, flnode); + return ret; +} + +/* + * Called by the message handler after a (still compressed) page has been + * fetched from the remote machine in response to an "is_remote" tmem_get + * or persistent tmem_localify. For a tmem_get, "extra" is the address of + * the page that is to be filled to successfully resolve the tmem_get; for + * a (persistent) tmem_localify, "extra" is NULL (as the data is placed only + * in the local zcache). "data" points to "size" bytes of (compressed) data + * passed in the message. In the case of a persistent remote get, if + * pre-allocation was successful (see ramster_repatriate_preload), the page + * is placed into both local zcache and at "extra". + */ +int ramster_localify(int pool_id, struct tmem_oid *oidp, uint32_t index, + char *data, unsigned int size, void *extra) +{ + int ret = -ENOENT; + unsigned long flags; + struct tmem_pool *pool; + bool eph, delete = false; + void *pampd, *saved_hb; + struct tmem_obj *obj; + + pool = zcache_get_pool_by_id(LOCAL_CLIENT, pool_id); + if (unlikely(pool == NULL)) + /* pool doesn't exist anymore */ + goto out; + eph = is_ephemeral(pool); + local_irq_save(flags); /* FIXME: maybe only disable softirqs? */ + pampd = tmem_localify_get_pampd(pool, oidp, index, &obj, &saved_hb); + if (pampd == NULL) { + /* hmmm... must have been a flush while waiting */ +#ifdef RAMSTER_TESTING + pr_err("UNTESTED pampd==NULL in ramster_localify\n"); +#endif + if (eph) + ramster_remote_eph_pages_unsucc_get++; + else + ramster_remote_pers_pages_unsucc_get++; + obj = NULL; + goto finish; + } else if (unlikely(!pampd_is_remote(pampd))) { + /* hmmm... must have been a dup put while waiting */ +#ifdef RAMSTER_TESTING + pr_err("UNTESTED dup while waiting in ramster_localify\n"); +#endif + if (eph) + ramster_remote_eph_pages_unsucc_get++; + else + ramster_remote_pers_pages_unsucc_get++; + obj = NULL; + pampd = NULL; + ret = -EEXIST; + goto finish; + } else if (size == 0) { + /* no remote data, delete the local is_remote pampd */ + pampd = NULL; + if (eph) + ramster_remote_eph_pages_unsucc_get++; + else + BUG(); + delete = true; + goto finish; + } + if (pampd_is_intransit(pampd)) { + /* + * a pampd is marked intransit if it is remote and space has + * been allocated for it locally (note, only happens for + * persistent pages, in which case the remote copy is freed) + */ + BUG_ON(eph); + pampd = pampd_mask_intransit_and_remote(pampd); + zbud_copy_to_zbud(pampd, data, size); + } else { + /* + * setting pampd to NULL tells tmem_localify_finish to leave + * pampd alone... meaning it is left pointing to the + * remote copy + */ + pampd = NULL; + obj = NULL; + } + /* + * but in all cases, we decompress direct-to-memory to complete + * the remotify and return success + */ + BUG_ON(extra == NULL); + zcache_decompress_to_page(data, size, (struct page *)extra); + if (eph) + ramster_remote_eph_pages_succ_get++; + else + ramster_remote_pers_pages_succ_get++; + ret = 0; +finish: + tmem_localify_finish(obj, index, pampd, saved_hb, delete); + zcache_put_pool(pool); + local_irq_restore(flags); +out: + return ret; +} + +void ramster_pampd_new_obj(struct tmem_obj *obj) +{ + obj->extra = NULL; +} + +void ramster_pampd_free_obj(struct tmem_pool *pool, struct tmem_obj *obj, + bool pool_destroy) +{ + struct flushlist_node *flnode; + + BUG_ON(preemptible()); + if (obj->extra == NULL) + return; + if (pool_destroy && is_ephemeral(pool)) + /* FIXME don't bother with remote eph data for now */ + return; + BUG_ON(!pampd_is_remote(obj->extra)); + flnode = ramster_flnode_alloc(pool); + flnode->xh.client_id = pampd_remote_node(obj->extra); + flnode->xh.pool_id = pool->pool_id; + flnode->xh.oid = obj->oid; + flnode->xh.index = FLUSH_ENTIRE_OBJECT; + flnode->rem_op.op = RAMSTER_REMOTIFY_FLUSH_OBJ; + spin_lock(&ramster_rem_op_list_lock); + list_add(&flnode->rem_op.list, &ramster_rem_op_list); + spin_unlock(&ramster_rem_op_list_lock); +} + +/* + * Called on a remote persistent tmem_get to attempt to preallocate + * local storage for the data contained in the remote persistent page. + * If successfully preallocated, returns the pampd, marked as remote and + * in_transit. Else returns NULL. Note that the appropriate tmem data + * structure must be locked. + */ +void *ramster_pampd_repatriate_preload(void *pampd, struct tmem_pool *pool, + struct tmem_oid *oidp, uint32_t index, + bool *intransit) +{ + int clen = pampd_remote_size(pampd), c; + void *ret_pampd = NULL; + unsigned long flags; + struct tmem_handle th; + + BUG_ON(!pampd_is_remote(pampd)); + BUG_ON(is_ephemeral(pool)); + if (use_frontswap_exclusive_gets) + /* don't need local storage */ + goto out; + if (pampd_is_intransit(pampd)) { + /* + * to avoid multiple allocations (and maybe a memory leak) + * don't preallocate if already in the process of being + * repatriated + */ + *intransit = true; + goto out; + } + *intransit = false; + local_irq_save(flags); + th.client_id = pampd_remote_node(pampd); + th.pool_id = pool->pool_id; + th.oid = *oidp; + th.index = index; + ret_pampd = zcache_pampd_create(NULL, clen, true, false, &th); + if (ret_pampd != NULL) { + /* + * a pampd is marked intransit if it is remote and space has + * been allocated for it locally (note, only happens for + * persistent pages, in which case the remote copy is freed) + */ + ret_pampd = pampd_mark_intransit(ret_pampd); + c = atomic_dec_return(&ramster_remote_pers_pages); + WARN_ON_ONCE(c < 0); + } else { + ramster_pers_pages_remote_nomem++; + } + local_irq_restore(flags); +out: + return ret_pampd; +} + +/* + * Called on a remote tmem_get to invoke a message to fetch the page. + * Might sleep so no tmem locks can be held. "extra" is passed + * all the way through the round-trip messaging to ramster_localify. + */ +int ramster_pampd_repatriate(void *fake_pampd, void *real_pampd, + struct tmem_pool *pool, + struct tmem_oid *oid, uint32_t index, + bool free, void *extra) +{ + struct tmem_xhandle xh; + int ret; + + if (pampd_is_intransit(real_pampd)) + /* have local space pre-reserved, so free remote copy */ + free = true; + xh = tmem_xhandle_fill(LOCAL_CLIENT, pool, oid, index); + /* unreliable request/response for now */ + ret = r2net_remote_async_get(&xh, free, + pampd_remote_node(fake_pampd), + pampd_remote_size(fake_pampd), + pampd_remote_cksum(fake_pampd), + extra); + return ret; +} + +bool ramster_pampd_is_remote(void *pampd) +{ + return pampd_is_remote(pampd); +} + +int ramster_pampd_replace_in_obj(void *new_pampd, struct tmem_obj *obj) +{ + int ret = -1; + + if (new_pampd != NULL) { + if (obj->extra == NULL) + obj->extra = new_pampd; + /* enforce that all remote pages in an object reside + * in the same node! */ + else if (pampd_remote_node(new_pampd) != + pampd_remote_node((void *)(obj->extra))) + BUG(); + ret = 0; + } + return ret; +} + +void *ramster_pampd_free(void *pampd, struct tmem_pool *pool, + struct tmem_oid *oid, uint32_t index, bool acct) +{ + bool eph = is_ephemeral(pool); + void *local_pampd = NULL; + int c; + + BUG_ON(preemptible()); + BUG_ON(!pampd_is_remote(pampd)); + WARN_ON(acct == false); + if (oid == NULL) { + /* + * a NULL oid means to ignore this pampd free + * as the remote freeing will be handled elsewhere + */ + } else if (eph) { + /* FIXME remote flush optional but probably good idea */ + } else if (pampd_is_intransit(pampd)) { + /* did a pers remote get_and_free, so just free local */ + local_pampd = pampd_mask_intransit_and_remote(pampd); + } else { + struct flushlist_node *flnode = + ramster_flnode_alloc(pool); + + flnode->xh.client_id = pampd_remote_node(pampd); + flnode->xh.pool_id = pool->pool_id; + flnode->xh.oid = *oid; + flnode->xh.index = index; + flnode->rem_op.op = RAMSTER_REMOTIFY_FLUSH_PAGE; + spin_lock(&ramster_rem_op_list_lock); + list_add(&flnode->rem_op.list, &ramster_rem_op_list); + spin_unlock(&ramster_rem_op_list_lock); + c = atomic_dec_return(&ramster_remote_pers_pages); + WARN_ON_ONCE(c < 0); + } + return local_pampd; +} + +void ramster_count_foreign_pages(bool eph, int count) +{ + int c; + + BUG_ON(count != 1 && count != -1); + if (eph) { + if (count > 0) { + c = atomic_inc_return( + &ramster_foreign_eph_pages_atomic); + if (c > ramster_foreign_eph_pages_max) + ramster_foreign_eph_pages_max = c; + } else { + c = atomic_dec_return(&ramster_foreign_eph_pages_atomic); + WARN_ON_ONCE(c < 0); + } + ramster_foreign_eph_pages = c; + } else { + if (count > 0) { + c = atomic_inc_return( + &ramster_foreign_pers_pages_atomic); + if (c > ramster_foreign_pers_pages_max) + ramster_foreign_pers_pages_max = c; + } else { + c = atomic_dec_return( + &ramster_foreign_pers_pages_atomic); + WARN_ON_ONCE(c < 0); + } + ramster_foreign_pers_pages = c; + } +} + +/* + * For now, just push over a few pages every few seconds to + * ensure that it basically works + */ +static struct workqueue_struct *ramster_remotify_workqueue; +static void ramster_remotify_process(struct work_struct *work); +static DECLARE_DELAYED_WORK(ramster_remotify_worker, + ramster_remotify_process); + +static void ramster_remotify_queue_delayed_work(unsigned long delay) +{ + if (!queue_delayed_work(ramster_remotify_workqueue, + &ramster_remotify_worker, delay)) + pr_err("ramster_remotify: bad workqueue\n"); +} + +static void ramster_remote_flush_page(struct flushlist_node *flnode) +{ + struct tmem_xhandle *xh; + int remotenode, ret; + + preempt_disable(); + xh = &flnode->xh; + remotenode = flnode->xh.client_id; + ret = r2net_remote_flush(xh, remotenode); + if (ret >= 0) + ramster_remote_pages_flushed++; + else + ramster_remote_page_flushes_failed++; + preempt_enable_no_resched(); + ramster_flnode_free(flnode, NULL); +} + +static void ramster_remote_flush_object(struct flushlist_node *flnode) +{ + struct tmem_xhandle *xh; + int remotenode, ret; + + preempt_disable(); + xh = &flnode->xh; + remotenode = flnode->xh.client_id; + ret = r2net_remote_flush_object(xh, remotenode); + if (ret >= 0) + ramster_remote_objects_flushed++; + else + ramster_remote_object_flushes_failed++; + preempt_enable_no_resched(); + ramster_flnode_free(flnode, NULL); +} + +int ramster_remotify_pageframe(bool eph) +{ + struct tmem_xhandle xh; + unsigned int size; + int remotenode, ret, zbuds; + struct tmem_pool *pool; + unsigned long flags; + unsigned char cksum; + char *p; + int i, j; + unsigned char *tmpmem[2]; + struct tmem_handle th[2]; + unsigned int zsize[2]; + + tmpmem[0] = __get_cpu_var(ramster_remoteputmem1); + tmpmem[1] = __get_cpu_var(ramster_remoteputmem2); + local_bh_disable(); + zbuds = zbud_make_zombie_lru(&th[0], &tmpmem[0], &zsize[0], eph); + /* now OK to release lock set in caller */ + local_bh_enable(); + if (zbuds == 0) + goto out; + BUG_ON(zbuds > 2); + for (i = 0; i < zbuds; i++) { + xh.client_id = th[i].client_id; + xh.pool_id = th[i].pool_id; + xh.oid = th[i].oid; + xh.index = th[i].index; + size = zsize[i]; + BUG_ON(size == 0 || size > zbud_max_buddy_size()); + for (p = tmpmem[i], cksum = 0, j = 0; j < size; j++) + cksum += *p++; + ret = r2net_remote_put(&xh, tmpmem[i], size, eph, &remotenode); + if (ret != 0) { + /* + * This is some form of a memory leak... if the remote put + * fails, there will never be another attempt to remotify + * this page. But since we've dropped the zv pointer, + * the page may have been freed or the data replaced + * so we can't just "put it back" in the remote op list. + * Even if we could, not sure where to put it in the list + * because there may be flushes that must be strictly + * ordered vs the put. So leave this as a FIXME for now. + * But count them so we know if it becomes a problem. + */ + if (eph) + ramster_eph_pages_remote_failed++; + else + ramster_pers_pages_remote_failed++; + break; + } else { + if (!eph) + atomic_inc(&ramster_remote_pers_pages); + } + if (eph) + ramster_eph_pages_remoted++; + else + ramster_pers_pages_remoted++; + /* + * data was successfully remoted so change the local version to + * point to the remote node where it landed + */ + local_bh_disable(); + pool = zcache_get_pool_by_id(LOCAL_CLIENT, xh.pool_id); + local_irq_save(flags); + (void)tmem_replace(pool, &xh.oid, xh.index, + pampd_make_remote(remotenode, size, cksum)); + local_irq_restore(flags); + zcache_put_pool(pool); + local_bh_enable(); + } +out: + return zbuds; +} + +static void zcache_do_remotify_flushes(void) +{ + struct ramster_remotify_hdr *rem_op; + union remotify_list_node *u; + + while (1) { + spin_lock(&ramster_rem_op_list_lock); + if (list_empty(&ramster_rem_op_list)) { + spin_unlock(&ramster_rem_op_list_lock); + goto out; + } + rem_op = list_first_entry(&ramster_rem_op_list, + struct ramster_remotify_hdr, list); + list_del_init(&rem_op->list); + spin_unlock(&ramster_rem_op_list_lock); + u = (union remotify_list_node *)rem_op; + switch (rem_op->op) { + case RAMSTER_REMOTIFY_FLUSH_PAGE: + ramster_remote_flush_page((struct flushlist_node *)u); + break; + case RAMSTER_REMOTIFY_FLUSH_OBJ: + ramster_remote_flush_object((struct flushlist_node *)u); + break; + default: + BUG(); + } + } +out: + return; +} + +static void ramster_remotify_process(struct work_struct *work) +{ + static bool remotify_in_progress; + int i; + + BUG_ON(irqs_disabled()); + if (remotify_in_progress) + goto requeue; + if (ramster_remote_target_nodenum == -1) + goto requeue; + remotify_in_progress = true; + if (use_cleancache && ramster_eph_remotify_enable) { + for (i = 0; i < 100; i++) { + zcache_do_remotify_flushes(); + (void)ramster_remotify_pageframe(true); + } + } + if (use_frontswap && ramster_pers_remotify_enable) { + for (i = 0; i < 100; i++) { + zcache_do_remotify_flushes(); + (void)ramster_remotify_pageframe(false); + } + } + remotify_in_progress = false; +requeue: + ramster_remotify_queue_delayed_work(HZ); +} + +void __init ramster_remotify_init(void) +{ + unsigned long n = 60UL; + ramster_remotify_workqueue = + create_singlethread_workqueue("ramster_remotify"); + ramster_remotify_queue_delayed_work(n * HZ); +} + +static ssize_t ramster_manual_node_up_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int i; + char *p = buf; + for (i = 0; i < MANUAL_NODES; i++) + if (ramster_nodes_manual_up[i]) + p += sprintf(p, "%d ", i); + p += sprintf(p, "\n"); + return p - buf; +} + +static ssize_t ramster_manual_node_up_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int err; + unsigned long node_num; + + err = kstrtoul(buf, 10, &node_num); + if (err) { + pr_err("ramster: bad strtoul?\n"); + return -EINVAL; + } + if (node_num >= MANUAL_NODES) { + pr_err("ramster: bad node_num=%lu?\n", node_num); + return -EINVAL; + } + if (ramster_nodes_manual_up[node_num]) { + pr_err("ramster: node %d already up, ignoring\n", + (int)node_num); + } else { + ramster_nodes_manual_up[node_num] = true; + r2net_hb_node_up_manual((int)node_num); + } + return count; +} + +static struct kobj_attribute ramster_manual_node_up_attr = { + .attr = { .name = "manual_node_up", .mode = 0644 }, + .show = ramster_manual_node_up_show, + .store = ramster_manual_node_up_store, +}; + +static ssize_t ramster_remote_target_nodenum_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + if (ramster_remote_target_nodenum == -1UL) + return sprintf(buf, "unset\n"); + else + return sprintf(buf, "%d\n", ramster_remote_target_nodenum); +} + +static ssize_t ramster_remote_target_nodenum_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int err; + unsigned long node_num; + + err = kstrtoul(buf, 10, &node_num); + if (err) { + pr_err("ramster: bad strtoul?\n"); + return -EINVAL; + } else if (node_num == -1UL) { + pr_err("ramster: disabling all remotification, " + "data may still reside on remote nodes however\n"); + return -EINVAL; + } else if (node_num >= MANUAL_NODES) { + pr_err("ramster: bad node_num=%lu?\n", node_num); + return -EINVAL; + } else if (!ramster_nodes_manual_up[node_num]) { + pr_err("ramster: node %d not up, ignoring setting " + "of remotification target\n", (int)node_num); + } else if (r2net_remote_target_node_set((int)node_num) >= 0) { + pr_info("ramster: node %d set as remotification target\n", + (int)node_num); + ramster_remote_target_nodenum = (int)node_num; + } else { + pr_err("ramster: bad num to node node_num=%d?\n", + (int)node_num); + return -EINVAL; + } + return count; +} + +static struct kobj_attribute ramster_remote_target_nodenum_attr = { + .attr = { .name = "remote_target_nodenum", .mode = 0644 }, + .show = ramster_remote_target_nodenum_show, + .store = ramster_remote_target_nodenum_store, +}; + +#define RAMSTER_SYSFS_RO(_name) \ + static ssize_t ramster_##_name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + return sprintf(buf, "%lu\n", ramster_##_name); \ + } \ + static struct kobj_attribute ramster_##_name##_attr = { \ + .attr = { .name = __stringify(_name), .mode = 0444 }, \ + .show = ramster_##_name##_show, \ + } + +#define RAMSTER_SYSFS_RW(_name) \ + static ssize_t ramster_##_name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + return sprintf(buf, "%lu\n", ramster_##_name); \ + } \ + static ssize_t ramster_##_name##_store(struct kobject *kobj, \ + struct kobj_attribute *attr, const char *buf, size_t count) \ + { \ + int err; \ + unsigned long enable; \ + err = kstrtoul(buf, 10, &enable); \ + if (err) \ + return -EINVAL; \ + ramster_##_name = enable; \ + return count; \ + } \ + static struct kobj_attribute ramster_##_name##_attr = { \ + .attr = { .name = __stringify(_name), .mode = 0644 }, \ + .show = ramster_##_name##_show, \ + .store = ramster_##_name##_store, \ + } + +#define RAMSTER_SYSFS_RO_ATOMIC(_name) \ + static ssize_t ramster_##_name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + return sprintf(buf, "%d\n", atomic_read(&ramster_##_name)); \ + } \ + static struct kobj_attribute ramster_##_name##_attr = { \ + .attr = { .name = __stringify(_name), .mode = 0444 }, \ + .show = ramster_##_name##_show, \ + } + +RAMSTER_SYSFS_RO(interface_revision); +RAMSTER_SYSFS_RO_ATOMIC(remote_pers_pages); +RAMSTER_SYSFS_RW(pers_remotify_enable); +RAMSTER_SYSFS_RW(eph_remotify_enable); + +static struct attribute *ramster_attrs[] = { + &ramster_interface_revision_attr.attr, + &ramster_remote_pers_pages_attr.attr, + &ramster_manual_node_up_attr.attr, + &ramster_remote_target_nodenum_attr.attr, + &ramster_pers_remotify_enable_attr.attr, + &ramster_eph_remotify_enable_attr.attr, + NULL, +}; + +static struct attribute_group ramster_attr_group = { + .attrs = ramster_attrs, + .name = "ramster", +}; + +/* + * frontswap selfshrinking + */ + +/* In HZ, controls frequency of worker invocation. */ +static unsigned int selfshrink_interval __read_mostly = 5; +/* Enable/disable with sysfs. */ +static bool frontswap_selfshrinking __read_mostly; + +static void selfshrink_process(struct work_struct *work); +static DECLARE_DELAYED_WORK(selfshrink_worker, selfshrink_process); + +/* Enable/disable with kernel boot option. */ +static bool use_frontswap_selfshrink __initdata = true; + +/* + * The default values for the following parameters were deemed reasonable + * by experimentation, may be workload-dependent, and can all be + * adjusted via sysfs. + */ + +/* Control rate for frontswap shrinking. Higher hysteresis is slower. */ +static unsigned int frontswap_hysteresis __read_mostly = 20; + +/* + * Number of selfshrink worker invocations to wait before observing that + * frontswap selfshrinking should commence. Note that selfshrinking does + * not use a separate worker thread. + */ +static unsigned int frontswap_inertia __read_mostly = 3; + +/* Countdown to next invocation of frontswap_shrink() */ +static unsigned long frontswap_inertia_counter; + +/* + * Invoked by the selfshrink worker thread, uses current number of pages + * in frontswap (frontswap_curr_pages()), previous status, and control + * values (hysteresis and inertia) to determine if frontswap should be + * shrunk and what the new frontswap size should be. Note that + * frontswap_shrink is essentially a partial swapoff that immediately + * transfers pages from the "swap device" (frontswap) back into kernel + * RAM; despite the name, frontswap "shrinking" is very different from + * the "shrinker" interface used by the kernel MM subsystem to reclaim + * memory. + */ +static void frontswap_selfshrink(void) +{ + static unsigned long cur_frontswap_pages; + static unsigned long last_frontswap_pages; + static unsigned long tgt_frontswap_pages; + + last_frontswap_pages = cur_frontswap_pages; + cur_frontswap_pages = frontswap_curr_pages(); + if (!cur_frontswap_pages || + (cur_frontswap_pages > last_frontswap_pages)) { + frontswap_inertia_counter = frontswap_inertia; + return; + } + if (frontswap_inertia_counter && --frontswap_inertia_counter) + return; + if (cur_frontswap_pages <= frontswap_hysteresis) + tgt_frontswap_pages = 0; + else + tgt_frontswap_pages = cur_frontswap_pages - + (cur_frontswap_pages / frontswap_hysteresis); + frontswap_shrink(tgt_frontswap_pages); +} + +static int __init ramster_nofrontswap_selfshrink_setup(char *s) +{ + use_frontswap_selfshrink = false; + return 1; +} + +__setup("noselfshrink", ramster_nofrontswap_selfshrink_setup); + +static void selfshrink_process(struct work_struct *work) +{ + if (frontswap_selfshrinking && frontswap_enabled) { + frontswap_selfshrink(); + schedule_delayed_work(&selfshrink_worker, + selfshrink_interval * HZ); + } +} + +void ramster_cpu_up(int cpu) +{ + unsigned char *p1 = kzalloc(PAGE_SIZE, GFP_KERNEL | __GFP_REPEAT); + unsigned char *p2 = kzalloc(PAGE_SIZE, GFP_KERNEL | __GFP_REPEAT); + BUG_ON(!p1 || !p2); + per_cpu(ramster_remoteputmem1, cpu) = p1; + per_cpu(ramster_remoteputmem2, cpu) = p2; +} + +void ramster_cpu_down(int cpu) +{ + struct ramster_preload *kp; + + kfree(per_cpu(ramster_remoteputmem1, cpu)); + per_cpu(ramster_remoteputmem1, cpu) = NULL; + kfree(per_cpu(ramster_remoteputmem2, cpu)); + per_cpu(ramster_remoteputmem2, cpu) = NULL; + kp = &per_cpu(ramster_preloads, cpu); + if (kp->flnode) { + kmem_cache_free(ramster_flnode_cache, kp->flnode); + kp->flnode = NULL; + } +} + +void ramster_register_pamops(struct tmem_pamops *pamops) +{ + pamops->free_obj = ramster_pampd_free_obj; + pamops->new_obj = ramster_pampd_new_obj; + pamops->replace_in_obj = ramster_pampd_replace_in_obj; + pamops->is_remote = ramster_pampd_is_remote; + pamops->repatriate = ramster_pampd_repatriate; + pamops->repatriate_preload = ramster_pampd_repatriate_preload; +} + +void __init ramster_init(bool cleancache, bool frontswap, + bool frontswap_exclusive_gets) +{ + int ret = 0; + + if (cleancache) + use_cleancache = true; + if (frontswap) + use_frontswap = true; + if (frontswap_exclusive_gets) + use_frontswap_exclusive_gets = true; + ramster_debugfs_init(); + ret = sysfs_create_group(mm_kobj, &ramster_attr_group); + if (ret) + pr_err("ramster: can't create sysfs for ramster\n"); + (void)r2net_register_handlers(); + INIT_LIST_HEAD(&ramster_rem_op_list); + ramster_flnode_cache = kmem_cache_create("ramster_flnode", + sizeof(struct flushlist_node), 0, 0, NULL); + frontswap_selfshrinking = use_frontswap_selfshrink; + if (frontswap_selfshrinking) { + pr_info("ramster: Initializing frontswap selfshrink driver.\n"); + schedule_delayed_work(&selfshrink_worker, + selfshrink_interval * HZ); + } + ramster_remotify_init(); +} diff --git a/drivers/staging/zcache/ramster/ramster.h b/drivers/staging/zcache/ramster/ramster.h new file mode 100644 index 0000000..12ae56f --- /dev/null +++ b/drivers/staging/zcache/ramster/ramster.h @@ -0,0 +1,161 @@ +/* + * ramster.h + * + * Peer-to-peer transcendent memory + * + * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. + */ + +#ifndef _RAMSTER_RAMSTER_H_ +#define _RAMSTER_RAMSTER_H_ + +#include "../tmem.h" + +enum ramster_remotify_op { + RAMSTER_REMOTIFY_FLUSH_PAGE, + RAMSTER_REMOTIFY_FLUSH_OBJ, +}; + +struct ramster_remotify_hdr { + enum ramster_remotify_op op; + struct list_head list; +}; + +struct flushlist_node { + struct ramster_remotify_hdr rem_op; + struct tmem_xhandle xh; +}; + +struct ramster_preload { + struct flushlist_node *flnode; +}; + +union remotify_list_node { + struct ramster_remotify_hdr rem_op; + struct { + struct ramster_remotify_hdr rem_op; + struct tmem_handle th; + } zbud_hdr; + struct flushlist_node flist; +}; + +/* + * format of remote pampd: + * bit 0 is reserved for zbud (in-page buddy selection) + * bit 1 == intransit + * bit 2 == is_remote... if this bit is set, then + * bit 3-10 == remotenode + * bit 11-23 == size + * bit 24-31 == cksum + */ +#define FAKE_PAMPD_INTRANSIT_BITS 1 +#define FAKE_PAMPD_ISREMOTE_BITS 1 +#define FAKE_PAMPD_REMOTENODE_BITS 8 +#define FAKE_PAMPD_REMOTESIZE_BITS 13 +#define FAKE_PAMPD_CHECKSUM_BITS 8 + +#define FAKE_PAMPD_INTRANSIT_SHIFT 1 +#define FAKE_PAMPD_ISREMOTE_SHIFT (FAKE_PAMPD_INTRANSIT_SHIFT + \ + FAKE_PAMPD_INTRANSIT_BITS) +#define FAKE_PAMPD_REMOTENODE_SHIFT (FAKE_PAMPD_ISREMOTE_SHIFT + \ + FAKE_PAMPD_ISREMOTE_BITS) +#define FAKE_PAMPD_REMOTESIZE_SHIFT (FAKE_PAMPD_REMOTENODE_SHIFT + \ + FAKE_PAMPD_REMOTENODE_BITS) +#define FAKE_PAMPD_CHECKSUM_SHIFT (FAKE_PAMPD_REMOTESIZE_SHIFT + \ + FAKE_PAMPD_REMOTESIZE_BITS) + +#define FAKE_PAMPD_MASK(x) ((1UL << (x)) - 1) + +static inline void *pampd_make_remote(int remotenode, size_t size, + unsigned char cksum) +{ + unsigned long fake_pampd = 0; + fake_pampd |= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT; + fake_pampd |= ((unsigned long)remotenode & + FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS)) << + FAKE_PAMPD_REMOTENODE_SHIFT; + fake_pampd |= ((unsigned long)size & + FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS)) << + FAKE_PAMPD_REMOTESIZE_SHIFT; + fake_pampd |= ((unsigned long)cksum & + FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS)) << + FAKE_PAMPD_CHECKSUM_SHIFT; + return (void *)fake_pampd; +} + +static inline unsigned int pampd_remote_node(void *pampd) +{ + unsigned long fake_pampd = (unsigned long)pampd; + return (fake_pampd >> FAKE_PAMPD_REMOTENODE_SHIFT) & + FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS); +} + +static inline unsigned int pampd_remote_size(void *pampd) +{ + unsigned long fake_pampd = (unsigned long)pampd; + return (fake_pampd >> FAKE_PAMPD_REMOTESIZE_SHIFT) & + FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS); +} + +static inline unsigned char pampd_remote_cksum(void *pampd) +{ + unsigned long fake_pampd = (unsigned long)pampd; + return (fake_pampd >> FAKE_PAMPD_CHECKSUM_SHIFT) & + FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS); +} + +static inline bool pampd_is_remote(void *pampd) +{ + unsigned long fake_pampd = (unsigned long)pampd; + return (fake_pampd >> FAKE_PAMPD_ISREMOTE_SHIFT) & + FAKE_PAMPD_MASK(FAKE_PAMPD_ISREMOTE_BITS); +} + +static inline bool pampd_is_intransit(void *pampd) +{ + unsigned long fake_pampd = (unsigned long)pampd; + return (fake_pampd >> FAKE_PAMPD_INTRANSIT_SHIFT) & + FAKE_PAMPD_MASK(FAKE_PAMPD_INTRANSIT_BITS); +} + +/* note that it is a BUG for intransit to be set without isremote also set */ +static inline void *pampd_mark_intransit(void *pampd) +{ + unsigned long fake_pampd = (unsigned long)pampd; + + fake_pampd |= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT; + fake_pampd |= 1UL << FAKE_PAMPD_INTRANSIT_SHIFT; + return (void *)fake_pampd; +} + +static inline void *pampd_mask_intransit_and_remote(void *marked_pampd) +{ + unsigned long pampd = (unsigned long)marked_pampd; + + pampd &= ~(1UL << FAKE_PAMPD_INTRANSIT_SHIFT); + pampd &= ~(1UL << FAKE_PAMPD_ISREMOTE_SHIFT); + return (void *)pampd; +} + +extern int r2net_remote_async_get(struct tmem_xhandle *, + bool, int, size_t, uint8_t, void *extra); +extern int r2net_remote_put(struct tmem_xhandle *, char *, size_t, + bool, int *); +extern int r2net_remote_flush(struct tmem_xhandle *, int); +extern int r2net_remote_flush_object(struct tmem_xhandle *, int); +extern int r2net_register_handlers(void); +extern int r2net_remote_target_node_set(int); + +extern int ramster_remotify_pageframe(bool); +extern void ramster_init(bool, bool, bool); +extern void ramster_register_pamops(struct tmem_pamops *); +extern int ramster_localify(int, struct tmem_oid *oidp, uint32_t, char *, + unsigned int, void *); +extern void *ramster_pampd_free(void *, struct tmem_pool *, struct tmem_oid *, + uint32_t, bool); +extern void ramster_count_foreign_pages(bool, int); +extern int ramster_do_preload_flnode(struct tmem_pool *); +extern void ramster_cpu_up(int); +extern void ramster_cpu_down(int); + +#endif /* _RAMSTER_RAMSTER_H */ diff --git a/drivers/staging/zcache/ramster/ramster_nodemanager.h b/drivers/staging/zcache/ramster/ramster_nodemanager.h new file mode 100644 index 0000000..49f879d --- /dev/null +++ b/drivers/staging/zcache/ramster/ramster_nodemanager.h @@ -0,0 +1,39 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * ramster_nodemanager.h + * + * Header describing the interface between userspace and the kernel + * for the ramster_nodemanager module. + * + * Copyright (C) 2002, 2004, 2012 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + */ + +#ifndef _RAMSTER_NODEMANAGER_H +#define _RAMSTER_NODEMANAGER_H + +#define R2NM_API_VERSION 5 + +#define R2NM_MAX_NODES 255 +#define R2NM_INVALID_NODE_NUM 255 + +/* host name, group name, cluster name all 64 bytes */ +#define R2NM_MAX_NAME_LEN 64 /* __NEW_UTS_LEN */ + +#endif /* _RAMSTER_NODEMANAGER_H */ diff --git a/drivers/staging/zcache/ramster/tcp.c b/drivers/staging/zcache/ramster/tcp.c new file mode 100644 index 0000000..aa2a1a7 --- /dev/null +++ b/drivers/staging/zcache/ramster/tcp.c @@ -0,0 +1,2253 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * Copyright (C) 2004 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + * ---- + * + * Callers for this were originally written against a very simple synchronus + * API. This implementation reflects those simple callers. Some day I'm sure + * we'll need to move to a more robust posting/callback mechanism. + * + * Transmit calls pass in kernel virtual addresses and block copying this into + * the socket's tx buffers via a usual blocking sendmsg. They'll block waiting + * for a failed socket to timeout. TX callers can also pass in a poniter to an + * 'int' which gets filled with an errno off the wire in response to the + * message they send. + * + * Handlers for unsolicited messages are registered. Each socket has a page + * that incoming data is copied into. First the header, then the data. + * Handlers are called from only one thread with a reference to this per-socket + * page. This page is destroyed after the handler call, so it can't be + * referenced beyond the call. Handlers may block but are discouraged from + * doing so. + * + * Any framing errors (bad magic, large payload lengths) close a connection. + * + * Our sock_container holds the state we associate with a socket. It's current + * framing state is held there as well as the refcounting we do around when it + * is safe to tear down the socket. The socket is only finally torn down from + * the container when the container loses all of its references -- so as long + * as you hold a ref on the container you can trust that the socket is valid + * for use with kernel socket APIs. + * + * Connections are initiated between a pair of nodes when the node with the + * higher node number gets a heartbeat callback which indicates that the lower + * numbered node has started heartbeating. The lower numbered node is passive + * and only accepts the connection if the higher numbered node is heartbeating. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "heartbeat.h" +#include "tcp.h" +#include "nodemanager.h" +#define MLOG_MASK_PREFIX ML_TCP +#include "masklog.h" + +#include "tcp_internal.h" + +#define SC_NODEF_FMT "node %s (num %u) at %pI4:%u" + +/* + * In the following two log macros, the whitespace after the ',' just + * before ##args is intentional. Otherwise, gcc 2.95 will eat the + * previous token if args expands to nothing. + */ +#define msglog(hdr, fmt, args...) do { \ + typeof(hdr) __hdr = (hdr); \ + mlog(ML_MSG, "[mag %u len %u typ %u stat %d sys_stat %d " \ + "key %08x num %u] " fmt, \ + be16_to_cpu(__hdr->magic), be16_to_cpu(__hdr->data_len), \ + be16_to_cpu(__hdr->msg_type), be32_to_cpu(__hdr->status), \ + be32_to_cpu(__hdr->sys_status), be32_to_cpu(__hdr->key), \ + be32_to_cpu(__hdr->msg_num) , ##args); \ +} while (0) + +#define sclog(sc, fmt, args...) do { \ + typeof(sc) __sc = (sc); \ + mlog(ML_SOCKET, "[sc %p refs %d sock %p node %u page %p " \ + "pg_off %zu] " fmt, __sc, \ + atomic_read(&__sc->sc_kref.refcount), __sc->sc_sock, \ + __sc->sc_node->nd_num, __sc->sc_page, __sc->sc_page_off , \ + ##args); \ +} while (0) + +static DEFINE_RWLOCK(r2net_handler_lock); +static struct rb_root r2net_handler_tree = RB_ROOT; + +static struct r2net_node r2net_nodes[R2NM_MAX_NODES]; + +/* XXX someday we'll need better accounting */ +static struct socket *r2net_listen_sock; + +/* + * listen work is only queued by the listening socket callbacks on the + * r2net_wq. teardown detaches the callbacks before destroying the workqueue. + * quorum work is queued as sock containers are shutdown.. stop_listening + * tears down all the node's sock containers, preventing future shutdowns + * and queued quorum work, before canceling delayed quorum work and + * destroying the work queue. + */ +static struct workqueue_struct *r2net_wq; +static struct work_struct r2net_listen_work; + +static struct r2hb_callback_func r2net_hb_up, r2net_hb_down; +#define R2NET_HB_PRI 0x1 + +static struct r2net_handshake *r2net_hand; +static struct r2net_msg *r2net_keep_req, *r2net_keep_resp; + +static int r2net_sys_err_translations[R2NET_ERR_MAX] = { + [R2NET_ERR_NONE] = 0, + [R2NET_ERR_NO_HNDLR] = -ENOPROTOOPT, + [R2NET_ERR_OVERFLOW] = -EOVERFLOW, + [R2NET_ERR_DIED] = -EHOSTDOWN,}; + +/* can't quite avoid *all* internal declarations :/ */ +static void r2net_sc_connect_completed(struct work_struct *work); +static void r2net_rx_until_empty(struct work_struct *work); +static void r2net_shutdown_sc(struct work_struct *work); +static void r2net_listen_data_ready(struct sock *sk, int bytes); +static void r2net_sc_send_keep_req(struct work_struct *work); +static void r2net_idle_timer(unsigned long data); +static void r2net_sc_postpone_idle(struct r2net_sock_container *sc); +static void r2net_sc_reset_idle_timer(struct r2net_sock_container *sc); + +#ifdef CONFIG_DEBUG_FS +static void r2net_init_nst(struct r2net_send_tracking *nst, u32 msgtype, + u32 msgkey, struct task_struct *task, u8 node) +{ + INIT_LIST_HEAD(&nst->st_net_debug_item); + nst->st_task = task; + nst->st_msg_type = msgtype; + nst->st_msg_key = msgkey; + nst->st_node = node; +} + +static inline void r2net_set_nst_sock_time(struct r2net_send_tracking *nst) +{ + nst->st_sock_time = ktime_get(); +} + +static inline void r2net_set_nst_send_time(struct r2net_send_tracking *nst) +{ + nst->st_send_time = ktime_get(); +} + +static inline void r2net_set_nst_status_time(struct r2net_send_tracking *nst) +{ + nst->st_status_time = ktime_get(); +} + +static inline void r2net_set_nst_sock_container(struct r2net_send_tracking *nst, + struct r2net_sock_container *sc) +{ + nst->st_sc = sc; +} + +static inline void r2net_set_nst_msg_id(struct r2net_send_tracking *nst, + u32 msg_id) +{ + nst->st_id = msg_id; +} + +static inline void r2net_set_sock_timer(struct r2net_sock_container *sc) +{ + sc->sc_tv_timer = ktime_get(); +} + +static inline void r2net_set_data_ready_time(struct r2net_sock_container *sc) +{ + sc->sc_tv_data_ready = ktime_get(); +} + +static inline void r2net_set_advance_start_time(struct r2net_sock_container *sc) +{ + sc->sc_tv_advance_start = ktime_get(); +} + +static inline void r2net_set_advance_stop_time(struct r2net_sock_container *sc) +{ + sc->sc_tv_advance_stop = ktime_get(); +} + +static inline void r2net_set_func_start_time(struct r2net_sock_container *sc) +{ + sc->sc_tv_func_start = ktime_get(); +} + +static inline void r2net_set_func_stop_time(struct r2net_sock_container *sc) +{ + sc->sc_tv_func_stop = ktime_get(); +} + +#else /* CONFIG_DEBUG_FS */ +# define r2net_init_nst(a, b, c, d, e) +# define r2net_set_nst_sock_time(a) +# define r2net_set_nst_send_time(a) +# define r2net_set_nst_status_time(a) +# define r2net_set_nst_sock_container(a, b) +# define r2net_set_nst_msg_id(a, b) +# define r2net_set_sock_timer(a) +# define r2net_set_data_ready_time(a) +# define r2net_set_advance_start_time(a) +# define r2net_set_advance_stop_time(a) +# define r2net_set_func_start_time(a) +# define r2net_set_func_stop_time(a) +#endif /* CONFIG_DEBUG_FS */ + +#ifdef CONFIG_RAMSTER_FS_STATS +static ktime_t r2net_get_func_run_time(struct r2net_sock_container *sc) +{ + return ktime_sub(sc->sc_tv_func_stop, sc->sc_tv_func_start); +} + +static void r2net_update_send_stats(struct r2net_send_tracking *nst, + struct r2net_sock_container *sc) +{ + sc->sc_tv_status_total = ktime_add(sc->sc_tv_status_total, + ktime_sub(ktime_get(), + nst->st_status_time)); + sc->sc_tv_send_total = ktime_add(sc->sc_tv_send_total, + ktime_sub(nst->st_status_time, + nst->st_send_time)); + sc->sc_tv_acquiry_total = ktime_add(sc->sc_tv_acquiry_total, + ktime_sub(nst->st_send_time, + nst->st_sock_time)); + sc->sc_send_count++; +} + +static void r2net_update_recv_stats(struct r2net_sock_container *sc) +{ + sc->sc_tv_process_total = ktime_add(sc->sc_tv_process_total, + r2net_get_func_run_time(sc)); + sc->sc_recv_count++; +} + +#else + +# define r2net_update_send_stats(a, b) + +# define r2net_update_recv_stats(sc) + +#endif /* CONFIG_RAMSTER_FS_STATS */ + +static inline int r2net_reconnect_delay(void) +{ + return r2nm_single_cluster->cl_reconnect_delay_ms; +} + +static inline int r2net_keepalive_delay(void) +{ + return r2nm_single_cluster->cl_keepalive_delay_ms; +} + +static inline int r2net_idle_timeout(void) +{ + return r2nm_single_cluster->cl_idle_timeout_ms; +} + +static inline int r2net_sys_err_to_errno(enum r2net_system_error err) +{ + int trans; + BUG_ON(err >= R2NET_ERR_MAX); + trans = r2net_sys_err_translations[err]; + + /* Just in case we mess up the translation table above */ + BUG_ON(err != R2NET_ERR_NONE && trans == 0); + return trans; +} + +struct r2net_node *r2net_nn_from_num(u8 node_num) +{ + BUG_ON(node_num >= ARRAY_SIZE(r2net_nodes)); + return &r2net_nodes[node_num]; +} + +static u8 r2net_num_from_nn(struct r2net_node *nn) +{ + BUG_ON(nn == NULL); + return nn - r2net_nodes; +} + +/* ------------------------------------------------------------ */ + +static int r2net_prep_nsw(struct r2net_node *nn, struct r2net_status_wait *nsw) +{ + int ret = 0; + + do { + if (!idr_pre_get(&nn->nn_status_idr, GFP_ATOMIC)) { + ret = -EAGAIN; + break; + } + spin_lock(&nn->nn_lock); + ret = idr_get_new(&nn->nn_status_idr, nsw, &nsw->ns_id); + if (ret == 0) + list_add_tail(&nsw->ns_node_item, + &nn->nn_status_list); + spin_unlock(&nn->nn_lock); + } while (ret == -EAGAIN); + + if (ret == 0) { + init_waitqueue_head(&nsw->ns_wq); + nsw->ns_sys_status = R2NET_ERR_NONE; + nsw->ns_status = 0; + } + + return ret; +} + +static void r2net_complete_nsw_locked(struct r2net_node *nn, + struct r2net_status_wait *nsw, + enum r2net_system_error sys_status, + s32 status) +{ + assert_spin_locked(&nn->nn_lock); + + if (!list_empty(&nsw->ns_node_item)) { + list_del_init(&nsw->ns_node_item); + nsw->ns_sys_status = sys_status; + nsw->ns_status = status; + idr_remove(&nn->nn_status_idr, nsw->ns_id); + wake_up(&nsw->ns_wq); + } +} + +static void r2net_complete_nsw(struct r2net_node *nn, + struct r2net_status_wait *nsw, + u64 id, enum r2net_system_error sys_status, + s32 status) +{ + spin_lock(&nn->nn_lock); + if (nsw == NULL) { + if (id > INT_MAX) + goto out; + + nsw = idr_find(&nn->nn_status_idr, id); + if (nsw == NULL) + goto out; + } + + r2net_complete_nsw_locked(nn, nsw, sys_status, status); + +out: + spin_unlock(&nn->nn_lock); + return; +} + +static void r2net_complete_nodes_nsw(struct r2net_node *nn) +{ + struct r2net_status_wait *nsw, *tmp; + unsigned int num_kills = 0; + + assert_spin_locked(&nn->nn_lock); + + list_for_each_entry_safe(nsw, tmp, &nn->nn_status_list, ns_node_item) { + r2net_complete_nsw_locked(nn, nsw, R2NET_ERR_DIED, 0); + num_kills++; + } + + mlog(0, "completed %d messages for node %u\n", num_kills, + r2net_num_from_nn(nn)); +} + +static int r2net_nsw_completed(struct r2net_node *nn, + struct r2net_status_wait *nsw) +{ + int completed; + spin_lock(&nn->nn_lock); + completed = list_empty(&nsw->ns_node_item); + spin_unlock(&nn->nn_lock); + return completed; +} + +/* ------------------------------------------------------------ */ + +static void sc_kref_release(struct kref *kref) +{ + struct r2net_sock_container *sc = container_of(kref, + struct r2net_sock_container, sc_kref); + BUG_ON(timer_pending(&sc->sc_idle_timeout)); + + sclog(sc, "releasing\n"); + + if (sc->sc_sock) { + sock_release(sc->sc_sock); + sc->sc_sock = NULL; + } + + r2nm_undepend_item(&sc->sc_node->nd_item); + r2nm_node_put(sc->sc_node); + sc->sc_node = NULL; + + r2net_debug_del_sc(sc); + kfree(sc); +} + +static void sc_put(struct r2net_sock_container *sc) +{ + sclog(sc, "put\n"); + kref_put(&sc->sc_kref, sc_kref_release); +} +static void sc_get(struct r2net_sock_container *sc) +{ + sclog(sc, "get\n"); + kref_get(&sc->sc_kref); +} +static struct r2net_sock_container *sc_alloc(struct r2nm_node *node) +{ + struct r2net_sock_container *sc, *ret = NULL; + struct page *page = NULL; + int status = 0; + + page = alloc_page(GFP_NOFS); + sc = kzalloc(sizeof(*sc), GFP_NOFS); + if (sc == NULL || page == NULL) + goto out; + + kref_init(&sc->sc_kref); + r2nm_node_get(node); + sc->sc_node = node; + + /* pin the node item of the remote node */ + status = r2nm_depend_item(&node->nd_item); + if (status) { + mlog_errno(status); + r2nm_node_put(node); + goto out; + } + INIT_WORK(&sc->sc_connect_work, r2net_sc_connect_completed); + INIT_WORK(&sc->sc_rx_work, r2net_rx_until_empty); + INIT_WORK(&sc->sc_shutdown_work, r2net_shutdown_sc); + INIT_DELAYED_WORK(&sc->sc_keepalive_work, r2net_sc_send_keep_req); + + init_timer(&sc->sc_idle_timeout); + sc->sc_idle_timeout.function = r2net_idle_timer; + sc->sc_idle_timeout.data = (unsigned long)sc; + + sclog(sc, "alloced\n"); + + ret = sc; + sc->sc_page = page; + r2net_debug_add_sc(sc); + sc = NULL; + page = NULL; + +out: + if (page) + __free_page(page); + kfree(sc); + + return ret; +} + +/* ------------------------------------------------------------ */ + +static void r2net_sc_queue_work(struct r2net_sock_container *sc, + struct work_struct *work) +{ + sc_get(sc); + if (!queue_work(r2net_wq, work)) + sc_put(sc); +} +static void r2net_sc_queue_delayed_work(struct r2net_sock_container *sc, + struct delayed_work *work, + int delay) +{ + sc_get(sc); + if (!queue_delayed_work(r2net_wq, work, delay)) + sc_put(sc); +} +static void r2net_sc_cancel_delayed_work(struct r2net_sock_container *sc, + struct delayed_work *work) +{ + if (cancel_delayed_work(work)) + sc_put(sc); +} + +static atomic_t r2net_connected_peers = ATOMIC_INIT(0); + +int r2net_num_connected_peers(void) +{ + return atomic_read(&r2net_connected_peers); +} + +static void r2net_set_nn_state(struct r2net_node *nn, + struct r2net_sock_container *sc, + unsigned valid, int err) +{ + int was_valid = nn->nn_sc_valid; + int was_err = nn->nn_persistent_error; + struct r2net_sock_container *old_sc = nn->nn_sc; + + assert_spin_locked(&nn->nn_lock); + + if (old_sc && !sc) + atomic_dec(&r2net_connected_peers); + else if (!old_sc && sc) + atomic_inc(&r2net_connected_peers); + + /* the node num comparison and single connect/accept path should stop + * an non-null sc from being overwritten with another */ + BUG_ON(sc && nn->nn_sc && nn->nn_sc != sc); + mlog_bug_on_msg(err && valid, "err %d valid %u\n", err, valid); + mlog_bug_on_msg(valid && !sc, "valid %u sc %p\n", valid, sc); + + if (was_valid && !valid && err == 0) + err = -ENOTCONN; + + mlog(ML_CONN, "node %u sc: %p -> %p, valid %u -> %u, err %d -> %d\n", + r2net_num_from_nn(nn), nn->nn_sc, sc, nn->nn_sc_valid, valid, + nn->nn_persistent_error, err); + + nn->nn_sc = sc; + nn->nn_sc_valid = valid ? 1 : 0; + nn->nn_persistent_error = err; + + /* mirrors r2net_tx_can_proceed() */ + if (nn->nn_persistent_error || nn->nn_sc_valid) + wake_up(&nn->nn_sc_wq); + + if (!was_err && nn->nn_persistent_error) { + queue_delayed_work(r2net_wq, &nn->nn_still_up, + msecs_to_jiffies(R2NET_QUORUM_DELAY_MS)); + } + + if (was_valid && !valid) { + pr_notice("ramster: No longer connected to " SC_NODEF_FMT "\n", + old_sc->sc_node->nd_name, old_sc->sc_node->nd_num, + &old_sc->sc_node->nd_ipv4_address, + ntohs(old_sc->sc_node->nd_ipv4_port)); + r2net_complete_nodes_nsw(nn); + } + + if (!was_valid && valid) { + cancel_delayed_work(&nn->nn_connect_expired); + pr_notice("ramster: %s " SC_NODEF_FMT "\n", + r2nm_this_node() > sc->sc_node->nd_num ? + "Connected to" : "Accepted connection from", + sc->sc_node->nd_name, sc->sc_node->nd_num, + &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port)); + } + + /* trigger the connecting worker func as long as we're not valid, + * it will back off if it shouldn't connect. This can be called + * from node config teardown and so needs to be careful about + * the work queue actually being up. */ + if (!valid && r2net_wq) { + unsigned long delay; + /* delay if we're within a RECONNECT_DELAY of the + * last attempt */ + delay = (nn->nn_last_connect_attempt + + msecs_to_jiffies(r2net_reconnect_delay())) + - jiffies; + if (delay > msecs_to_jiffies(r2net_reconnect_delay())) + delay = 0; + mlog(ML_CONN, "queueing conn attempt in %lu jiffies\n", delay); + queue_delayed_work(r2net_wq, &nn->nn_connect_work, delay); + + /* + * Delay the expired work after idle timeout. + * + * We might have lots of failed connection attempts that run + * through here but we only cancel the connect_expired work when + * a connection attempt succeeds. So only the first enqueue of + * the connect_expired work will do anything. The rest will see + * that it's already queued and do nothing. + */ + delay += msecs_to_jiffies(r2net_idle_timeout()); + queue_delayed_work(r2net_wq, &nn->nn_connect_expired, delay); + } + + /* keep track of the nn's sc ref for the caller */ + if ((old_sc == NULL) && sc) + sc_get(sc); + if (old_sc && (old_sc != sc)) { + r2net_sc_queue_work(old_sc, &old_sc->sc_shutdown_work); + sc_put(old_sc); + } +} + +/* see r2net_register_callbacks() */ +static void r2net_data_ready(struct sock *sk, int bytes) +{ + void (*ready)(struct sock *sk, int bytes); + + read_lock(&sk->sk_callback_lock); + if (sk->sk_user_data) { + struct r2net_sock_container *sc = sk->sk_user_data; + sclog(sc, "data_ready hit\n"); + r2net_set_data_ready_time(sc); + r2net_sc_queue_work(sc, &sc->sc_rx_work); + ready = sc->sc_data_ready; + } else { + ready = sk->sk_data_ready; + } + read_unlock(&sk->sk_callback_lock); + + ready(sk, bytes); +} + +/* see r2net_register_callbacks() */ +static void r2net_state_change(struct sock *sk) +{ + void (*state_change)(struct sock *sk); + struct r2net_sock_container *sc; + + read_lock(&sk->sk_callback_lock); + sc = sk->sk_user_data; + if (sc == NULL) { + state_change = sk->sk_state_change; + goto out; + } + + sclog(sc, "state_change to %d\n", sk->sk_state); + + state_change = sc->sc_state_change; + + switch (sk->sk_state) { + + /* ignore connecting sockets as they make progress */ + case TCP_SYN_SENT: + case TCP_SYN_RECV: + break; + case TCP_ESTABLISHED: + r2net_sc_queue_work(sc, &sc->sc_connect_work); + break; + default: + pr_info("ramster: Connection to " + SC_NODEF_FMT " shutdown, state %d\n", + sc->sc_node->nd_name, sc->sc_node->nd_num, + &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), sk->sk_state); + r2net_sc_queue_work(sc, &sc->sc_shutdown_work); + break; + + } +out: + read_unlock(&sk->sk_callback_lock); + state_change(sk); +} + +/* + * we register callbacks so we can queue work on events before calling + * the original callbacks. our callbacks are careful to test user_data + * to discover when they've reaced with r2net_unregister_callbacks(). + */ +static void r2net_register_callbacks(struct sock *sk, + struct r2net_sock_container *sc) +{ + write_lock_bh(&sk->sk_callback_lock); + + /* accepted sockets inherit the old listen socket data ready */ + if (sk->sk_data_ready == r2net_listen_data_ready) { + sk->sk_data_ready = sk->sk_user_data; + sk->sk_user_data = NULL; + } + + BUG_ON(sk->sk_user_data != NULL); + sk->sk_user_data = sc; + sc_get(sc); + + sc->sc_data_ready = sk->sk_data_ready; + sc->sc_state_change = sk->sk_state_change; + sk->sk_data_ready = r2net_data_ready; + sk->sk_state_change = r2net_state_change; + + mutex_init(&sc->sc_send_lock); + + write_unlock_bh(&sk->sk_callback_lock); +} + +static int r2net_unregister_callbacks(struct sock *sk, + struct r2net_sock_container *sc) +{ + int ret = 0; + + write_lock_bh(&sk->sk_callback_lock); + if (sk->sk_user_data == sc) { + ret = 1; + sk->sk_user_data = NULL; + sk->sk_data_ready = sc->sc_data_ready; + sk->sk_state_change = sc->sc_state_change; + } + write_unlock_bh(&sk->sk_callback_lock); + + return ret; +} + +/* + * this is a little helper that is called by callers who have seen a problem + * with an sc and want to detach it from the nn if someone already hasn't beat + * them to it. if an error is given then the shutdown will be persistent + * and pending transmits will be canceled. + */ +static void r2net_ensure_shutdown(struct r2net_node *nn, + struct r2net_sock_container *sc, + int err) +{ + spin_lock(&nn->nn_lock); + if (nn->nn_sc == sc) + r2net_set_nn_state(nn, NULL, 0, err); + spin_unlock(&nn->nn_lock); +} + +/* + * This work queue function performs the blocking parts of socket shutdown. A + * few paths lead here. set_nn_state will trigger this callback if it sees an + * sc detached from the nn. state_change will also trigger this callback + * directly when it sees errors. In that case we need to call set_nn_state + * ourselves as state_change couldn't get the nn_lock and call set_nn_state + * itself. + */ +static void r2net_shutdown_sc(struct work_struct *work) +{ + struct r2net_sock_container *sc = + container_of(work, struct r2net_sock_container, + sc_shutdown_work); + struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); + + sclog(sc, "shutting down\n"); + + /* drop the callbacks ref and call shutdown only once */ + if (r2net_unregister_callbacks(sc->sc_sock->sk, sc)) { + /* we shouldn't flush as we're in the thread, the + * races with pending sc work structs are harmless */ + del_timer_sync(&sc->sc_idle_timeout); + r2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); + sc_put(sc); + kernel_sock_shutdown(sc->sc_sock, SHUT_RDWR); + } + + /* not fatal so failed connects before the other guy has our + * heartbeat can be retried */ + r2net_ensure_shutdown(nn, sc, 0); + sc_put(sc); +} + +/* ------------------------------------------------------------ */ + +static int r2net_handler_cmp(struct r2net_msg_handler *nmh, u32 msg_type, + u32 key) +{ + int ret = memcmp(&nmh->nh_key, &key, sizeof(key)); + + if (ret == 0) + ret = memcmp(&nmh->nh_msg_type, &msg_type, sizeof(msg_type)); + + return ret; +} + +static struct r2net_msg_handler * +r2net_handler_tree_lookup(u32 msg_type, u32 key, struct rb_node ***ret_p, + struct rb_node **ret_parent) +{ + struct rb_node **p = &r2net_handler_tree.rb_node; + struct rb_node *parent = NULL; + struct r2net_msg_handler *nmh, *ret = NULL; + int cmp; + + while (*p) { + parent = *p; + nmh = rb_entry(parent, struct r2net_msg_handler, nh_node); + cmp = r2net_handler_cmp(nmh, msg_type, key); + + if (cmp < 0) + p = &(*p)->rb_left; + else if (cmp > 0) + p = &(*p)->rb_right; + else { + ret = nmh; + break; + } + } + + if (ret_p != NULL) + *ret_p = p; + if (ret_parent != NULL) + *ret_parent = parent; + + return ret; +} + +static void r2net_handler_kref_release(struct kref *kref) +{ + struct r2net_msg_handler *nmh; + nmh = container_of(kref, struct r2net_msg_handler, nh_kref); + + kfree(nmh); +} + +static void r2net_handler_put(struct r2net_msg_handler *nmh) +{ + kref_put(&nmh->nh_kref, r2net_handler_kref_release); +} + +/* max_len is protection for the handler func. incoming messages won't + * be given to the handler if their payload is longer than the max. */ +int r2net_register_handler(u32 msg_type, u32 key, u32 max_len, + r2net_msg_handler_func *func, void *data, + r2net_post_msg_handler_func *post_func, + struct list_head *unreg_list) +{ + struct r2net_msg_handler *nmh = NULL; + struct rb_node **p, *parent; + int ret = 0; + + if (max_len > R2NET_MAX_PAYLOAD_BYTES) { + mlog(0, "max_len for message handler out of range: %u\n", + max_len); + ret = -EINVAL; + goto out; + } + + if (!msg_type) { + mlog(0, "no message type provided: %u, %p\n", msg_type, func); + ret = -EINVAL; + goto out; + + } + if (!func) { + mlog(0, "no message handler provided: %u, %p\n", + msg_type, func); + ret = -EINVAL; + goto out; + } + + nmh = kzalloc(sizeof(struct r2net_msg_handler), GFP_NOFS); + if (nmh == NULL) { + ret = -ENOMEM; + goto out; + } + + nmh->nh_func = func; + nmh->nh_func_data = data; + nmh->nh_post_func = post_func; + nmh->nh_msg_type = msg_type; + nmh->nh_max_len = max_len; + nmh->nh_key = key; + /* the tree and list get this ref.. they're both removed in + * unregister when this ref is dropped */ + kref_init(&nmh->nh_kref); + INIT_LIST_HEAD(&nmh->nh_unregister_item); + + write_lock(&r2net_handler_lock); + if (r2net_handler_tree_lookup(msg_type, key, &p, &parent)) + ret = -EEXIST; + else { + rb_link_node(&nmh->nh_node, parent, p); + rb_insert_color(&nmh->nh_node, &r2net_handler_tree); + list_add_tail(&nmh->nh_unregister_item, unreg_list); + + mlog(ML_TCP, "registered handler func %p type %u key %08x\n", + func, msg_type, key); + /* we've had some trouble with handlers seemingly vanishing. */ + mlog_bug_on_msg(r2net_handler_tree_lookup(msg_type, key, &p, + &parent) == NULL, + "couldn't find handler we *just* registered " + "for type %u key %08x\n", msg_type, key); + } + write_unlock(&r2net_handler_lock); + if (ret) + goto out; + +out: + if (ret) + kfree(nmh); + + return ret; +} +EXPORT_SYMBOL_GPL(r2net_register_handler); + +void r2net_unregister_handler_list(struct list_head *list) +{ + struct r2net_msg_handler *nmh, *n; + + write_lock(&r2net_handler_lock); + list_for_each_entry_safe(nmh, n, list, nh_unregister_item) { + mlog(ML_TCP, "unregistering handler func %p type %u key %08x\n", + nmh->nh_func, nmh->nh_msg_type, nmh->nh_key); + rb_erase(&nmh->nh_node, &r2net_handler_tree); + list_del_init(&nmh->nh_unregister_item); + kref_put(&nmh->nh_kref, r2net_handler_kref_release); + } + write_unlock(&r2net_handler_lock); +} +EXPORT_SYMBOL_GPL(r2net_unregister_handler_list); + +static struct r2net_msg_handler *r2net_handler_get(u32 msg_type, u32 key) +{ + struct r2net_msg_handler *nmh; + + read_lock(&r2net_handler_lock); + nmh = r2net_handler_tree_lookup(msg_type, key, NULL, NULL); + if (nmh) + kref_get(&nmh->nh_kref); + read_unlock(&r2net_handler_lock); + + return nmh; +} + +/* ------------------------------------------------------------ */ + +static int r2net_recv_tcp_msg(struct socket *sock, void *data, size_t len) +{ + int ret; + mm_segment_t oldfs; + struct kvec vec = { + .iov_len = len, + .iov_base = data, + }; + struct msghdr msg = { + .msg_iovlen = 1, + .msg_iov = (struct iovec *)&vec, + .msg_flags = MSG_DONTWAIT, + }; + + oldfs = get_fs(); + set_fs(get_ds()); + ret = sock_recvmsg(sock, &msg, len, msg.msg_flags); + set_fs(oldfs); + + return ret; +} + +static int r2net_send_tcp_msg(struct socket *sock, struct kvec *vec, + size_t veclen, size_t total) +{ + int ret; + mm_segment_t oldfs; + struct msghdr msg = { + .msg_iov = (struct iovec *)vec, + .msg_iovlen = veclen, + }; + + if (sock == NULL) { + ret = -EINVAL; + goto out; + } + + oldfs = get_fs(); + set_fs(get_ds()); + ret = sock_sendmsg(sock, &msg, total); + set_fs(oldfs); + if (ret != total) { + mlog(ML_ERROR, "sendmsg returned %d instead of %zu\n", ret, + total); + if (ret >= 0) + ret = -EPIPE; /* should be smarter, I bet */ + goto out; + } + + ret = 0; +out: + if (ret < 0) + mlog(0, "returning error: %d\n", ret); + return ret; +} + +static void r2net_sendpage(struct r2net_sock_container *sc, + void *kmalloced_virt, + size_t size) +{ + struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); + ssize_t ret; + + while (1) { + mutex_lock(&sc->sc_send_lock); + ret = sc->sc_sock->ops->sendpage(sc->sc_sock, + virt_to_page(kmalloced_virt), + (long)kmalloced_virt & ~PAGE_MASK, + size, MSG_DONTWAIT); + mutex_unlock(&sc->sc_send_lock); + if (ret == size) + break; + if (ret == (ssize_t)-EAGAIN) { + mlog(0, "sendpage of size %zu to " SC_NODEF_FMT + " returned EAGAIN\n", size, sc->sc_node->nd_name, + sc->sc_node->nd_num, + &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port)); + cond_resched(); + continue; + } + mlog(ML_ERROR, "sendpage of size %zu to " SC_NODEF_FMT + " failed with %zd\n", size, sc->sc_node->nd_name, + sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), ret); + r2net_ensure_shutdown(nn, sc, 0); + break; + } +} + +static void r2net_init_msg(struct r2net_msg *msg, u16 data_len, + u16 msg_type, u32 key) +{ + memset(msg, 0, sizeof(struct r2net_msg)); + msg->magic = cpu_to_be16(R2NET_MSG_MAGIC); + msg->data_len = cpu_to_be16(data_len); + msg->msg_type = cpu_to_be16(msg_type); + msg->sys_status = cpu_to_be32(R2NET_ERR_NONE); + msg->status = 0; + msg->key = cpu_to_be32(key); +} + +static int r2net_tx_can_proceed(struct r2net_node *nn, + struct r2net_sock_container **sc_ret, + int *error) +{ + int ret = 0; + + spin_lock(&nn->nn_lock); + if (nn->nn_persistent_error) { + ret = 1; + *sc_ret = NULL; + *error = nn->nn_persistent_error; + } else if (nn->nn_sc_valid) { + kref_get(&nn->nn_sc->sc_kref); + + ret = 1; + *sc_ret = nn->nn_sc; + *error = 0; + } + spin_unlock(&nn->nn_lock); + + return ret; +} + +/* Get a map of all nodes to which this node is currently connected to */ +void r2net_fill_node_map(unsigned long *map, unsigned bytes) +{ + struct r2net_sock_container *sc; + int node, ret; + + BUG_ON(bytes < (BITS_TO_LONGS(R2NM_MAX_NODES) * sizeof(unsigned long))); + + memset(map, 0, bytes); + for (node = 0; node < R2NM_MAX_NODES; ++node) { + r2net_tx_can_proceed(r2net_nn_from_num(node), &sc, &ret); + if (!ret) { + set_bit(node, map); + sc_put(sc); + } + } +} +EXPORT_SYMBOL_GPL(r2net_fill_node_map); + +int r2net_send_message_vec(u32 msg_type, u32 key, struct kvec *caller_vec, + size_t caller_veclen, u8 target_node, int *status) +{ + int ret = 0; + struct r2net_msg *msg = NULL; + size_t veclen, caller_bytes = 0; + struct kvec *vec = NULL; + struct r2net_sock_container *sc = NULL; + struct r2net_node *nn = r2net_nn_from_num(target_node); + struct r2net_status_wait nsw = { + .ns_node_item = LIST_HEAD_INIT(nsw.ns_node_item), + }; + struct r2net_send_tracking nst; + + /* this may be a general bug fix */ + init_waitqueue_head(&nsw.ns_wq); + + r2net_init_nst(&nst, msg_type, key, current, target_node); + + if (r2net_wq == NULL) { + mlog(0, "attempt to tx without r2netd running\n"); + ret = -ESRCH; + goto out; + } + + if (caller_veclen == 0) { + mlog(0, "bad kvec array length\n"); + ret = -EINVAL; + goto out; + } + + caller_bytes = iov_length((struct iovec *)caller_vec, caller_veclen); + if (caller_bytes > R2NET_MAX_PAYLOAD_BYTES) { + mlog(0, "total payload len %zu too large\n", caller_bytes); + ret = -EINVAL; + goto out; + } + + if (target_node == r2nm_this_node()) { + ret = -ELOOP; + goto out; + } + + r2net_debug_add_nst(&nst); + + r2net_set_nst_sock_time(&nst); + + wait_event(nn->nn_sc_wq, r2net_tx_can_proceed(nn, &sc, &ret)); + if (ret) + goto out; + + r2net_set_nst_sock_container(&nst, sc); + + veclen = caller_veclen + 1; + vec = kmalloc(sizeof(struct kvec) * veclen, GFP_ATOMIC); + if (vec == NULL) { + mlog(0, "failed to %zu element kvec!\n", veclen); + ret = -ENOMEM; + goto out; + } + + msg = kmalloc(sizeof(struct r2net_msg), GFP_ATOMIC); + if (!msg) { + mlog(0, "failed to allocate a r2net_msg!\n"); + ret = -ENOMEM; + goto out; + } + + r2net_init_msg(msg, caller_bytes, msg_type, key); + + vec[0].iov_len = sizeof(struct r2net_msg); + vec[0].iov_base = msg; + memcpy(&vec[1], caller_vec, caller_veclen * sizeof(struct kvec)); + + ret = r2net_prep_nsw(nn, &nsw); + if (ret) + goto out; + + msg->msg_num = cpu_to_be32(nsw.ns_id); + r2net_set_nst_msg_id(&nst, nsw.ns_id); + + r2net_set_nst_send_time(&nst); + + /* finally, convert the message header to network byte-order + * and send */ + mutex_lock(&sc->sc_send_lock); + ret = r2net_send_tcp_msg(sc->sc_sock, vec, veclen, + sizeof(struct r2net_msg) + caller_bytes); + mutex_unlock(&sc->sc_send_lock); + msglog(msg, "sending returned %d\n", ret); + if (ret < 0) { + mlog(0, "error returned from r2net_send_tcp_msg=%d\n", ret); + goto out; + } + + /* wait on other node's handler */ + r2net_set_nst_status_time(&nst); + wait_event(nsw.ns_wq, r2net_nsw_completed(nn, &nsw) || + nn->nn_persistent_error || !nn->nn_sc_valid); + + r2net_update_send_stats(&nst, sc); + + /* Note that we avoid overwriting the callers status return + * variable if a system error was reported on the other + * side. Callers beware. */ + ret = r2net_sys_err_to_errno(nsw.ns_sys_status); + if (status && !ret) + *status = nsw.ns_status; + + mlog(0, "woken, returning system status %d, user status %d\n", + ret, nsw.ns_status); +out: + r2net_debug_del_nst(&nst); /* must be before dropping sc and node */ + if (sc) + sc_put(sc); + kfree(vec); + kfree(msg); + r2net_complete_nsw(nn, &nsw, 0, 0, 0); + return ret; +} +EXPORT_SYMBOL_GPL(r2net_send_message_vec); + +int r2net_send_message(u32 msg_type, u32 key, void *data, u32 len, + u8 target_node, int *status) +{ + struct kvec vec = { + .iov_base = data, + .iov_len = len, + }; + return r2net_send_message_vec(msg_type, key, &vec, 1, + target_node, status); +} +EXPORT_SYMBOL_GPL(r2net_send_message); + +static int r2net_send_status_magic(struct socket *sock, struct r2net_msg *hdr, + enum r2net_system_error syserr, int err) +{ + struct kvec vec = { + .iov_base = hdr, + .iov_len = sizeof(struct r2net_msg), + }; + + BUG_ON(syserr >= R2NET_ERR_MAX); + + /* leave other fields intact from the incoming message, msg_num + * in particular */ + hdr->sys_status = cpu_to_be32(syserr); + hdr->status = cpu_to_be32(err); + /* twiddle the magic */ + hdr->magic = cpu_to_be16(R2NET_MSG_STATUS_MAGIC); + hdr->data_len = 0; + + msglog(hdr, "about to send status magic %d\n", err); + /* hdr has been in host byteorder this whole time */ + return r2net_send_tcp_msg(sock, &vec, 1, sizeof(struct r2net_msg)); +} + +/* + * "data magic" is a long version of "status magic" where the message + * payload actually contains data to be passed in reply to certain messages + */ +static int r2net_send_data_magic(struct r2net_sock_container *sc, + struct r2net_msg *hdr, + void *data, size_t data_len, + enum r2net_system_error syserr, int err) +{ + struct kvec vec[2]; + int ret; + + vec[0].iov_base = hdr; + vec[0].iov_len = sizeof(struct r2net_msg); + vec[1].iov_base = data; + vec[1].iov_len = data_len; + + BUG_ON(syserr >= R2NET_ERR_MAX); + + /* leave other fields intact from the incoming message, msg_num + * in particular */ + hdr->sys_status = cpu_to_be32(syserr); + hdr->status = cpu_to_be32(err); + hdr->magic = cpu_to_be16(R2NET_MSG_DATA_MAGIC); /* twiddle magic */ + hdr->data_len = cpu_to_be16(data_len); + + msglog(hdr, "about to send data magic %d\n", err); + /* hdr has been in host byteorder this whole time */ + ret = r2net_send_tcp_msg(sc->sc_sock, vec, 2, + sizeof(struct r2net_msg) + data_len); + return ret; +} + +/* + * called by a message handler to convert an otherwise normal reply + * message into a "data magic" message + */ +void r2net_force_data_magic(struct r2net_msg *hdr, u16 msgtype, u32 msgkey) +{ + hdr->magic = cpu_to_be16(R2NET_MSG_DATA_MAGIC); + hdr->msg_type = cpu_to_be16(msgtype); + hdr->key = cpu_to_be32(msgkey); +} + +/* this returns -errno if the header was unknown or too large, etc. + * after this is called the buffer us reused for the next message */ +static int r2net_process_message(struct r2net_sock_container *sc, + struct r2net_msg *hdr) +{ + struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); + int ret = 0, handler_status; + enum r2net_system_error syserr; + struct r2net_msg_handler *nmh = NULL; + void *ret_data = NULL; + int data_magic = 0; + + msglog(hdr, "processing message\n"); + + r2net_sc_postpone_idle(sc); + + switch (be16_to_cpu(hdr->magic)) { + + case R2NET_MSG_STATUS_MAGIC: + /* special type for returning message status */ + r2net_complete_nsw(nn, NULL, be32_to_cpu(hdr->msg_num), + be32_to_cpu(hdr->sys_status), + be32_to_cpu(hdr->status)); + goto out; + case R2NET_MSG_KEEP_REQ_MAGIC: + r2net_sendpage(sc, r2net_keep_resp, sizeof(*r2net_keep_resp)); + goto out; + case R2NET_MSG_KEEP_RESP_MAGIC: + goto out; + case R2NET_MSG_MAGIC: + break; + case R2NET_MSG_DATA_MAGIC: + /* + * unlike a normal status magic, a data magic DOES + * (MUST) have a handler, so the control flow is + * a little funky here as a result + */ + data_magic = 1; + break; + default: + msglog(hdr, "bad magic\n"); + ret = -EINVAL; + goto out; + break; + } + + /* find a handler for it */ + handler_status = 0; + nmh = r2net_handler_get(be16_to_cpu(hdr->msg_type), + be32_to_cpu(hdr->key)); + if (!nmh) { + mlog(ML_TCP, "couldn't find handler for type %u key %08x\n", + be16_to_cpu(hdr->msg_type), be32_to_cpu(hdr->key)); + syserr = R2NET_ERR_NO_HNDLR; + goto out_respond; + } + + syserr = R2NET_ERR_NONE; + + if (be16_to_cpu(hdr->data_len) > nmh->nh_max_len) + syserr = R2NET_ERR_OVERFLOW; + + if (syserr != R2NET_ERR_NONE) { + pr_err("ramster_r2net, message length problem\n"); + goto out_respond; + } + + r2net_set_func_start_time(sc); + sc->sc_msg_key = be32_to_cpu(hdr->key); + sc->sc_msg_type = be16_to_cpu(hdr->msg_type); + handler_status = (nmh->nh_func)(hdr, sizeof(struct r2net_msg) + + be16_to_cpu(hdr->data_len), + nmh->nh_func_data, &ret_data); + if (data_magic) { + /* + * handler handled data sent in reply to request + * so complete the transaction + */ + r2net_complete_nsw(nn, NULL, be32_to_cpu(hdr->msg_num), + be32_to_cpu(hdr->sys_status), handler_status); + goto out; + } + /* + * handler changed magic to DATA_MAGIC to reply to request for data, + * implies ret_data points to data to return and handler_status + * is the number of bytes of data + */ + if (be16_to_cpu(hdr->magic) == R2NET_MSG_DATA_MAGIC) { + ret = r2net_send_data_magic(sc, hdr, + ret_data, handler_status, + syserr, 0); + hdr = NULL; + mlog(0, "sending data reply %d, syserr %d returned %d\n", + handler_status, syserr, ret); + r2net_set_func_stop_time(sc); + + r2net_update_recv_stats(sc); + goto out; + } + r2net_set_func_stop_time(sc); + + r2net_update_recv_stats(sc); + +out_respond: + /* this destroys the hdr, so don't use it after this */ + mutex_lock(&sc->sc_send_lock); + ret = r2net_send_status_magic(sc->sc_sock, hdr, syserr, + handler_status); + mutex_unlock(&sc->sc_send_lock); + hdr = NULL; + mlog(0, "sending handler status %d, syserr %d returned %d\n", + handler_status, syserr, ret); + + if (nmh) { + BUG_ON(ret_data != NULL && nmh->nh_post_func == NULL); + if (nmh->nh_post_func) + (nmh->nh_post_func)(handler_status, nmh->nh_func_data, + ret_data); + } + +out: + if (nmh) + r2net_handler_put(nmh); + return ret; +} + +static int r2net_check_handshake(struct r2net_sock_container *sc) +{ + struct r2net_handshake *hand = page_address(sc->sc_page); + struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); + + if (hand->protocol_version != cpu_to_be64(R2NET_PROTOCOL_VERSION)) { + pr_notice("ramster: " SC_NODEF_FMT " Advertised net " + "protocol version %llu but %llu is required. " + "Disconnecting.\n", sc->sc_node->nd_name, + sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), + (unsigned long long)be64_to_cpu(hand->protocol_version), + R2NET_PROTOCOL_VERSION); + + /* don't bother reconnecting if its the wrong version. */ + r2net_ensure_shutdown(nn, sc, -ENOTCONN); + return -1; + } + + /* + * Ensure timeouts are consistent with other nodes, otherwise + * we can end up with one node thinking that the other must be down, + * but isn't. This can ultimately cause corruption. + */ + if (be32_to_cpu(hand->r2net_idle_timeout_ms) != + r2net_idle_timeout()) { + pr_notice("ramster: " SC_NODEF_FMT " uses a network " + "idle timeout of %u ms, but we use %u ms locally. " + "Disconnecting.\n", sc->sc_node->nd_name, + sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), + be32_to_cpu(hand->r2net_idle_timeout_ms), + r2net_idle_timeout()); + r2net_ensure_shutdown(nn, sc, -ENOTCONN); + return -1; + } + + if (be32_to_cpu(hand->r2net_keepalive_delay_ms) != + r2net_keepalive_delay()) { + pr_notice("ramster: " SC_NODEF_FMT " uses a keepalive " + "delay of %u ms, but we use %u ms locally. " + "Disconnecting.\n", sc->sc_node->nd_name, + sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), + be32_to_cpu(hand->r2net_keepalive_delay_ms), + r2net_keepalive_delay()); + r2net_ensure_shutdown(nn, sc, -ENOTCONN); + return -1; + } + + if (be32_to_cpu(hand->r2hb_heartbeat_timeout_ms) != + R2HB_MAX_WRITE_TIMEOUT_MS) { + pr_notice("ramster: " SC_NODEF_FMT " uses a heartbeat " + "timeout of %u ms, but we use %u ms locally. " + "Disconnecting.\n", sc->sc_node->nd_name, + sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), + be32_to_cpu(hand->r2hb_heartbeat_timeout_ms), + R2HB_MAX_WRITE_TIMEOUT_MS); + r2net_ensure_shutdown(nn, sc, -ENOTCONN); + return -1; + } + + sc->sc_handshake_ok = 1; + + spin_lock(&nn->nn_lock); + /* set valid and queue the idle timers only if it hasn't been + * shut down already */ + if (nn->nn_sc == sc) { + r2net_sc_reset_idle_timer(sc); + atomic_set(&nn->nn_timeout, 0); + r2net_set_nn_state(nn, sc, 1, 0); + } + spin_unlock(&nn->nn_lock); + + /* shift everything up as though it wasn't there */ + sc->sc_page_off -= sizeof(struct r2net_handshake); + if (sc->sc_page_off) + memmove(hand, hand + 1, sc->sc_page_off); + + return 0; +} + +/* this demuxes the queued rx bytes into header or payload bits and calls + * handlers as each full message is read off the socket. it returns -error, + * == 0 eof, or > 0 for progress made.*/ +static int r2net_advance_rx(struct r2net_sock_container *sc) +{ + struct r2net_msg *hdr; + int ret = 0; + void *data; + size_t datalen; + + sclog(sc, "receiving\n"); + r2net_set_advance_start_time(sc); + + if (unlikely(sc->sc_handshake_ok == 0)) { + if (sc->sc_page_off < sizeof(struct r2net_handshake)) { + data = page_address(sc->sc_page) + sc->sc_page_off; + datalen = sizeof(struct r2net_handshake) - + sc->sc_page_off; + ret = r2net_recv_tcp_msg(sc->sc_sock, data, datalen); + if (ret > 0) + sc->sc_page_off += ret; + } + + if (sc->sc_page_off == sizeof(struct r2net_handshake)) { + r2net_check_handshake(sc); + if (unlikely(sc->sc_handshake_ok == 0)) + ret = -EPROTO; + } + goto out; + } + + /* do we need more header? */ + if (sc->sc_page_off < sizeof(struct r2net_msg)) { + data = page_address(sc->sc_page) + sc->sc_page_off; + datalen = sizeof(struct r2net_msg) - sc->sc_page_off; + ret = r2net_recv_tcp_msg(sc->sc_sock, data, datalen); + if (ret > 0) { + sc->sc_page_off += ret; + /* only swab incoming here.. we can + * only get here once as we cross from + * being under to over */ + if (sc->sc_page_off == sizeof(struct r2net_msg)) { + hdr = page_address(sc->sc_page); + if (be16_to_cpu(hdr->data_len) > + R2NET_MAX_PAYLOAD_BYTES) + ret = -EOVERFLOW; + WARN_ON_ONCE(ret == -EOVERFLOW); + } + } + if (ret <= 0) + goto out; + } + + if (sc->sc_page_off < sizeof(struct r2net_msg)) { + /* oof, still don't have a header */ + goto out; + } + + /* this was swabbed above when we first read it */ + hdr = page_address(sc->sc_page); + + msglog(hdr, "at page_off %zu\n", sc->sc_page_off); + + /* do we need more payload? */ + if (sc->sc_page_off - sizeof(struct r2net_msg) < + be16_to_cpu(hdr->data_len)) { + /* need more payload */ + data = page_address(sc->sc_page) + sc->sc_page_off; + datalen = (sizeof(struct r2net_msg) + + be16_to_cpu(hdr->data_len)) - + sc->sc_page_off; + ret = r2net_recv_tcp_msg(sc->sc_sock, data, datalen); + if (ret > 0) + sc->sc_page_off += ret; + if (ret <= 0) + goto out; + } + + if (sc->sc_page_off - sizeof(struct r2net_msg) == + be16_to_cpu(hdr->data_len)) { + /* we can only get here once, the first time we read + * the payload.. so set ret to progress if the handler + * works out. after calling this the message is toast */ + ret = r2net_process_message(sc, hdr); + if (ret == 0) + ret = 1; + sc->sc_page_off = 0; + } + +out: + sclog(sc, "ret = %d\n", ret); + r2net_set_advance_stop_time(sc); + return ret; +} + +/* this work func is triggerd by data ready. it reads until it can read no + * more. it interprets 0, eof, as fatal. if data_ready hits while we're doing + * our work the work struct will be marked and we'll be called again. */ +static void r2net_rx_until_empty(struct work_struct *work) +{ + struct r2net_sock_container *sc = + container_of(work, struct r2net_sock_container, sc_rx_work); + int ret; + + do { + ret = r2net_advance_rx(sc); + } while (ret > 0); + + if (ret <= 0 && ret != -EAGAIN) { + struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); + sclog(sc, "saw error %d, closing\n", ret); + /* not permanent so read failed handshake can retry */ + r2net_ensure_shutdown(nn, sc, 0); + } + sc_put(sc); +} + +static int r2net_set_nodelay(struct socket *sock) +{ + int ret, val = 1; + mm_segment_t oldfs; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + + /* + * Dear unsuspecting programmer, + * + * Don't use sock_setsockopt() for SOL_TCP. It doesn't check its level + * argument and assumes SOL_SOCKET so, say, your TCP_NODELAY will + * silently turn into SO_DEBUG. + * + * Yours, + * Keeper of hilariously fragile interfaces. + */ + ret = sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, + (char __user *)&val, sizeof(val)); + + set_fs(oldfs); + return ret; +} + +static void r2net_initialize_handshake(void) +{ + r2net_hand->r2hb_heartbeat_timeout_ms = cpu_to_be32( + R2HB_MAX_WRITE_TIMEOUT_MS); + r2net_hand->r2net_idle_timeout_ms = cpu_to_be32(r2net_idle_timeout()); + r2net_hand->r2net_keepalive_delay_ms = cpu_to_be32( + r2net_keepalive_delay()); + r2net_hand->r2net_reconnect_delay_ms = cpu_to_be32( + r2net_reconnect_delay()); +} + +/* ------------------------------------------------------------ */ + +/* called when a connect completes and after a sock is accepted. the + * rx path will see the response and mark the sc valid */ +static void r2net_sc_connect_completed(struct work_struct *work) +{ + struct r2net_sock_container *sc = + container_of(work, struct r2net_sock_container, + sc_connect_work); + + mlog(ML_MSG, "sc sending handshake with ver %llu id %llx\n", + (unsigned long long)R2NET_PROTOCOL_VERSION, + (unsigned long long)be64_to_cpu(r2net_hand->connector_id)); + + r2net_initialize_handshake(); + r2net_sendpage(sc, r2net_hand, sizeof(*r2net_hand)); + sc_put(sc); +} + +/* this is called as a work_struct func. */ +static void r2net_sc_send_keep_req(struct work_struct *work) +{ + struct r2net_sock_container *sc = + container_of(work, struct r2net_sock_container, + sc_keepalive_work.work); + + r2net_sendpage(sc, r2net_keep_req, sizeof(*r2net_keep_req)); + sc_put(sc); +} + +/* socket shutdown does a del_timer_sync against this as it tears down. + * we can't start this timer until we've got to the point in sc buildup + * where shutdown is going to be involved */ +static void r2net_idle_timer(unsigned long data) +{ + struct r2net_sock_container *sc = (struct r2net_sock_container *)data; + struct r2net_node *nn = r2net_nn_from_num(sc->sc_node->nd_num); +#ifdef CONFIG_DEBUG_FS + unsigned long msecs = ktime_to_ms(ktime_get()) - + ktime_to_ms(sc->sc_tv_timer); +#else + unsigned long msecs = r2net_idle_timeout(); +#endif + + pr_notice("ramster: Connection to " SC_NODEF_FMT " has been " + "idle for %lu.%lu secs, shutting it down.\n", + sc->sc_node->nd_name, sc->sc_node->nd_num, + &sc->sc_node->nd_ipv4_address, ntohs(sc->sc_node->nd_ipv4_port), + msecs / 1000, msecs % 1000); + + /* + * Initialize the nn_timeout so that the next connection attempt + * will continue in r2net_start_connect. + */ + atomic_set(&nn->nn_timeout, 1); + r2net_sc_queue_work(sc, &sc->sc_shutdown_work); +} + +static void r2net_sc_reset_idle_timer(struct r2net_sock_container *sc) +{ + r2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); + r2net_sc_queue_delayed_work(sc, &sc->sc_keepalive_work, + msecs_to_jiffies(r2net_keepalive_delay())); + r2net_set_sock_timer(sc); + mod_timer(&sc->sc_idle_timeout, + jiffies + msecs_to_jiffies(r2net_idle_timeout())); +} + +static void r2net_sc_postpone_idle(struct r2net_sock_container *sc) +{ + /* Only push out an existing timer */ + if (timer_pending(&sc->sc_idle_timeout)) + r2net_sc_reset_idle_timer(sc); +} + +/* this work func is kicked whenever a path sets the nn state which doesn't + * have valid set. This includes seeing hb come up, losing a connection, + * having a connect attempt fail, etc. This centralizes the logic which decides + * if a connect attempt should be made or if we should give up and all future + * transmit attempts should fail */ +static void r2net_start_connect(struct work_struct *work) +{ + struct r2net_node *nn = + container_of(work, struct r2net_node, nn_connect_work.work); + struct r2net_sock_container *sc = NULL; + struct r2nm_node *node = NULL, *mynode = NULL; + struct socket *sock = NULL; + struct sockaddr_in myaddr = {0, }, remoteaddr = {0, }; + int ret = 0, stop; + unsigned int timeout; + + /* if we're greater we initiate tx, otherwise we accept */ + if (r2nm_this_node() <= r2net_num_from_nn(nn)) + goto out; + + /* watch for racing with tearing a node down */ + node = r2nm_get_node_by_num(r2net_num_from_nn(nn)); + if (node == NULL) { + ret = 0; + goto out; + } + + mynode = r2nm_get_node_by_num(r2nm_this_node()); + if (mynode == NULL) { + ret = 0; + goto out; + } + + spin_lock(&nn->nn_lock); + /* + * see if we already have one pending or have given up. + * For nn_timeout, it is set when we close the connection + * because of the idle time out. So it means that we have + * at least connected to that node successfully once, + * now try to connect to it again. + */ + timeout = atomic_read(&nn->nn_timeout); + stop = (nn->nn_sc || + (nn->nn_persistent_error && + (nn->nn_persistent_error != -ENOTCONN || timeout == 0))); + spin_unlock(&nn->nn_lock); + if (stop) + goto out; + + nn->nn_last_connect_attempt = jiffies; + + sc = sc_alloc(node); + if (sc == NULL) { + mlog(0, "couldn't allocate sc\n"); + ret = -ENOMEM; + goto out; + } + + ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); + if (ret < 0) { + mlog(0, "can't create socket: %d\n", ret); + goto out; + } + sc->sc_sock = sock; /* freed by sc_kref_release */ + + sock->sk->sk_allocation = GFP_ATOMIC; + + myaddr.sin_family = AF_INET; + myaddr.sin_addr.s_addr = mynode->nd_ipv4_address; + myaddr.sin_port = htons(0); /* any port */ + + ret = sock->ops->bind(sock, (struct sockaddr *)&myaddr, + sizeof(myaddr)); + if (ret) { + mlog(ML_ERROR, "bind failed with %d at address %pI4\n", + ret, &mynode->nd_ipv4_address); + goto out; + } + + ret = r2net_set_nodelay(sc->sc_sock); + if (ret) { + mlog(ML_ERROR, "setting TCP_NODELAY failed with %d\n", ret); + goto out; + } + + r2net_register_callbacks(sc->sc_sock->sk, sc); + + spin_lock(&nn->nn_lock); + /* handshake completion will set nn->nn_sc_valid */ + r2net_set_nn_state(nn, sc, 0, 0); + spin_unlock(&nn->nn_lock); + + remoteaddr.sin_family = AF_INET; + remoteaddr.sin_addr.s_addr = node->nd_ipv4_address; + remoteaddr.sin_port = node->nd_ipv4_port; + + ret = sc->sc_sock->ops->connect(sc->sc_sock, + (struct sockaddr *)&remoteaddr, + sizeof(remoteaddr), + O_NONBLOCK); + if (ret == -EINPROGRESS) + ret = 0; + +out: + if (ret) { + pr_notice("ramster: Connect attempt to " SC_NODEF_FMT + " failed with errno %d\n", sc->sc_node->nd_name, + sc->sc_node->nd_num, &sc->sc_node->nd_ipv4_address, + ntohs(sc->sc_node->nd_ipv4_port), ret); + /* 0 err so that another will be queued and attempted + * from set_nn_state */ + if (sc) + r2net_ensure_shutdown(nn, sc, 0); + } + if (sc) + sc_put(sc); + if (node) + r2nm_node_put(node); + if (mynode) + r2nm_node_put(mynode); + + return; +} + +static void r2net_connect_expired(struct work_struct *work) +{ + struct r2net_node *nn = + container_of(work, struct r2net_node, nn_connect_expired.work); + + spin_lock(&nn->nn_lock); + if (!nn->nn_sc_valid) { + pr_notice("ramster: No connection established with " + "node %u after %u.%u seconds, giving up.\n", + r2net_num_from_nn(nn), + r2net_idle_timeout() / 1000, + r2net_idle_timeout() % 1000); + + r2net_set_nn_state(nn, NULL, 0, -ENOTCONN); + } + spin_unlock(&nn->nn_lock); +} + +static void r2net_still_up(struct work_struct *work) +{ +} + +/* ------------------------------------------------------------ */ + +void r2net_disconnect_node(struct r2nm_node *node) +{ + struct r2net_node *nn = r2net_nn_from_num(node->nd_num); + + /* don't reconnect until it's heartbeating again */ + spin_lock(&nn->nn_lock); + atomic_set(&nn->nn_timeout, 0); + r2net_set_nn_state(nn, NULL, 0, -ENOTCONN); + spin_unlock(&nn->nn_lock); + + if (r2net_wq) { + cancel_delayed_work(&nn->nn_connect_expired); + cancel_delayed_work(&nn->nn_connect_work); + cancel_delayed_work(&nn->nn_still_up); + flush_workqueue(r2net_wq); + } +} + +static void r2net_hb_node_down_cb(struct r2nm_node *node, int node_num, + void *data) +{ + if (!node) + return; + + if (node_num != r2nm_this_node()) + r2net_disconnect_node(node); + + BUG_ON(atomic_read(&r2net_connected_peers) < 0); +} + +static void r2net_hb_node_up_cb(struct r2nm_node *node, int node_num, + void *data) +{ + struct r2net_node *nn = r2net_nn_from_num(node_num); + + BUG_ON(!node); + + /* ensure an immediate connect attempt */ + nn->nn_last_connect_attempt = jiffies - + (msecs_to_jiffies(r2net_reconnect_delay()) + 1); + + if (node_num != r2nm_this_node()) { + /* believe it or not, accept and node hearbeating testing + * can succeed for this node before we got here.. so + * only use set_nn_state to clear the persistent error + * if that hasn't already happened */ + spin_lock(&nn->nn_lock); + atomic_set(&nn->nn_timeout, 0); + if (nn->nn_persistent_error) + r2net_set_nn_state(nn, NULL, 0, 0); + spin_unlock(&nn->nn_lock); + } +} + +void r2net_unregister_hb_callbacks(void) +{ + r2hb_unregister_callback(NULL, &r2net_hb_up); + r2hb_unregister_callback(NULL, &r2net_hb_down); +} + +int r2net_register_hb_callbacks(void) +{ + int ret; + + r2hb_setup_callback(&r2net_hb_down, R2HB_NODE_DOWN_CB, + r2net_hb_node_down_cb, NULL, R2NET_HB_PRI); + r2hb_setup_callback(&r2net_hb_up, R2HB_NODE_UP_CB, + r2net_hb_node_up_cb, NULL, R2NET_HB_PRI); + + ret = r2hb_register_callback(NULL, &r2net_hb_up); + if (ret == 0) + ret = r2hb_register_callback(NULL, &r2net_hb_down); + + if (ret) + r2net_unregister_hb_callbacks(); + + return ret; +} + +/* ------------------------------------------------------------ */ + +static int r2net_accept_one(struct socket *sock) +{ + int ret, slen; + struct sockaddr_in sin; + struct socket *new_sock = NULL; + struct r2nm_node *node = NULL; + struct r2nm_node *local_node = NULL; + struct r2net_sock_container *sc = NULL; + struct r2net_node *nn; + + BUG_ON(sock == NULL); + ret = sock_create_lite(sock->sk->sk_family, sock->sk->sk_type, + sock->sk->sk_protocol, &new_sock); + if (ret) + goto out; + + new_sock->type = sock->type; + new_sock->ops = sock->ops; + ret = sock->ops->accept(sock, new_sock, O_NONBLOCK); + if (ret < 0) + goto out; + + new_sock->sk->sk_allocation = GFP_ATOMIC; + + ret = r2net_set_nodelay(new_sock); + if (ret) { + mlog(ML_ERROR, "setting TCP_NODELAY failed with %d\n", ret); + goto out; + } + + slen = sizeof(sin); + ret = new_sock->ops->getname(new_sock, (struct sockaddr *) &sin, + &slen, 1); + if (ret < 0) + goto out; + + node = r2nm_get_node_by_ip(sin.sin_addr.s_addr); + if (node == NULL) { + pr_notice("ramster: Attempt to connect from unknown " + "node at %pI4:%d\n", &sin.sin_addr.s_addr, + ntohs(sin.sin_port)); + ret = -EINVAL; + goto out; + } + + if (r2nm_this_node() >= node->nd_num) { + local_node = r2nm_get_node_by_num(r2nm_this_node()); + pr_notice("ramster: Unexpected connect attempt seen " + "at node '%s' (%u, %pI4:%d) from node '%s' (%u, " + "%pI4:%d)\n", local_node->nd_name, local_node->nd_num, + &(local_node->nd_ipv4_address), + ntohs(local_node->nd_ipv4_port), node->nd_name, + node->nd_num, &sin.sin_addr.s_addr, ntohs(sin.sin_port)); + ret = -EINVAL; + goto out; + } + + /* this happens all the time when the other node sees our heartbeat + * and tries to connect before we see their heartbeat */ + if (!r2hb_check_node_heartbeating_from_callback(node->nd_num)) { + mlog(ML_CONN, "attempt to connect from node '%s' at " + "%pI4:%d but it isn't heartbeating\n", + node->nd_name, &sin.sin_addr.s_addr, + ntohs(sin.sin_port)); + ret = -EINVAL; + goto out; + } + + nn = r2net_nn_from_num(node->nd_num); + + spin_lock(&nn->nn_lock); + if (nn->nn_sc) + ret = -EBUSY; + else + ret = 0; + spin_unlock(&nn->nn_lock); + if (ret) { + pr_notice("ramster: Attempt to connect from node '%s' " + "at %pI4:%d but it already has an open connection\n", + node->nd_name, &sin.sin_addr.s_addr, + ntohs(sin.sin_port)); + goto out; + } + + sc = sc_alloc(node); + if (sc == NULL) { + ret = -ENOMEM; + goto out; + } + + sc->sc_sock = new_sock; + new_sock = NULL; + + spin_lock(&nn->nn_lock); + atomic_set(&nn->nn_timeout, 0); + r2net_set_nn_state(nn, sc, 0, 0); + spin_unlock(&nn->nn_lock); + + r2net_register_callbacks(sc->sc_sock->sk, sc); + r2net_sc_queue_work(sc, &sc->sc_rx_work); + + r2net_initialize_handshake(); + r2net_sendpage(sc, r2net_hand, sizeof(*r2net_hand)); + +out: + if (new_sock) + sock_release(new_sock); + if (node) + r2nm_node_put(node); + if (local_node) + r2nm_node_put(local_node); + if (sc) + sc_put(sc); + return ret; +} + +static void r2net_accept_many(struct work_struct *work) +{ + struct socket *sock = r2net_listen_sock; + while (r2net_accept_one(sock) == 0) + cond_resched(); +} + +static void r2net_listen_data_ready(struct sock *sk, int bytes) +{ + void (*ready)(struct sock *sk, int bytes); + + read_lock(&sk->sk_callback_lock); + ready = sk->sk_user_data; + if (ready == NULL) { /* check for teardown race */ + ready = sk->sk_data_ready; + goto out; + } + + /* ->sk_data_ready is also called for a newly established child socket + * before it has been accepted and the acceptor has set up their + * data_ready.. we only want to queue listen work for our listening + * socket */ + if (sk->sk_state == TCP_LISTEN) { + mlog(ML_TCP, "bytes: %d\n", bytes); + queue_work(r2net_wq, &r2net_listen_work); + } + +out: + read_unlock(&sk->sk_callback_lock); + ready(sk, bytes); +} + +static int r2net_open_listening_sock(__be32 addr, __be16 port) +{ + struct socket *sock = NULL; + int ret; + struct sockaddr_in sin = { + .sin_family = PF_INET, + .sin_addr = { .s_addr = addr }, + .sin_port = port, + }; + + ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); + if (ret < 0) { + pr_err("ramster: Error %d while creating socket\n", ret); + goto out; + } + + sock->sk->sk_allocation = GFP_ATOMIC; + + write_lock_bh(&sock->sk->sk_callback_lock); + sock->sk->sk_user_data = sock->sk->sk_data_ready; + sock->sk->sk_data_ready = r2net_listen_data_ready; + write_unlock_bh(&sock->sk->sk_callback_lock); + + r2net_listen_sock = sock; + INIT_WORK(&r2net_listen_work, r2net_accept_many); + + sock->sk->sk_reuse = /* SK_CAN_REUSE FIXME FOR 3.4 */ 1; + ret = sock->ops->bind(sock, (struct sockaddr *)&sin, sizeof(sin)); + if (ret < 0) { + pr_err("ramster: Error %d while binding socket at %pI4:%u\n", + ret, &addr, ntohs(port)); + goto out; + } + + ret = sock->ops->listen(sock, 64); + if (ret < 0) + pr_err("ramster: Error %d while listening on %pI4:%u\n", + ret, &addr, ntohs(port)); + +out: + if (ret) { + r2net_listen_sock = NULL; + if (sock) + sock_release(sock); + } + return ret; +} + +/* + * called from node manager when we should bring up our network listening + * socket. node manager handles all the serialization to only call this + * once and to match it with r2net_stop_listening(). note, + * r2nm_this_node() doesn't work yet as we're being called while it + * is being set up. + */ +int r2net_start_listening(struct r2nm_node *node) +{ + int ret = 0; + + BUG_ON(r2net_wq != NULL); + BUG_ON(r2net_listen_sock != NULL); + + mlog(ML_KTHREAD, "starting r2net thread...\n"); + r2net_wq = create_singlethread_workqueue("r2net"); + if (r2net_wq == NULL) { + mlog(ML_ERROR, "unable to launch r2net thread\n"); + return -ENOMEM; /* ? */ + } + + ret = r2net_open_listening_sock(node->nd_ipv4_address, + node->nd_ipv4_port); + if (ret) { + destroy_workqueue(r2net_wq); + r2net_wq = NULL; + } + + return ret; +} + +/* again, r2nm_this_node() doesn't work here as we're involved in + * tearing it down */ +void r2net_stop_listening(struct r2nm_node *node) +{ + struct socket *sock = r2net_listen_sock; + size_t i; + + BUG_ON(r2net_wq == NULL); + BUG_ON(r2net_listen_sock == NULL); + + /* stop the listening socket from generating work */ + write_lock_bh(&sock->sk->sk_callback_lock); + sock->sk->sk_data_ready = sock->sk->sk_user_data; + sock->sk->sk_user_data = NULL; + write_unlock_bh(&sock->sk->sk_callback_lock); + + for (i = 0; i < ARRAY_SIZE(r2net_nodes); i++) { + struct r2nm_node *node = r2nm_get_node_by_num(i); + if (node) { + r2net_disconnect_node(node); + r2nm_node_put(node); + } + } + + /* finish all work and tear down the work queue */ + mlog(ML_KTHREAD, "waiting for r2net thread to exit....\n"); + destroy_workqueue(r2net_wq); + r2net_wq = NULL; + + sock_release(r2net_listen_sock); + r2net_listen_sock = NULL; +} + +void r2net_hb_node_up_manual(int node_num) +{ + struct r2nm_node dummy; + if (r2nm_single_cluster == NULL) + pr_err("ramster: cluster not alive, node_up_manual ignored\n"); + else { + r2hb_manual_set_node_heartbeating(node_num); + r2net_hb_node_up_cb(&dummy, node_num, NULL); + } +} + +/* ------------------------------------------------------------ */ + +int r2net_init(void) +{ + unsigned long i; + + if (r2net_debugfs_init()) + return -ENOMEM; + + r2net_hand = kzalloc(sizeof(struct r2net_handshake), GFP_KERNEL); + r2net_keep_req = kzalloc(sizeof(struct r2net_msg), GFP_KERNEL); + r2net_keep_resp = kzalloc(sizeof(struct r2net_msg), GFP_KERNEL); + if (!r2net_hand || !r2net_keep_req || !r2net_keep_resp) { + kfree(r2net_hand); + kfree(r2net_keep_req); + kfree(r2net_keep_resp); + return -ENOMEM; + } + + r2net_hand->protocol_version = cpu_to_be64(R2NET_PROTOCOL_VERSION); + r2net_hand->connector_id = cpu_to_be64(1); + + r2net_keep_req->magic = cpu_to_be16(R2NET_MSG_KEEP_REQ_MAGIC); + r2net_keep_resp->magic = cpu_to_be16(R2NET_MSG_KEEP_RESP_MAGIC); + + for (i = 0; i < ARRAY_SIZE(r2net_nodes); i++) { + struct r2net_node *nn = r2net_nn_from_num(i); + + atomic_set(&nn->nn_timeout, 0); + spin_lock_init(&nn->nn_lock); + INIT_DELAYED_WORK(&nn->nn_connect_work, r2net_start_connect); + INIT_DELAYED_WORK(&nn->nn_connect_expired, + r2net_connect_expired); + INIT_DELAYED_WORK(&nn->nn_still_up, r2net_still_up); + /* until we see hb from a node we'll return einval */ + nn->nn_persistent_error = -ENOTCONN; + init_waitqueue_head(&nn->nn_sc_wq); + idr_init(&nn->nn_status_idr); + INIT_LIST_HEAD(&nn->nn_status_list); + } + + return 0; +} + +void r2net_exit(void) +{ + kfree(r2net_hand); + kfree(r2net_keep_req); + kfree(r2net_keep_resp); + r2net_debugfs_exit(); +} diff --git a/drivers/staging/zcache/ramster/tcp.h b/drivers/staging/zcache/ramster/tcp.h new file mode 100644 index 0000000..9d05833 --- /dev/null +++ b/drivers/staging/zcache/ramster/tcp.h @@ -0,0 +1,159 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * tcp.h + * + * Function prototypes + * + * Copyright (C) 2004 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + */ + +#ifndef R2CLUSTER_TCP_H +#define R2CLUSTER_TCP_H + +#include +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif +#include +#include + +struct r2net_msg { + __be16 magic; + __be16 data_len; + __be16 msg_type; + __be16 pad1; + __be32 sys_status; + __be32 status; + __be32 key; + __be32 msg_num; + __u8 buf[0]; +}; + +typedef int (r2net_msg_handler_func)(struct r2net_msg *msg, u32 len, void *data, + void **ret_data); +typedef void (r2net_post_msg_handler_func)(int status, void *data, + void *ret_data); + +#define R2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct r2net_msg)) + +/* same as hb delay, we're waiting for another node to recognize our hb */ +#define R2NET_RECONNECT_DELAY_MS_DEFAULT 2000 + +#define R2NET_KEEPALIVE_DELAY_MS_DEFAULT 2000 +#define R2NET_IDLE_TIMEOUT_MS_DEFAULT 30000 + + +/* TODO: figure this out.... */ +static inline int r2net_link_down(int err, struct socket *sock) +{ + if (sock) { + if (sock->sk->sk_state != TCP_ESTABLISHED && + sock->sk->sk_state != TCP_CLOSE_WAIT) + return 1; + } + + if (err >= 0) + return 0; + switch (err) { + + /* ????????????????????????? */ + case -ERESTARTSYS: + case -EBADF: + /* When the server has died, an ICMP port unreachable + * message prompts ECONNREFUSED. */ + case -ECONNREFUSED: + case -ENOTCONN: + case -ECONNRESET: + case -EPIPE: + return 1; + + } + return 0; +} + +enum { + R2NET_DRIVER_UNINITED, + R2NET_DRIVER_READY, +}; + +int r2net_send_message(u32 msg_type, u32 key, void *data, u32 len, + u8 target_node, int *status); +int r2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec, + size_t veclen, u8 target_node, int *status); + +int r2net_register_handler(u32 msg_type, u32 key, u32 max_len, + r2net_msg_handler_func *func, void *data, + r2net_post_msg_handler_func *post_func, + struct list_head *unreg_list); +void r2net_unregister_handler_list(struct list_head *list); + +void r2net_fill_node_map(unsigned long *map, unsigned bytes); + +void r2net_force_data_magic(struct r2net_msg *, u16, u32); +void r2net_hb_node_up_manual(int); +struct r2net_node *r2net_nn_from_num(u8); + +struct r2nm_node; +int r2net_register_hb_callbacks(void); +void r2net_unregister_hb_callbacks(void); +int r2net_start_listening(struct r2nm_node *node); +void r2net_stop_listening(struct r2nm_node *node); +void r2net_disconnect_node(struct r2nm_node *node); +int r2net_num_connected_peers(void); + +int r2net_init(void); +void r2net_exit(void); + +struct r2net_send_tracking; +struct r2net_sock_container; + +#if 0 +int r2net_debugfs_init(void); +void r2net_debugfs_exit(void); +void r2net_debug_add_nst(struct r2net_send_tracking *nst); +void r2net_debug_del_nst(struct r2net_send_tracking *nst); +void r2net_debug_add_sc(struct r2net_sock_container *sc); +void r2net_debug_del_sc(struct r2net_sock_container *sc); +#else +static inline int r2net_debugfs_init(void) +{ + return 0; +} +static inline void r2net_debugfs_exit(void) +{ +} +static inline void r2net_debug_add_nst(struct r2net_send_tracking *nst) +{ +} +static inline void r2net_debug_del_nst(struct r2net_send_tracking *nst) +{ +} +static inline void r2net_debug_add_sc(struct r2net_sock_container *sc) +{ +} +static inline void r2net_debug_del_sc(struct r2net_sock_container *sc) +{ +} +#endif /* CONFIG_DEBUG_FS */ + +#endif /* R2CLUSTER_TCP_H */ diff --git a/drivers/staging/zcache/ramster/tcp_internal.h b/drivers/staging/zcache/ramster/tcp_internal.h new file mode 100644 index 0000000..4d8cc9f --- /dev/null +++ b/drivers/staging/zcache/ramster/tcp_internal.h @@ -0,0 +1,248 @@ +/* -*- mode: c; c-basic-offset: 8; -*- + * vim: noexpandtab sw=8 ts=8 sts=0: + * + * Copyright (C) 2005 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef R2CLUSTER_TCP_INTERNAL_H +#define R2CLUSTER_TCP_INTERNAL_H + +#define R2NET_MSG_MAGIC ((u16)0xfa55) +#define R2NET_MSG_STATUS_MAGIC ((u16)0xfa56) +#define R2NET_MSG_KEEP_REQ_MAGIC ((u16)0xfa57) +#define R2NET_MSG_KEEP_RESP_MAGIC ((u16)0xfa58) +/* + * "data magic" is a long version of "status magic" where the message + * payload actually contains data to be passed in reply to certain messages + */ +#define R2NET_MSG_DATA_MAGIC ((u16)0xfa59) + +/* we're delaying our quorum decision so that heartbeat will have timed + * out truly dead nodes by the time we come around to making decisions + * on their number */ +#define R2NET_QUORUM_DELAY_MS \ + ((r2hb_dead_threshold + 2) * R2HB_REGION_TIMEOUT_MS) + +/* + * This version number represents quite a lot, unfortunately. It not + * only represents the raw network message protocol on the wire but also + * locking semantics of the file system using the protocol. It should + * be somewhere else, I'm sure, but right now it isn't. + * + * With version 11, we separate out the filesystem locking portion. The + * filesystem now has a major.minor version it negotiates. Version 11 + * introduces this negotiation to the r2dlm protocol, and as such the + * version here in tcp_internal.h should not need to be bumped for + * filesystem locking changes. + * + * New in version 11 + * - Negotiation of filesystem locking in the dlm join. + * + * New in version 10: + * - Meta/data locks combined + * + * New in version 9: + * - All votes removed + * + * New in version 8: + * - Replace delete inode votes with a cluster lock + * + * New in version 7: + * - DLM join domain includes the live nodemap + * + * New in version 6: + * - DLM lockres remote refcount fixes. + * + * New in version 5: + * - Network timeout checking protocol + * + * New in version 4: + * - Remove i_generation from lock names for better stat performance. + * + * New in version 3: + * - Replace dentry votes with a cluster lock + * + * New in version 2: + * - full 64 bit i_size in the metadata lock lvbs + * - introduction of "rw" lock and pushing meta/data locking down + */ +#define R2NET_PROTOCOL_VERSION 11ULL +struct r2net_handshake { + __be64 protocol_version; + __be64 connector_id; + __be32 r2hb_heartbeat_timeout_ms; + __be32 r2net_idle_timeout_ms; + __be32 r2net_keepalive_delay_ms; + __be32 r2net_reconnect_delay_ms; +}; + +struct r2net_node { + /* this is never called from int/bh */ + spinlock_t nn_lock; + + /* set the moment an sc is allocated and a connect is started */ + struct r2net_sock_container *nn_sc; + /* _valid is only set after the handshake passes and tx can happen */ + unsigned nn_sc_valid:1; + /* if this is set tx just returns it */ + int nn_persistent_error; + /* It is only set to 1 after the idle time out. */ + atomic_t nn_timeout; + + /* threads waiting for an sc to arrive wait on the wq for generation + * to increase. it is increased when a connecting socket succeeds + * or fails or when an accepted socket is attached. */ + wait_queue_head_t nn_sc_wq; + + struct idr nn_status_idr; + struct list_head nn_status_list; + + /* connects are attempted from when heartbeat comes up until either hb + * goes down, the node is unconfigured, no connect attempts succeed + * before R2NET_CONN_IDLE_DELAY, or a connect succeeds. connect_work + * is queued from set_nn_state both from hb up and from itself if a + * connect attempt fails and so can be self-arming. shutdown is + * careful to first mark the nn such that no connects will be attempted + * before canceling delayed connect work and flushing the queue. */ + struct delayed_work nn_connect_work; + unsigned long nn_last_connect_attempt; + + /* this is queued as nodes come up and is canceled when a connection is + * established. this expiring gives up on the node and errors out + * transmits */ + struct delayed_work nn_connect_expired; + + /* after we give up on a socket we wait a while before deciding + * that it is still heartbeating and that we should do some + * quorum work */ + struct delayed_work nn_still_up; +}; + +struct r2net_sock_container { + struct kref sc_kref; + /* the next two are valid for the life time of the sc */ + struct socket *sc_sock; + struct r2nm_node *sc_node; + + /* all of these sc work structs hold refs on the sc while they are + * queued. they should not be able to ref a freed sc. the teardown + * race is with r2net_wq destruction in r2net_stop_listening() */ + + /* rx and connect work are generated from socket callbacks. sc + * shutdown removes the callbacks and then flushes the work queue */ + struct work_struct sc_rx_work; + struct work_struct sc_connect_work; + /* shutdown work is triggered in two ways. the simple way is + * for a code path calls ensure_shutdown which gets a lock, removes + * the sc from the nn, and queues the work. in this case the + * work is single-shot. the work is also queued from a sock + * callback, though, and in this case the work will find the sc + * still on the nn and will call ensure_shutdown itself.. this + * ends up triggering the shutdown work again, though nothing + * will be done in that second iteration. so work queue teardown + * has to be careful to remove the sc from the nn before waiting + * on the work queue so that the shutdown work doesn't remove the + * sc and rearm itself. + */ + struct work_struct sc_shutdown_work; + + struct timer_list sc_idle_timeout; + struct delayed_work sc_keepalive_work; + + unsigned sc_handshake_ok:1; + + struct page *sc_page; + size_t sc_page_off; + + /* original handlers for the sockets */ + void (*sc_state_change)(struct sock *sk); + void (*sc_data_ready)(struct sock *sk, int bytes); + + u32 sc_msg_key; + u16 sc_msg_type; + +#ifdef CONFIG_DEBUG_FS + struct list_head sc_net_debug_item; + ktime_t sc_tv_timer; + ktime_t sc_tv_data_ready; + ktime_t sc_tv_advance_start; + ktime_t sc_tv_advance_stop; + ktime_t sc_tv_func_start; + ktime_t sc_tv_func_stop; +#endif +#ifdef CONFIG_RAMSTER_FS_STATS + ktime_t sc_tv_acquiry_total; + ktime_t sc_tv_send_total; + ktime_t sc_tv_status_total; + u32 sc_send_count; + u32 sc_recv_count; + ktime_t sc_tv_process_total; +#endif + struct mutex sc_send_lock; +}; + +struct r2net_msg_handler { + struct rb_node nh_node; + u32 nh_max_len; + u32 nh_msg_type; + u32 nh_key; + r2net_msg_handler_func *nh_func; + r2net_msg_handler_func *nh_func_data; + r2net_post_msg_handler_func + *nh_post_func; + struct kref nh_kref; + struct list_head nh_unregister_item; +}; + +enum r2net_system_error { + R2NET_ERR_NONE = 0, + R2NET_ERR_NO_HNDLR, + R2NET_ERR_OVERFLOW, + R2NET_ERR_DIED, + R2NET_ERR_MAX +}; + +struct r2net_status_wait { + enum r2net_system_error ns_sys_status; + s32 ns_status; + int ns_id; + wait_queue_head_t ns_wq; + struct list_head ns_node_item; +}; + +#ifdef CONFIG_DEBUG_FS +/* just for state dumps */ +struct r2net_send_tracking { + struct list_head st_net_debug_item; + struct task_struct *st_task; + struct r2net_sock_container *st_sc; + u32 st_id; + u32 st_msg_type; + u32 st_msg_key; + u8 st_node; + ktime_t st_sock_time; + ktime_t st_send_time; + ktime_t st_status_time; +}; +#else +struct r2net_send_tracking { + u32 dummy; +}; +#endif /* CONFIG_DEBUG_FS */ + +#endif /* R2CLUSTER_TCP_INTERNAL_H */ diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c new file mode 100644 index 0000000..a2b7e03 --- /dev/null +++ b/drivers/staging/zcache/tmem.c @@ -0,0 +1,894 @@ +/* + * In-kernel transcendent memory (generic implementation) + * + * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. + * + * The primary purpose of Transcedent Memory ("tmem") is to map object-oriented + * "handles" (triples containing a pool id, and object id, and an index), to + * pages in a page-accessible memory (PAM). Tmem references the PAM pages via + * an abstract "pampd" (PAM page-descriptor), which can be operated on by a + * set of functions (pamops). Each pampd contains some representation of + * PAGE_SIZE bytes worth of data. For those familiar with key-value stores, + * the tmem handle is a three-level hierarchical key, and the value is always + * reconstituted (but not necessarily stored) as PAGE_SIZE bytes and is + * referenced in the datastore by the pampd. The hierarchy is required + * to ensure that certain invalidation functions can be performed efficiently + * (i.e. flush all indexes associated with this object_id, or + * flush all objects associated with this pool). + * + * Tmem must support potentially millions of pages and must be able to insert, + * find, and delete these pages at a potential frequency of thousands per + * second concurrently across many CPUs, (and, if used with KVM, across many + * vcpus across many guests). Tmem is tracked with a hierarchy of data + * structures, organized by the elements in the handle-tuple: pool_id, + * object_id, and page index. One or more "clients" (e.g. guests) each + * provide one or more tmem_pools. Each pool, contains a hash table of + * rb_trees of tmem_objs. Each tmem_obj contains a radix-tree-like tree + * of pointers, with intermediate nodes called tmem_objnodes. Each leaf + * pointer in this tree points to a pampd, which is accessible only through + * a small set of callbacks registered by the PAM implementation (see + * tmem_register_pamops). Tmem only needs to memory allocation for objs + * and objnodes and this is done via a set of callbacks that must be + * registered by the tmem host implementation (e.g. see tmem_register_hostops). + */ + +#include +#include +#include +#ifdef CONFIG_RAMSTER +#include +#endif + +#include "tmem.h" + +/* data structure sentinels used for debugging... see tmem.h */ +#define POOL_SENTINEL 0x87658765 +#define OBJ_SENTINEL 0x12345678 +#define OBJNODE_SENTINEL 0xfedcba09 + +/* + * A tmem host implementation must use this function to register callbacks + * for memory allocation. + */ +static struct tmem_hostops tmem_hostops; + +static void tmem_objnode_tree_init(void); + +void tmem_register_hostops(struct tmem_hostops *m) +{ + tmem_objnode_tree_init(); + tmem_hostops = *m; +} + +/* + * A tmem host implementation must use this function to register + * callbacks for a page-accessible memory (PAM) implementation. + */ +static struct tmem_pamops tmem_pamops; + +void tmem_register_pamops(struct tmem_pamops *m) +{ + tmem_pamops = *m; +} + +/* + * Oid's are potentially very sparse and tmem_objs may have an indeterminately + * short life, being added and deleted at a relatively high frequency. + * So an rb_tree is an ideal data structure to manage tmem_objs. But because + * of the potentially huge number of tmem_objs, each pool manages a hashtable + * of rb_trees to reduce search, insert, delete, and rebalancing time. + * Each hashbucket also has a lock to manage concurrent access and no + * searches, inserts, or deletions can be performed unless the lock is held. + * As a result, care must be taken to ensure tmem routines are not called + * recursively; the vast majority of the time, a recursive call may work + * but a deadlock will occur a small fraction of the time due to the + * hashbucket lock. + * + * The following routines manage tmem_objs. In all of these routines, + * the hashbucket lock is already held. + */ + +/* Search for object==oid in pool, returns object if found. */ +static struct tmem_obj *__tmem_obj_find(struct tmem_hashbucket *hb, + struct tmem_oid *oidp, + struct rb_node **parent, + struct rb_node ***link) +{ + struct rb_node *_parent = NULL, **rbnode; + struct tmem_obj *obj = NULL; + + rbnode = &hb->obj_rb_root.rb_node; + while (*rbnode) { + BUG_ON(RB_EMPTY_NODE(*rbnode)); + _parent = *rbnode; + obj = rb_entry(*rbnode, struct tmem_obj, + rb_tree_node); + switch (tmem_oid_compare(oidp, &obj->oid)) { + case 0: /* equal */ + goto out; + case -1: + rbnode = &(*rbnode)->rb_left; + break; + case 1: + rbnode = &(*rbnode)->rb_right; + break; + } + } + + if (parent) + *parent = _parent; + if (link) + *link = rbnode; + obj = NULL; +out: + return obj; +} + +static struct tmem_obj *tmem_obj_find(struct tmem_hashbucket *hb, + struct tmem_oid *oidp) +{ + return __tmem_obj_find(hb, oidp, NULL, NULL); +} + +static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *, bool); + +/* Free an object that has no more pampds in it. */ +static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb) +{ + struct tmem_pool *pool; + + BUG_ON(obj == NULL); + ASSERT_SENTINEL(obj, OBJ); + BUG_ON(obj->pampd_count > 0); + pool = obj->pool; + BUG_ON(pool == NULL); + if (obj->objnode_tree_root != NULL) /* may be "stump" with no leaves */ + tmem_pampd_destroy_all_in_obj(obj, false); + BUG_ON(obj->objnode_tree_root != NULL); + BUG_ON((long)obj->objnode_count != 0); + atomic_dec(&pool->obj_count); + BUG_ON(atomic_read(&pool->obj_count) < 0); + INVERT_SENTINEL(obj, OBJ); + obj->pool = NULL; + tmem_oid_set_invalid(&obj->oid); + rb_erase(&obj->rb_tree_node, &hb->obj_rb_root); +} + +/* + * Initialize, and insert an tmem_object_root (called only if find failed). + */ +static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb, + struct tmem_pool *pool, + struct tmem_oid *oidp) +{ + struct rb_root *root = &hb->obj_rb_root; + struct rb_node **new = NULL, *parent = NULL; + + BUG_ON(pool == NULL); + atomic_inc(&pool->obj_count); + obj->objnode_tree_height = 0; + obj->objnode_tree_root = NULL; + obj->pool = pool; + obj->oid = *oidp; + obj->objnode_count = 0; + obj->pampd_count = 0; +#ifdef CONFIG_RAMSTER + if (tmem_pamops.new_obj != NULL) + (*tmem_pamops.new_obj)(obj); +#endif + SET_SENTINEL(obj, OBJ); + + if (__tmem_obj_find(hb, oidp, &parent, &new)) + BUG(); + + rb_link_node(&obj->rb_tree_node, parent, new); + rb_insert_color(&obj->rb_tree_node, root); +} + +/* + * Tmem is managed as a set of tmem_pools with certain attributes, such as + * "ephemeral" vs "persistent". These attributes apply to all tmem_objs + * and all pampds that belong to a tmem_pool. A tmem_pool is created + * or deleted relatively rarely (for example, when a filesystem is + * mounted or unmounted). + */ + +/* flush all data from a pool and, optionally, free it */ +static void tmem_pool_flush(struct tmem_pool *pool, bool destroy) +{ + struct rb_node *rbnode; + struct tmem_obj *obj; + struct tmem_hashbucket *hb = &pool->hashbucket[0]; + int i; + + BUG_ON(pool == NULL); + for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) { + spin_lock(&hb->lock); + rbnode = rb_first(&hb->obj_rb_root); + while (rbnode != NULL) { + obj = rb_entry(rbnode, struct tmem_obj, rb_tree_node); + rbnode = rb_next(rbnode); + tmem_pampd_destroy_all_in_obj(obj, true); + tmem_obj_free(obj, hb); + (*tmem_hostops.obj_free)(obj, pool); + } + spin_unlock(&hb->lock); + } + if (destroy) + list_del(&pool->pool_list); +} + +/* + * A tmem_obj contains a radix-tree-like tree in which the intermediate + * nodes are called tmem_objnodes. (The kernel lib/radix-tree.c implementation + * is very specialized and tuned for specific uses and is not particularly + * suited for use from this code, though some code from the core algorithms has + * been reused, thus the copyright notices below). Each tmem_objnode contains + * a set of pointers which point to either a set of intermediate tmem_objnodes + * or a set of of pampds. + * + * Portions Copyright (C) 2001 Momchil Velikov + * Portions Copyright (C) 2001 Christoph Hellwig + * Portions Copyright (C) 2005 SGI, Christoph Lameter + */ + +struct tmem_objnode_tree_path { + struct tmem_objnode *objnode; + int offset; +}; + +/* objnode height_to_maxindex translation */ +static unsigned long tmem_objnode_tree_h2max[OBJNODE_TREE_MAX_PATH + 1]; + +static void tmem_objnode_tree_init(void) +{ + unsigned int ht, tmp; + + for (ht = 0; ht < ARRAY_SIZE(tmem_objnode_tree_h2max); ht++) { + tmp = ht * OBJNODE_TREE_MAP_SHIFT; + if (tmp >= OBJNODE_TREE_INDEX_BITS) + tmem_objnode_tree_h2max[ht] = ~0UL; + else + tmem_objnode_tree_h2max[ht] = + (~0UL >> (OBJNODE_TREE_INDEX_BITS - tmp - 1)) >> 1; + } +} + +static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj) +{ + struct tmem_objnode *objnode; + + ASSERT_SENTINEL(obj, OBJ); + BUG_ON(obj->pool == NULL); + ASSERT_SENTINEL(obj->pool, POOL); + objnode = (*tmem_hostops.objnode_alloc)(obj->pool); + if (unlikely(objnode == NULL)) + goto out; + objnode->obj = obj; + SET_SENTINEL(objnode, OBJNODE); + memset(&objnode->slots, 0, sizeof(objnode->slots)); + objnode->slots_in_use = 0; + obj->objnode_count++; +out: + return objnode; +} + +static void tmem_objnode_free(struct tmem_objnode *objnode) +{ + struct tmem_pool *pool; + int i; + + BUG_ON(objnode == NULL); + for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) + BUG_ON(objnode->slots[i] != NULL); + ASSERT_SENTINEL(objnode, OBJNODE); + INVERT_SENTINEL(objnode, OBJNODE); + BUG_ON(objnode->obj == NULL); + ASSERT_SENTINEL(objnode->obj, OBJ); + pool = objnode->obj->pool; + BUG_ON(pool == NULL); + ASSERT_SENTINEL(pool, POOL); + objnode->obj->objnode_count--; + objnode->obj = NULL; + (*tmem_hostops.objnode_free)(objnode, pool); +} + +/* + * Lookup index in object and return associated pampd (or NULL if not found). + */ +static void **__tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) +{ + unsigned int height, shift; + struct tmem_objnode **slot = NULL; + + BUG_ON(obj == NULL); + ASSERT_SENTINEL(obj, OBJ); + BUG_ON(obj->pool == NULL); + ASSERT_SENTINEL(obj->pool, POOL); + + height = obj->objnode_tree_height; + if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) + goto out; + if (height == 0 && obj->objnode_tree_root) { + slot = &obj->objnode_tree_root; + goto out; + } + shift = (height-1) * OBJNODE_TREE_MAP_SHIFT; + slot = &obj->objnode_tree_root; + while (height > 0) { + if (*slot == NULL) + goto out; + slot = (struct tmem_objnode **) + ((*slot)->slots + + ((index >> shift) & OBJNODE_TREE_MAP_MASK)); + shift -= OBJNODE_TREE_MAP_SHIFT; + height--; + } +out: + return slot != NULL ? (void **)slot : NULL; +} + +static void *tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) +{ + struct tmem_objnode **slot; + + slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index); + return slot != NULL ? *slot : NULL; +} + +#ifdef CONFIG_RAMSTER +static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index, + void *new_pampd, bool no_free) +{ + struct tmem_objnode **slot; + void *ret = NULL; + + slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index); + if ((slot != NULL) && (*slot != NULL)) { + void *old_pampd = *(void **)slot; + *(void **)slot = new_pampd; + if (!no_free) + (*tmem_pamops.free)(old_pampd, obj->pool, + NULL, 0, false); + ret = new_pampd; + } + return ret; +} +#endif + +static int tmem_pampd_add_to_obj(struct tmem_obj *obj, uint32_t index, + void *pampd) +{ + int ret = 0; + struct tmem_objnode *objnode = NULL, *newnode, *slot; + unsigned int height, shift; + int offset = 0; + + /* if necessary, extend the tree to be higher */ + if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) { + height = obj->objnode_tree_height + 1; + if (index > tmem_objnode_tree_h2max[height]) + while (index > tmem_objnode_tree_h2max[height]) + height++; + if (obj->objnode_tree_root == NULL) { + obj->objnode_tree_height = height; + goto insert; + } + do { + newnode = tmem_objnode_alloc(obj); + if (!newnode) { + ret = -ENOMEM; + goto out; + } + newnode->slots[0] = obj->objnode_tree_root; + newnode->slots_in_use = 1; + obj->objnode_tree_root = newnode; + obj->objnode_tree_height++; + } while (height > obj->objnode_tree_height); + } +insert: + slot = obj->objnode_tree_root; + height = obj->objnode_tree_height; + shift = (height-1) * OBJNODE_TREE_MAP_SHIFT; + while (height > 0) { + if (slot == NULL) { + /* add a child objnode. */ + slot = tmem_objnode_alloc(obj); + if (!slot) { + ret = -ENOMEM; + goto out; + } + if (objnode) { + + objnode->slots[offset] = slot; + objnode->slots_in_use++; + } else + obj->objnode_tree_root = slot; + } + /* go down a level */ + offset = (index >> shift) & OBJNODE_TREE_MAP_MASK; + objnode = slot; + slot = objnode->slots[offset]; + shift -= OBJNODE_TREE_MAP_SHIFT; + height--; + } + BUG_ON(slot != NULL); + if (objnode) { + objnode->slots_in_use++; + objnode->slots[offset] = pampd; + } else + obj->objnode_tree_root = pampd; + obj->pampd_count++; +out: + return ret; +} + +static void *tmem_pampd_delete_from_obj(struct tmem_obj *obj, uint32_t index) +{ + struct tmem_objnode_tree_path path[OBJNODE_TREE_MAX_PATH + 1]; + struct tmem_objnode_tree_path *pathp = path; + struct tmem_objnode *slot = NULL; + unsigned int height, shift; + int offset; + + BUG_ON(obj == NULL); + ASSERT_SENTINEL(obj, OBJ); + BUG_ON(obj->pool == NULL); + ASSERT_SENTINEL(obj->pool, POOL); + height = obj->objnode_tree_height; + if (index > tmem_objnode_tree_h2max[height]) + goto out; + slot = obj->objnode_tree_root; + if (height == 0 && obj->objnode_tree_root) { + obj->objnode_tree_root = NULL; + goto out; + } + shift = (height - 1) * OBJNODE_TREE_MAP_SHIFT; + pathp->objnode = NULL; + do { + if (slot == NULL) + goto out; + pathp++; + offset = (index >> shift) & OBJNODE_TREE_MAP_MASK; + pathp->offset = offset; + pathp->objnode = slot; + slot = slot->slots[offset]; + shift -= OBJNODE_TREE_MAP_SHIFT; + height--; + } while (height > 0); + if (slot == NULL) + goto out; + while (pathp->objnode) { + pathp->objnode->slots[pathp->offset] = NULL; + pathp->objnode->slots_in_use--; + if (pathp->objnode->slots_in_use) { + if (pathp->objnode == obj->objnode_tree_root) { + while (obj->objnode_tree_height > 0 && + obj->objnode_tree_root->slots_in_use == 1 && + obj->objnode_tree_root->slots[0]) { + struct tmem_objnode *to_free = + obj->objnode_tree_root; + + obj->objnode_tree_root = + to_free->slots[0]; + obj->objnode_tree_height--; + to_free->slots[0] = NULL; + to_free->slots_in_use = 0; + tmem_objnode_free(to_free); + } + } + goto out; + } + tmem_objnode_free(pathp->objnode); /* 0 slots used, free it */ + pathp--; + } + obj->objnode_tree_height = 0; + obj->objnode_tree_root = NULL; + +out: + if (slot != NULL) + obj->pampd_count--; + BUG_ON(obj->pampd_count < 0); + return slot; +} + +/* Recursively walk the objnode_tree destroying pampds and objnodes. */ +static void tmem_objnode_node_destroy(struct tmem_obj *obj, + struct tmem_objnode *objnode, + unsigned int ht) +{ + int i; + + if (ht == 0) + return; + for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) { + if (objnode->slots[i]) { + if (ht == 1) { + obj->pampd_count--; + (*tmem_pamops.free)(objnode->slots[i], + obj->pool, NULL, 0, true); + objnode->slots[i] = NULL; + continue; + } + tmem_objnode_node_destroy(obj, objnode->slots[i], ht-1); + tmem_objnode_free(objnode->slots[i]); + objnode->slots[i] = NULL; + } + } +} + +static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj, + bool pool_destroy) +{ + if (obj->objnode_tree_root == NULL) + return; + if (obj->objnode_tree_height == 0) { + obj->pampd_count--; + (*tmem_pamops.free)(obj->objnode_tree_root, + obj->pool, NULL, 0, true); + } else { + tmem_objnode_node_destroy(obj, obj->objnode_tree_root, + obj->objnode_tree_height); + tmem_objnode_free(obj->objnode_tree_root); + obj->objnode_tree_height = 0; + } + obj->objnode_tree_root = NULL; +#ifdef CONFIG_RAMSTER + if (tmem_pamops.free_obj != NULL) + (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy); +#endif +} + +/* + * Tmem is operated on by a set of well-defined actions: + * "put", "get", "flush", "flush_object", "new pool" and "destroy pool". + * (The tmem ABI allows for subpages and exchanges but these operations + * are not included in this implementation.) + * + * These "tmem core" operations are implemented in the following functions. + */ + +/* + * "Put" a page, e.g. associate the passed pampd with the passed handle. + * Tmem_put is complicated by a corner case: What if a page with matching + * handle already exists in tmem? To guarantee coherency, one of two + * actions is necessary: Either the data for the page must be overwritten, + * or the page must be "flushed" so that the data is not accessible to a + * subsequent "get". Since these "duplicate puts" are relatively rare, + * this implementation always flushes for simplicity. + */ +int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, + bool raw, void *pampd_to_use) +{ + struct tmem_obj *obj = NULL, *objfound = NULL, *objnew = NULL; + void *pampd = NULL, *pampd_del = NULL; + int ret = -ENOMEM; + struct tmem_hashbucket *hb; + + hb = &pool->hashbucket[tmem_oid_hash(oidp)]; + spin_lock(&hb->lock); + obj = objfound = tmem_obj_find(hb, oidp); + if (obj != NULL) { + pampd = tmem_pampd_lookup_in_obj(objfound, index); + if (pampd != NULL) { + /* if found, is a dup put, flush the old one */ + pampd_del = tmem_pampd_delete_from_obj(obj, index); + BUG_ON(pampd_del != pampd); + (*tmem_pamops.free)(pampd, pool, oidp, index, true); + if (obj->pampd_count == 0) { + objnew = obj; + objfound = NULL; + } + pampd = NULL; + } + } else { + obj = objnew = (*tmem_hostops.obj_alloc)(pool); + if (unlikely(obj == NULL)) { + ret = -ENOMEM; + goto out; + } + tmem_obj_init(obj, hb, pool, oidp); + } + BUG_ON(obj == NULL); + BUG_ON(((objnew != obj) && (objfound != obj)) || (objnew == objfound)); + pampd = pampd_to_use; + BUG_ON(pampd_to_use == NULL); + ret = tmem_pampd_add_to_obj(obj, index, pampd); + if (unlikely(ret == -ENOMEM)) + /* may have partially built objnode tree ("stump") */ + goto delete_and_free; + (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool)); + goto out; + +delete_and_free: + (void)tmem_pampd_delete_from_obj(obj, index); + if (pampd) + (*tmem_pamops.free)(pampd, pool, NULL, 0, true); + if (objnew) { + tmem_obj_free(objnew, hb); + (*tmem_hostops.obj_free)(objnew, pool); + } +out: + spin_unlock(&hb->lock); + return ret; +} + +#ifdef CONFIG_RAMSTER +/* + * For ramster only: The following routines provide a two-step sequence + * to allow the caller to replace a pampd in the tmem data structures with + * another pampd. Here, we lookup the passed handle and, if found, return the + * associated pampd and object, leaving the hashbucket locked and returning + * a reference to it. The caller is expected to immediately call the + * matching tmem_localify_finish routine which will handles the replacement + * and unlocks the hashbucket. + */ +void *tmem_localify_get_pampd(struct tmem_pool *pool, struct tmem_oid *oidp, + uint32_t index, struct tmem_obj **ret_obj, + void **saved_hb) +{ + struct tmem_hashbucket *hb; + struct tmem_obj *obj = NULL; + void *pampd = NULL; + + hb = &pool->hashbucket[tmem_oid_hash(oidp)]; + spin_lock(&hb->lock); + obj = tmem_obj_find(hb, oidp); + if (likely(obj != NULL)) + pampd = tmem_pampd_lookup_in_obj(obj, index); + *ret_obj = obj; + *saved_hb = (void *)hb; + /* note, hashbucket remains locked */ + return pampd; +} + +void tmem_localify_finish(struct tmem_obj *obj, uint32_t index, + void *pampd, void *saved_hb, bool delete) +{ + struct tmem_hashbucket *hb = (struct tmem_hashbucket *)saved_hb; + + BUG_ON(!spin_is_locked(&hb->lock)); + if (pampd != NULL) { + BUG_ON(obj == NULL); + (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1); + (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool)); + } else if (delete) { + BUG_ON(obj == NULL); + (void)tmem_pampd_delete_from_obj(obj, index); + } + spin_unlock(&hb->lock); +} + +/* + * For ramster only. Helper function to support asynchronous tmem_get. + */ +static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb, + struct tmem_pool *pool, struct tmem_oid *oidp, + uint32_t index, bool free, char *data) +{ + void *old_pampd = *ppampd, *new_pampd = NULL; + bool intransit = false; + int ret = 0; + + if (!is_ephemeral(pool)) + new_pampd = (*tmem_pamops.repatriate_preload)( + old_pampd, pool, oidp, index, &intransit); + if (intransit) + ret = -EAGAIN; + else if (new_pampd != NULL) + *ppampd = new_pampd; + /* must release the hb->lock else repatriate can't sleep */ + spin_unlock(&hb->lock); + if (!intransit) + ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool, + oidp, index, free, data); + if (ret == -EAGAIN) { + /* rare I think, but should cond_resched()??? */ + usleep_range(10, 1000); + } else if (ret == -ENOTCONN || ret == -EHOSTDOWN) { + ret = -1; + } else if (ret != 0 && ret != -ENOENT) { + ret = -1; + } + /* note hb->lock has now been unlocked */ + return ret; +} + +/* + * For ramster only. If a page in tmem matches the handle, replace the + * page so that any subsequent "get" gets the new page. Returns 0 if + * there was a page to replace, else returns -1. + */ +int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp, + uint32_t index, void *new_pampd) +{ + struct tmem_obj *obj; + int ret = -1; + struct tmem_hashbucket *hb; + + hb = &pool->hashbucket[tmem_oid_hash(oidp)]; + spin_lock(&hb->lock); + obj = tmem_obj_find(hb, oidp); + if (obj == NULL) + goto out; + new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0); + /* if we bug here, pamops wasn't properly set up for ramster */ + BUG_ON(tmem_pamops.replace_in_obj == NULL); + ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj); +out: + spin_unlock(&hb->lock); + return ret; +} +#endif + +/* + * "Get" a page, e.g. if a pampd can be found matching the passed handle, + * use a pamops callback to recreated the page from the pampd with the + * matching handle. By tmem definition, when a "get" is successful on + * an ephemeral page, the page is "flushed", and when a "get" is successful + * on a persistent page, the page is retained in tmem. Note that to preserve + * coherency, "get" can never be skipped if tmem contains the data. + * That is, if a get is done with a certain handle and fails, any + * subsequent "get" must also fail (unless of course there is a + * "put" done with the same handle). + */ +int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, + char *data, size_t *sizep, bool raw, int get_and_free) +{ + struct tmem_obj *obj; + void *pampd = NULL; + bool ephemeral = is_ephemeral(pool); + int ret = -1; + struct tmem_hashbucket *hb; + bool free = (get_and_free == 1) || ((get_and_free == 0) && ephemeral); + bool lock_held = false; + void **ppampd; + + do { + hb = &pool->hashbucket[tmem_oid_hash(oidp)]; + spin_lock(&hb->lock); + lock_held = true; + obj = tmem_obj_find(hb, oidp); + if (obj == NULL) + goto out; + ppampd = __tmem_pampd_lookup_in_obj(obj, index); + if (ppampd == NULL) + goto out; +#ifdef CONFIG_RAMSTER + if ((tmem_pamops.is_remote != NULL) && + tmem_pamops.is_remote(*ppampd)) { + ret = tmem_repatriate(ppampd, hb, pool, oidp, + index, free, data); + /* tmem_repatriate releases hb->lock */ + lock_held = false; + *sizep = PAGE_SIZE; + if (ret != -EAGAIN) + goto out; + } +#endif + } while (ret == -EAGAIN); + if (free) + pampd = tmem_pampd_delete_from_obj(obj, index); + else + pampd = tmem_pampd_lookup_in_obj(obj, index); + if (pampd == NULL) + goto out; + if (free) { + if (obj->pampd_count == 0) { + tmem_obj_free(obj, hb); + (*tmem_hostops.obj_free)(obj, pool); + obj = NULL; + } + } + if (free) + ret = (*tmem_pamops.get_data_and_free)( + data, sizep, raw, pampd, pool, oidp, index); + else + ret = (*tmem_pamops.get_data)( + data, sizep, raw, pampd, pool, oidp, index); + if (ret < 0) + goto out; + ret = 0; +out: + if (lock_held) + spin_unlock(&hb->lock); + return ret; +} + +/* + * If a page in tmem matches the handle, "flush" this page from tmem such + * that any subsequent "get" does not succeed (unless, of course, there + * was another "put" with the same handle). + */ +int tmem_flush_page(struct tmem_pool *pool, + struct tmem_oid *oidp, uint32_t index) +{ + struct tmem_obj *obj; + void *pampd; + int ret = -1; + struct tmem_hashbucket *hb; + + hb = &pool->hashbucket[tmem_oid_hash(oidp)]; + spin_lock(&hb->lock); + obj = tmem_obj_find(hb, oidp); + if (obj == NULL) + goto out; + pampd = tmem_pampd_delete_from_obj(obj, index); + if (pampd == NULL) + goto out; + (*tmem_pamops.free)(pampd, pool, oidp, index, true); + if (obj->pampd_count == 0) { + tmem_obj_free(obj, hb); + (*tmem_hostops.obj_free)(obj, pool); + } + ret = 0; + +out: + spin_unlock(&hb->lock); + return ret; +} + +/* + * "Flush" all pages in tmem matching this oid. + */ +int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp) +{ + struct tmem_obj *obj; + struct tmem_hashbucket *hb; + int ret = -1; + + hb = &pool->hashbucket[tmem_oid_hash(oidp)]; + spin_lock(&hb->lock); + obj = tmem_obj_find(hb, oidp); + if (obj == NULL) + goto out; + tmem_pampd_destroy_all_in_obj(obj, false); + tmem_obj_free(obj, hb); + (*tmem_hostops.obj_free)(obj, pool); + ret = 0; + +out: + spin_unlock(&hb->lock); + return ret; +} + +/* + * "Flush" all pages (and tmem_objs) from this tmem_pool and disable + * all subsequent access to this tmem_pool. + */ +int tmem_destroy_pool(struct tmem_pool *pool) +{ + int ret = -1; + + if (pool == NULL) + goto out; + tmem_pool_flush(pool, 1); + ret = 0; +out: + return ret; +} + +static LIST_HEAD(tmem_global_pool_list); + +/* + * Create a new tmem_pool with the provided flag and return + * a pool id provided by the tmem host implementation. + */ +void tmem_new_pool(struct tmem_pool *pool, uint32_t flags) +{ + int persistent = flags & TMEM_POOL_PERSIST; + int shared = flags & TMEM_POOL_SHARED; + struct tmem_hashbucket *hb = &pool->hashbucket[0]; + int i; + + for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) { + hb->obj_rb_root = RB_ROOT; + spin_lock_init(&hb->lock); + } + INIT_LIST_HEAD(&pool->pool_list); + atomic_set(&pool->obj_count, 0); + SET_SENTINEL(pool, POOL); + list_add_tail(&pool->pool_list, &tmem_global_pool_list); + pool->persistent = persistent; + pool->shared = shared; +} diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h new file mode 100644 index 0000000..adbe5a8 --- /dev/null +++ b/drivers/staging/zcache/tmem.h @@ -0,0 +1,259 @@ +/* + * tmem.h + * + * Transcendent memory + * + * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp. + */ + +#ifndef _TMEM_H_ +#define _TMEM_H_ + +#include +#include +#include +#include + +/* + * These are defined by the Xen<->Linux ABI so should remain consistent + */ +#define TMEM_POOL_PERSIST 1 +#define TMEM_POOL_SHARED 2 +#define TMEM_POOL_PRECOMPRESSED 4 +#define TMEM_POOL_PAGESIZE_SHIFT 4 +#define TMEM_POOL_PAGESIZE_MASK 0xf +#define TMEM_POOL_RESERVED_BITS 0x00ffff00 + +/* + * sentinels have proven very useful for debugging but can be removed + * or disabled before final merge. + */ +#undef SENTINELS +#ifdef SENTINELS +#define DECL_SENTINEL uint32_t sentinel; +#define SET_SENTINEL(_x, _y) (_x->sentinel = _y##_SENTINEL) +#define INVERT_SENTINEL(_x, _y) (_x->sentinel = ~_y##_SENTINEL) +#define ASSERT_SENTINEL(_x, _y) WARN_ON(_x->sentinel != _y##_SENTINEL) +#define ASSERT_INVERTED_SENTINEL(_x, _y) WARN_ON(_x->sentinel != ~_y##_SENTINEL) +#else +#define DECL_SENTINEL +#define SET_SENTINEL(_x, _y) do { } while (0) +#define INVERT_SENTINEL(_x, _y) do { } while (0) +#define ASSERT_SENTINEL(_x, _y) do { } while (0) +#define ASSERT_INVERTED_SENTINEL(_x, _y) do { } while (0) +#endif + +#define ASSERT_SPINLOCK(_l) lockdep_assert_held(_l) + +/* + * A pool is the highest-level data structure managed by tmem and + * usually corresponds to a large independent set of pages such as + * a filesystem. Each pool has an id, and certain attributes and counters. + * It also contains a set of hash buckets, each of which contains an rbtree + * of objects and a lock to manage concurrency within the pool. + */ + +#define TMEM_HASH_BUCKET_BITS 8 +#define TMEM_HASH_BUCKETS (1<persistent) +#define is_ephemeral(_p) (!(_p->persistent)) + +/* + * An object id ("oid") is large: 192-bits (to ensure, for example, files + * in a modern filesystem can be uniquely identified). + */ + +struct tmem_oid { + uint64_t oid[3]; +}; + +static inline void tmem_oid_set_invalid(struct tmem_oid *oidp) +{ + oidp->oid[0] = oidp->oid[1] = oidp->oid[2] = -1UL; +} + +static inline bool tmem_oid_valid(struct tmem_oid *oidp) +{ + return oidp->oid[0] != -1UL || oidp->oid[1] != -1UL || + oidp->oid[2] != -1UL; +} + +static inline int tmem_oid_compare(struct tmem_oid *left, + struct tmem_oid *right) +{ + int ret; + + if (left->oid[2] == right->oid[2]) { + if (left->oid[1] == right->oid[1]) { + if (left->oid[0] == right->oid[0]) + ret = 0; + else if (left->oid[0] < right->oid[0]) + ret = -1; + else + return 1; + } else if (left->oid[1] < right->oid[1]) + ret = -1; + else + ret = 1; + } else if (left->oid[2] < right->oid[2]) + ret = -1; + else + ret = 1; + return ret; +} + +static inline unsigned tmem_oid_hash(struct tmem_oid *oidp) +{ + return hash_long(oidp->oid[0] ^ oidp->oid[1] ^ oidp->oid[2], + TMEM_HASH_BUCKET_BITS); +} + +#ifdef CONFIG_RAMSTER +struct tmem_xhandle { + uint8_t client_id; + uint8_t xh_data_cksum; + uint16_t xh_data_size; + uint16_t pool_id; + struct tmem_oid oid; + uint32_t index; + void *extra; +}; + +static inline struct tmem_xhandle tmem_xhandle_fill(uint16_t client_id, + struct tmem_pool *pool, + struct tmem_oid *oidp, + uint32_t index) +{ + struct tmem_xhandle xh; + xh.client_id = client_id; + xh.xh_data_cksum = (uint8_t)-1; + xh.xh_data_size = (uint16_t)-1; + xh.pool_id = pool->pool_id; + xh.oid = *oidp; + xh.index = index; + return xh; +} +#endif + + +/* + * A tmem_obj contains an identifier (oid), pointers to the parent + * pool and the rb_tree to which it belongs, counters, and an ordered + * set of pampds, structured in a radix-tree-like tree. The intermediate + * nodes of the tree are called tmem_objnodes. + */ + +struct tmem_objnode; + +struct tmem_obj { + struct tmem_oid oid; + struct tmem_pool *pool; + struct rb_node rb_tree_node; + struct tmem_objnode *objnode_tree_root; + unsigned int objnode_tree_height; + unsigned long objnode_count; + long pampd_count; +#ifdef CONFIG_RAMSTER + /* + * for current design of ramster, all pages belonging to + * an object reside on the same remotenode and extra is + * used to record the number of the remotenode so a + * flush-object operation can specify it + */ + void *extra; /* for private use by pampd implementation */ +#endif + DECL_SENTINEL +}; + +#define OBJNODE_TREE_MAP_SHIFT 6 +#define OBJNODE_TREE_MAP_SIZE (1UL << OBJNODE_TREE_MAP_SHIFT) +#define OBJNODE_TREE_MAP_MASK (OBJNODE_TREE_MAP_SIZE-1) +#define OBJNODE_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long)) +#define OBJNODE_TREE_MAX_PATH \ + (OBJNODE_TREE_INDEX_BITS/OBJNODE_TREE_MAP_SHIFT + 2) + +struct tmem_objnode { + struct tmem_obj *obj; + DECL_SENTINEL + void *slots[OBJNODE_TREE_MAP_SIZE]; + unsigned int slots_in_use; +}; + +struct tmem_handle { + struct tmem_oid oid; /* 24 bytes */ + uint32_t index; + uint16_t pool_id; + uint16_t client_id; +}; + + +/* pampd abstract datatype methods provided by the PAM implementation */ +struct tmem_pamops { + void (*create_finish)(void *, bool); + int (*get_data)(char *, size_t *, bool, void *, struct tmem_pool *, + struct tmem_oid *, uint32_t); + int (*get_data_and_free)(char *, size_t *, bool, void *, + struct tmem_pool *, struct tmem_oid *, + uint32_t); + void (*free)(void *, struct tmem_pool *, + struct tmem_oid *, uint32_t, bool); +#ifdef CONFIG_RAMSTER + void (*new_obj)(struct tmem_obj *); + void (*free_obj)(struct tmem_pool *, struct tmem_obj *, bool); + void *(*repatriate_preload)(void *, struct tmem_pool *, + struct tmem_oid *, uint32_t, bool *); + int (*repatriate)(void *, void *, struct tmem_pool *, + struct tmem_oid *, uint32_t, bool, void *); + bool (*is_remote)(void *); + int (*replace_in_obj)(void *, struct tmem_obj *); +#endif +}; +extern void tmem_register_pamops(struct tmem_pamops *m); + +/* memory allocation methods provided by the host implementation */ +struct tmem_hostops { + struct tmem_obj *(*obj_alloc)(struct tmem_pool *); + void (*obj_free)(struct tmem_obj *, struct tmem_pool *); + struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *); + void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *); +}; +extern void tmem_register_hostops(struct tmem_hostops *m); + +/* core tmem accessor functions */ +extern int tmem_put(struct tmem_pool *, struct tmem_oid *, uint32_t index, + bool, void *); +extern int tmem_get(struct tmem_pool *, struct tmem_oid *, uint32_t index, + char *, size_t *, bool, int); +extern int tmem_flush_page(struct tmem_pool *, struct tmem_oid *, + uint32_t index); +extern int tmem_flush_object(struct tmem_pool *, struct tmem_oid *); +extern int tmem_destroy_pool(struct tmem_pool *); +extern void tmem_new_pool(struct tmem_pool *, uint32_t); +#ifdef CONFIG_RAMSTER +extern int tmem_replace(struct tmem_pool *, struct tmem_oid *, uint32_t index, + void *); +extern void *tmem_localify_get_pampd(struct tmem_pool *, struct tmem_oid *, + uint32_t index, struct tmem_obj **, + void **); +extern void tmem_localify_finish(struct tmem_obj *, uint32_t index, + void *, void *, bool); +#endif +#endif /* _TMEM_H */ diff --git a/drivers/staging/zcache/zbud.c b/drivers/staging/zcache/zbud.c new file mode 100644 index 0000000..a7c4361 --- /dev/null +++ b/drivers/staging/zcache/zbud.c @@ -0,0 +1,1060 @@ +/* + * zbud.c - Compression buddies allocator + * + * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. + * + * Compression buddies ("zbud") provides for efficiently packing two + * (or, possibly in the future, more) compressed pages ("zpages") into + * a single "raw" pageframe and for tracking both zpages and pageframes + * so that whole pageframes can be easily reclaimed in LRU-like order. + * It is designed to be used in conjunction with transcendent memory + * ("tmem"); for example separate LRU lists are maintained for persistent + * vs. ephemeral pages. + * + * A zbudpage is an overlay for a struct page and thus each zbudpage + * refers to a physical pageframe of RAM. When the caller passes a + * struct page from the kernel's page allocator, zbud "transforms" it + * to a zbudpage which sets/uses a different set of fields than the + * struct-page and thus must "untransform" it back by reinitializing + * certain fields before the struct-page can be freed. The fields + * of a zbudpage include a page lock for controlling access to the + * corresponding pageframe, and there is a size field for each zpage. + * Each zbudpage also lives on two linked lists: a "budlist" which is + * used to support efficient buddying of zpages; and an "lru" which + * is used for reclaiming pageframes in approximately least-recently-used + * order. + * + * A zbudpageframe is a pageframe divided up into aligned 64-byte "chunks" + * which contain the compressed data for zero, one, or two zbuds. Contained + * with the compressed data is a tmem_handle which is a key to allow + * the same data to be found via the tmem interface so the zpage can + * be invalidated (for ephemeral pages) or repatriated to the swap cache + * (for persistent pages). The contents of a zbudpageframe must never + * be accessed without holding the page lock for the corresponding + * zbudpage and, to accomodate highmem machines, the contents may + * only be examined or changes when kmapped. Thus, when in use, a + * kmapped zbudpageframe is referred to in the zbud code as "void *zbpg". + * + * Note that the term "zbud" refers to the combination of a zpage and + * a tmem_handle that is stored as one of possibly two "buddied" zpages; + * it also generically refers to this allocator... sorry for any confusion. + * + * A zbudref is a pointer to a struct zbudpage (which can be cast to a + * struct page), with the LSB either cleared or set to indicate, respectively, + * the first or second zpage in the zbudpageframe. Since a zbudref can be + * cast to a pointer, it is used as the tmem "pampd" pointer and uniquely + * references a stored tmem page and so is the only zbud data structure + * externally visible to zbud.c/zbud.h. + * + * Since we wish to reclaim entire pageframes but zpages may be randomly + * added and deleted to any given pageframe, we approximate LRU by + * promoting a pageframe to MRU when a zpage is added to it, but + * leaving it at the current place in the list when a zpage is deleted + * from it. As a side effect, zpages that are difficult to buddy (e.g. + * very large paages) will be reclaimed faster than average, which seems + * reasonable. + * + * In the current implementation, no more than two zpages may be stored in + * any pageframe and no zpage ever crosses a pageframe boundary. While + * other zpage allocation mechanisms may allow greater density, this two + * zpage-per-pageframe limit both ensures simple reclaim of pageframes + * (including garbage collection of references to the contents of those + * pageframes from tmem data structures) AND avoids the need for compaction. + * With additional complexity, zbud could be modified to support storing + * up to three zpages per pageframe or, to handle larger average zpages, + * up to three zpages per pair of pageframes, but it is not clear if the + * additional complexity would be worth it. So consider it an exercise + * for future developers. + * + * Note also that zbud does no page allocation or freeing. This is so + * that the caller has complete control over and, for accounting, visibility + * into if/when pages are allocated and freed. + * + * Finally, note that zbud limits the size of zpages it can store; the + * caller must check the zpage size with zbud_max_buddy_size before + * storing it, else BUGs will result. User beware. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "tmem.h" +#include "zcache.h" +#include "zbud.h" + +/* + * We need to ensure that a struct zbudpage is never larger than a + * struct page. This is checked with a BUG_ON in zbud_init. + * + * The unevictable field indicates that a zbud is being added to the + * zbudpage. Since this is a two-phase process (due to tmem locking), + * this field locks the zbudpage against eviction when a zbud match + * or creation is in process. Since this addition process may occur + * in parallel for two zbuds in one zbudpage, the field is a counter + * that must not exceed two. + */ +struct zbudpage { + union { + struct page page; + struct { + unsigned long space_for_flags; + struct { + unsigned zbud0_size:12; + unsigned zbud1_size:12; + unsigned unevictable:2; + }; + struct list_head budlist; + struct list_head lru; + }; + }; +}; + +struct zbudref { + union { + struct zbudpage *zbudpage; + unsigned long zbudref; + }; +}; + +#define CHUNK_SHIFT 6 +#define CHUNK_SIZE (1 << CHUNK_SHIFT) +#define CHUNK_MASK (~(CHUNK_SIZE-1)) +#define NCHUNKS (PAGE_SIZE >> CHUNK_SHIFT) +#define MAX_CHUNK (NCHUNKS-1) + +/* + * The following functions deal with the difference between struct + * page and struct zbudpage. Note the hack of using the pageflags + * from struct page; this is to avoid duplicating all the complex + * pageflag macros. + */ +static inline void zbudpage_spin_lock(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + while (unlikely(test_and_set_bit_lock(PG_locked, &page->flags))) { + do { + cpu_relax(); + } while (test_bit(PG_locked, &page->flags)); + } +} + +static inline void zbudpage_spin_unlock(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + clear_bit(PG_locked, &page->flags); +} + +static inline int zbudpage_spin_trylock(struct zbudpage *zbudpage) +{ + return trylock_page((struct page *)zbudpage); +} + +static inline int zbudpage_is_locked(struct zbudpage *zbudpage) +{ + return PageLocked((struct page *)zbudpage); +} + +static inline void *kmap_zbudpage_atomic(struct zbudpage *zbudpage) +{ + return kmap_atomic((struct page *)zbudpage); +} + +/* + * A dying zbudpage is an ephemeral page in the process of being evicted. + * Any data contained in the zbudpage is invalid and we are just waiting for + * the tmem pampds to be invalidated before freeing the page + */ +static inline int zbudpage_is_dying(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + return test_bit(PG_reclaim, &page->flags); +} + +static inline void zbudpage_set_dying(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + set_bit(PG_reclaim, &page->flags); +} + +static inline void zbudpage_clear_dying(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + clear_bit(PG_reclaim, &page->flags); +} + +/* + * A zombie zbudpage is a persistent page in the process of being evicted. + * The data contained in the zbudpage is valid and we are just waiting for + * the tmem pampds to be invalidated before freeing the page + */ +static inline int zbudpage_is_zombie(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + return test_bit(PG_dirty, &page->flags); +} + +static inline void zbudpage_set_zombie(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + set_bit(PG_dirty, &page->flags); +} + +static inline void zbudpage_clear_zombie(struct zbudpage *zbudpage) +{ + struct page *page = (struct page *)zbudpage; + + clear_bit(PG_dirty, &page->flags); +} + +static inline void kunmap_zbudpage_atomic(void *zbpg) +{ + kunmap_atomic(zbpg); +} + +/* + * zbud "translation" and helper functions + */ + +static inline struct zbudpage *zbudref_to_zbudpage(struct zbudref *zref) +{ + unsigned long zbud = (unsigned long)zref; + zbud &= ~1UL; + return (struct zbudpage *)zbud; +} + +static inline struct zbudref *zbudpage_to_zbudref(struct zbudpage *zbudpage, + unsigned budnum) +{ + unsigned long zbud = (unsigned long)zbudpage; + BUG_ON(budnum > 1); + zbud |= budnum; + return (struct zbudref *)zbud; +} + +static inline int zbudref_budnum(struct zbudref *zbudref) +{ + unsigned long zbud = (unsigned long)zbudref; + return zbud & 1UL; +} + +static inline unsigned zbud_max_size(void) +{ + return MAX_CHUNK << CHUNK_SHIFT; +} + +static inline unsigned zbud_size_to_chunks(unsigned size) +{ + BUG_ON(size == 0 || size > zbud_max_size()); + return (size + CHUNK_SIZE - 1) >> CHUNK_SHIFT; +} + +/* can only be used between kmap_zbudpage_atomic/kunmap_zbudpage_atomic! */ +static inline char *zbud_data(void *zbpg, + unsigned budnum, unsigned size) +{ + char *p; + + BUG_ON(size == 0 || size > zbud_max_size()); + p = (char *)zbpg; + if (budnum == 1) + p += PAGE_SIZE - ((size + CHUNK_SIZE - 1) & CHUNK_MASK); + return p; +} + +/* + * These are all informative and exposed through debugfs... except for + * the arrays... anyone know how to do that? To avoid confusion for + * debugfs viewers, some of these should also be atomic_long_t, but + * I don't know how to expose atomics via debugfs either... + */ +static unsigned long zbud_eph_pageframes; +static unsigned long zbud_pers_pageframes; +static unsigned long zbud_eph_zpages; +static unsigned long zbud_pers_zpages; +static u64 zbud_eph_zbytes; +static u64 zbud_pers_zbytes; +static unsigned long zbud_eph_evicted_pageframes; +static unsigned long zbud_pers_evicted_pageframes; +static unsigned long zbud_eph_cumul_zpages; +static unsigned long zbud_pers_cumul_zpages; +static u64 zbud_eph_cumul_zbytes; +static u64 zbud_pers_cumul_zbytes; +static unsigned long zbud_eph_cumul_chunk_counts[NCHUNKS]; +static unsigned long zbud_pers_cumul_chunk_counts[NCHUNKS]; +static unsigned long zbud_eph_buddied_count; +static unsigned long zbud_pers_buddied_count; +static unsigned long zbud_eph_unbuddied_count; +static unsigned long zbud_pers_unbuddied_count; +static unsigned long zbud_eph_zombie_count; +static unsigned long zbud_pers_zombie_count; +static atomic_t zbud_eph_zombie_atomic; +static atomic_t zbud_pers_zombie_atomic; + +#ifdef CONFIG_DEBUG_FS +#include +#define zdfs debugfs_create_size_t +#define zdfs64 debugfs_create_u64 +static int zbud_debugfs_init(void) +{ + struct dentry *root = debugfs_create_dir("zbud", NULL); + if (root == NULL) + return -ENXIO; + + /* + * would be nice to dump the sizes of the unbuddied + * arrays, like was done with sysfs, but it doesn't + * look like debugfs is flexible enough to do that + */ + zdfs64("eph_zbytes", S_IRUGO, root, &zbud_eph_zbytes); + zdfs64("eph_cumul_zbytes", S_IRUGO, root, &zbud_eph_cumul_zbytes); + zdfs64("pers_zbytes", S_IRUGO, root, &zbud_pers_zbytes); + zdfs64("pers_cumul_zbytes", S_IRUGO, root, &zbud_pers_cumul_zbytes); + zdfs("eph_cumul_zpages", S_IRUGO, root, &zbud_eph_cumul_zpages); + zdfs("eph_evicted_pageframes", S_IRUGO, root, + &zbud_eph_evicted_pageframes); + zdfs("eph_zpages", S_IRUGO, root, &zbud_eph_zpages); + zdfs("eph_pageframes", S_IRUGO, root, &zbud_eph_pageframes); + zdfs("eph_buddied_count", S_IRUGO, root, &zbud_eph_buddied_count); + zdfs("eph_unbuddied_count", S_IRUGO, root, &zbud_eph_unbuddied_count); + zdfs("pers_cumul_zpages", S_IRUGO, root, &zbud_pers_cumul_zpages); + zdfs("pers_evicted_pageframes", S_IRUGO, root, + &zbud_pers_evicted_pageframes); + zdfs("pers_zpages", S_IRUGO, root, &zbud_pers_zpages); + zdfs("pers_pageframes", S_IRUGO, root, &zbud_pers_pageframes); + zdfs("pers_buddied_count", S_IRUGO, root, &zbud_pers_buddied_count); + zdfs("pers_unbuddied_count", S_IRUGO, root, &zbud_pers_unbuddied_count); + zdfs("pers_zombie_count", S_IRUGO, root, &zbud_pers_zombie_count); + return 0; +} +#undef zdfs +#undef zdfs64 +#endif + +/* protects the buddied list and all unbuddied lists */ +static DEFINE_SPINLOCK(zbud_eph_lists_lock); +static DEFINE_SPINLOCK(zbud_pers_lists_lock); + +struct zbud_unbuddied { + struct list_head list; + unsigned count; +}; + +/* list N contains pages with N chunks USED and NCHUNKS-N unused */ +/* element 0 is never used but optimizing that isn't worth it */ +static struct zbud_unbuddied zbud_eph_unbuddied[NCHUNKS]; +static struct zbud_unbuddied zbud_pers_unbuddied[NCHUNKS]; +static LIST_HEAD(zbud_eph_lru_list); +static LIST_HEAD(zbud_pers_lru_list); +static LIST_HEAD(zbud_eph_buddied_list); +static LIST_HEAD(zbud_pers_buddied_list); +static LIST_HEAD(zbud_eph_zombie_list); +static LIST_HEAD(zbud_pers_zombie_list); + +/* + * Given a struct page, transform it to a zbudpage so that it can be + * used by zbud and initialize fields as necessary. + */ +static inline struct zbudpage *zbud_init_zbudpage(struct page *page, bool eph) +{ + struct zbudpage *zbudpage = (struct zbudpage *)page; + + BUG_ON(page == NULL); + INIT_LIST_HEAD(&zbudpage->budlist); + INIT_LIST_HEAD(&zbudpage->lru); + zbudpage->zbud0_size = 0; + zbudpage->zbud1_size = 0; + zbudpage->unevictable = 0; + if (eph) + zbud_eph_pageframes++; + else + zbud_pers_pageframes++; + return zbudpage; +} + +/* "Transform" a zbudpage back to a struct page suitable to free. */ +static inline struct page *zbud_unuse_zbudpage(struct zbudpage *zbudpage, + bool eph) +{ + struct page *page = (struct page *)zbudpage; + + BUG_ON(!list_empty(&zbudpage->budlist)); + BUG_ON(!list_empty(&zbudpage->lru)); + BUG_ON(zbudpage->zbud0_size != 0); + BUG_ON(zbudpage->zbud1_size != 0); + BUG_ON(!PageLocked(page)); + BUG_ON(zbudpage->unevictable != 0); + BUG_ON(zbudpage_is_dying(zbudpage)); + BUG_ON(zbudpage_is_zombie(zbudpage)); + if (eph) + zbud_eph_pageframes--; + else + zbud_pers_pageframes--; + zbudpage_spin_unlock(zbudpage); + reset_page_mapcount(page); + init_page_count(page); + page->index = 0; + return page; +} + +/* Mark a zbud as unused and do accounting */ +static inline void zbud_unuse_zbud(struct zbudpage *zbudpage, + int budnum, bool eph) +{ + unsigned size; + + BUG_ON(!zbudpage_is_locked(zbudpage)); + if (budnum == 0) { + size = zbudpage->zbud0_size; + zbudpage->zbud0_size = 0; + } else { + size = zbudpage->zbud1_size; + zbudpage->zbud1_size = 0; + } + if (eph) { + zbud_eph_zbytes -= size; + zbud_eph_zpages--; + } else { + zbud_pers_zbytes -= size; + zbud_pers_zpages--; + } +} + +/* + * Given a zbudpage/budnum/size, a tmem handle, and a kmapped pointer + * to some data, set up the zbud appropriately including data copying + * and accounting. Note that if cdata is NULL, the data copying is + * skipped. (This is useful for lazy writes such as for RAMster.) + */ +static void zbud_init_zbud(struct zbudpage *zbudpage, struct tmem_handle *th, + bool eph, void *cdata, + unsigned budnum, unsigned size) +{ + char *to; + void *zbpg; + struct tmem_handle *to_th; + unsigned nchunks = zbud_size_to_chunks(size); + + BUG_ON(!zbudpage_is_locked(zbudpage)); + zbpg = kmap_zbudpage_atomic(zbudpage); + to = zbud_data(zbpg, budnum, size); + to_th = (struct tmem_handle *)to; + to_th->index = th->index; + to_th->oid = th->oid; + to_th->pool_id = th->pool_id; + to_th->client_id = th->client_id; + to += sizeof(struct tmem_handle); + if (cdata != NULL) + memcpy(to, cdata, size - sizeof(struct tmem_handle)); + kunmap_zbudpage_atomic(zbpg); + if (budnum == 0) + zbudpage->zbud0_size = size; + else + zbudpage->zbud1_size = size; + if (eph) { + zbud_eph_cumul_chunk_counts[nchunks]++; + zbud_eph_zpages++; + zbud_eph_cumul_zpages++; + zbud_eph_zbytes += size; + zbud_eph_cumul_zbytes += size; + } else { + zbud_pers_cumul_chunk_counts[nchunks]++; + zbud_pers_zpages++; + zbud_pers_cumul_zpages++; + zbud_pers_zbytes += size; + zbud_pers_cumul_zbytes += size; + } +} + +/* + * Given a locked dying zbudpage, read out the tmem handles from the data, + * unlock the page, then use the handles to tell tmem to flush out its + * references + */ +static void zbud_evict_tmem(struct zbudpage *zbudpage) +{ + int i, j; + uint32_t pool_id[2], client_id[2]; + uint32_t index[2]; + struct tmem_oid oid[2]; + struct tmem_pool *pool; + void *zbpg; + struct tmem_handle *th; + unsigned size; + + /* read out the tmem handles from the data and set aside */ + zbpg = kmap_zbudpage_atomic(zbudpage); + for (i = 0, j = 0; i < 2; i++) { + size = (i == 0) ? zbudpage->zbud0_size : zbudpage->zbud1_size; + if (size) { + th = (struct tmem_handle *)zbud_data(zbpg, i, size); + client_id[j] = th->client_id; + pool_id[j] = th->pool_id; + oid[j] = th->oid; + index[j] = th->index; + j++; + zbud_unuse_zbud(zbudpage, i, true); + } + } + kunmap_zbudpage_atomic(zbpg); + zbudpage_spin_unlock(zbudpage); + /* zbudpage is now an unlocked dying... tell tmem to flush pointers */ + for (i = 0; i < j; i++) { + pool = zcache_get_pool_by_id(client_id[i], pool_id[i]); + if (pool != NULL) { + tmem_flush_page(pool, &oid[i], index[i]); + zcache_put_pool(pool); + } + } +} + +/* + * Externally callable zbud handling routines. + */ + +/* + * Return the maximum size compressed page that can be stored (secretly + * setting aside space for the tmem handle. + */ +unsigned int zbud_max_buddy_size(void) +{ + return zbud_max_size() - sizeof(struct tmem_handle); +} + +/* + * Given a zbud reference, free the corresponding zbud from all lists, + * mark it as unused, do accounting, and if the freeing of the zbud + * frees up an entire pageframe, return it to the caller (else NULL). + */ +struct page *zbud_free_and_delist(struct zbudref *zref, bool eph, + unsigned int *zsize, unsigned int *zpages) +{ + unsigned long budnum = zbudref_budnum(zref); + struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); + struct page *page = NULL; + unsigned chunks, bud_size, other_bud_size; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + struct zbud_unbuddied *unbud = + eph ? zbud_eph_unbuddied : zbud_pers_unbuddied; + + + spin_lock(lists_lock); + zbudpage_spin_lock(zbudpage); + if (zbudpage_is_dying(zbudpage)) { + /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); + *zpages = 0; + *zsize = 0; + goto out; + } + if (budnum == 0) { + bud_size = zbudpage->zbud0_size; + other_bud_size = zbudpage->zbud1_size; + } else { + bud_size = zbudpage->zbud1_size; + other_bud_size = zbudpage->zbud0_size; + } + *zsize = bud_size - sizeof(struct tmem_handle); + *zpages = 1; + zbud_unuse_zbud(zbudpage, budnum, eph); + if (other_bud_size == 0) { /* was unbuddied: unlist and free */ + chunks = zbud_size_to_chunks(bud_size) ; + if (zbudpage_is_zombie(zbudpage)) { + if (eph) + zbud_pers_zombie_count = + atomic_dec_return(&zbud_eph_zombie_atomic); + else + zbud_pers_zombie_count = + atomic_dec_return(&zbud_pers_zombie_atomic); + zbudpage_clear_zombie(zbudpage); + } else { + BUG_ON(list_empty(&unbud[chunks].list)); + list_del_init(&zbudpage->budlist); + unbud[chunks].count--; + } + list_del_init(&zbudpage->lru); + spin_unlock(lists_lock); + if (eph) + zbud_eph_unbuddied_count--; + else + zbud_pers_unbuddied_count--; + page = zbud_unuse_zbudpage(zbudpage, eph); + } else { /* was buddied: move remaining buddy to unbuddied list */ + chunks = zbud_size_to_chunks(other_bud_size) ; + if (!zbudpage_is_zombie(zbudpage)) { + list_del_init(&zbudpage->budlist); + list_add_tail(&zbudpage->budlist, &unbud[chunks].list); + unbud[chunks].count++; + } + if (eph) { + zbud_eph_buddied_count--; + zbud_eph_unbuddied_count++; + } else { + zbud_pers_unbuddied_count++; + zbud_pers_buddied_count--; + } + /* don't mess with lru, no need to move it */ + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); + } +out: + return page; +} + +/* + * Given a tmem handle, and a kmapped pointer to compressed data of + * the given size, try to find an unbuddied zbudpage in which to + * create a zbud. If found, put it there, mark the zbudpage unevictable, + * and return a zbudref to it. Else return NULL. + */ +struct zbudref *zbud_match_prep(struct tmem_handle *th, bool eph, + void *cdata, unsigned size) +{ + struct zbudpage *zbudpage = NULL, *zbudpage2; + unsigned long budnum = 0UL; + unsigned nchunks; + int i, found_good_buddy = 0; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + struct zbud_unbuddied *unbud = + eph ? zbud_eph_unbuddied : zbud_pers_unbuddied; + + size += sizeof(struct tmem_handle); + nchunks = zbud_size_to_chunks(size); + for (i = MAX_CHUNK - nchunks + 1; i > 0; i--) { + spin_lock(lists_lock); + if (!list_empty(&unbud[i].list)) { + list_for_each_entry_safe(zbudpage, zbudpage2, + &unbud[i].list, budlist) { + if (zbudpage_spin_trylock(zbudpage)) { + found_good_buddy = i; + goto found_unbuddied; + } + } + } + spin_unlock(lists_lock); + } + zbudpage = NULL; + goto out; + +found_unbuddied: + BUG_ON(!zbudpage_is_locked(zbudpage)); + BUG_ON(!((zbudpage->zbud0_size == 0) ^ (zbudpage->zbud1_size == 0))); + if (zbudpage->zbud0_size == 0) + budnum = 0UL; + else if (zbudpage->zbud1_size == 0) + budnum = 1UL; + list_del_init(&zbudpage->budlist); + if (eph) { + list_add_tail(&zbudpage->budlist, &zbud_eph_buddied_list); + unbud[found_good_buddy].count--; + zbud_eph_unbuddied_count--; + zbud_eph_buddied_count++; + /* "promote" raw zbudpage to most-recently-used */ + list_del_init(&zbudpage->lru); + list_add_tail(&zbudpage->lru, &zbud_eph_lru_list); + } else { + list_add_tail(&zbudpage->budlist, &zbud_pers_buddied_list); + unbud[found_good_buddy].count--; + zbud_pers_unbuddied_count--; + zbud_pers_buddied_count++; + /* "promote" raw zbudpage to most-recently-used */ + list_del_init(&zbudpage->lru); + list_add_tail(&zbudpage->lru, &zbud_pers_lru_list); + } + zbud_init_zbud(zbudpage, th, eph, cdata, budnum, size); + zbudpage->unevictable++; + BUG_ON(zbudpage->unevictable == 3); + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); +out: + return zbudpage_to_zbudref(zbudpage, budnum); + +} + +/* + * Given a tmem handle, and a kmapped pointer to compressed data of + * the given size, and a newly allocated struct page, create an unevictable + * zbud in that new page and return a zbudref to it. + */ +struct zbudref *zbud_create_prep(struct tmem_handle *th, bool eph, + void *cdata, unsigned size, + struct page *newpage) +{ + struct zbudpage *zbudpage; + unsigned long budnum = 0; + unsigned nchunks; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + struct zbud_unbuddied *unbud = + eph ? zbud_eph_unbuddied : zbud_pers_unbuddied; + +#if 0 + /* this may be worth it later to support decompress-in-place? */ + static unsigned long counter; + budnum = counter++ & 1; /* alternate using zbud0 and zbud1 */ +#endif + + if (size > zbud_max_buddy_size()) + return NULL; + if (newpage == NULL) + return NULL; + + size += sizeof(struct tmem_handle); + nchunks = zbud_size_to_chunks(size) ; + spin_lock(lists_lock); + zbudpage = zbud_init_zbudpage(newpage, eph); + zbudpage_spin_lock(zbudpage); + list_add_tail(&zbudpage->budlist, &unbud[nchunks].list); + if (eph) { + list_add_tail(&zbudpage->lru, &zbud_eph_lru_list); + zbud_eph_unbuddied_count++; + } else { + list_add_tail(&zbudpage->lru, &zbud_pers_lru_list); + zbud_pers_unbuddied_count++; + } + unbud[nchunks].count++; + zbud_init_zbud(zbudpage, th, eph, cdata, budnum, size); + zbudpage->unevictable++; + BUG_ON(zbudpage->unevictable == 3); + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); + return zbudpage_to_zbudref(zbudpage, budnum); +} + +/* + * Finish creation of a zbud by, assuming another zbud isn't being created + * in parallel, marking it evictable. + */ +void zbud_create_finish(struct zbudref *zref, bool eph) +{ + struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + + spin_lock(lists_lock); + zbudpage_spin_lock(zbudpage); + BUG_ON(zbudpage_is_dying(zbudpage)); + zbudpage->unevictable--; + BUG_ON((int)zbudpage->unevictable < 0); + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); +} + +/* + * Given a zbudref and a struct page, decompress the data from + * the zbud into the physical page represented by the struct page + * by upcalling to zcache_decompress + */ +int zbud_decompress(struct page *data_page, struct zbudref *zref, bool eph, + void (*decompress)(char *, unsigned int, char *)) +{ + struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); + unsigned long budnum = zbudref_budnum(zref); + void *zbpg; + char *to_va, *from_va; + unsigned size; + int ret = -1; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + + spin_lock(lists_lock); + zbudpage_spin_lock(zbudpage); + if (zbudpage_is_dying(zbudpage)) { + /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ + goto out; + } + zbpg = kmap_zbudpage_atomic(zbudpage); + to_va = kmap_atomic(data_page); + if (budnum == 0) + size = zbudpage->zbud0_size; + else + size = zbudpage->zbud1_size; + BUG_ON(size == 0 || size > zbud_max_size()); + from_va = zbud_data(zbpg, budnum, size); + from_va += sizeof(struct tmem_handle); + size -= sizeof(struct tmem_handle); + decompress(from_va, size, to_va); + kunmap_atomic(to_va); + kunmap_zbudpage_atomic(zbpg); + ret = 0; +out: + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); + return ret; +} + +/* + * Given a zbudref and a kernel pointer, copy the data from + * the zbud to the kernel pointer. + */ +int zbud_copy_from_zbud(char *to_va, struct zbudref *zref, + size_t *sizep, bool eph) +{ + struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); + unsigned long budnum = zbudref_budnum(zref); + void *zbpg; + char *from_va; + unsigned size; + int ret = -1; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + + spin_lock(lists_lock); + zbudpage_spin_lock(zbudpage); + if (zbudpage_is_dying(zbudpage)) { + /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ + goto out; + } + zbpg = kmap_zbudpage_atomic(zbudpage); + if (budnum == 0) + size = zbudpage->zbud0_size; + else + size = zbudpage->zbud1_size; + BUG_ON(size == 0 || size > zbud_max_size()); + from_va = zbud_data(zbpg, budnum, size); + from_va += sizeof(struct tmem_handle); + size -= sizeof(struct tmem_handle); + *sizep = size; + memcpy(to_va, from_va, size); + + kunmap_zbudpage_atomic(zbpg); + ret = 0; +out: + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); + return ret; +} + +/* + * Given a zbudref and a kernel pointer, copy the data from + * the kernel pointer to the zbud. + */ +int zbud_copy_to_zbud(struct zbudref *zref, char *from_va, bool eph) +{ + struct zbudpage *zbudpage = zbudref_to_zbudpage(zref); + unsigned long budnum = zbudref_budnum(zref); + void *zbpg; + char *to_va; + unsigned size; + int ret = -1; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + + spin_lock(lists_lock); + zbudpage_spin_lock(zbudpage); + if (zbudpage_is_dying(zbudpage)) { + /* ignore dying zbudpage... see zbud_evict_pageframe_lru() */ + goto out; + } + zbpg = kmap_zbudpage_atomic(zbudpage); + if (budnum == 0) + size = zbudpage->zbud0_size; + else + size = zbudpage->zbud1_size; + BUG_ON(size == 0 || size > zbud_max_size()); + to_va = zbud_data(zbpg, budnum, size); + to_va += sizeof(struct tmem_handle); + size -= sizeof(struct tmem_handle); + memcpy(to_va, from_va, size); + + kunmap_zbudpage_atomic(zbpg); + ret = 0; +out: + zbudpage_spin_unlock(zbudpage); + spin_unlock(lists_lock); + return ret; +} + +/* + * Choose an ephemeral LRU zbudpage that is evictable (not locked), ensure + * there are no references to it remaining, and return the now unused + * (and re-init'ed) struct page and the total amount of compressed + * data that was evicted. + */ +struct page *zbud_evict_pageframe_lru(unsigned int *zsize, unsigned int *zpages) +{ + struct zbudpage *zbudpage = NULL, *zbudpage2; + struct zbud_unbuddied *unbud = zbud_eph_unbuddied; + struct page *page = NULL; + bool irqs_disabled = irqs_disabled(); + + /* + * Since this can be called indirectly from cleancache_put, which + * has interrupts disabled, as well as frontswap_put, which does not, + * we need to be able to handle both cases, even though it is ugly. + */ + if (irqs_disabled) + spin_lock(&zbud_eph_lists_lock); + else + spin_lock_bh(&zbud_eph_lists_lock); + *zsize = 0; + if (list_empty(&zbud_eph_lru_list)) + goto unlock_out; + list_for_each_entry_safe(zbudpage, zbudpage2, &zbud_eph_lru_list, lru) { + /* skip a locked zbudpage */ + if (unlikely(!zbudpage_spin_trylock(zbudpage))) + continue; + /* skip an unevictable zbudpage */ + if (unlikely(zbudpage->unevictable != 0)) { + zbudpage_spin_unlock(zbudpage); + continue; + } + /* got a locked evictable page */ + goto evict_page; + + } +unlock_out: + /* no unlocked evictable pages, give up */ + if (irqs_disabled) + spin_unlock(&zbud_eph_lists_lock); + else + spin_unlock_bh(&zbud_eph_lists_lock); + goto out; + +evict_page: + list_del_init(&zbudpage->budlist); + list_del_init(&zbudpage->lru); + zbudpage_set_dying(zbudpage); + /* + * the zbudpage is now "dying" and attempts to read, write, + * or delete data from it will be ignored + */ + if (zbudpage->zbud0_size != 0 && zbudpage->zbud1_size != 0) { + *zsize = zbudpage->zbud0_size + zbudpage->zbud1_size - + (2 * sizeof(struct tmem_handle)); + *zpages = 2; + } else if (zbudpage->zbud0_size != 0) { + unbud[zbud_size_to_chunks(zbudpage->zbud0_size)].count--; + *zsize = zbudpage->zbud0_size - sizeof(struct tmem_handle); + *zpages = 1; + } else if (zbudpage->zbud1_size != 0) { + unbud[zbud_size_to_chunks(zbudpage->zbud1_size)].count--; + *zsize = zbudpage->zbud1_size - sizeof(struct tmem_handle); + *zpages = 1; + } else { + BUG(); + } + spin_unlock(&zbud_eph_lists_lock); + zbud_eph_evicted_pageframes++; + if (*zpages == 1) + zbud_eph_unbuddied_count--; + else + zbud_eph_buddied_count--; + zbud_evict_tmem(zbudpage); + zbudpage_spin_lock(zbudpage); + zbudpage_clear_dying(zbudpage); + page = zbud_unuse_zbudpage(zbudpage, true); + if (!irqs_disabled) + local_bh_enable(); +out: + return page; +} + +/* + * Choose a persistent LRU zbudpage that is evictable (not locked), zombify it, + * read the tmem_handle(s) out of it into the passed array, and return the + * number of zbuds. Caller must perform necessary tmem functions and, + * indirectly, zbud functions to fetch any valid data and cause the + * now-zombified zbudpage to eventually be freed. We track the zombified + * zbudpage count so it is possible to observe if there is a leak. + FIXME: describe (ramster) case where data pointers are passed in for memcpy + */ +unsigned int zbud_make_zombie_lru(struct tmem_handle *th, unsigned char **data, + unsigned int *zsize, bool eph) +{ + struct zbudpage *zbudpage = NULL, *zbudpag2; + struct tmem_handle *thfrom; + char *from_va; + void *zbpg; + unsigned size; + int ret = 0, i; + spinlock_t *lists_lock = + eph ? &zbud_eph_lists_lock : &zbud_pers_lists_lock; + struct list_head *lru_list = + eph ? &zbud_eph_lru_list : &zbud_pers_lru_list; + + spin_lock_bh(lists_lock); + if (list_empty(lru_list)) + goto out; + list_for_each_entry_safe(zbudpage, zbudpag2, lru_list, lru) { + /* skip a locked zbudpage */ + if (unlikely(!zbudpage_spin_trylock(zbudpage))) + continue; + /* skip an unevictable zbudpage */ + if (unlikely(zbudpage->unevictable != 0)) { + zbudpage_spin_unlock(zbudpage); + continue; + } + /* got a locked evictable page */ + goto zombify_page; + } + /* no unlocked evictable pages, give up */ + goto out; + +zombify_page: + /* got an unlocked evictable page, zombify it */ + list_del_init(&zbudpage->budlist); + zbudpage_set_zombie(zbudpage); + /* FIXME what accounting do I need to do here? */ + list_del_init(&zbudpage->lru); + if (eph) { + list_add_tail(&zbudpage->lru, &zbud_eph_zombie_list); + zbud_eph_zombie_count = + atomic_inc_return(&zbud_eph_zombie_atomic); + } else { + list_add_tail(&zbudpage->lru, &zbud_pers_zombie_list); + zbud_pers_zombie_count = + atomic_inc_return(&zbud_pers_zombie_atomic); + } + /* FIXME what accounting do I need to do here? */ + zbpg = kmap_zbudpage_atomic(zbudpage); + for (i = 0; i < 2; i++) { + size = (i == 0) ? zbudpage->zbud0_size : zbudpage->zbud1_size; + if (size) { + from_va = zbud_data(zbpg, i, size); + thfrom = (struct tmem_handle *)from_va; + from_va += sizeof(struct tmem_handle); + size -= sizeof(struct tmem_handle); + if (th != NULL) + th[ret] = *thfrom; + if (data != NULL) + memcpy(data[ret], from_va, size); + if (zsize != NULL) + *zsize++ = size; + ret++; + } + } + kunmap_zbudpage_atomic(zbpg); + zbudpage_spin_unlock(zbudpage); +out: + spin_unlock_bh(lists_lock); + return ret; +} + +void __init zbud_init(void) +{ + int i; + +#ifdef CONFIG_DEBUG_FS + zbud_debugfs_init(); +#endif + BUG_ON((sizeof(struct tmem_handle) * 2 > CHUNK_SIZE)); + BUG_ON(sizeof(struct zbudpage) > sizeof(struct page)); + for (i = 0; i < NCHUNKS; i++) { + INIT_LIST_HEAD(&zbud_eph_unbuddied[i].list); + INIT_LIST_HEAD(&zbud_pers_unbuddied[i].list); + } +} diff --git a/drivers/staging/zcache/zbud.h b/drivers/staging/zcache/zbud.h new file mode 100644 index 0000000..891e8a7 --- /dev/null +++ b/drivers/staging/zcache/zbud.h @@ -0,0 +1,33 @@ +/* + * zbud.h + * + * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. + * + */ + +#ifndef _ZBUD_H_ +#define _ZBUD_H_ + +#include "tmem.h" + +struct zbudref; + +extern unsigned int zbud_max_buddy_size(void); +extern struct zbudref *zbud_match_prep(struct tmem_handle *th, bool eph, + void *cdata, unsigned size); +extern struct zbudref *zbud_create_prep(struct tmem_handle *th, bool eph, + void *cdata, unsigned size, + struct page *newpage); +extern void zbud_create_finish(struct zbudref *, bool); +extern int zbud_decompress(struct page *, struct zbudref *, bool, + void (*func)(char *, unsigned int, char *)); +extern int zbud_copy_from_zbud(char *, struct zbudref *, size_t *, bool); +extern int zbud_copy_to_zbud(struct zbudref *, char *, bool); +extern struct page *zbud_free_and_delist(struct zbudref *, bool eph, + unsigned int *, unsigned int *); +extern struct page *zbud_evict_pageframe_lru(unsigned int *, unsigned int *); +extern unsigned int zbud_make_zombie_lru(struct tmem_handle *, unsigned char **, + unsigned int *, bool); +extern void zbud_init(void); + +#endif /* _ZBUD_H_ */ diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c new file mode 100644 index 0000000..a09dd5c --- /dev/null +++ b/drivers/staging/zcache/zcache-main.c @@ -0,0 +1,1820 @@ +/* + * zcache.c + * + * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp. + * Copyright (c) 2010,2011, Nitin Gupta + * + * Zcache provides an in-kernel "host implementation" for transcendent memory + * ("tmem") and, thus indirectly, for cleancache and frontswap. Zcache uses + * lzo1x compression to improve density and an embedded allocator called + * "zbud" which "buddies" two compressed pages semi-optimally in each physical + * pageframe. Zbud is integrally tied into tmem to allow pageframes to + * be "reclaimed" efficiently. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "tmem.h" +#include "zcache.h" +#include "zbud.h" +#include "ramster.h" +#ifdef CONFIG_RAMSTER +static int ramster_enabled; +#else +#define ramster_enabled 0 +#endif + +#ifndef __PG_WAS_ACTIVE +static inline bool PageWasActive(struct page *page) +{ + return true; +} + +static inline void SetPageWasActive(struct page *page) +{ +} +#endif + +#ifdef FRONTSWAP_HAS_EXCLUSIVE_GETS +static bool frontswap_has_exclusive_gets __read_mostly = true; +#else +static bool frontswap_has_exclusive_gets __read_mostly; +static inline void frontswap_tmem_exclusive_gets(bool b) +{ +} +#endif + +static int zcache_enabled __read_mostly; +static int disable_cleancache __read_mostly; +static int disable_frontswap __read_mostly; +static int disable_frontswap_ignore_nonactive __read_mostly; +static int disable_cleancache_ignore_nonactive __read_mostly; +static char *namestr __read_mostly = "zcache"; + +#define ZCACHE_GFP_MASK \ + (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC) + +MODULE_LICENSE("GPL"); + +/* crypto API for zcache */ +#define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME +static char zcache_comp_name[ZCACHE_COMP_NAME_SZ] __read_mostly; +static struct crypto_comp * __percpu *zcache_comp_pcpu_tfms __read_mostly; + +enum comp_op { + ZCACHE_COMPOP_COMPRESS, + ZCACHE_COMPOP_DECOMPRESS +}; + +static inline int zcache_comp_op(enum comp_op op, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen) +{ + struct crypto_comp *tfm; + int ret = -1; + + BUG_ON(!zcache_comp_pcpu_tfms); + tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, get_cpu()); + BUG_ON(!tfm); + switch (op) { + case ZCACHE_COMPOP_COMPRESS: + ret = crypto_comp_compress(tfm, src, slen, dst, dlen); + break; + case ZCACHE_COMPOP_DECOMPRESS: + ret = crypto_comp_decompress(tfm, src, slen, dst, dlen); + break; + default: + ret = -EINVAL; + } + put_cpu(); + return ret; +} + +/* + * policy parameters + */ + +/* + * byte count defining poor compression; pages with greater zsize will be + * rejected + */ +static unsigned int zbud_max_zsize __read_mostly = (PAGE_SIZE / 8) * 7; +/* + * byte count defining poor *mean* compression; pages with greater zsize + * will be rejected until sufficient better-compressed pages are accepted + * driving the mean below this threshold + */ +static unsigned int zbud_max_mean_zsize __read_mostly = (PAGE_SIZE / 8) * 5; + +/* + * for now, used named slabs so can easily track usage; later can + * either just use kmalloc, or perhaps add a slab-like allocator + * to more carefully manage total memory utilization + */ +static struct kmem_cache *zcache_objnode_cache; +static struct kmem_cache *zcache_obj_cache; + +static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, }; + +/* we try to keep these statistics SMP-consistent */ +static long zcache_obj_count; +static atomic_t zcache_obj_atomic = ATOMIC_INIT(0); +static long zcache_obj_count_max; +static long zcache_objnode_count; +static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0); +static long zcache_objnode_count_max; +static u64 zcache_eph_zbytes; +static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0); +static u64 zcache_eph_zbytes_max; +static u64 zcache_pers_zbytes; +static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0); +static u64 zcache_pers_zbytes_max; +static long zcache_eph_pageframes; +static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0); +static long zcache_eph_pageframes_max; +static long zcache_pers_pageframes; +static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0); +static long zcache_pers_pageframes_max; +static long zcache_pageframes_alloced; +static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0); +static long zcache_pageframes_freed; +static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0); +static long zcache_eph_zpages; +static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0); +static long zcache_eph_zpages_max; +static long zcache_pers_zpages; +static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0); +static long zcache_pers_zpages_max; + +/* but for the rest of these, counting races are ok */ +static unsigned long zcache_flush_total; +static unsigned long zcache_flush_found; +static unsigned long zcache_flobj_total; +static unsigned long zcache_flobj_found; +static unsigned long zcache_failed_eph_puts; +static unsigned long zcache_failed_pers_puts; +static unsigned long zcache_failed_getfreepages; +static unsigned long zcache_failed_alloc; +static unsigned long zcache_put_to_flush; +static unsigned long zcache_compress_poor; +static unsigned long zcache_mean_compress_poor; +static unsigned long zcache_eph_ate_tail; +static unsigned long zcache_eph_ate_tail_failed; +static unsigned long zcache_pers_ate_eph; +static unsigned long zcache_pers_ate_eph_failed; +static unsigned long zcache_evicted_eph_zpages; +static unsigned long zcache_evicted_eph_pageframes; +static unsigned long zcache_last_active_file_pageframes; +static unsigned long zcache_last_inactive_file_pageframes; +static unsigned long zcache_last_active_anon_pageframes; +static unsigned long zcache_last_inactive_anon_pageframes; +static unsigned long zcache_eph_nonactive_puts_ignored; +static unsigned long zcache_pers_nonactive_puts_ignored; + +#ifdef CONFIG_DEBUG_FS +#include +#define zdfs debugfs_create_size_t +#define zdfs64 debugfs_create_u64 +static int zcache_debugfs_init(void) +{ + struct dentry *root = debugfs_create_dir("zcache", NULL); + if (root == NULL) + return -ENXIO; + + zdfs("obj_count", S_IRUGO, root, &zcache_obj_count); + zdfs("obj_count_max", S_IRUGO, root, &zcache_obj_count_max); + zdfs("objnode_count", S_IRUGO, root, &zcache_objnode_count); + zdfs("objnode_count_max", S_IRUGO, root, &zcache_objnode_count_max); + zdfs("flush_total", S_IRUGO, root, &zcache_flush_total); + zdfs("flush_found", S_IRUGO, root, &zcache_flush_found); + zdfs("flobj_total", S_IRUGO, root, &zcache_flobj_total); + zdfs("flobj_found", S_IRUGO, root, &zcache_flobj_found); + zdfs("failed_eph_puts", S_IRUGO, root, &zcache_failed_eph_puts); + zdfs("failed_pers_puts", S_IRUGO, root, &zcache_failed_pers_puts); + zdfs("failed_get_free_pages", S_IRUGO, root, + &zcache_failed_getfreepages); + zdfs("failed_alloc", S_IRUGO, root, &zcache_failed_alloc); + zdfs("put_to_flush", S_IRUGO, root, &zcache_put_to_flush); + zdfs("compress_poor", S_IRUGO, root, &zcache_compress_poor); + zdfs("mean_compress_poor", S_IRUGO, root, &zcache_mean_compress_poor); + zdfs("eph_ate_tail", S_IRUGO, root, &zcache_eph_ate_tail); + zdfs("eph_ate_tail_failed", S_IRUGO, root, &zcache_eph_ate_tail_failed); + zdfs("pers_ate_eph", S_IRUGO, root, &zcache_pers_ate_eph); + zdfs("pers_ate_eph_failed", S_IRUGO, root, &zcache_pers_ate_eph_failed); + zdfs("evicted_eph_zpages", S_IRUGO, root, &zcache_evicted_eph_zpages); + zdfs("evicted_eph_pageframes", S_IRUGO, root, + &zcache_evicted_eph_pageframes); + zdfs("eph_pageframes", S_IRUGO, root, &zcache_eph_pageframes); + zdfs("eph_pageframes_max", S_IRUGO, root, &zcache_eph_pageframes_max); + zdfs("pers_pageframes", S_IRUGO, root, &zcache_pers_pageframes); + zdfs("pers_pageframes_max", S_IRUGO, root, &zcache_pers_pageframes_max); + zdfs("eph_zpages", S_IRUGO, root, &zcache_eph_zpages); + zdfs("eph_zpages_max", S_IRUGO, root, &zcache_eph_zpages_max); + zdfs("pers_zpages", S_IRUGO, root, &zcache_pers_zpages); + zdfs("pers_zpages_max", S_IRUGO, root, &zcache_pers_zpages_max); + zdfs("last_active_file_pageframes", S_IRUGO, root, + &zcache_last_active_file_pageframes); + zdfs("last_inactive_file_pageframes", S_IRUGO, root, + &zcache_last_inactive_file_pageframes); + zdfs("last_active_anon_pageframes", S_IRUGO, root, + &zcache_last_active_anon_pageframes); + zdfs("last_inactive_anon_pageframes", S_IRUGO, root, + &zcache_last_inactive_anon_pageframes); + zdfs("eph_nonactive_puts_ignored", S_IRUGO, root, + &zcache_eph_nonactive_puts_ignored); + zdfs("pers_nonactive_puts_ignored", S_IRUGO, root, + &zcache_pers_nonactive_puts_ignored); + zdfs64("eph_zbytes", S_IRUGO, root, &zcache_eph_zbytes); + zdfs64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max); + zdfs64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes); + zdfs64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max); + return 0; +} +#undef zdebugfs +#undef zdfs64 +#endif + +#define ZCACHE_DEBUG +#ifdef ZCACHE_DEBUG +/* developers can call this in case of ooms, e.g. to find memory leaks */ +void zcache_dump(void) +{ + pr_info("zcache: obj_count=%lu\n", zcache_obj_count); + pr_info("zcache: obj_count_max=%lu\n", zcache_obj_count_max); + pr_info("zcache: objnode_count=%lu\n", zcache_objnode_count); + pr_info("zcache: objnode_count_max=%lu\n", zcache_objnode_count_max); + pr_info("zcache: flush_total=%lu\n", zcache_flush_total); + pr_info("zcache: flush_found=%lu\n", zcache_flush_found); + pr_info("zcache: flobj_total=%lu\n", zcache_flobj_total); + pr_info("zcache: flobj_found=%lu\n", zcache_flobj_found); + pr_info("zcache: failed_eph_puts=%lu\n", zcache_failed_eph_puts); + pr_info("zcache: failed_pers_puts=%lu\n", zcache_failed_pers_puts); + pr_info("zcache: failed_get_free_pages=%lu\n", + zcache_failed_getfreepages); + pr_info("zcache: failed_alloc=%lu\n", zcache_failed_alloc); + pr_info("zcache: put_to_flush=%lu\n", zcache_put_to_flush); + pr_info("zcache: compress_poor=%lu\n", zcache_compress_poor); + pr_info("zcache: mean_compress_poor=%lu\n", + zcache_mean_compress_poor); + pr_info("zcache: eph_ate_tail=%lu\n", zcache_eph_ate_tail); + pr_info("zcache: eph_ate_tail_failed=%lu\n", + zcache_eph_ate_tail_failed); + pr_info("zcache: pers_ate_eph=%lu\n", zcache_pers_ate_eph); + pr_info("zcache: pers_ate_eph_failed=%lu\n", + zcache_pers_ate_eph_failed); + pr_info("zcache: evicted_eph_zpages=%lu\n", zcache_evicted_eph_zpages); + pr_info("zcache: evicted_eph_pageframes=%lu\n", + zcache_evicted_eph_pageframes); + pr_info("zcache: eph_pageframes=%lu\n", zcache_eph_pageframes); + pr_info("zcache: eph_pageframes_max=%lu\n", zcache_eph_pageframes_max); + pr_info("zcache: pers_pageframes=%lu\n", zcache_pers_pageframes); + pr_info("zcache: pers_pageframes_max=%lu\n", + zcache_pers_pageframes_max); + pr_info("zcache: eph_zpages=%lu\n", zcache_eph_zpages); + pr_info("zcache: eph_zpages_max=%lu\n", zcache_eph_zpages_max); + pr_info("zcache: pers_zpages=%lu\n", zcache_pers_zpages); + pr_info("zcache: pers_zpages_max=%lu\n", zcache_pers_zpages_max); + pr_info("zcache: eph_zbytes=%llu\n", + (unsigned long long)zcache_eph_zbytes); + pr_info("zcache: eph_zbytes_max=%llu\n", + (unsigned long long)zcache_eph_zbytes_max); + pr_info("zcache: pers_zbytes=%llu\n", + (unsigned long long)zcache_pers_zbytes); + pr_info("zcache: pers_zbytes_max=%llu\n", + (unsigned long long)zcache_pers_zbytes_max); +} +#endif + +/* + * zcache core code starts here + */ + +static struct zcache_client zcache_host; +static struct zcache_client zcache_clients[MAX_CLIENTS]; + +static inline bool is_local_client(struct zcache_client *cli) +{ + return cli == &zcache_host; +} + +static struct zcache_client *zcache_get_client_by_id(uint16_t cli_id) +{ + struct zcache_client *cli = &zcache_host; + + if (cli_id != LOCAL_CLIENT) { + if (cli_id >= MAX_CLIENTS) + goto out; + cli = &zcache_clients[cli_id]; + } +out: + return cli; +} + +/* + * Tmem operations assume the poolid implies the invoking client. + * Zcache only has one client (the kernel itself): LOCAL_CLIENT. + * RAMster has each client numbered by cluster node, and a KVM version + * of zcache would have one client per guest and each client might + * have a poolid==N. + */ +struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid) +{ + struct tmem_pool *pool = NULL; + struct zcache_client *cli = NULL; + + cli = zcache_get_client_by_id(cli_id); + if (cli == NULL) + goto out; + if (!is_local_client(cli)) + atomic_inc(&cli->refcount); + if (poolid < MAX_POOLS_PER_CLIENT) { + pool = cli->tmem_pools[poolid]; + if (pool != NULL) + atomic_inc(&pool->refcount); + } +out: + return pool; +} + +void zcache_put_pool(struct tmem_pool *pool) +{ + struct zcache_client *cli = NULL; + + if (pool == NULL) + BUG(); + cli = pool->client; + atomic_dec(&pool->refcount); + if (!is_local_client(cli)) + atomic_dec(&cli->refcount); +} + +int zcache_new_client(uint16_t cli_id) +{ + struct zcache_client *cli; + int ret = -1; + + cli = zcache_get_client_by_id(cli_id); + if (cli == NULL) + goto out; + if (cli->allocated) + goto out; + cli->allocated = 1; + ret = 0; +out: + return ret; +} + +/* + * zcache implementation for tmem host ops + */ + +static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool) +{ + struct tmem_objnode *objnode = NULL; + struct zcache_preload *kp; + int i; + + kp = &__get_cpu_var(zcache_preloads); + for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) { + objnode = kp->objnodes[i]; + if (objnode != NULL) { + kp->objnodes[i] = NULL; + break; + } + } + BUG_ON(objnode == NULL); + zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic); + if (zcache_objnode_count > zcache_objnode_count_max) + zcache_objnode_count_max = zcache_objnode_count; + return objnode; +} + +static void zcache_objnode_free(struct tmem_objnode *objnode, + struct tmem_pool *pool) +{ + zcache_objnode_count = + atomic_dec_return(&zcache_objnode_atomic); + BUG_ON(zcache_objnode_count < 0); + kmem_cache_free(zcache_objnode_cache, objnode); +} + +static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool) +{ + struct tmem_obj *obj = NULL; + struct zcache_preload *kp; + + kp = &__get_cpu_var(zcache_preloads); + obj = kp->obj; + BUG_ON(obj == NULL); + kp->obj = NULL; + zcache_obj_count = atomic_inc_return(&zcache_obj_atomic); + if (zcache_obj_count > zcache_obj_count_max) + zcache_obj_count_max = zcache_obj_count; + return obj; +} + +static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) +{ + zcache_obj_count = + atomic_dec_return(&zcache_obj_atomic); + BUG_ON(zcache_obj_count < 0); + kmem_cache_free(zcache_obj_cache, obj); +} + +static struct tmem_hostops zcache_hostops = { + .obj_alloc = zcache_obj_alloc, + .obj_free = zcache_obj_free, + .objnode_alloc = zcache_objnode_alloc, + .objnode_free = zcache_objnode_free, +}; + +static struct page *zcache_alloc_page(void) +{ + struct page *page = alloc_page(ZCACHE_GFP_MASK); + + if (page != NULL) + zcache_pageframes_alloced = + atomic_inc_return(&zcache_pageframes_alloced_atomic); + return page; +} + +#ifdef FRONTSWAP_HAS_UNUSE +static void zcache_unacct_page(void) +{ + zcache_pageframes_freed = + atomic_inc_return(&zcache_pageframes_freed_atomic); +} +#endif + +static void zcache_free_page(struct page *page) +{ + long curr_pageframes; + static long max_pageframes, min_pageframes; + + if (page == NULL) + BUG(); + __free_page(page); + zcache_pageframes_freed = + atomic_inc_return(&zcache_pageframes_freed_atomic); + curr_pageframes = zcache_pageframes_alloced - + atomic_read(&zcache_pageframes_freed_atomic) - + atomic_read(&zcache_eph_pageframes_atomic) - + atomic_read(&zcache_pers_pageframes_atomic); + if (curr_pageframes > max_pageframes) + max_pageframes = curr_pageframes; + if (curr_pageframes < min_pageframes) + min_pageframes = curr_pageframes; +#ifdef ZCACHE_DEBUG + if (curr_pageframes > 2L || curr_pageframes < -2L) { + /* pr_info here */ + } +#endif +} + +/* + * zcache implementations for PAM page descriptor ops + */ + +/* forward reference */ +static void zcache_compress(struct page *from, + void **out_va, unsigned *out_len); + +static struct page *zcache_evict_eph_pageframe(void); + +static void *zcache_pampd_eph_create(char *data, size_t size, bool raw, + struct tmem_handle *th) +{ + void *pampd = NULL, *cdata = data; + unsigned clen = size; + struct page *page = (struct page *)(data), *newpage; + + if (!raw) { + zcache_compress(page, &cdata, &clen); + if (clen > zbud_max_buddy_size()) { + zcache_compress_poor++; + goto out; + } + } else { + BUG_ON(clen > zbud_max_buddy_size()); + } + + /* look for space via an existing match first */ + pampd = (void *)zbud_match_prep(th, true, cdata, clen); + if (pampd != NULL) + goto got_pampd; + + /* no match, now we need to find (or free up) a full page */ + newpage = zcache_alloc_page(); + if (newpage != NULL) + goto create_in_new_page; + + zcache_failed_getfreepages++; + /* can't allocate a page, evict an ephemeral page via LRU */ + newpage = zcache_evict_eph_pageframe(); + if (newpage == NULL) { + zcache_eph_ate_tail_failed++; + goto out; + } + zcache_eph_ate_tail++; + +create_in_new_page: + pampd = (void *)zbud_create_prep(th, true, cdata, clen, newpage); + BUG_ON(pampd == NULL); + zcache_eph_pageframes = + atomic_inc_return(&zcache_eph_pageframes_atomic); + if (zcache_eph_pageframes > zcache_eph_pageframes_max) + zcache_eph_pageframes_max = zcache_eph_pageframes; + +got_pampd: + zcache_eph_zbytes = + atomic_long_add_return(clen, &zcache_eph_zbytes_atomic); + if (zcache_eph_zbytes > zcache_eph_zbytes_max) + zcache_eph_zbytes_max = zcache_eph_zbytes; + zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic); + if (zcache_eph_zpages > zcache_eph_zpages_max) + zcache_eph_zpages_max = zcache_eph_zpages; + if (ramster_enabled && raw) + ramster_count_foreign_pages(true, 1); +out: + return pampd; +} + +static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, + struct tmem_handle *th) +{ + void *pampd = NULL, *cdata = data; + unsigned clen = size; + struct page *page = (struct page *)(data), *newpage; + unsigned long zbud_mean_zsize; + unsigned long curr_pers_zpages, total_zsize; + + if (data == NULL) { + BUG_ON(!ramster_enabled); + goto create_pampd; + } + curr_pers_zpages = zcache_pers_zpages; +/* FIXME CONFIG_RAMSTER... subtract atomic remote_pers_pages here? */ + if (!raw) + zcache_compress(page, &cdata, &clen); + /* reject if compression is too poor */ + if (clen > zbud_max_zsize) { + zcache_compress_poor++; + goto out; + } + /* reject if mean compression is too poor */ + if ((clen > zbud_max_mean_zsize) && (curr_pers_zpages > 0)) { + total_zsize = zcache_pers_zbytes; + if ((long)total_zsize < 0) + total_zsize = 0; + zbud_mean_zsize = div_u64(total_zsize, + curr_pers_zpages); + if (zbud_mean_zsize > zbud_max_mean_zsize) { + zcache_mean_compress_poor++; + goto out; + } + } + +create_pampd: + /* look for space via an existing match first */ + pampd = (void *)zbud_match_prep(th, false, cdata, clen); + if (pampd != NULL) + goto got_pampd; + + /* no match, now we need to find (or free up) a full page */ + newpage = zcache_alloc_page(); + if (newpage != NULL) + goto create_in_new_page; + /* + * FIXME do the following only if eph is oversized? + * if (zcache_eph_pageframes > + * (global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE) + + * global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE))) + */ + zcache_failed_getfreepages++; + /* can't allocate a page, evict an ephemeral page via LRU */ + newpage = zcache_evict_eph_pageframe(); + if (newpage == NULL) { + zcache_pers_ate_eph_failed++; + goto out; + } + zcache_pers_ate_eph++; + +create_in_new_page: + pampd = (void *)zbud_create_prep(th, false, cdata, clen, newpage); + BUG_ON(pampd == NULL); + zcache_pers_pageframes = + atomic_inc_return(&zcache_pers_pageframes_atomic); + if (zcache_pers_pageframes > zcache_pers_pageframes_max) + zcache_pers_pageframes_max = zcache_pers_pageframes; + +got_pampd: + zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic); + if (zcache_pers_zpages > zcache_pers_zpages_max) + zcache_pers_zpages_max = zcache_pers_zpages; + zcache_pers_zbytes = + atomic_long_add_return(clen, &zcache_pers_zbytes_atomic); + if (zcache_pers_zbytes > zcache_pers_zbytes_max) + zcache_pers_zbytes_max = zcache_pers_zbytes; + if (ramster_enabled && raw) + ramster_count_foreign_pages(false, 1); +out: + return pampd; +} + +/* + * This is called directly from zcache_put_page to pre-allocate space + * to store a zpage. + */ +void *zcache_pampd_create(char *data, unsigned int size, bool raw, + int eph, struct tmem_handle *th) +{ + void *pampd = NULL; + struct zcache_preload *kp; + struct tmem_objnode *objnode; + struct tmem_obj *obj; + int i; + + BUG_ON(!irqs_disabled()); + /* pre-allocate per-cpu metadata */ + BUG_ON(zcache_objnode_cache == NULL); + BUG_ON(zcache_obj_cache == NULL); + kp = &__get_cpu_var(zcache_preloads); + for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) { + objnode = kp->objnodes[i]; + if (objnode == NULL) { + objnode = kmem_cache_alloc(zcache_objnode_cache, + ZCACHE_GFP_MASK); + if (unlikely(objnode == NULL)) { + zcache_failed_alloc++; + goto out; + } + kp->objnodes[i] = objnode; + } + } + if (kp->obj == NULL) { + obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK); + kp->obj = obj; + } + if (unlikely(kp->obj == NULL)) { + zcache_failed_alloc++; + goto out; + } + /* + * ok, have all the metadata pre-allocated, now do the data + * but since how we allocate the data is dependent on ephemeral + * or persistent, we split the call here to different sub-functions + */ + if (eph) + pampd = zcache_pampd_eph_create(data, size, raw, th); + else + pampd = zcache_pampd_pers_create(data, size, raw, th); +out: + return pampd; +} + +/* + * This is a pamops called via tmem_put and is necessary to "finish" + * a pampd creation. + */ +void zcache_pampd_create_finish(void *pampd, bool eph) +{ + zbud_create_finish((struct zbudref *)pampd, eph); +} + +/* + * This is passed as a function parameter to zbud_decompress so that + * zbud need not be familiar with the details of crypto. It assumes that + * the bytes from_va and to_va through from_va+size-1 and to_va+size-1 are + * kmapped. It must be successful, else there is a logic bug somewhere. + */ +static void zcache_decompress(char *from_va, unsigned int size, char *to_va) +{ + int ret; + unsigned int outlen = PAGE_SIZE; + + ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, from_va, size, + to_va, &outlen); + BUG_ON(ret); + BUG_ON(outlen != PAGE_SIZE); +} + +/* + * Decompress from the kernel va to a pageframe + */ +void zcache_decompress_to_page(char *from_va, unsigned int size, + struct page *to_page) +{ + char *to_va = kmap_atomic(to_page); + zcache_decompress(from_va, size, to_va); + kunmap_atomic(to_va); +} + +/* + * fill the pageframe corresponding to the struct page with the data + * from the passed pampd + */ +static int zcache_pampd_get_data(char *data, size_t *sizep, bool raw, + void *pampd, struct tmem_pool *pool, + struct tmem_oid *oid, uint32_t index) +{ + int ret; + bool eph = !is_persistent(pool); + + BUG_ON(preemptible()); + BUG_ON(eph); /* fix later if shared pools get implemented */ + BUG_ON(pampd_is_remote(pampd)); + if (raw) + ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, + sizep, eph); + else { + ret = zbud_decompress((struct page *)(data), + (struct zbudref *)pampd, false, + zcache_decompress); + *sizep = PAGE_SIZE; + } + return ret; +} + +/* + * fill the pageframe corresponding to the struct page with the data + * from the passed pampd + */ +static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, + void *pampd, struct tmem_pool *pool, + struct tmem_oid *oid, uint32_t index) +{ + int ret; + bool eph = !is_persistent(pool); + struct page *page = NULL; + unsigned int zsize, zpages; + + BUG_ON(preemptible()); + BUG_ON(pampd_is_remote(pampd)); + if (raw) + ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, + sizep, eph); + else { + ret = zbud_decompress((struct page *)(data), + (struct zbudref *)pampd, eph, + zcache_decompress); + *sizep = PAGE_SIZE; + } + page = zbud_free_and_delist((struct zbudref *)pampd, eph, + &zsize, &zpages); + if (eph) { + if (page) + zcache_eph_pageframes = + atomic_dec_return(&zcache_eph_pageframes_atomic); + zcache_eph_zpages = + atomic_sub_return(zpages, &zcache_eph_zpages_atomic); + zcache_eph_zbytes = + atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic); + } else { + if (page) + zcache_pers_pageframes = + atomic_dec_return(&zcache_pers_pageframes_atomic); + zcache_pers_zpages = + atomic_sub_return(zpages, &zcache_pers_zpages_atomic); + zcache_pers_zbytes = + atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic); + } + if (!is_local_client(pool->client)) + ramster_count_foreign_pages(eph, -1); + if (page) + zcache_free_page(page); + return ret; +} + +/* + * free the pampd and remove it from any zcache lists + * pampd must no longer be pointed to from any tmem data structures! + */ +static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, + struct tmem_oid *oid, uint32_t index, bool acct) +{ + struct page *page = NULL; + unsigned int zsize, zpages; + + BUG_ON(preemptible()); + if (pampd_is_remote(pampd)) { + BUG_ON(!ramster_enabled); + pampd = ramster_pampd_free(pampd, pool, oid, index, acct); + if (pampd == NULL) + return; + } + if (is_ephemeral(pool)) { + page = zbud_free_and_delist((struct zbudref *)pampd, + true, &zsize, &zpages); + if (page) + zcache_eph_pageframes = + atomic_dec_return(&zcache_eph_pageframes_atomic); + zcache_eph_zpages = + atomic_sub_return(zpages, &zcache_eph_zpages_atomic); + zcache_eph_zbytes = + atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic); + /* FIXME CONFIG_RAMSTER... check acct parameter? */ + } else { + page = zbud_free_and_delist((struct zbudref *)pampd, + false, &zsize, &zpages); + if (page) + zcache_pers_pageframes = + atomic_dec_return(&zcache_pers_pageframes_atomic); + zcache_pers_zpages = + atomic_sub_return(zpages, &zcache_pers_zpages_atomic); + zcache_pers_zbytes = + atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic); + } + if (!is_local_client(pool->client)) + ramster_count_foreign_pages(is_ephemeral(pool), -1); + if (page) + zcache_free_page(page); +} + +static struct tmem_pamops zcache_pamops = { + .create_finish = zcache_pampd_create_finish, + .get_data = zcache_pampd_get_data, + .get_data_and_free = zcache_pampd_get_data_and_free, + .free = zcache_pampd_free, +}; + +/* + * zcache compression/decompression and related per-cpu stuff + */ + +static DEFINE_PER_CPU(unsigned char *, zcache_dstmem); +#define ZCACHE_DSTMEM_ORDER 1 + +static void zcache_compress(struct page *from, void **out_va, unsigned *out_len) +{ + int ret; + unsigned char *dmem = __get_cpu_var(zcache_dstmem); + char *from_va; + + BUG_ON(!irqs_disabled()); + /* no buffer or no compressor so can't compress */ + BUG_ON(dmem == NULL); + *out_len = PAGE_SIZE << ZCACHE_DSTMEM_ORDER; + from_va = kmap_atomic(from); + mb(); + ret = zcache_comp_op(ZCACHE_COMPOP_COMPRESS, from_va, PAGE_SIZE, dmem, + out_len); + BUG_ON(ret); + *out_va = dmem; + kunmap_atomic(from_va); +} + +static int zcache_comp_cpu_up(int cpu) +{ + struct crypto_comp *tfm; + + tfm = crypto_alloc_comp(zcache_comp_name, 0, 0); + if (IS_ERR(tfm)) + return NOTIFY_BAD; + *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = tfm; + return NOTIFY_OK; +} + +static void zcache_comp_cpu_down(int cpu) +{ + struct crypto_comp *tfm; + + tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu); + crypto_free_comp(tfm); + *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = NULL; +} + +static int zcache_cpu_notifier(struct notifier_block *nb, + unsigned long action, void *pcpu) +{ + int ret, i, cpu = (long)pcpu; + struct zcache_preload *kp; + + switch (action) { + case CPU_UP_PREPARE: + ret = zcache_comp_cpu_up(cpu); + if (ret != NOTIFY_OK) { + pr_err("%s: can't allocate compressor xform\n", + namestr); + return ret; + } + per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages( + GFP_KERNEL | __GFP_REPEAT, ZCACHE_DSTMEM_ORDER); + if (ramster_enabled) + ramster_cpu_up(cpu); + break; + case CPU_DEAD: + case CPU_UP_CANCELED: + zcache_comp_cpu_down(cpu); + free_pages((unsigned long)per_cpu(zcache_dstmem, cpu), + ZCACHE_DSTMEM_ORDER); + per_cpu(zcache_dstmem, cpu) = NULL; + kp = &per_cpu(zcache_preloads, cpu); + for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) { + if (kp->objnodes[i]) + kmem_cache_free(zcache_objnode_cache, + kp->objnodes[i]); + } + if (kp->obj) { + kmem_cache_free(zcache_obj_cache, kp->obj); + kp->obj = NULL; + } + if (ramster_enabled) + ramster_cpu_down(cpu); + break; + default: + break; + } + return NOTIFY_OK; +} + +static struct notifier_block zcache_cpu_notifier_block = { + .notifier_call = zcache_cpu_notifier +}; + +/* + * The following code interacts with the zbud eviction and zbud + * zombify code to access LRU pages + */ + +static struct page *zcache_evict_eph_pageframe(void) +{ + struct page *page; + unsigned int zsize = 0, zpages = 0; + + page = zbud_evict_pageframe_lru(&zsize, &zpages); + if (page == NULL) + goto out; + zcache_eph_zbytes = atomic_long_sub_return(zsize, + &zcache_eph_zbytes_atomic); + zcache_eph_zpages = atomic_sub_return(zpages, + &zcache_eph_zpages_atomic); + zcache_evicted_eph_zpages++; + zcache_eph_pageframes = + atomic_dec_return(&zcache_eph_pageframes_atomic); + zcache_evicted_eph_pageframes++; +out: + return page; +} + +#ifdef FRONTSWAP_HAS_UNUSE +static void unswiz(struct tmem_oid oid, u32 index, + unsigned *type, pgoff_t *offset); + +/* + * Choose an LRU persistent pageframe and attempt to "unuse" it by + * calling frontswap_unuse on both zpages. + * + * This is work-in-progress. + */ + +static int zcache_frontswap_unuse(void) +{ + struct tmem_handle th[2]; + int ret = -ENOMEM; + int nzbuds, unuse_ret; + unsigned type; + struct page *newpage1 = NULL, *newpage2 = NULL; + struct page *evictpage1 = NULL, *evictpage2 = NULL; + pgoff_t offset; + + newpage1 = alloc_page(ZCACHE_GFP_MASK); + newpage2 = alloc_page(ZCACHE_GFP_MASK); + if (newpage1 == NULL) + evictpage1 = zcache_evict_eph_pageframe(); + if (newpage2 == NULL) + evictpage2 = zcache_evict_eph_pageframe(); + if (evictpage1 == NULL || evictpage2 == NULL) + goto free_and_out; + /* ok, we have two pages pre-allocated */ + nzbuds = zbud_make_zombie_lru(&th[0], NULL, NULL, false); + if (nzbuds == 0) { + ret = -ENOENT; + goto free_and_out; + } + unswiz(th[0].oid, th[0].index, &type, &offset); + unuse_ret = frontswap_unuse(type, offset, + newpage1 != NULL ? newpage1 : evictpage1, + ZCACHE_GFP_MASK); + if (unuse_ret != 0) + goto free_and_out; + else if (evictpage1 != NULL) + zcache_unacct_page(); + newpage1 = NULL; + evictpage1 = NULL; + if (nzbuds == 2) { + unswiz(th[1].oid, th[1].index, &type, &offset); + unuse_ret = frontswap_unuse(type, offset, + newpage2 != NULL ? newpage2 : evictpage2, + ZCACHE_GFP_MASK); + if (unuse_ret != 0) { + goto free_and_out; + } else if (evictpage2 != NULL) { + zcache_unacct_page(); + } + } + ret = 0; + goto out; + +free_and_out: + if (newpage1 != NULL) + __free_page(newpage1); + if (newpage2 != NULL) + __free_page(newpage2); + if (evictpage1 != NULL) + zcache_free_page(evictpage1); + if (evictpage2 != NULL) + zcache_free_page(evictpage2); +out: + return ret; +} +#endif + +/* + * When zcache is disabled ("frozen"), pools can be created and destroyed, + * but all puts (and thus all other operations that require memory allocation) + * must fail. If zcache is unfrozen, accepts puts, then frozen again, + * data consistency requires all puts while frozen to be converted into + * flushes. + */ +static bool zcache_freeze; + +/* + * This zcache shrinker interface reduces the number of ephemeral pageframes + * used by zcache to approximately the same as the total number of LRU_FILE + * pageframes in use. + */ +static int shrink_zcache_memory(struct shrinker *shrink, + struct shrink_control *sc) +{ + static bool in_progress; + int ret = -1; + int nr = sc->nr_to_scan; + int nr_evict = 0; + int nr_unuse = 0; + struct page *page; +#ifdef FRONTSWAP_HAS_UNUSE + int unuse_ret; +#endif + + if (nr <= 0) + goto skip_evict; + + /* don't allow more than one eviction thread at a time */ + if (in_progress) + goto skip_evict; + + in_progress = true; + + /* we are going to ignore nr, and target a different value */ + zcache_last_active_file_pageframes = + global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); + zcache_last_inactive_file_pageframes = + global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); + nr_evict = zcache_eph_pageframes - zcache_last_active_file_pageframes + + zcache_last_inactive_file_pageframes; + while (nr_evict-- > 0) { + page = zcache_evict_eph_pageframe(); + if (page == NULL) + break; + zcache_free_page(page); + } + + zcache_last_active_anon_pageframes = + global_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON); + zcache_last_inactive_anon_pageframes = + global_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON); + nr_unuse = zcache_pers_pageframes - zcache_last_active_anon_pageframes + + zcache_last_inactive_anon_pageframes; +#ifdef FRONTSWAP_HAS_UNUSE + /* rate limit for testing */ + if (nr_unuse > 32) + nr_unuse = 32; + while (nr_unuse-- > 0) { + unuse_ret = zcache_frontswap_unuse(); + if (unuse_ret == -ENOMEM) + break; + } +#endif + in_progress = false; + +skip_evict: + /* resample: has changed, but maybe not all the way yet */ + zcache_last_active_file_pageframes = + global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); + zcache_last_inactive_file_pageframes = + global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); + ret = zcache_eph_pageframes - zcache_last_active_file_pageframes + + zcache_last_inactive_file_pageframes; + if (ret < 0) + ret = 0; + return ret; +} + +static struct shrinker zcache_shrinker = { + .shrink = shrink_zcache_memory, + .seeks = DEFAULT_SEEKS, +}; + +/* + * zcache shims between cleancache/frontswap ops and tmem + */ + +/* FIXME rename these core routines to zcache_tmemput etc? */ +int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp, + uint32_t index, void *page, + unsigned int size, bool raw, int ephemeral) +{ + struct tmem_pool *pool; + struct tmem_handle th; + int ret = -1; + void *pampd = NULL; + + BUG_ON(!irqs_disabled()); + pool = zcache_get_pool_by_id(cli_id, pool_id); + if (unlikely(pool == NULL)) + goto out; + if (!zcache_freeze) { + ret = 0; + th.client_id = cli_id; + th.pool_id = pool_id; + th.oid = *oidp; + th.index = index; + pampd = zcache_pampd_create((char *)page, size, raw, + ephemeral, &th); + if (pampd == NULL) { + ret = -ENOMEM; + if (ephemeral) + zcache_failed_eph_puts++; + else + zcache_failed_pers_puts++; + } else { + if (ramster_enabled) + ramster_do_preload_flnode(pool); + ret = tmem_put(pool, oidp, index, 0, pampd); + if (ret < 0) + BUG(); + } + zcache_put_pool(pool); + } else { + zcache_put_to_flush++; + if (ramster_enabled) + ramster_do_preload_flnode(pool); + if (atomic_read(&pool->obj_count) > 0) + /* the put fails whether the flush succeeds or not */ + (void)tmem_flush_page(pool, oidp, index); + zcache_put_pool(pool); + } +out: + return ret; +} + +int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp, + uint32_t index, void *page, + size_t *sizep, bool raw, int get_and_free) +{ + struct tmem_pool *pool; + int ret = -1; + bool eph; + + if (!raw) { + BUG_ON(irqs_disabled()); + BUG_ON(in_softirq()); + } + pool = zcache_get_pool_by_id(cli_id, pool_id); + eph = is_ephemeral(pool); + if (likely(pool != NULL)) { + if (atomic_read(&pool->obj_count) > 0) + ret = tmem_get(pool, oidp, index, (char *)(page), + sizep, raw, get_and_free); + zcache_put_pool(pool); + } + WARN_ONCE((!is_ephemeral(pool) && (ret != 0)), + "zcache_get fails on persistent pool, " + "bad things are very likely to happen soon\n"); +#ifdef RAMSTER_TESTING + if (ret != 0 && ret != -1 && !(ret == -EINVAL && is_ephemeral(pool))) + pr_err("TESTING zcache_get tmem_get returns ret=%d\n", ret); +#endif + return ret; +} + +int zcache_flush_page(int cli_id, int pool_id, + struct tmem_oid *oidp, uint32_t index) +{ + struct tmem_pool *pool; + int ret = -1; + unsigned long flags; + + local_irq_save(flags); + zcache_flush_total++; + pool = zcache_get_pool_by_id(cli_id, pool_id); + if (ramster_enabled) + ramster_do_preload_flnode(pool); + if (likely(pool != NULL)) { + if (atomic_read(&pool->obj_count) > 0) + ret = tmem_flush_page(pool, oidp, index); + zcache_put_pool(pool); + } + if (ret >= 0) + zcache_flush_found++; + local_irq_restore(flags); + return ret; +} + +int zcache_flush_object(int cli_id, int pool_id, + struct tmem_oid *oidp) +{ + struct tmem_pool *pool; + int ret = -1; + unsigned long flags; + + local_irq_save(flags); + zcache_flobj_total++; + pool = zcache_get_pool_by_id(cli_id, pool_id); + if (ramster_enabled) + ramster_do_preload_flnode(pool); + if (likely(pool != NULL)) { + if (atomic_read(&pool->obj_count) > 0) + ret = tmem_flush_object(pool, oidp); + zcache_put_pool(pool); + } + if (ret >= 0) + zcache_flobj_found++; + local_irq_restore(flags); + return ret; +} + +static int zcache_client_destroy_pool(int cli_id, int pool_id) +{ + struct tmem_pool *pool = NULL; + struct zcache_client *cli = NULL; + int ret = -1; + + if (pool_id < 0) + goto out; + if (cli_id == LOCAL_CLIENT) + cli = &zcache_host; + else if ((unsigned int)cli_id < MAX_CLIENTS) + cli = &zcache_clients[cli_id]; + if (cli == NULL) + goto out; + atomic_inc(&cli->refcount); + pool = cli->tmem_pools[pool_id]; + if (pool == NULL) + goto out; + cli->tmem_pools[pool_id] = NULL; + /* wait for pool activity on other cpus to quiesce */ + while (atomic_read(&pool->refcount) != 0) + ; + atomic_dec(&cli->refcount); + local_bh_disable(); + ret = tmem_destroy_pool(pool); + local_bh_enable(); + kfree(pool); + if (cli_id == LOCAL_CLIENT) + pr_info("%s: destroyed local pool id=%d\n", namestr, pool_id); + else + pr_info("%s: destroyed pool id=%d, client=%d\n", + namestr, pool_id, cli_id); +out: + return ret; +} + +int zcache_new_pool(uint16_t cli_id, uint32_t flags) +{ + int poolid = -1; + struct tmem_pool *pool; + struct zcache_client *cli = NULL; + + if (cli_id == LOCAL_CLIENT) + cli = &zcache_host; + else if ((unsigned int)cli_id < MAX_CLIENTS) + cli = &zcache_clients[cli_id]; + if (cli == NULL) + goto out; + atomic_inc(&cli->refcount); + pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC); + if (pool == NULL) { + pr_info("%s: pool creation failed: out of memory\n", namestr); + goto out; + } + + for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++) + if (cli->tmem_pools[poolid] == NULL) + break; + if (poolid >= MAX_POOLS_PER_CLIENT) { + pr_info("%s: pool creation failed: max exceeded\n", namestr); + kfree(pool); + poolid = -1; + goto out; + } + atomic_set(&pool->refcount, 0); + pool->client = cli; + pool->pool_id = poolid; + tmem_new_pool(pool, flags); + cli->tmem_pools[poolid] = pool; + if (cli_id == LOCAL_CLIENT) + pr_info("%s: created %s local tmem pool, id=%d\n", namestr, + flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", + poolid); + else + pr_info("%s: created %s tmem pool, id=%d, client=%d\n", namestr, + flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", + poolid, cli_id); +out: + if (cli != NULL) + atomic_dec(&cli->refcount); + return poolid; +} + +static int zcache_local_new_pool(uint32_t flags) +{ + return zcache_new_pool(LOCAL_CLIENT, flags); +} + +int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph) +{ + struct tmem_pool *pool; + struct zcache_client *cli; + uint32_t flags = eph ? 0 : TMEM_POOL_PERSIST; + int ret = -1; + + BUG_ON(!ramster_enabled); + if (cli_id == LOCAL_CLIENT) + goto out; + if (pool_id >= MAX_POOLS_PER_CLIENT) + goto out; + if (cli_id >= MAX_CLIENTS) + goto out; + + cli = &zcache_clients[cli_id]; + if ((eph && disable_cleancache) || (!eph && disable_frontswap)) { + pr_err("zcache_autocreate_pool: pool type disabled\n"); + goto out; + } + if (!cli->allocated) { + if (zcache_new_client(cli_id)) { + pr_err("zcache_autocreate_pool: can't create client\n"); + goto out; + } + cli = &zcache_clients[cli_id]; + } + atomic_inc(&cli->refcount); + pool = cli->tmem_pools[pool_id]; + if (pool != NULL) { + if (pool->persistent && eph) { + pr_err("zcache_autocreate_pool: type mismatch\n"); + goto out; + } + ret = 0; + goto out; + } + pool = kmalloc(sizeof(struct tmem_pool), GFP_KERNEL); + if (pool == NULL) { + pr_info("%s: pool creation failed: out of memory\n", namestr); + goto out; + } + atomic_set(&pool->refcount, 0); + pool->client = cli; + pool->pool_id = pool_id; + tmem_new_pool(pool, flags); + cli->tmem_pools[pool_id] = pool; + pr_info("%s: AUTOcreated %s tmem poolid=%d, for remote client=%d\n", + namestr, flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", + pool_id, cli_id); + ret = 0; +out: + if (cli != NULL) + atomic_dec(&cli->refcount); + return ret; +} + +/********** + * Two kernel functionalities currently can be layered on top of tmem. + * These are "cleancache" which is used as a second-chance cache for clean + * page cache pages; and "frontswap" which is used for swap pages + * to avoid writes to disk. A generic "shim" is provided here for each + * to translate in-kernel semantics to zcache semantics. + */ + +static void zcache_cleancache_put_page(int pool_id, + struct cleancache_filekey key, + pgoff_t index, struct page *page) +{ + u32 ind = (u32) index; + struct tmem_oid oid = *(struct tmem_oid *)&key; + + if (!disable_cleancache_ignore_nonactive && !PageWasActive(page)) { + zcache_eph_nonactive_puts_ignored++; + return; + } + if (likely(ind == index)) + (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index, + page, PAGE_SIZE, false, 1); +} + +static int zcache_cleancache_get_page(int pool_id, + struct cleancache_filekey key, + pgoff_t index, struct page *page) +{ + u32 ind = (u32) index; + struct tmem_oid oid = *(struct tmem_oid *)&key; + size_t size; + int ret = -1; + + if (likely(ind == index)) { + ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index, + page, &size, false, 0); + BUG_ON(ret >= 0 && size != PAGE_SIZE); + if (ret == 0) + SetPageWasActive(page); + } + return ret; +} + +static void zcache_cleancache_flush_page(int pool_id, + struct cleancache_filekey key, + pgoff_t index) +{ + u32 ind = (u32) index; + struct tmem_oid oid = *(struct tmem_oid *)&key; + + if (likely(ind == index)) + (void)zcache_flush_page(LOCAL_CLIENT, pool_id, &oid, ind); +} + +static void zcache_cleancache_flush_inode(int pool_id, + struct cleancache_filekey key) +{ + struct tmem_oid oid = *(struct tmem_oid *)&key; + + (void)zcache_flush_object(LOCAL_CLIENT, pool_id, &oid); +} + +static void zcache_cleancache_flush_fs(int pool_id) +{ + if (pool_id >= 0) + (void)zcache_client_destroy_pool(LOCAL_CLIENT, pool_id); +} + +static int zcache_cleancache_init_fs(size_t pagesize) +{ + BUG_ON(sizeof(struct cleancache_filekey) != + sizeof(struct tmem_oid)); + BUG_ON(pagesize != PAGE_SIZE); + return zcache_local_new_pool(0); +} + +static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize) +{ + /* shared pools are unsupported and map to private */ + BUG_ON(sizeof(struct cleancache_filekey) != + sizeof(struct tmem_oid)); + BUG_ON(pagesize != PAGE_SIZE); + return zcache_local_new_pool(0); +} + +static struct cleancache_ops zcache_cleancache_ops = { + .put_page = zcache_cleancache_put_page, + .get_page = zcache_cleancache_get_page, + .invalidate_page = zcache_cleancache_flush_page, + .invalidate_inode = zcache_cleancache_flush_inode, + .invalidate_fs = zcache_cleancache_flush_fs, + .init_shared_fs = zcache_cleancache_init_shared_fs, + .init_fs = zcache_cleancache_init_fs +}; + +struct cleancache_ops zcache_cleancache_register_ops(void) +{ + struct cleancache_ops old_ops = + cleancache_register_ops(&zcache_cleancache_ops); + + return old_ops; +} + +/* a single tmem poolid is used for all frontswap "types" (swapfiles) */ +static int zcache_frontswap_poolid __read_mostly = -1; + +/* + * Swizzling increases objects per swaptype, increasing tmem concurrency + * for heavy swaploads. Later, larger nr_cpus -> larger SWIZ_BITS + * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from + * frontswap_get_page(), but has side-effects. Hence using 8. + */ +#define SWIZ_BITS 8 +#define SWIZ_MASK ((1 << SWIZ_BITS) - 1) +#define _oswiz(_type, _ind) ((_type << SWIZ_BITS) | (_ind & SWIZ_MASK)) +#define iswiz(_ind) (_ind >> SWIZ_BITS) + +static inline struct tmem_oid oswiz(unsigned type, u32 ind) +{ + struct tmem_oid oid = { .oid = { 0 } }; + oid.oid[0] = _oswiz(type, ind); + return oid; +} + +#ifdef FRONTSWAP_HAS_UNUSE +static void unswiz(struct tmem_oid oid, u32 index, + unsigned *type, pgoff_t *offset) +{ + *type = (unsigned)(oid.oid[0] >> SWIZ_BITS); + *offset = (pgoff_t)((index << SWIZ_BITS) | + (oid.oid[0] & SWIZ_MASK)); +} +#endif + +static int zcache_frontswap_put_page(unsigned type, pgoff_t offset, + struct page *page) +{ + u64 ind64 = (u64)offset; + u32 ind = (u32)offset; + struct tmem_oid oid = oswiz(type, ind); + int ret = -1; + unsigned long flags; + + BUG_ON(!PageLocked(page)); + if (!disable_frontswap_ignore_nonactive && !PageWasActive(page)) { + zcache_pers_nonactive_puts_ignored++; + ret = -ERANGE; + goto out; + } + if (likely(ind64 == ind)) { + local_irq_save(flags); + ret = zcache_put_page(LOCAL_CLIENT, zcache_frontswap_poolid, + &oid, iswiz(ind), + page, PAGE_SIZE, false, 0); + local_irq_restore(flags); + } +out: + return ret; +} + +/* returns 0 if the page was successfully gotten from frontswap, -1 if + * was not present (should never happen!) */ +static int zcache_frontswap_get_page(unsigned type, pgoff_t offset, + struct page *page) +{ + u64 ind64 = (u64)offset; + u32 ind = (u32)offset; + struct tmem_oid oid = oswiz(type, ind); + size_t size; + int ret = -1, get_and_free; + + if (frontswap_has_exclusive_gets) + get_and_free = 1; + else + get_and_free = -1; + BUG_ON(!PageLocked(page)); + if (likely(ind64 == ind)) { + ret = zcache_get_page(LOCAL_CLIENT, zcache_frontswap_poolid, + &oid, iswiz(ind), + page, &size, false, get_and_free); + BUG_ON(ret >= 0 && size != PAGE_SIZE); + } + return ret; +} + +/* flush a single page from frontswap */ +static void zcache_frontswap_flush_page(unsigned type, pgoff_t offset) +{ + u64 ind64 = (u64)offset; + u32 ind = (u32)offset; + struct tmem_oid oid = oswiz(type, ind); + + if (likely(ind64 == ind)) + (void)zcache_flush_page(LOCAL_CLIENT, zcache_frontswap_poolid, + &oid, iswiz(ind)); +} + +/* flush all pages from the passed swaptype */ +static void zcache_frontswap_flush_area(unsigned type) +{ + struct tmem_oid oid; + int ind; + + for (ind = SWIZ_MASK; ind >= 0; ind--) { + oid = oswiz(type, ind); + (void)zcache_flush_object(LOCAL_CLIENT, + zcache_frontswap_poolid, &oid); + } +} + +static void zcache_frontswap_init(unsigned ignored) +{ + /* a single tmem poolid is used for all frontswap "types" (swapfiles) */ + if (zcache_frontswap_poolid < 0) + zcache_frontswap_poolid = + zcache_local_new_pool(TMEM_POOL_PERSIST); +} + +static struct frontswap_ops zcache_frontswap_ops = { + .store = zcache_frontswap_put_page, + .load = zcache_frontswap_get_page, + .invalidate_page = zcache_frontswap_flush_page, + .invalidate_area = zcache_frontswap_flush_area, + .init = zcache_frontswap_init +}; + +struct frontswap_ops zcache_frontswap_register_ops(void) +{ + struct frontswap_ops old_ops = + frontswap_register_ops(&zcache_frontswap_ops); + + return old_ops; +} + +/* + * zcache initialization + * NOTE FOR NOW zcache or ramster MUST BE PROVIDED AS A KERNEL BOOT PARAMETER + * OR NOTHING HAPPENS! + */ + +static int __init enable_zcache(char *s) +{ + zcache_enabled = 1; + return 1; +} +__setup("zcache", enable_zcache); + +static int __init enable_ramster(char *s) +{ + zcache_enabled = 1; +#ifdef CONFIG_RAMSTER + ramster_enabled = 1; +#endif + return 1; +} +__setup("ramster", enable_ramster); + +/* allow independent dynamic disabling of cleancache and frontswap */ + +static int __init no_cleancache(char *s) +{ + disable_cleancache = 1; + return 1; +} + +__setup("nocleancache", no_cleancache); + +static int __init no_frontswap(char *s) +{ + disable_frontswap = 1; + return 1; +} + +__setup("nofrontswap", no_frontswap); + +static int __init no_frontswap_exclusive_gets(char *s) +{ + frontswap_has_exclusive_gets = false; + return 1; +} + +__setup("nofrontswapexclusivegets", no_frontswap_exclusive_gets); + +static int __init no_frontswap_ignore_nonactive(char *s) +{ + disable_frontswap_ignore_nonactive = 1; + return 1; +} + +__setup("nofrontswapignorenonactive", no_frontswap_ignore_nonactive); + +static int __init no_cleancache_ignore_nonactive(char *s) +{ + disable_cleancache_ignore_nonactive = 1; + return 1; +} + +__setup("nocleancacheignorenonactive", no_cleancache_ignore_nonactive); + +static int __init enable_zcache_compressor(char *s) +{ + strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ); + zcache_enabled = 1; + return 1; +} +__setup("zcache=", enable_zcache_compressor); + + +static int __init zcache_comp_init(void) +{ + int ret = 0; + + /* check crypto algorithm */ + if (*zcache_comp_name != '\0') { + ret = crypto_has_comp(zcache_comp_name, 0, 0); + if (!ret) + pr_info("zcache: %s not supported\n", + zcache_comp_name); + } + if (!ret) + strcpy(zcache_comp_name, "lzo"); + ret = crypto_has_comp(zcache_comp_name, 0, 0); + if (!ret) { + ret = 1; + goto out; + } + pr_info("zcache: using %s compressor\n", zcache_comp_name); + + /* alloc percpu transforms */ + ret = 0; + zcache_comp_pcpu_tfms = alloc_percpu(struct crypto_comp *); + if (!zcache_comp_pcpu_tfms) + ret = 1; +out: + return ret; +} + +static int __init zcache_init(void) +{ + int ret = 0; + + if (ramster_enabled) { + namestr = "ramster"; + ramster_register_pamops(&zcache_pamops); + } +#ifdef CONFIG_DEBUG_FS + zcache_debugfs_init(); +#endif + if (zcache_enabled) { + unsigned int cpu; + + tmem_register_hostops(&zcache_hostops); + tmem_register_pamops(&zcache_pamops); + ret = register_cpu_notifier(&zcache_cpu_notifier_block); + if (ret) { + pr_err("%s: can't register cpu notifier\n", namestr); + goto out; + } + ret = zcache_comp_init(); + if (ret) { + pr_err("%s: compressor initialization failed\n", + namestr); + goto out; + } + for_each_online_cpu(cpu) { + void *pcpu = (void *)(long)cpu; + zcache_cpu_notifier(&zcache_cpu_notifier_block, + CPU_UP_PREPARE, pcpu); + } + } + zcache_objnode_cache = kmem_cache_create("zcache_objnode", + sizeof(struct tmem_objnode), 0, 0, NULL); + zcache_obj_cache = kmem_cache_create("zcache_obj", + sizeof(struct tmem_obj), 0, 0, NULL); + ret = zcache_new_client(LOCAL_CLIENT); + if (ret) { + pr_err("%s: can't create client\n", namestr); + goto out; + } + zbud_init(); + if (zcache_enabled && !disable_cleancache) { + struct cleancache_ops old_ops; + + register_shrinker(&zcache_shrinker); + old_ops = zcache_cleancache_register_ops(); + pr_info("%s: cleancache enabled using kernel transcendent " + "memory and compression buddies\n", namestr); +#ifdef ZCACHE_DEBUG + pr_info("%s: cleancache: ignorenonactive = %d\n", + namestr, !disable_cleancache_ignore_nonactive); +#endif + if (old_ops.init_fs != NULL) + pr_warn("%s: cleancache_ops overridden\n", namestr); + } + if (zcache_enabled && !disable_frontswap) { + struct frontswap_ops old_ops; + + old_ops = zcache_frontswap_register_ops(); + if (frontswap_has_exclusive_gets) + frontswap_tmem_exclusive_gets(true); + pr_info("%s: frontswap enabled using kernel transcendent " + "memory and compression buddies\n", namestr); +#ifdef ZCACHE_DEBUG + pr_info("%s: frontswap: excl gets = %d active only = %d\n", + namestr, frontswap_has_exclusive_gets, + !disable_frontswap_ignore_nonactive); +#endif + if (old_ops.init != NULL) + pr_warn("%s: frontswap_ops overridden\n", namestr); + } + if (ramster_enabled) + ramster_init(!disable_cleancache, !disable_frontswap, + frontswap_has_exclusive_gets); +out: + return ret; +} + +late_initcall(zcache_init); diff --git a/drivers/staging/zcache/zcache.h b/drivers/staging/zcache/zcache.h new file mode 100644 index 0000000..81722b3 --- /dev/null +++ b/drivers/staging/zcache/zcache.h @@ -0,0 +1,53 @@ + +/* + * zcache.h + * + * Copyright (c) 2012, Dan Magenheimer, Oracle Corp. + */ + +#ifndef _ZCACHE_H_ +#define _ZCACHE_H_ + +struct zcache_preload { + struct tmem_obj *obj; + struct tmem_objnode *objnodes[OBJNODE_TREE_MAX_PATH]; +}; + +struct tmem_pool; + +#define MAX_POOLS_PER_CLIENT 16 + +#define MAX_CLIENTS 16 +#define LOCAL_CLIENT ((uint16_t)-1) + +struct zcache_client { + struct tmem_pool *tmem_pools[MAX_POOLS_PER_CLIENT]; + bool allocated; + atomic_t refcount; +}; + +extern struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, + uint16_t poolid); +extern void zcache_put_pool(struct tmem_pool *pool); + +extern int zcache_put_page(int, int, struct tmem_oid *, + uint32_t, void *, + unsigned int, bool, int); +extern int zcache_get_page(int, int, struct tmem_oid *, uint32_t, + void *, size_t *, bool, int); +extern int zcache_flush_page(int, int, struct tmem_oid *, uint32_t); +extern int zcache_flush_object(int, int, struct tmem_oid *); +extern void zcache_decompress_to_page(char *, unsigned int, struct page *); + +#ifdef CONFIG_RAMSTER +extern void *zcache_pampd_create(char *, unsigned int, bool, int, + struct tmem_handle *); +int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph); +#endif + +#define MAX_POOLS_PER_CLIENT 16 + +#define MAX_CLIENTS 16 +#define LOCAL_CLIENT ((uint16_t)-1) + +#endif /* _ZCACHE_H_ */ -- cgit v0.10.2 From d651b886e49cfaa0b3ff634a2c9388ae4ce7d65c Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Fri, 18 Jan 2013 13:24:25 -0800 Subject: staging: zcache: adjustments to config/build files due to renaming [V2: no code changes, patchset now generated via git format-patch -M] In staging/zcache, adjust config/build due to ramster->zcache renaming Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig index 3abf661..c1dbd04 100644 --- a/drivers/staging/zcache/Kconfig +++ b/drivers/staging/zcache/Kconfig @@ -1,23 +1,18 @@ -config ZCACHE2 +config ZCACHE bool "Dynamic compression of swap pages and clean pagecache pages" - depends on CRYPTO=y && SWAP=y && CLEANCACHE && FRONTSWAP && !ZCACHE + depends on CRYPTO=y && SWAP=y && CLEANCACHE && FRONTSWAP select CRYPTO_LZO default n help - Zcache2 doubles RAM efficiency while providing a significant - performance boosts on many workloads. Zcache2 uses + Zcache doubles RAM efficiency while providing a significant + performance boosts on many workloads. Zcache uses compression and an in-kernel implementation of transcendent memory to store clean page cache pages and swap in RAM, - providing a noticeable reduction in disk I/O. Zcache2 - is a complete rewrite of the older zcache; it was intended to - be a merge but that has been blocked due to political and - technical disagreements. It is intended that they will merge - again in the future. Until then, zcache2 is a single-node - version of ramster. + providing a noticeable reduction in disk I/O. config RAMSTER bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem" - depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE2=y + depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE=y depends on NET # must ensure struct page is 8-byte aligned select HAVE_ALIGNED_STRUCT_PAGE if !64_BIT diff --git a/drivers/staging/zcache/Makefile b/drivers/staging/zcache/Makefile index 2d8b9d0..4711049 100644 --- a/drivers/staging/zcache/Makefile +++ b/drivers/staging/zcache/Makefile @@ -3,4 +3,4 @@ zcache-$(CONFIG_RAMSTER) += ramster/ramster.o ramster/r2net.o zcache-$(CONFIG_RAMSTER) += ramster/nodemanager.o ramster/tcp.o zcache-$(CONFIG_RAMSTER) += ramster/heartbeat.o ramster/masklog.o -obj-$(CONFIG_ZCACHE2) += zcache.o +obj-$(CONFIG_ZCACHE) += zcache.o -- cgit v0.10.2 From 112a35edd6a6fc0ef91c2a57ca679d5eaaa18ab5 Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Fri, 18 Jan 2013 13:24:26 -0800 Subject: staging: zcache: re-enable config/build of zcache after renaming In staging, re-enable config/build of zcache after ramster->zcache renaming. Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index eb61455..0b47a06 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -138,4 +138,6 @@ source "drivers/staging/sb105x/Kconfig" source "drivers/staging/fwserial/Kconfig" +source "drivers/staging/zcache/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index 18420b8..b026ea3 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -61,3 +61,4 @@ obj-$(CONFIG_DRM_IMX) += imx-drm/ obj-$(CONFIG_DGRP) += dgrp/ obj-$(CONFIG_SB105X) += sb105x/ obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ +obj-$(CONFIG_ZCACHE) += zcache/ -- cgit v0.10.2 From d6c19b6e7a2f040dd45a69f8afe051638b666a59 Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Fri, 18 Jan 2013 13:24:27 -0800 Subject: staging: zcache: fix uninitialized variable compile warning [V2: no code changes, patchset now generated via git format-patch -M] Fix unitialized variable in zcache which generates warning during build Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index a09dd5c..6ab13e1 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -1346,7 +1346,7 @@ static int zcache_local_new_pool(uint32_t flags) int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph) { struct tmem_pool *pool; - struct zcache_client *cli; + struct zcache_client *cli = NULL; uint32_t flags = eph ? 0 : TMEM_POOL_PERSIST; int ret = -1; -- cgit v0.10.2 From 4156a7603709b2232603b10f1835f351d89b263e Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Fri, 18 Jan 2013 20:23:36 -0500 Subject: Staging: Comedi: amplc_dio200: Fixed bracing issue Fixed coding style error Signed-off-by: Jake Champlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c index 5f309ba..b09269d 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.c +++ b/drivers/staging/comedi/drivers/amplc_dio200.c @@ -1977,8 +1977,7 @@ static int dio200_auto_attach(struct comedi_device *dev, devpriv->io.u.iobase = (unsigned long)base; devpriv->io.regtype = io_regtype; } - switch (thisboard->model) - { + switch (thisboard->model) { case pcie215_model: case pcie236_model: case pcie296_model: -- cgit v0.10.2 From 52070c709dbc493da550086709934e6028457a7c Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Sun, 20 Jan 2013 16:24:45 +0100 Subject: wlan-ng/prism2mgmt.c: added parantheses to macro Enclose the macro into braces so that it can be closed by a semicolon Signed-off-by: Sebastian Wankerl Signed-off-by: Sebastian Ehrenfels Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c index 4efa9bc..62b94b0 100644 --- a/drivers/staging/wlan-ng/prism2mgmt.c +++ b/drivers/staging/wlan-ng/prism2mgmt.c @@ -415,11 +415,14 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp) break; #define REQBASICRATE(N) \ - if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \ - req->basicrate ## N .data = item->supprates[(N)-1]; \ - req->basicrate ## N .status = \ - P80211ENUM_msgitem_status_data_ok; \ - } + do { \ + if ((count >= N) && DOT11_RATE5_ISBASIC_GET( \ + item->supprates[(N)-1])) { \ + req->basicrate ## N .data = item->supprates[(N)-1]; \ + req->basicrate ## N .status = \ + P80211ENUM_msgitem_status_data_ok; \ + } \ + } while (0) REQBASICRATE(1); REQBASICRATE(2); @@ -431,11 +434,13 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp) REQBASICRATE(8); #define REQSUPPRATE(N) \ - if (count >= N) { \ - req->supprate ## N .data = item->supprates[(N)-1]; \ - req->supprate ## N .status = \ - P80211ENUM_msgitem_status_data_ok; \ - } + do { \ + if (count >= N) { \ + req->supprate ## N .data = item->supprates[(N)-1]; \ + req->supprate ## N .status = \ + P80211ENUM_msgitem_status_data_ok; \ + } \ + } while (0) REQSUPPRATE(1); REQSUPPRATE(2); -- cgit v0.10.2 From 25c97da8b975d8717a0242c651896b56b2696060 Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Sun, 20 Jan 2013 16:30:54 +0100 Subject: wlan-ng/prism2mgmt.c: formated too long lines Formated pr_debug() calls Signed-off-by: Sebastian Wankerl Signed-off-by: Sebastian Ehrenfels Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c index 62b94b0..fba4af80 100644 --- a/drivers/staging/wlan-ng/prism2mgmt.c +++ b/drivers/staging/wlan-ng/prism2mgmt.c @@ -1144,9 +1144,8 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp) /* Enable the port */ result = hfa384x_drvr_enable(hw, 0); if (result) { - pr_debug - ("failed to enable port to presniff setting, result=%d\n", - result); + pr_debug("failed to enable port to presniff setting, result=%d\n", + result); goto failed; } } else { @@ -1186,18 +1185,16 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp) hfa384x_drvr_stop(hw); result = hfa384x_drvr_start(hw); if (result) { - pr_debug - ("failed to restart the card for sniffing, result=%d\n", - result); + pr_debug("failed to restart the card for sniffing, result=%d\n", + result); goto failed; } } else { /* Disable the port */ result = hfa384x_drvr_disable(hw, 0); if (result) { - pr_debug - ("failed to enable port for sniffing, result=%d\n", - result); + pr_debug("failed to enable port for sniffing, result=%d\n", + result); goto failed; } } -- cgit v0.10.2 From 98115f1df394706556bd03e20418fa50e42e04dd Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Sat, 19 Jan 2013 09:59:00 +0100 Subject: staging: line6: drop CONFIG_LINE6_USB_DUMP_PCM The CONFIG_LINE6_USB_DUMP_PCM config option prints a hexdump of PCM audio data as URBs are sent and received. The usbmon feature should be used instead of manually dumping PCM URBs. There are a few advantages to using usbmon: * Can be turned on/off at runtime * Provides full USB-level traffic * tcpdump and wireshark support for powerful analysis * No driver-specific code is required This is the last user of line6_write_hexdump() so we drop it too. Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/Kconfig b/drivers/staging/line6/Kconfig index b635436..4f1219b 100644 --- a/drivers/staging/line6/Kconfig +++ b/drivers/staging/line6/Kconfig @@ -23,16 +23,6 @@ menuconfig LINE6_USB if LINE6_USB -config LINE6_USB_DUMP_PCM - bool "dump PCM data" - default n - help - Say Y here to write PCM data sent to and received from Line6 - devices to the syslog. This will produce a huge amount of - syslog data during playback and capture. - - If unsure, say N. - config LINE6_USB_IMPULSE_RESPONSE bool "measure impulse response" default n diff --git a/drivers/staging/line6/capture.c b/drivers/staging/line6/capture.c index 389c41f..f8316b7 100644 --- a/drivers/staging/line6/capture.c +++ b/drivers/staging/line6/capture.c @@ -216,16 +216,6 @@ static void audio_in_callback(struct urb *urb) if (urb == line6pcm->urb_audio_in[index]) break; -#ifdef CONFIG_LINE6_USB_DUMP_PCM - for (i = 0; i < LINE6_ISO_PACKETS; ++i) { - struct usb_iso_packet_descriptor *fout = - &urb->iso_frame_desc[i]; - line6_write_hexdump(line6pcm->line6, 'C', - urb->transfer_buffer + fout->offset, - fout->length); - } -#endif - spin_lock_irqsave(&line6pcm->lock_audio_in, flags); for (i = 0; i < LINE6_ISO_PACKETS; ++i) { diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c index 1b05633..9f9a21a 100644 --- a/drivers/staging/line6/driver.c +++ b/drivers/staging/line6/driver.c @@ -135,47 +135,6 @@ static void line6_stop_listen(struct usb_line6 *line6) usb_kill_urb(line6->urb_listen); } -#ifdef CONFIG_LINE6_USB_DUMP_ANY -/* - Write hexdump to syslog. -*/ -void line6_write_hexdump(struct usb_line6 *line6, char dir, - const unsigned char *buffer, int size) -{ - static const int BYTES_PER_LINE = 8; - char hexdump[100]; - char asc[BYTES_PER_LINE + 1]; - int i, j; - - for (i = 0; i < size; i += BYTES_PER_LINE) { - int hexdumpsize = sizeof(hexdump); - char *p = hexdump; - int n = min(size - i, BYTES_PER_LINE); - asc[n] = 0; - - for (j = 0; j < BYTES_PER_LINE; ++j) { - int bytes; - - if (j < n) { - unsigned char val = buffer[i + j]; - bytes = snprintf(p, hexdumpsize, " %02X", val); - asc[j] = ((val >= 0x20) - && (val < 0x7f)) ? val : '.'; - } else - bytes = snprintf(p, hexdumpsize, " "); - - if (bytes > hexdumpsize) - break; /* buffer overflow */ - - p += bytes; - hexdumpsize -= bytes; - } - - dev_info(line6->ifcdev, "%c%04X:%s %s\n", dir, i, hexdump, asc); - } -} -#endif - /* Send raw message in pieces of wMaxPacketSize bytes. */ diff --git a/drivers/staging/line6/driver.h b/drivers/staging/line6/driver.h index 2e0f134..a8341f9 100644 --- a/drivers/staging/line6/driver.h +++ b/drivers/staging/line6/driver.h @@ -20,10 +20,6 @@ #define DRIVER_NAME "line6usb" -#if defined(CONFIG_LINE6_USB_DUMP_PCM) -#define CONFIG_LINE6_USB_DUMP_ANY -#endif - #define LINE6_TIMEOUT 1 #define LINE6_BUFSIZE_LISTEN 32 #define LINE6_MESSAGE_MAXLEN 256 @@ -219,9 +215,4 @@ extern int line6_version_request_async(struct usb_line6 *line6); extern int line6_write_data(struct usb_line6 *line6, int address, void *data, size_t datalen); -#ifdef CONFIG_LINE6_USB_DUMP_ANY -extern void line6_write_hexdump(struct usb_line6 *line6, char dir, - const unsigned char *buffer, int size); -#endif - #endif diff --git a/drivers/staging/line6/playback.c b/drivers/staging/line6/playback.c index 4cf23af..f9135c7 100644 --- a/drivers/staging/line6/playback.c +++ b/drivers/staging/line6/playback.c @@ -264,15 +264,6 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) } #endif } -#ifdef CONFIG_LINE6_USB_DUMP_PCM - for (i = 0; i < LINE6_ISO_PACKETS; ++i) { - struct usb_iso_packet_descriptor *fout = - &urb_out->iso_frame_desc[i]; - line6_write_hexdump(line6pcm->line6, 'P', - urb_out->transfer_buffer + fout->offset, - fout->length); - } -#endif ret = usb_submit_urb(urb_out, GFP_ATOMIC); -- cgit v0.10.2 From 4e6a8ffba2add23223dc0231c1f818d00813c55b Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Sat, 19 Jan 2013 11:18:43 +0100 Subject: staging: line6: clean up line6_pod_process_message() Previous versions of the line6 driver snooped MIDI traffic in order to make device state accessible via sysfs attributes. This involved a lot of logic in line6_pod_process_message() that has since been removed. Drop unused conditionals in line6_pod_process_message() and reduce the levels of indentation. Only two MIDI messages are still tracked: the POD version message on startup and monitor level changes originating from the device. Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/pod.c b/drivers/staging/line6/pod.c index ba6fed4..74898c3 100644 --- a/drivers/staging/line6/pod.c +++ b/drivers/staging/line6/pod.c @@ -135,85 +135,27 @@ void line6_pod_process_message(struct usb_line6_pod *pod) { const unsigned char *buf = pod->line6.buffer_message; - /* filter messages by type */ - switch (buf[0] & 0xf0) { - case LINE6_PARAM_CHANGE: - case LINE6_PROGRAM_CHANGE: - case LINE6_SYSEX_BEGIN: - break; /* handle these further down */ - - default: - return; /* ignore all others */ + if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) { + pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15]; + pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) | + (int) buf[10]; + pod_startup3(pod); + return; + } + + /* Only look for sysex messages from this device */ + if (buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE) && + buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN)) { + return; + } + if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0) { + return; } - /* process all remaining messages */ - switch (buf[0]) { - case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE: - case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST: - break; - - case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE: - case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST: - break; - - case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE: - case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN: - if (memcmp(buf + 1, line6_midi_id, - sizeof(line6_midi_id)) == 0) { - switch (buf[5]) { - case POD_SYSEX_DUMP: - break; - - case POD_SYSEX_SYSTEM:{ - short value = - ((int)buf[7] << 12) | ((int)buf[8] - << 8) | - ((int)buf[9] << 4) | (int)buf[10]; - - if (buf[6] == POD_MONITOR_LEVEL) - pod->monitor_level = value; - break; - } - - case POD_SYSEX_FINISH: - /* do we need to respond to this? */ - break; - - case POD_SYSEX_SAVE: - break; - - case POD_SYSEX_STORE: - dev_dbg(pod->line6.ifcdev, - "message %02X not yet implemented\n", - buf[5]); - break; - - default: - dev_dbg(pod->line6.ifcdev, - "unknown sysex message %02X\n", - buf[5]); - } - } else - if (memcmp - (buf, pod_version_header, - sizeof(pod_version_header)) == 0) { - pod->firmware_version = - buf[13] * 100 + buf[14] * 10 + buf[15]; - pod->device_id = - ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int) - buf[10]; - pod_startup3(pod); - } else - dev_dbg(pod->line6.ifcdev, "unknown sysex header\n"); - - break; - - case LINE6_SYSEX_END: - break; - - default: - dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n", - buf[0]); + if (buf[5] == POD_SYSEX_SYSTEM && buf[6] == POD_MONITOR_LEVEL) { + short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) | + ((int)buf[9] << 4) | (int)buf[10]; + pod->monitor_level = value; } } -- cgit v0.10.2 From 3d1390389fe8124b2afde7fdbe306cbe2a99019d Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Sat, 19 Jan 2013 11:18:44 +0100 Subject: staging: line6: clean up line6_variax_process_message() Previous versions of the line6 driver snooped MIDI traffic in order to make device state accessible via sysfs attributes. This involved a lot of logic in line6_variax_process_message() that has since been removed. Drop unused conditionals in line6_variax_process_message(). Signed-off-by: Stefan Hajnoczi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/line6/variax.c b/drivers/staging/line6/variax.c index 4fca58f..bd0f694 100644 --- a/drivers/staging/line6/variax.c +++ b/drivers/staging/line6/variax.c @@ -133,13 +133,6 @@ void line6_variax_process_message(struct usb_line6_variax *variax) const unsigned char *buf = variax->line6.buffer_message; switch (buf[0]) { - case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST: - break; - - case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE: - case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST: - break; - case LINE6_RESET: dev_info(variax->line6.ifcdev, "VARIAX reset\n"); break; @@ -154,13 +147,6 @@ void line6_variax_process_message(struct usb_line6_variax *variax) variax_startup4((unsigned long)variax); } break; - - case LINE6_SYSEX_END: - break; - - default: - dev_dbg(variax->line6.ifcdev, - "Variax: unknown message %02X\n", buf[0]); } } -- cgit v0.10.2 From 74c7c503c792b36ee8943363bac021ec9ed5f9b8 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Sat, 19 Jan 2013 01:03:32 -0500 Subject: Staging: Comedi: pcl818: Fixed Coding Style Issues Fixed single line if statement brace issues as well as pointer errors from checkpatch.pl Signed-off-by: Jake Champlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c index 06127a5..b5af22e 100644 --- a/drivers/staging/comedi/drivers/pcl818.c +++ b/drivers/staging/comedi/drivers/pcl818.c @@ -243,8 +243,8 @@ static const struct comedi_lrange range_pcl818l_h_ai = { 4, { }; static const struct comedi_lrange range718_bipolar1 = { 1, {BIP_RANGE(1),} }; -static const struct comedi_lrange range718_bipolar0_5 = - { 1, {BIP_RANGE(0.5),} }; +static const struct comedi_lrange range718_bipolar0_5 = { + 1, {BIP_RANGE(0.5),} }; static const struct comedi_lrange range718_unipolar2 = { 1, {UNI_RANGE(2),} }; static const struct comedi_lrange range718_unipolar1 = { 1, {BIP_RANGE(1),} }; @@ -1005,17 +1005,14 @@ static int pcl818_ai_cmd_mode(int mode, struct comedi_device *dev, switch (devpriv->dma) { case 1: /* DMA */ case 3: - if (devpriv->dma_rtc == 0) { + if (devpriv->dma_rtc == 0) pcl818_ai_mode13dma_int(mode, dev, s); - } #ifdef unused - else { + else pcl818_ai_mode13dma_rtc(mode, dev, s); - } #else - else { + else return -EINVAL; - } #endif break; case 0: @@ -1069,7 +1066,7 @@ static int pcl818_ai_cmd_mode(int mode, struct comedi_device *dev, */ #ifdef PCL818_MODE13_AO static int pcl818_ao_mode13(int mode, struct comedi_device *dev, - struct comedi_subdevice *s, comedi_trig * it) + struct comedi_subdevice *s, comedi_trig *it) { struct pcl818_private *devpriv = dev->private; int divisor1 = 0, divisor2 = 0; @@ -1124,7 +1121,7 @@ static int pcl818_ao_mode13(int mode, struct comedi_device *dev, ANALOG OUTPUT MODE 1, 818 cards */ static int pcl818_ao_mode1(struct comedi_device *dev, - struct comedi_subdevice *s, comedi_trig * it) + struct comedi_subdevice *s, comedi_trig *it) { return pcl818_ao_mode13(1, dev, s, it); } @@ -1134,7 +1131,7 @@ static int pcl818_ao_mode1(struct comedi_device *dev, ANALOG OUTPUT MODE 3, 818 cards */ static int pcl818_ao_mode3(struct comedi_device *dev, - struct comedi_subdevice *s, comedi_trig * it) + struct comedi_subdevice *s, comedi_trig *it) { return pcl818_ao_mode13(3, dev, s, it); } -- cgit v0.10.2 From 7648e109422b6cd684491c144eeee40e89d19631 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Fri, 18 Jan 2013 21:44:07 -0500 Subject: Staging: Comedi: daqboard2000: Fixed Coding Style Issue Fixed Coding Style Warning Signed-off-by: Jake Champlin Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index 992e557..d206c7b 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -485,7 +485,7 @@ static void daqboard2000_pulseProgPin(struct comedi_device *dev) writel(DAQBOARD2000_SECRProgPinHi, devpriv->plx + 0x6c); udelay(10000); writel(DAQBOARD2000_SECRProgPinLo, devpriv->plx + 0x6c); - udelay(10000); /* Not in the original code, but I like symmetry... */ + udelay(10000); /* Not in the original code, but I like symmetry... */ } static int daqboard2000_pollCPLD(struct comedi_device *dev, int mask) -- cgit v0.10.2 From 56810a92c689c64d586a51a1078c5d307b24e8eb Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Mon, 21 Jan 2013 02:57:47 +0200 Subject: staging: xgifb: use XGIRegInit() Avoid copy-paste and use XGIRegInit() to initialize registers addresses. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index e0f745d..68a216f 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -233,7 +233,7 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, return 1; } -static void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr) +void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr) { XGI_Pr->P3c4 = BaseAddr + 0x14; XGI_Pr->P3d4 = BaseAddr + 0x24; diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index 2b791c1..e768ee1 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -1299,23 +1299,7 @@ unsigned char XGIInitNew(struct pci_dev *pdev) outb(0x67, (pVBInfo->BaseAddr + 0x12)); /* 3c2 <- 67 ,ynlai */ - pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14; - pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24; - pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10; - pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e; - pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12; - pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a; - pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16; - pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17; - pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18; - pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19; - pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A; - pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00; - pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04; - pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10; - pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12; - pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14; - pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2; + XGIRegInit(pVBInfo, xgifb_info->vga_base); if (HwDeviceExtension->jChipType < XG20) /* Run XGI_GetVBType before InitTo330Pointer */ diff --git a/drivers/staging/xgifb/vb_init.h b/drivers/staging/xgifb/vb_init.h index d548983..2457302 100644 --- a/drivers/staging/xgifb/vb_init.h +++ b/drivers/staging/xgifb/vb_init.h @@ -1,5 +1,6 @@ #ifndef _VBINIT_ #define _VBINIT_ extern unsigned char XGIInitNew(struct pci_dev *pdev); +extern void XGIRegInit(struct vb_device_info *, unsigned long); #endif diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index d723a25..3e9f9d6 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2,6 +2,7 @@ #include "XGIfb.h" #include "vb_def.h" +#include "vb_init.h" #include "vb_util.h" #include "vb_table.h" #include "vb_setmode.h" @@ -5961,24 +5962,7 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info, pVBInfo->IF_DEF_CRT2Monitor = 1; } - pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14; - pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24; - pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10; - pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e; - pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12; - pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C; - pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a; - pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16; - pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17; - pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18; - pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19; - pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A; - pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00; - pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04; - pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10; - pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12; - pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14; - pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2; + XGIRegInit(pVBInfo, xgifb_info->vga_base); /* for x86 Linux, XG21 LVDS */ if (HwDeviceExtension->jChipType == XG21) { -- cgit v0.10.2 From b8e1cc5c8dec9df1b70ca8ec4f081dc31ef69667 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Mon, 21 Jan 2013 02:57:48 +0200 Subject: staging: xgifb: do not use pVBInfo->BaseAddr Use pre-calculated register addresses instead of pVBInfo->BaseAddr. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index e768ee1..3115415 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -1297,10 +1297,10 @@ unsigned char XGIInitNew(struct pci_dev *pdev) return 0; } - outb(0x67, (pVBInfo->BaseAddr + 0x12)); /* 3c2 <- 67 ,ynlai */ - XGIRegInit(pVBInfo, xgifb_info->vga_base); + outb(0x67, pVBInfo->P3c2); + if (HwDeviceExtension->jChipType < XG20) /* Run XGI_GetVBType before InitTo330Pointer */ XGI_GetVBType(pVBInfo); -- cgit v0.10.2 From cdbbc618f8f483d72e82af05f2873621cc9c2314 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Mon, 21 Jan 2013 02:57:49 +0200 Subject: staging: xgifb: delete pVBInfo->BaseAddr Delete redundant field. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index 3115415..dd34570 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -1286,16 +1286,10 @@ unsigned char XGIInitNew(struct pci_dev *pdev) pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress; - pVBInfo->BaseAddr = xgifb_info->vga_base; - if (pVBInfo->FBAddr == NULL) { dev_dbg(&pdev->dev, "pVBInfo->FBAddr == 0\n"); return 0; } - if (pVBInfo->BaseAddr == 0) { - dev_dbg(&pdev->dev, "pVBInfo->BaseAddr == 0\n"); - return 0; - } XGIRegInit(pVBInfo, xgifb_info->vga_base); diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 3e9f9d6..53b5557 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -5948,7 +5948,6 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info, unsigned short ModeIdIndex; struct vb_device_info VBINF; struct vb_device_info *pVBInfo = &VBINF; - pVBInfo->BaseAddr = xgifb_info->vga_base; pVBInfo->IF_DEF_LVDS = 0; if (HwDeviceExtension->jChipType >= XG20) { diff --git a/drivers/staging/xgifb/vb_struct.h b/drivers/staging/xgifb/vb_struct.h index acf6e7f..e570bae 100644 --- a/drivers/staging/xgifb/vb_struct.h +++ b/drivers/staging/xgifb/vb_struct.h @@ -156,7 +156,6 @@ struct vb_device_info { unsigned short SelectCRT2Rate; void __iomem *FBAddr; - unsigned long BaseAddr; unsigned char const (*SR15)[8]; unsigned char const (*CR40)[8]; -- cgit v0.10.2 From ec7e0aef31e2eece787f7c49df1f031f2a983265 Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Mon, 21 Jan 2013 17:33:26 +0800 Subject: staging: tidspbridge/pmgr: additional checking after return from strlen_user strlen_user will return the length including final NUL. and will return 0 if failed (for example: if user string not NUL terminated) so need check whether it is an invalid parameter. addtional info: can reference the comments of strlen_user in lib/strnlen_user.c Signed-off-by: Chen Gang Cc: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c index 9ef1ad9..5a18a94 100644 --- a/drivers/staging/tidspbridge/pmgr/dspapi.c +++ b/drivers/staging/tidspbridge/pmgr/dspapi.c @@ -414,10 +414,13 @@ u32 mgrwrap_register_object(union trapped_args *args, void *pr_ctxt) CP_FM_USR(&uuid_obj, args->args_mgr_registerobject.uuid_obj, status, 1); if (status) goto func_end; - /* path_size is increased by 1 to accommodate NULL */ path_size = strlen_user((char *) - args->args_mgr_registerobject.sz_path_name) + - 1; + args->args_mgr_registerobject.sz_path_name); + if (!path_size) { + status = -EINVAL; + goto func_end; + } + psz_path_name = kmalloc(path_size, GFP_KERNEL); if (!psz_path_name) { status = -ENOMEM; -- cgit v0.10.2 From 9814a8750e7af236030c237a98bba79f5eb3c214 Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Mon, 21 Jan 2013 17:35:00 +0800 Subject: staging: tidspbridge/pmgr: use strlcpy instead of strncpy The fields must be null-terminated, or next strcpy in dbll_find_dsp_symbol, will cause issue additoinal info: dbll_find_dsp_symbol call find_symbol_callback to get name. and then call strcpy to copy the name to upper caller. Signed-off-by: Chen Gang Cc: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/pmgr/dbll.c b/drivers/staging/tidspbridge/pmgr/dbll.c index 9f07036..c191ae2 100644 --- a/drivers/staging/tidspbridge/pmgr/dbll.c +++ b/drivers/staging/tidspbridge/pmgr/dbll.c @@ -1382,7 +1382,7 @@ void find_symbol_callback(void *elem, void *user_data) offset < context->cur_best_offset) { context->cur_best_offset = offset; context->sym_addr = symbol_addr; - strncpy(context->name, symbol->name, sizeof(context->name)); + strlcpy(context->name, symbol->name, sizeof(context->name)); } return; -- cgit v0.10.2 From 4b90d01425468cac50275ce2bd3b35218b56282d Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Mon, 21 Jan 2013 17:36:33 +0800 Subject: staging: tidspbridge/pmgr: another using strlcpy instead of strncpy The fields must be null-terminated, or next strstr in dcd_get_objects, will cause issue additoinal info: nldr_create may call cod_get_base_name, let sz_zl_file to get name (sz_name) and then call dcd_get_objects, passing sz_zl_file as a name string. Signed-off-by: Chen Gang Cc: Omar Ramirez Luna Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/pmgr/cod.c b/drivers/staging/tidspbridge/pmgr/cod.c index 4007826..6c29379 100644 --- a/drivers/staging/tidspbridge/pmgr/cod.c +++ b/drivers/staging/tidspbridge/pmgr/cod.c @@ -289,7 +289,7 @@ int cod_get_base_name(struct cod_manager *cod_mgr_obj, char *sz_name, int status = 0; if (usize <= COD_MAXPATHLENGTH) - strncpy(sz_name, cod_mgr_obj->sz_zl_file, usize); + strlcpy(sz_name, cod_mgr_obj->sz_zl_file, usize); else status = -EPERM; -- cgit v0.10.2 From 82ebecc503d3d76a4d56d7a9b00d87543a28b3e3 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Mon, 21 Jan 2013 14:02:47 +0100 Subject: staging: omap-thermal/omap-bandgap.c: adjust duplicate test Delete successive tests to the same location. There was a previous test on ret and it has not been updated since then. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // @s exists@ local idexpression y; expression x,e; @@ *if ( \(x == NULL\|IS_ERR(x)\|y != 0\) ) { ... when forall return ...; } ... when != \(y = e\|y += e\|y -= e\|y |= e\|y &= e\|y++\|y--\|&y\) when != \(XT_GETPAGE(...,y)\|WMI_CMD_BUF(...)\) *if ( \(x == NULL\|IS_ERR(x)\|y != 0\) ) { ... when forall return ...; } // Signed-off-by: Julia Lawall Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/omap-thermal/omap-bandgap.c b/drivers/staging/omap-thermal/omap-bandgap.c index 8346e345..89f7180 100644 --- a/drivers/staging/omap-thermal/omap-bandgap.c +++ b/drivers/staging/omap-thermal/omap-bandgap.c @@ -568,8 +568,6 @@ int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id, tsr = bg_ptr->conf->sensors[id].registers; time = omap_bandgap_readl(bg_ptr, tsr->bgap_counter); - if (ret) - return ret; time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask); time = time * 1000 / bg_ptr->clk_rate; -- cgit v0.10.2 From 3eb4fd1f560767b3ce5aeaa151c61c44134ce139 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 21 Jan 2013 17:21:23 +0000 Subject: staging: comedi: Allow comedi on ARM Bernd Porr reports success getting comedi to work on ARM. He writes: """ comedi works nicely on the Raspberry PI. I've compiled the rpi kernel with comedi enabled and it works with the USBDUX-sigma (need to test the other boards). With comedirecord running I can plot one channel at 1kHz without buffer overflow (resulting to 70% load). So, I guess we just need to add "ARM" to Kconfig in the comedi subdir? depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || X86 || ARM I'm running just now 3.2.27 but also the development kernel compiles with ARM enabled (haven't tested yet). /Bernd """ Enable the COMEDI config option to be selected for ARM. Signed-off-by: Ian Abbott Cc: Bernd Porr Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 39cf735..081e994 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1,7 +1,8 @@ config COMEDI tristate "Data acquisition support (comedi)" depends on m - depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || X86 + depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || \ + X86 || ARM ---help--- Enable support a wide range of data acquisition devices for Linux. -- cgit v0.10.2 From 35be8425384df44a819413ed238287586219d579 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 21 Jan 2013 14:19:45 -0800 Subject: Staging: comedi: enable it to build on all arches Hopefully all of the arch-specific problems are now resolved, so let's let this subsystem be enabled on all arches. If there are problems found, we will fix them up. Cc: Ian Abbott Cc: H Hartley Sweeten Cc: Bernd Porr Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 081e994..b1d1a0e 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1,8 +1,6 @@ config COMEDI tristate "Data acquisition support (comedi)" depends on m - depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || \ - X86 || ARM ---help--- Enable support a wide range of data acquisition devices for Linux. -- cgit v0.10.2 From 24d8e51ef3671f7dff0aaee0f3cf4c55d33c7292 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 21 Jan 2013 21:29:43 +0100 Subject: staging/comedi: Use bool initializations Found with coccicheck. The semantic patch that makes this output is available in scripts/coccinelle/misc/boolinit.cocci. More information about semantic patching is available at http://coccinelle.lip6.fr/ Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 3e82ab9..dc3588a 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -58,7 +58,7 @@ MODULE_PARM_DESC(comedi_debug, ); #endif -bool comedi_autoconfig = 1; +bool comedi_autoconfig = true; module_param(comedi_autoconfig, bool, S_IRUGO); MODULE_PARM_DESC(comedi_autoconfig, "enable drivers to auto-configure comedi devices (default 1)"); @@ -2437,7 +2437,7 @@ static int __init comedi_init(void) * comedi_num_legacy_minors are zero, so we might as well adjust the * defaults in that case */ - if (comedi_autoconfig == 0 && comedi_num_legacy_minors == 0) + if (!comedi_autoconfig && comedi_num_legacy_minors == 0) comedi_num_legacy_minors = 16; memset(comedi_file_info_table, 0, -- cgit v0.10.2 From 49d2dbee8b05ad12a3e5da9c7f28074ca30621b7 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 21 Jan 2013 22:23:46 +0100 Subject: staging/comedi: Add pci_driver.name to skel driver This patch adds the comedi_driver.name to pci_driver.name to the skel driver, so we can remove the workaround in drivers.c Signed-off-by: Peter Huewe Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c index e2d7970..48178ca 100644 --- a/drivers/staging/comedi/drivers/skel.c +++ b/drivers/staging/comedi/drivers/skel.c @@ -713,6 +713,7 @@ static void skel_pci_remove(struct pci_dev *dev) } static struct pci_driver skel_pci_driver = { + .name = "dummy", .id_table = skel_pci_table, .probe = &skel_pci_probe, .remove = &skel_pci_remove -- cgit v0.10.2 From 37fbb4acda89447b8b37e0cc5d1bd8f7ce9b1bb4 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 21 Jan 2013 21:51:57 +0100 Subject: staging/comedi: remove workaround for !pci_driver.name All pci drivers in drivers/ have the pci_driver.name field set, so we can remove this workaround and the accompanying todo. Signed-off-by: Peter Huewe Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 8b681ac..cebdd9e 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -536,10 +536,6 @@ int comedi_pci_driver_register(struct comedi_driver *comedi_driver, if (ret < 0) return ret; - /* FIXME: Remove this test after auditing all comedi pci drivers */ - if (!pci_driver->name) - pci_driver->name = comedi_driver->driver_name; - ret = pci_register_driver(pci_driver); if (ret < 0) { comedi_driver_unregister(comedi_driver); -- cgit v0.10.2 From 5b6cbd87d3b9324e2c4200dd5b1b275999044ad8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 14:02:59 -0700 Subject: staging: comedi: comedi_fops: remove last forward declaration There is still a forward declaration in this file for parse_insn(). Remove the need for it by moving do_insnlist_ioctl() down a bit. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index dc3588a..b798e42 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -842,96 +842,6 @@ copyback: return 0; } -static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn, - unsigned int *data, void *file); -/* - * COMEDI_INSNLIST - * synchronous instructions - * - * arg: - * pointer to sync cmd structure - * - * reads: - * sync cmd struct at arg - * instruction list - * data (for writes) - * - * writes: - * data (for reads) - */ -/* arbitrary limits */ -#define MAX_SAMPLES 256 -static int do_insnlist_ioctl(struct comedi_device *dev, - struct comedi_insnlist __user *arg, void *file) -{ - struct comedi_insnlist insnlist; - struct comedi_insn *insns = NULL; - unsigned int *data = NULL; - int i = 0; - int ret = 0; - - if (copy_from_user(&insnlist, arg, sizeof(insnlist))) - return -EFAULT; - - data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL); - if (!data) { - DPRINTK("kmalloc failed\n"); - ret = -ENOMEM; - goto error; - } - - insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL); - if (!insns) { - DPRINTK("kmalloc failed\n"); - ret = -ENOMEM; - goto error; - } - - if (copy_from_user(insns, insnlist.insns, - sizeof(*insns) * insnlist.n_insns)) { - DPRINTK("copy_from_user failed\n"); - ret = -EFAULT; - goto error; - } - - for (i = 0; i < insnlist.n_insns; i++) { - if (insns[i].n > MAX_SAMPLES) { - DPRINTK("number of samples too large\n"); - ret = -EINVAL; - goto error; - } - if (insns[i].insn & INSN_MASK_WRITE) { - if (copy_from_user(data, insns[i].data, - insns[i].n * sizeof(unsigned int))) { - DPRINTK("copy_from_user failed\n"); - ret = -EFAULT; - goto error; - } - } - ret = parse_insn(dev, insns + i, data, file); - if (ret < 0) - goto error; - if (insns[i].insn & INSN_MASK_READ) { - if (copy_to_user(insns[i].data, data, - insns[i].n * sizeof(unsigned int))) { - DPRINTK("copy_to_user failed\n"); - ret = -EFAULT; - goto error; - } - } - if (need_resched()) - schedule(); - } - -error: - kfree(insns); - kfree(data); - - if (ret < 0) - return ret; - return i; -} - static int check_insn_config_length(struct comedi_insn *insn, unsigned int *data) { @@ -1163,6 +1073,94 @@ out: } /* + * COMEDI_INSNLIST + * synchronous instructions + * + * arg: + * pointer to sync cmd structure + * + * reads: + * sync cmd struct at arg + * instruction list + * data (for writes) + * + * writes: + * data (for reads) + */ +/* arbitrary limits */ +#define MAX_SAMPLES 256 +static int do_insnlist_ioctl(struct comedi_device *dev, + struct comedi_insnlist __user *arg, void *file) +{ + struct comedi_insnlist insnlist; + struct comedi_insn *insns = NULL; + unsigned int *data = NULL; + int i = 0; + int ret = 0; + + if (copy_from_user(&insnlist, arg, sizeof(insnlist))) + return -EFAULT; + + data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL); + if (!data) { + DPRINTK("kmalloc failed\n"); + ret = -ENOMEM; + goto error; + } + + insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL); + if (!insns) { + DPRINTK("kmalloc failed\n"); + ret = -ENOMEM; + goto error; + } + + if (copy_from_user(insns, insnlist.insns, + sizeof(*insns) * insnlist.n_insns)) { + DPRINTK("copy_from_user failed\n"); + ret = -EFAULT; + goto error; + } + + for (i = 0; i < insnlist.n_insns; i++) { + if (insns[i].n > MAX_SAMPLES) { + DPRINTK("number of samples too large\n"); + ret = -EINVAL; + goto error; + } + if (insns[i].insn & INSN_MASK_WRITE) { + if (copy_from_user(data, insns[i].data, + insns[i].n * sizeof(unsigned int))) { + DPRINTK("copy_from_user failed\n"); + ret = -EFAULT; + goto error; + } + } + ret = parse_insn(dev, insns + i, data, file); + if (ret < 0) + goto error; + if (insns[i].insn & INSN_MASK_READ) { + if (copy_to_user(insns[i].data, data, + insns[i].n * sizeof(unsigned int))) { + DPRINTK("copy_to_user failed\n"); + ret = -EFAULT; + goto error; + } + } + if (need_resched()) + schedule(); + } + +error: + kfree(insns); + kfree(data); + + if (ret < 0) + return ret; + return i; +} + +/* * COMEDI_INSN * synchronous instructions * -- cgit v0.10.2 From 01fca37863afc312afaf79c56a565d8b69058561 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 14:36:11 -0700 Subject: staging: comedi: drivers (core): remove forward declarations Move a couple of the functions to avoid the need for the forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index cebdd9e..27a4800 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -45,14 +45,6 @@ #include "comedidev.h" #include "comedi_internal.h" -static int postconfig(struct comedi_device *dev); -static int insn_rw_emulate_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); -static void *comedi_recognize(struct comedi_driver *driv, const char *name); -static void comedi_report_boards(struct comedi_driver *driv); -static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s); - struct comedi_driver *comedi_drivers; int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) @@ -131,121 +123,53 @@ void comedi_device_detach(struct comedi_device *dev) __comedi_device_detach(dev); } -/* do a little post-config cleanup */ -/* called with module refcount incremented, decrements it */ -static int comedi_device_postconfig(struct comedi_device *dev) -{ - int ret = postconfig(dev); - module_put(dev->driver->module); - if (ret < 0) { - __comedi_device_detach(dev); - return ret; - } - if (!dev->board_name) { - dev_warn(dev->class_dev, "BUG: dev->board_name=NULL\n"); - dev->board_name = "BUG"; - } - smp_wmb(); - dev->attached = 1; - return 0; -} - -int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s) { - struct comedi_driver *driv; - int ret; - - if (dev->attached) - return -EBUSY; - - for (driv = comedi_drivers; driv; driv = driv->next) { - if (!try_module_get(driv->module)) - continue; - if (driv->num_names) { - dev->board_ptr = comedi_recognize(driv, it->board_name); - if (dev->board_ptr) - break; - } else if (strcmp(driv->driver_name, it->board_name) == 0) - break; - module_put(driv->module); - } - if (driv == NULL) { - /* recognize has failed if we get here */ - /* report valid board names before returning error */ - for (driv = comedi_drivers; driv; driv = driv->next) { - if (!try_module_get(driv->module)) - continue; - comedi_report_boards(driv); - module_put(driv->module); - } - return -EIO; - } - if (driv->attach == NULL) { - /* driver does not support manual configuration */ - dev_warn(dev->class_dev, - "driver '%s' does not support attach using comedi_config\n", - driv->driver_name); - module_put(driv->module); - return -ENOSYS; - } - /* initialize dev->driver here so - * comedi_error() can be called from attach */ - dev->driver = driv; - ret = driv->attach(dev, it); - if (ret < 0) { - module_put(dev->driver->module); - __comedi_device_detach(dev); - return ret; - } - return comedi_device_postconfig(dev); + return -EINVAL; } -int comedi_driver_register(struct comedi_driver *driver) +int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { - driver->next = comedi_drivers; - comedi_drivers = driver; - - return 0; + return -EINVAL; } -EXPORT_SYMBOL(comedi_driver_register); -int comedi_driver_unregister(struct comedi_driver *driver) +static int insn_rw_emulate_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { - struct comedi_driver *prev; - int i; - - /* check for devices using this driver */ - for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { - struct comedi_device *dev = comedi_dev_from_minor(i); + struct comedi_insn new_insn; + int ret; + static const unsigned channels_per_bitfield = 32; - if (!dev) - continue; + unsigned chan = CR_CHAN(insn->chanspec); + const unsigned base_bitfield_channel = + (chan < channels_per_bitfield) ? 0 : chan; + unsigned int new_data[2]; + memset(new_data, 0, sizeof(new_data)); + memset(&new_insn, 0, sizeof(new_insn)); + new_insn.insn = INSN_BITS; + new_insn.chanspec = base_bitfield_channel; + new_insn.n = 2; + new_insn.subdev = insn->subdev; - mutex_lock(&dev->mutex); - if (dev->attached && dev->driver == driver) { - if (dev->use_count) - dev_warn(dev->class_dev, - "BUG! detaching device with use_count=%d\n", - dev->use_count); - comedi_device_detach(dev); - } - mutex_unlock(&dev->mutex); + if (insn->insn == INSN_WRITE) { + if (!(s->subdev_flags & SDF_WRITABLE)) + return -EINVAL; + new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */ + new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel)) + : 0; /* bits */ } - if (comedi_drivers == driver) { - comedi_drivers = driver->next; - return 0; - } + ret = s->insn_bits(dev, s, &new_insn, new_data); + if (ret < 0) + return ret; - for (prev = comedi_drivers; prev->next; prev = prev->next) { - if (prev->next == driver) { - prev->next = driver->next; - return 0; - } - } - return -EINVAL; + if (insn->insn == INSN_READ) + data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1; + + return 1; } -EXPORT_SYMBOL(comedi_driver_unregister); static int postconfig(struct comedi_device *dev) { @@ -326,6 +250,25 @@ static int postconfig(struct comedi_device *dev) return 0; } +/* do a little post-config cleanup */ +/* called with module refcount incremented, decrements it */ +static int comedi_device_postconfig(struct comedi_device *dev) +{ + int ret = postconfig(dev); + module_put(dev->driver->module); + if (ret < 0) { + __comedi_device_detach(dev); + return ret; + } + if (!dev->board_name) { + dev_warn(dev->class_dev, "BUG: dev->board_name=NULL\n"); + dev->board_name = "BUG"; + } + smp_wmb(); + dev->attached = 1; + return 0; +} + /* * Generic recognize function for drivers that register their supported * board names. @@ -384,53 +327,102 @@ static void comedi_report_boards(struct comedi_driver *driv) pr_info(" %s\n", driv->driver_name); } -static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s) +int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) { - return -EINVAL; + struct comedi_driver *driv; + int ret; + + if (dev->attached) + return -EBUSY; + + for (driv = comedi_drivers; driv; driv = driv->next) { + if (!try_module_get(driv->module)) + continue; + if (driv->num_names) { + dev->board_ptr = comedi_recognize(driv, it->board_name); + if (dev->board_ptr) + break; + } else if (strcmp(driv->driver_name, it->board_name) == 0) + break; + module_put(driv->module); + } + if (driv == NULL) { + /* recognize has failed if we get here */ + /* report valid board names before returning error */ + for (driv = comedi_drivers; driv; driv = driv->next) { + if (!try_module_get(driv->module)) + continue; + comedi_report_boards(driv); + module_put(driv->module); + } + return -EIO; + } + if (driv->attach == NULL) { + /* driver does not support manual configuration */ + dev_warn(dev->class_dev, + "driver '%s' does not support attach using comedi_config\n", + driv->driver_name); + module_put(driv->module); + return -ENOSYS; + } + /* initialize dev->driver here so + * comedi_error() can be called from attach */ + dev->driver = driv; + ret = driv->attach(dev, it); + if (ret < 0) { + module_put(dev->driver->module); + __comedi_device_detach(dev); + return ret; + } + return comedi_device_postconfig(dev); } -int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +int comedi_driver_register(struct comedi_driver *driver) { - return -EINVAL; + driver->next = comedi_drivers; + comedi_drivers = driver; + + return 0; } +EXPORT_SYMBOL(comedi_driver_register); -static int insn_rw_emulate_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +int comedi_driver_unregister(struct comedi_driver *driver) { - struct comedi_insn new_insn; - int ret; - static const unsigned channels_per_bitfield = 32; + struct comedi_driver *prev; + int i; - unsigned chan = CR_CHAN(insn->chanspec); - const unsigned base_bitfield_channel = - (chan < channels_per_bitfield) ? 0 : chan; - unsigned int new_data[2]; - memset(new_data, 0, sizeof(new_data)); - memset(&new_insn, 0, sizeof(new_insn)); - new_insn.insn = INSN_BITS; - new_insn.chanspec = base_bitfield_channel; - new_insn.n = 2; - new_insn.subdev = insn->subdev; + /* check for devices using this driver */ + for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { + struct comedi_device *dev = comedi_dev_from_minor(i); - if (insn->insn == INSN_WRITE) { - if (!(s->subdev_flags & SDF_WRITABLE)) - return -EINVAL; - new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */ - new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel)) - : 0; /* bits */ - } + if (!dev) + continue; - ret = s->insn_bits(dev, s, &new_insn, new_data); - if (ret < 0) - return ret; + mutex_lock(&dev->mutex); + if (dev->attached && dev->driver == driver) { + if (dev->use_count) + dev_warn(dev->class_dev, + "BUG! detaching device with use_count=%d\n", + dev->use_count); + comedi_device_detach(dev); + } + mutex_unlock(&dev->mutex); + } - if (insn->insn == INSN_READ) - data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1; + if (comedi_drivers == driver) { + comedi_drivers = driver->next; + return 0; + } - return 1; + for (prev = comedi_drivers; prev->next; prev = prev->next) { + if (prev->next == driver) { + prev->next = driver->next; + return 0; + } + } + return -EINVAL; } +EXPORT_SYMBOL(comedi_driver_unregister); int comedi_auto_config(struct device *hardware_device, struct comedi_driver *driver, unsigned long context) -- cgit v0.10.2 From 40f58a65c9f6cbb540ec2db6ac9d963d402014c3 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 14:36:40 -0700 Subject: staging: comedi: drivers (core): factor out async subdevice postconfig Factor the setup of an async subdevice out of postconfig(). This allows bringing the code back a couple indents and makes the postconfig a bit clearer. For aesthetic reasons, rename postconfig() to __comedi_device_postconfig(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 27a4800..e5fe2e1 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -171,12 +171,50 @@ static int insn_rw_emulate_bits(struct comedi_device *dev, return 1; } -static int postconfig(struct comedi_device *dev) +static int __comedi_device_postconfig_async(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct comedi_async *async; + unsigned int buf_size; + int ret; + + BUG_ON((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0); + BUG_ON(!s->do_cmdtest); + + async = kzalloc(sizeof(*async), GFP_KERNEL); + if (!async) { + dev_warn(dev->class_dev, "failed to allocate async struct\n"); + return -ENOMEM; + } + init_waitqueue_head(&async->wait_head); + async->subdevice = s; + s->async = async; + + async->max_bufsize = comedi_default_buf_maxsize_kb * 1024; + buf_size = comedi_default_buf_size_kb * 1024; + if (buf_size > async->max_bufsize) + buf_size = async->max_bufsize; + + if (comedi_buf_alloc(dev, s, buf_size) < 0) { + dev_warn(dev->class_dev, "Buffer allocation failed\n"); + return -ENOMEM; + } + if (s->buf_change) { + ret = s->buf_change(dev, s, buf_size); + if (ret < 0) + return ret; + } + + comedi_alloc_subdevice_minor(dev, s); + + return 0; +} + +static int __comedi_device_postconfig(struct comedi_device *dev) { - int i; struct comedi_subdevice *s; - struct comedi_async *async = NULL; int ret; + int i; for (i = 0; i < dev->n_subdevices; i++) { s = &dev->subdevices[i]; @@ -188,42 +226,9 @@ static int postconfig(struct comedi_device *dev) s->len_chanlist = 1; if (s->do_cmd) { - unsigned int buf_size; - - BUG_ON((s->subdev_flags & (SDF_CMD_READ | - SDF_CMD_WRITE)) == 0); - BUG_ON(!s->do_cmdtest); - - async = - kzalloc(sizeof(struct comedi_async), GFP_KERNEL); - if (async == NULL) { - dev_warn(dev->class_dev, - "failed to allocate async struct\n"); - return -ENOMEM; - } - init_waitqueue_head(&async->wait_head); - async->subdevice = s; - s->async = async; - - async->max_bufsize = - comedi_default_buf_maxsize_kb * 1024; - buf_size = comedi_default_buf_size_kb * 1024; - if (buf_size > async->max_bufsize) - buf_size = async->max_bufsize; - - async->prealloc_buf = NULL; - async->prealloc_bufsz = 0; - if (comedi_buf_alloc(dev, s, buf_size) < 0) { - dev_warn(dev->class_dev, - "Buffer allocation failed\n"); - return -ENOMEM; - } - if (s->buf_change) { - ret = s->buf_change(dev, s, buf_size); - if (ret < 0) - return ret; - } - comedi_alloc_subdevice_minor(dev, s); + ret = __comedi_device_postconfig_async(dev, s); + if (ret) + return ret; } if (!s->range_table && !s->range_table_list) @@ -254,7 +259,7 @@ static int postconfig(struct comedi_device *dev) /* called with module refcount incremented, decrements it */ static int comedi_device_postconfig(struct comedi_device *dev) { - int ret = postconfig(dev); + int ret = __comedi_device_postconfig(dev); module_put(dev->driver->module); if (ret < 0) { __comedi_device_detach(dev); -- cgit v0.10.2 From 57b71c3e6f4c8b944e6721d89ccb566aee439f97 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 14:37:15 -0700 Subject: staging: comedi: drivers (core): don't BUG_ON due to faulty drivers The postconfig for drivers that support async commands currently can BUG_ON if the subdevice was improperly configured by the driver. Change the BUG_ON so that a dev_warn() is output and the postconfig returns -EINVAL. This will prevent the comedi core from attaching to the faulty driver but does not BUG the kernel. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index e5fe2e1..7e8ee5d 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -178,8 +178,16 @@ static int __comedi_device_postconfig_async(struct comedi_device *dev, unsigned int buf_size; int ret; - BUG_ON((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0); - BUG_ON(!s->do_cmdtest); + if ((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0) { + dev_warn(dev->class_dev, + "async subdevices must support SDF_CMD_READ or SDF_CMD_WRITE\n"); + return -EINVAL; + } + if (!s->do_cmdtest) { + dev_warn(dev->class_dev, + "async subdevices must have a do_cmdtest() function\n"); + return -EINVAL; + } async = kzalloc(sizeof(*async), GFP_KERNEL); if (!async) { -- cgit v0.10.2 From de59c285a4787dfc2ac4f2546ef0082ae08754e2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 14:37:46 -0700 Subject: staging: comedi: drivers (core): remove BUG_ON in comedi_auto_unconfig() comedi_find_board_minor() will always return a ninor number between 0 and < COMEDI_NUM_BOARD_MINORS, or -ENODEV if a minor is not found. Remove the unnecessary BUG_ON(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 7e8ee5d..1c7d4da 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -493,7 +493,6 @@ void comedi_auto_unconfig(struct device *hardware_device) minor = comedi_find_board_minor(hardware_device); if (minor < 0) return; - BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS); comedi_free_board_minor(minor); } EXPORT_SYMBOL_GPL(comedi_auto_unconfig); -- cgit v0.10.2 From 934efe63e8bece28c69d18ea5e3bfd1619fc23b2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:17:05 -0700 Subject: staging: comedi: addi_apci_2200: use addi_watchdog module The current watchdog support in hwdrv_apci2200.c does not conform to the comedi API. Use the addi_watchdog module to provide support for the watchdog subdevice and remove the now unneeded hwdrv_apci2200.c file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c deleted file mode 100644 index 4d32509..0000000 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c +++ /dev/null @@ -1,176 +0,0 @@ -/** -@verbatim - -Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. - - ADDI-DATA GmbH - Dieselstrasse 3 - D-77833 Ottersweier - Tel: +19(0)7223/9493-0 - Fax: +49(0)7223/9493-92 - http://www.addi-data.com - info@addi-data.com - -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - -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. - -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - -@endverbatim -*/ -/* - - +-----------------------------------------------------------------------+ - | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier | - +-----------------------------------------------------------------------+ - | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | - | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | - +-------------------------------+---------------------------------------+ - | Project : APCI-2200 | Compiler : GCC | - | Module name : hwdrv_apci2200.c| Version : 2.96 | - +-------------------------------+---------------------------------------+ - | Project manager: Eric Stolz | Date : 02/12/2002 | - +-------------------------------+---------------------------------------+ - | Description : Hardware Layer Access For APCI-2200 | - +-----------------------------------------------------------------------+ - | UPDATES | - +----------+-----------+------------------------------------------------+ - | Date | Author | Description of updates | - +----------+-----------+------------------------------------------------+ - | | | | - | | | | - | | | | - +----------+-----------+------------------------------------------------+ -*/ - -/* TIMER COUNTER WATCHDOG DEFINES */ - -#define APCI2200_WATCHDOG 0x08 -#define APCI2200_WATCHDOG_ENABLEDISABLE 12 -#define APCI2200_WATCHDOG_RELOAD_VALUE 4 -#define APCI2200_WATCHDOG_STATUS 16 - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI2200_ConfigWatchdog(struct comedi_device *dev, -| struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) | -| | -+----------------------------------------------------------------------------+ -| Task : Configures The Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| struct comedi_subdevice *s, :pointer to subdevice structure -| struct comedi_insn *insn :pointer to insn structure | -| unsigned int *data : Data Pointer to read status | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI2200_ConfigWatchdog(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - if (data[0] == 0) { - /* Disable the watchdog */ - outw(0x0, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); - /* Loading the Reload value */ - outw(data[1], dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE); - data[1] = data[1] >> 16; - outw(data[1], dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE + 2); - } /* if(data[0]==0) */ - else { - printk("\nThe input parameters are wrong\n"); - return -EINVAL; - } /* elseif(data[0]==0) */ - - return insn->n; -} - - /* - +----------------------------------------------------------------------------+ - | Function Name : int i_APCI2200_StartStopWriteWatchdog | - | (struct comedi_device *dev,struct comedi_subdevice *s, - struct comedi_insn *insn,unsigned int *data); | - +----------------------------------------------------------------------------+ - | Task : Start / Stop The Watchdog | - +----------------------------------------------------------------------------+ - | Input Parameters : struct comedi_device *dev : Driver handle | - | struct comedi_subdevice *s, :pointer to subdevice structure - struct comedi_insn *insn :pointer to insn structure | - | unsigned int *data : Data Pointer to read status | - +----------------------------------------------------------------------------+ - | Output Parameters : -- | - +----------------------------------------------------------------------------+ - | Return Value : TRUE : No error occur | - | : FALSE : Error occur. Return the error | - | | - +----------------------------------------------------------------------------+ - */ - -static int i_APCI2200_StartStopWriteWatchdog(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - switch (data[0]) { - case 0: /* stop the watchdog */ - outw(0x0, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); - break; - case 1: /* start the watchdog */ - outw(0x0001, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); - break; - case 2: /* Software trigger */ - outw(0x0201, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); - break; - default: - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - } /* switch(data[0]) */ - return insn->n; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI2200_ReadWatchdog | -| (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn, -| unsigned int *data); | -+----------------------------------------------------------------------------+ -| Task : Read The Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| struct comedi_subdevice *s, :pointer to subdevice structure -| struct comedi_insn *insn :pointer to insn structure | -| unsigned int *data : Data Pointer to read status | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI2200_ReadWatchdog(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - data[0] = inw(dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_STATUS) & 0x1; - return insn->n; -} diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 15a84e5..99a206a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -1,25 +1,21 @@ #include "../comedidev.h" +#include "addi_watchdog.h" #include "comedi_fc.h" #include "addi-data/addi_common.h" -#include "addi-data/hwdrv_apci2200.c" - /* * I/O Register Map */ #define APCI2200_DI_REG 0x00 #define APCI2200_DO_REG 0x04 +#define APCI2200_WDOG_REG 0x08 static const struct addi_board apci2200_boardtypes[] = { { .pc_DriverName = "apci2200", .i_VendorId = PCI_VENDOR_ID_ADDIDATA, .i_DeviceId = 0x1005, - .i_Timer = 1, - .timer_config = i_APCI2200_ConfigWatchdog, - .timer_write = i_APCI2200_StartStopWriteWatchdog, - .timer_read = i_APCI2200_ReadWatchdog, }, }; @@ -57,12 +53,8 @@ static int apci2200_do_insn_bits(struct comedi_device *dev, static int apci2200_reset(struct comedi_device *dev) { outw(0x0, dev->iobase + APCI2200_DO_REG); - outw(0x0, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_ENABLEDISABLE); - outw(0x0, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE); - outw(0x0, dev->iobase + APCI2200_WATCHDOG + - APCI2200_WATCHDOG_RELOAD_VALUE + 2); + + addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG); return 0; } @@ -143,21 +135,9 @@ static int apci2200_auto_attach(struct comedi_device *dev, /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; - if (this_board->i_Timer) { - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = 1; - s->maxdata = 0; - s->len_chanlist = 1; - s->range_table = &range_digital; - - s->insn_write = this_board->timer_write; - s->insn_read = this_board->timer_read; - s->insn_config = this_board->timer_config; - s->insn_bits = this_board->timer_bits; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG); + if (ret) + return ret; /* Allocate and Initialise TTL */ s = &dev->subdevices[5]; @@ -180,6 +160,8 @@ static void apci2200_detach(struct comedi_device *dev) if (dev->iobase) apci2200_reset(dev); } + if (dev->subdevices) + addi_watchdog_cleanup(&dev->subdevices[4]); if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); -- cgit v0.10.2 From 3f8e9e67cb8c0f99b3cb7936d650ad16adedbc34 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:17:40 -0700 Subject: staging: comedi: addi_apci_2200: remove devpriv allocation The 'devpriv' is not used in this driver. Remove it's allocation in the auto_attach and the check for it in the detach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 99a206a..7ea0dc6 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -81,7 +81,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, { struct pci_dev *pcidev = comedi_to_pci_dev(dev); const struct addi_board *this_board; - struct addi_private *devpriv; struct comedi_subdevice *s; int ret, n_subdevices; @@ -91,11 +90,6 @@ static int apci2200_auto_attach(struct comedi_device *dev, dev->board_ptr = this_board; dev->board_name = this_board->pc_DriverName; - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - ret = comedi_pci_enable(pcidev, dev->board_name); if (ret) return ret; @@ -154,12 +148,9 @@ static int apci2200_auto_attach(struct comedi_device *dev, static void apci2200_detach(struct comedi_device *dev) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - struct addi_private *devpriv = dev->private; - if (devpriv) { - if (dev->iobase) - apci2200_reset(dev); - } + if (dev->iobase) + apci2200_reset(dev); if (dev->subdevices) addi_watchdog_cleanup(&dev->subdevices[4]); if (pcidev) { -- cgit v0.10.2 From 2762a09d7702bd14af499ac42e0a20ab876baa09 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:18:30 -0700 Subject: staging: comedi: addi_apci_2200: remove unnecessary boardinfo The boardinfo is not longer needed by this driver. Remove it as well as the addi_find_boardinfo() function. This removes the final ties to the addi-data "common" code so remove the #include for it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 7ea0dc6..6e490fd 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -2,8 +2,6 @@ #include "addi_watchdog.h" #include "comedi_fc.h" -#include "addi-data/addi_common.h" - /* * I/O Register Map */ @@ -11,14 +9,6 @@ #define APCI2200_DO_REG 0x04 #define APCI2200_WDOG_REG 0x08 -static const struct addi_board apci2200_boardtypes[] = { - { - .pc_DriverName = "apci2200", - .i_VendorId = PCI_VENDOR_ID_ADDIDATA, - .i_DeviceId = 0x1005, - }, -}; - static int apci2200_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -59,36 +49,14 @@ static int apci2200_reset(struct comedi_device *dev) return 0; } -static const void *addi_find_boardinfo(struct comedi_device *dev, - struct pci_dev *pcidev) -{ - const void *p = dev->driver->board_name; - const struct addi_board *this_board; - int i; - - for (i = 0; i < dev->driver->num_names; i++) { - this_board = p; - if (this_board->i_VendorId == pcidev->vendor && - this_board->i_DeviceId == pcidev->device) - return this_board; - p += dev->driver->offset; - } - return NULL; -} - static int apci2200_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct addi_board *this_board; struct comedi_subdevice *s; int ret, n_subdevices; - this_board = addi_find_boardinfo(dev, pcidev); - if (!this_board) - return -ENODEV; - dev->board_ptr = this_board; - dev->board_name = this_board->pc_DriverName; + dev->board_name = dev->driver->driver_name; ret = comedi_pci_enable(pcidev, dev->board_name); if (ret) @@ -164,9 +132,6 @@ static struct comedi_driver apci2200_driver = { .module = THIS_MODULE, .auto_attach = apci2200_auto_attach, .detach = apci2200_detach, - .num_names = ARRAY_SIZE(apci2200_boardtypes), - .board_name = &apci2200_boardtypes[0].pc_DriverName, - .offset = sizeof(struct addi_board), }; static int apci2200_pci_probe(struct pci_dev *dev, -- cgit v0.10.2 From 43ae290bf8153f87a2dc44e37f611b4adeac457c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:18:52 -0700 Subject: staging: comedi: addi_apci_2200: remove unnecessary include This driver does not use any of the support provided by comedi_fc.h. Remove it's include. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 6e490fd..b7812d2 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -1,6 +1,5 @@ #include "../comedidev.h" #include "addi_watchdog.h" -#include "comedi_fc.h" /* * I/O Register Map -- cgit v0.10.2 From 5872471364f0a49f95a8efbec80c622a24c7df6b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:19:13 -0700 Subject: staging: comedi: addi_apci_2200: add missing copyright comment Add the missing copyright information. This information was originally in the hwdrv_apci2200.c file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index b7812d2..2e527b0 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -1,3 +1,34 @@ +/* + * addi_apci_2200.c + * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. + * Project manager: Eric Stolz + * + * ADDI-DATA GmbH + * Dieselstrasse 3 + * D-77833 Ottersweier + * Tel: +19(0)7223/9493-0 + * Fax: +49(0)7223/9493-92 + * http://www.addi-data.com + * info@addi-data.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * You should also find the complete GPL in the COPYING file accompanying + * this source code. + */ + #include "../comedidev.h" #include "addi_watchdog.h" -- cgit v0.10.2 From 20f2e2e1ceee6575794e9957912399d7ead8458f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:19:32 -0700 Subject: staging: comedi: addi_apci_2200: only allocate needed subdevices The addi-data "common" code always allocated 7 subdevices. This driver only requires 3. Change the allocation and remove the unused subdevices. Update the comments for the initialization of each subdevice. Also, update the subdevice that is passed to addi_watchdog_cleanup() to match the new subdevice number. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 2e527b0..b8a8a3f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -84,7 +84,7 @@ static int apci2200_auto_attach(struct comedi_device *dev, { struct pci_dev *pcidev = comedi_to_pci_dev(dev); struct comedi_subdevice *s; - int ret, n_subdevices; + int ret; dev->board_name = dev->driver->driver_name; @@ -94,21 +94,12 @@ static int apci2200_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 1); - n_subdevices = 7; - ret = comedi_alloc_subdevices(dev, n_subdevices); + ret = comedi_alloc_subdevices(dev, 3); if (ret) return ret; - /* Allocate and Initialise AI Subdevice Structures */ + /* Initialize the digital input subdevice */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise AO Subdevice Structures */ - s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise DI Subdevice Structures */ - s = &dev->subdevices[2]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 8; @@ -116,8 +107,8 @@ static int apci2200_auto_attach(struct comedi_device *dev, s->range_table = &range_digital; s->insn_bits = apci2200_di_insn_bits; - /* Allocate and Initialise DO Subdevice Structures */ - s = &dev->subdevices[3]; + /* Initialize the digital output subdevice */ + s = &dev->subdevices[1]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 16; @@ -125,20 +116,12 @@ static int apci2200_auto_attach(struct comedi_device *dev, s->range_table = &range_digital; s->insn_bits = apci2200_do_insn_bits; - /* Allocate and Initialise Timer Subdevice Structures */ - s = &dev->subdevices[4]; + /* Initialize the watchdog subdevice */ + s = &dev->subdevices[2]; ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG); if (ret) return ret; - /* Allocate and Initialise TTL */ - s = &dev->subdevices[5]; - s->type = COMEDI_SUBD_UNUSED; - - /* EEPROM */ - s = &dev->subdevices[6]; - s->type = COMEDI_SUBD_UNUSED; - apci2200_reset(dev); return 0; } @@ -150,7 +133,7 @@ static void apci2200_detach(struct comedi_device *dev) if (dev->iobase) apci2200_reset(dev); if (dev->subdevices) - addi_watchdog_cleanup(&dev->subdevices[4]); + addi_watchdog_cleanup(&dev->subdevices[2]); if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); -- cgit v0.10.2 From 26b3989946c4b346e5c9181bde7f4a3c969089e0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 15:19:52 -0700 Subject: staging: comedi: addi_apci_2200: change the MODULE_DESCRIPTION Change the MODULE_DESCRIPTION to something more useful than the generic "Comedi low-level driver" so that modinfo provides a better description of the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index b1d1a0e..815c20a 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -634,6 +634,7 @@ config COMEDI_ADDI_APCI_2032 config COMEDI_ADDI_APCI_2200 tristate "ADDI-DATA APCI_2200 support" + select COMEDI_ADDI_WATCHDOG ---help--- Enable support for ADDI-DATA APCI_2200 cards diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index b8a8a3f..4092faa 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -172,6 +172,6 @@ static struct pci_driver apci2200_pci_driver = { }; module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver); +MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated"); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 92eb37959f0e98376969e97bb6518c0f4b738241 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 16:00:46 -0700 Subject: staging: comedi: addi_apci_16xx: rewrite low-level support code The current low-level support code in hwdrv_apci16xx.c is seriously broken. Besides that, it's overly complicated. Rewrite, and simplify, the low-level code so it complies with the comedi API. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c deleted file mode 100644 index 098ea59..0000000 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ /dev/null @@ -1,542 +0,0 @@ -/** -@verbatim - -Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. - - ADDI-DATA GmbH - Dieselstrasse 3 - D-77833 Ottersweier - Tel: +19(0)7223/9493-0 - Fax: +49(0)7223/9493-92 - http://www.addi-data.com - info@addi-data.com - -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - -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. - -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - -@endverbatim -*/ -/* - - +-----------------------------------------------------------------------+ - | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier | - +-----------------------------------------------------------------------+ - | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | - | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | - +-----------------------------------------------------------------------+ - | Project : API APCI1648 | Compiler : gcc | - | Module name : TTL.C | Version : 2.96 | - +-------------------------------+---------------------------------------+ - | Project manager: S. Weber | Date : 25/05/2005 | - +-----------------------------------------------------------------------+ - | Description : APCI-16XX TTL I/O module | - | | - | | - +-----------------------------------------------------------------------+ - | UPDATES | - +-----------------------------------------------------------------------+ - | Date | Author | Description of updates | - +----------+-----------+------------------------------------------------+ - |25.05.2005| S.Weber | Creation | - | | | | - +-----------------------------------------------------------------------+ -*/ - -#define APCI16XX_TTL_INIT 0 -#define APCI16XX_TTL_INITDIRECTION 1 -#define APCI16XX_TTL_OUTPUTMEMORY 2 - -#define APCI16XX_TTL_READCHANNEL 0 -#define APCI16XX_TTL_READPORT 1 - -#define APCI16XX_TTL_WRITECHANNEL_ON 0 -#define APCI16XX_TTL_WRITECHANNEL_OFF 1 -#define APCI16XX_TTL_WRITEPORT_ON 2 -#define APCI16XX_TTL_WRITEPORT_OFF 3 - -#define APCI16XX_TTL_READ_ALL_INPUTS 0 -#define APCI16XX_TTL_READ_ALL_OUTPUTS 1 - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI16XX_InsnConfigInitTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task APCI16XX_TTL_INIT (using defaults) : | -| Configure the TTL I/O operating mode from all ports | -| You must calling this function be | -| for you call any other function witch access of TTL. | -| APCI16XX_TTL_INITDIRECTION(user inputs for direction) | -+----------------------------------------------------------------------------+ -| Input Parameters : b_InitType = (unsigned char) data[0]; | -| b_Port0Mode = (unsigned char) data[1]; | -| b_Port1Mode = (unsigned char) data[2]; | -| b_Port2Mode = (unsigned char) data[3]; | -| b_Port3Mode = (unsigned char) data[4]; | -| ........ | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0: No error | -| -1: Port 0 mode selection is wrong | -| -2: Port 1 mode selection is wrong | -| -3: Port 2 mode selection is wrong | -| -4: Port 3 mode selection is wrong | -| -X: Port X-1 mode selection is wrong | -| .... | -| -100 : Config command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Command = 0; - unsigned char b_Cpt = 0; - unsigned char b_NumberOfPort = s->n_chan / 8; - - /* Test the buffer size */ - if (insn->n >= 1) { - /* Get the command */ - b_Command = (unsigned char) data[0]; - - /* Test the command */ - if ((b_Command == APCI16XX_TTL_INIT) || - (b_Command == APCI16XX_TTL_INITDIRECTION) || - (b_Command == APCI16XX_TTL_OUTPUTMEMORY)) { - /* Test the initialisation buffer size */ - if ((b_Command == APCI16XX_TTL_INITDIRECTION) - && ((unsigned char) (insn->n - 1) != b_NumberOfPort)) { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY) - && ((unsigned char) (insn->n) != 2)) { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - } else { - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - } else { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */ - if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION)) { - memset(devpriv->ul_TTLPortConfiguration, 0, - sizeof(devpriv->ul_TTLPortConfiguration)); - - /* Test the port direction selection */ - for (b_Cpt = 1; - (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0); - b_Cpt++) { - /* Test the direction */ - if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF)) { - printk("\nPort %d direction selection error", - (int) b_Cpt); - i_ReturnValue = -(int) b_Cpt; - } - - /* Save the configuration */ - devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] = - devpriv->ul_TTLPortConfiguration[(b_Cpt - - 1) / 4] | (data[b_Cpt] << (8 * ((b_Cpt - - 1) % 4))); - } - } - - /* Test if no error occur */ - if (i_ReturnValue >= 0) { - /* Test if TTL port initilaisation */ - if ((b_Command == APCI16XX_TTL_INIT) - || (b_Command == APCI16XX_TTL_INITDIRECTION)) { - /* Set all port configuration */ - for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt++) { - if ((b_Cpt % 4) == 0) { - /* Set the configuration */ - outl(devpriv-> - ul_TTLPortConfiguration[b_Cpt / - 4], - dev->iobase + 32 + b_Cpt); - } - } - } - } - - /* Test if output memory initialisation command */ - if (b_Command == APCI16XX_TTL_OUTPUTMEMORY) { - if (data[1]) { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; - } else { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - } - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI16XX_InsnBitsReadTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Read the status from selected TTL digital input | -| (b_InputChannel) | -+----------------------------------------------------------------------------+ -| Task : Read the status from digital input port | -| (b_SelectedPort) | -+----------------------------------------------------------------------------+ -| Input Parameters : | -| APCI16XX_TTL_READCHANNEL | -| b_SelectedPort= CR_RANGE(insn->chanspec); | -| b_InputChannel= CR_CHAN(insn->chanspec); | -| b_ReadType = (unsigned char) data[0]; | -| | -| APCI16XX_TTL_READPORT | -| b_SelectedPort= CR_RANGE(insn->chanspec); | -| b_ReadType = (unsigned char) data[0]; | -+----------------------------------------------------------------------------+ -| Output Parameters : data[0] 0 : Channle is not active | -| 1 : Channle is active | -+----------------------------------------------------------------------------+ -| Return Value : >0 : No error | -| -100 : Config command error | -| -101 : Data size error | -| -102 : The selected TTL input port is wrong | -| -103 : The selected TTL digital input is wrong | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Command = 0; - unsigned char b_NumberOfPort = s->n_chan / 8; - unsigned char b_SelectedPort = CR_RANGE(insn->chanspec); - unsigned char b_InputChannel = CR_CHAN(insn->chanspec); - unsigned char *pb_Status; - unsigned int dw_Status; - - /* Test the buffer size */ - if (insn->n >= 1) { - /* Get the command */ - b_Command = (unsigned char) data[0]; - - /* Test the command */ - if ((b_Command == APCI16XX_TTL_READCHANNEL) - || (b_Command == APCI16XX_TTL_READPORT)) { - /* Test the selected port */ - if (b_SelectedPort < b_NumberOfPort) { - /* Test if input port */ - if (((devpriv->ul_TTLPortConfiguration - [b_SelectedPort / - 4] >> (8 * - (b_SelectedPort - % - 4))) & - 0xFF) == 0) { - /* Test the channel number */ - if ((b_Command == - APCI16XX_TTL_READCHANNEL) - && (b_InputChannel > 7)) { - printk("\nChannel selection error"); - i_ReturnValue = -103; - } - } else { - printk("\nPort selection error"); - i_ReturnValue = -102; - } - } else { - printk("\nPort selection error"); - i_ReturnValue = -102; - } - } else { - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - } else { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - /* Test if no error occur */ - if (i_ReturnValue >= 0) { - pb_Status = (unsigned char *) &data[0]; - - /* Get the digital inpu status */ - dw_Status = - inl(dev->iobase + 8 + ((b_SelectedPort / 4) * 4)); - dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF; - - /* Save the port value */ - *pb_Status = (unsigned char) dw_Status; - - /* Test if read channel status command */ - if (b_Command == APCI16XX_TTL_READCHANNEL) { - *pb_Status = (*pb_Status >> b_InputChannel) & 1; - } - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI16XX_InsnReadTTLIOAllPortValue | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Read the status from all digital input ports | -+----------------------------------------------------------------------------+ -| Input Parameters : - | -+----------------------------------------------------------------------------+ -| Output Parameters : data[0] : Port 0 to 3 data | -| data[1] : Port 4 to 7 data | -| .... | -+----------------------------------------------------------------------------+ -| Return Value : 0: No error | -| -100 : Read command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - unsigned char b_Command = (unsigned char) CR_AREF(insn->chanspec); - int i_ReturnValue = insn->n; - unsigned char b_Cpt = 0; - unsigned char b_NumberOfPort = 0; - unsigned int *pls_ReadData = data; - - /* Test the command */ - if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) - || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) { - /* Get the number of 32-Bit ports */ - b_NumberOfPort = s->n_chan / 32; - if ((b_NumberOfPort * 32) < s->n_chan) - b_NumberOfPort = b_NumberOfPort + 1; - - /* Test the buffer size */ - if (insn->n >= b_NumberOfPort) { - if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS) { - /* Read all digital input */ - for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { - /* Read the 32-Bit port */ - pls_ReadData[b_Cpt] = - inl(dev->iobase + 8 + - (b_Cpt * 4)); - - /* Mask all channels used als outputs */ - pls_ReadData[b_Cpt] = - pls_ReadData[b_Cpt] & - (~devpriv-> - ul_TTLPortConfiguration[b_Cpt]); - } - } else { - /* Read all digital outputs */ - for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { - /* Read the 32-Bit port */ - pls_ReadData[b_Cpt] = - inl(dev->iobase + 20 + - (b_Cpt * 4)); - - /* Mask all channels used als outputs */ - pls_ReadData[b_Cpt] = - pls_ReadData[b_Cpt] & devpriv-> - ul_TTLPortConfiguration[b_Cpt]; - } - } - } else { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - } else { - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI16XX_InsnBitsWriteTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Set the state from selected TTL digital output | -| (b_OutputChannel) | -+----------------------------------------------------------------------------+ -| Task : Set the state from digital output port | -| (b_SelectedPort) | -+----------------------------------------------------------------------------+ -| Input Parameters : | -| APCI16XX_TTL_WRITECHANNEL_ON | APCI16XX_TTL_WRITECHANNEL_OFF | -| b_SelectedPort = CR_RANGE(insn->chanspec); | -| b_OutputChannel= CR_CHAN(insn->chanspec); | -| b_Command = (unsigned char) data[0]; | -| | -| APCI16XX_TTL_WRITEPORT_ON | APCI16XX_TTL_WRITEPORT_OFF | -| b_SelectedPort = CR_RANGE(insn->chanspec); | -| b_Command = (unsigned char) data[0]; | -+----------------------------------------------------------------------------+ -| Output Parameters : data[0] : TTL output port 0 to 3 data | -| data[1] : TTL output port 4 to 7 data | -| .... | -+----------------------------------------------------------------------------+ -| Return Value : >0 : No error | -| -100 : Command error | -| -101 : Data size error | -| -102 : The selected TTL output port is wrong | -| -103 : The selected TTL digital output is wrong | -| -104 : Output memory disabled | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Command = 0; - unsigned char b_NumberOfPort = s->n_chan / 8; - unsigned char b_SelectedPort = CR_RANGE(insn->chanspec); - unsigned char b_OutputChannel = CR_CHAN(insn->chanspec); - unsigned int dw_Status = 0; - - /* Test the buffer size */ - if (insn->n >= 1) { - /* Get the command */ - b_Command = (unsigned char) data[0]; - - /* Test the command */ - if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || - (b_Command == APCI16XX_TTL_WRITEPORT_ON) || - (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || - (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) { - /* Test the selected port */ - if (b_SelectedPort < b_NumberOfPort) { - /* Test if output port */ - if (((devpriv->ul_TTLPortConfiguration - [b_SelectedPort / - 4] >> (8 * - (b_SelectedPort - % - 4))) & - 0xFF) == 0xFF) { - /* Test the channel number */ - if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7)) { - printk("\nChannel selection error"); - i_ReturnValue = -103; - } - - if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)) { - printk("\nOutput memory disabled"); - i_ReturnValue = -104; - } - - /* Test the buffer size */ - if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2)) { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - } else { - printk("\nPort selection error %lX", - (unsigned long)devpriv-> - ul_TTLPortConfiguration[0]); - i_ReturnValue = -102; - } - } else { - printk("\nPort selection error %d %d", - b_SelectedPort, b_NumberOfPort); - i_ReturnValue = -102; - } - } else { - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - } else { - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - /* Test if no error occur */ - if (i_ReturnValue >= 0) { - /* Get the digital output state */ - dw_Status = - inl(dev->iobase + 20 + ((b_SelectedPort / 4) * 4)); - - /* Test if output memory not used */ - if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) { - /* Clear the selected port value */ - dw_Status = - dw_Status & (0xFFFFFFFFUL - - (0xFFUL << (8 * (b_SelectedPort % 4)))); - } - - /* Test if setting channel ON */ - if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON) { - dw_Status = - dw_Status | (1UL << ((8 * (b_SelectedPort % - 4)) + b_OutputChannel)); - } - - /* Test if setting port ON */ - if (b_Command == APCI16XX_TTL_WRITEPORT_ON) { - dw_Status = - dw_Status | ((data[1] & 0xFF) << (8 * - (b_SelectedPort % 4))); - } - - /* Test if setting channel OFF */ - if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) { - dw_Status = - dw_Status & (0xFFFFFFFFUL - - (1UL << ((8 * (b_SelectedPort % 4)) + - b_OutputChannel))); - } - - /* Test if setting port OFF */ - if (b_Command == APCI16XX_TTL_WRITEPORT_OFF) { - dw_Status = - dw_Status & (0xFFFFFFFFUL - - ((data[1] & 0xFF) << (8 * (b_SelectedPort % - 4)))); - } - - outl(dw_Status, - dev->iobase + 20 + ((b_SelectedPort / 4) * 4)); - } - - return i_ReturnValue; -} diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 899dae1..6c41f0b 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -1,9 +1,12 @@ #include "../comedidev.h" #include "comedi_fc.h" -#include "addi-data/addi_common.h" - -#include "addi-data/hwdrv_apci16xx.c" +/* + * Register I/O map + */ +#define APCI16XX_IN_REG(x) (((x) * 4) + 0x08) +#define APCI16XX_OUT_REG(x) (((x) * 4) + 0x14) +#define APCI16XX_DIR_REG(x) (((x) * 4) + 0x20) struct apci16xx_boardinfo { const char *name; @@ -17,15 +20,78 @@ static const struct apci16xx_boardinfo apci16xx_boardtypes[] = { .name = "apci1648", .vendor = PCI_VENDOR_ID_ADDIDATA, .device = 0x1009, - .n_chan = 48, + .n_chan = 48, /* 2 subdevices */ }, { .name = "apci1696", .vendor = PCI_VENDOR_ID_ADDIDATA, .device = 0x100A, - .n_chan = 96, + .n_chan = 96, /* 3 subdevices */ }, }; +static int apci16xx_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec); + unsigned int bits; + + /* + * Each 8-bit "port" is configurable as either input or + * output. Changing the configuration of any channel in + * a port changes the entire port. + */ + if (chan_mask & 0x000000ff) + bits = 0x000000ff; + else if (chan_mask & 0x0000ff00) + bits = 0x0000ff00; + else if (chan_mask & 0x00ff0000) + bits = 0x00ff0000; + else + bits = 0xff000000; + + switch (data[0]) { + case INSN_CONFIG_DIO_INPUT: + s->io_bits &= ~bits; + break; + case INSN_CONFIG_DIO_OUTPUT: + s->io_bits |= bits; + break; + case INSN_CONFIG_DIO_QUERY: + data[1] = (s->io_bits & bits) ? COMEDI_INPUT : COMEDI_OUTPUT; + return insn->n; + default: + return -EINVAL; + } + + outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(s->index)); + + return insn->n; +} + +static int apci16xx_dio_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int mask = data[0]; + unsigned int bits = data[1]; + + /* Only update the channels configured as outputs */ + mask &= s->io_bits; + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + outl(s->state, dev->iobase + APCI16XX_OUT_REG(s->index)); + } + + data[1] = inl(dev->iobase + APCI16XX_IN_REG(s->index)); + + return insn->n; +} + static const void *apci16xx_find_boardinfo(struct comedi_device *dev, struct pci_dev *pcidev) { @@ -46,8 +112,10 @@ static int apci16xx_auto_attach(struct comedi_device *dev, { struct pci_dev *pcidev = comedi_to_pci_dev(dev); const struct apci16xx_boardinfo *board; - struct addi_private *devpriv; struct comedi_subdevice *s; + unsigned int n_subdevs; + unsigned int last; + int i; int ret; board = apci16xx_find_boardinfo(dev, pcidev); @@ -56,34 +124,44 @@ static int apci16xx_auto_attach(struct comedi_device *dev, dev->board_ptr = board; dev->board_name = board->name; - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - ret = comedi_pci_enable(pcidev, dev->board_name); if (ret) return ret; dev->iobase = pci_resource_start(pcidev, 0); - ret = comedi_alloc_subdevices(dev, 1); + /* + * Work out the nubmer of subdevices needed to support all the + * digital i/o channels on the board. Each subdevice supports + * up to 32 channels. + */ + n_subdevs = board->n_chan / 32; + if ((n_subdevs * 32) < board->n_chan) { + last = board->n_chan - (n_subdevs * 32); + n_subdevs++; + } else { + last = 0; + } + + ret = comedi_alloc_subdevices(dev, n_subdevs); if (ret) return ret; - /* Initialize the TTL digital i/o */ - s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_WRITEABLE | SDF_READABLE; - s->n_chan = board->n_chan; - s->maxdata = 1; - s->io_bits = 0; /* all bits input */ - s->len_chanlist = board->n_chan; - s->range_table = &range_digital; - s->insn_config = i_APCI16XX_InsnConfigInitTTLIO; - s->insn_bits = i_APCI16XX_InsnBitsReadTTLIO; - s->insn_read = i_APCI16XX_InsnReadTTLIOAllPortValue; - s->insn_write = i_APCI16XX_InsnBitsWriteTTLIO; + /* Initialize the TTL digital i/o subdevices */ + for (i = 0; i < n_subdevs; i++) { + s = &dev->subdevices[i]; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITEABLE | SDF_READABLE; + s->n_chan = ((i * 32) < board->n_chan) ? 32 : last; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_config = apci16xx_insn_config; + s->insn_bits = apci16xx_dio_insn_bits; + + /* Default all channels to inputs */ + s->io_bits = 0; + outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(i)); + } return 0; } -- cgit v0.10.2 From 0ecb3ea9cef6fe92860d065a0d9a87c9f7f50243 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 16:01:07 -0700 Subject: staging: comedi: addi_apci_16xx: add missing copyright comment Add the missing copyright information. This information was originally in the hwdrv_apci16xx.c file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 6c41f0b..cb7786b 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -1,3 +1,34 @@ +/* + * addi_apci_16xx.c + * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. + * Project manager: S. Weber + * + * ADDI-DATA GmbH + * Dieselstrasse 3 + * D-77833 Ottersweier + * Tel: +19(0)7223/9493-0 + * Fax: +49(0)7223/9493-92 + * http://www.addi-data.com + * info@addi-data.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * You should also find the complete GPL in the COPYING file accompanying + * this source code. + */ + #include "../comedidev.h" #include "comedi_fc.h" -- cgit v0.10.2 From 1cc2be913965d34439d6fdbbd1627d4077d4892d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 16:01:28 -0700 Subject: staging: comedi: addi_apci_16xx: remove unnecessary include This driver does not use any of the functionality provided by comedi_fc.h. Remove the #include. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index cb7786b..c4f628d 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -30,7 +30,6 @@ */ #include "../comedidev.h" -#include "comedi_fc.h" /* * Register I/O map -- cgit v0.10.2 From 5e72c1744fda105e0f1de6e33bd901a4df1bbaed Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 16:01:47 -0700 Subject: staging: comedi: addi_apci_16xx: change the MODULE_DESCRIPTION Change the MODULE_DESCRIPTION to something more useful than the generic "Comedi low-level driver" so that modinfo provides a better description of the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index c4f628d..34af453 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -242,6 +242,6 @@ static struct pci_driver apci16xx_pci_driver = { }; module_comedi_pci_driver(apci16xx_driver, apci16xx_pci_driver); +MODULE_DESCRIPTION("ADDI-DATA APCI-1648/1696, TTL I/O boards"); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); MODULE_LICENSE("GPL"); -- cgit v0.10.2 From b194218dba531b9c36080d29d10fdf9ef96a15bf Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 21 Jan 2013 16:02:20 -0700 Subject: staging: comedi: addi_apci_16xx: add defines for the PCI device ids The PCI device ids supported by this driver are used multiple places in the code. To improve maintainability, create #define's for them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 34af453..a04d66c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -32,6 +32,12 @@ #include "../comedidev.h" /* + * PCI device ids supported by this driver + */ +#define PCI_DEVICE_ID_APCI1648 0x1009 +#define PCI_DEVICE_ID_APCI1696 0x100a + +/* * Register I/O map */ #define APCI16XX_IN_REG(x) (((x) * 4) + 0x08) @@ -49,12 +55,12 @@ static const struct apci16xx_boardinfo apci16xx_boardtypes[] = { { .name = "apci1648", .vendor = PCI_VENDOR_ID_ADDIDATA, - .device = 0x1009, + .device = PCI_DEVICE_ID_APCI1648, .n_chan = 48, /* 2 subdevices */ }, { .name = "apci1696", .vendor = PCI_VENDOR_ID_ADDIDATA, - .device = 0x100A, + .device = PCI_DEVICE_ID_APCI1696, .n_chan = 96, /* 3 subdevices */ }, }; @@ -228,8 +234,8 @@ static void apci16xx_pci_remove(struct pci_dev *dev) } static DEFINE_PCI_DEVICE_TABLE(apci16xx_pci_table) = { - { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1009) }, - { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x100a) }, + { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1648) }, + { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1696) }, { 0 } }; MODULE_DEVICE_TABLE(pci, apci16xx_pci_table); -- cgit v0.10.2 From 7b63c5772fd6eea71b1332570812297e45403126 Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Tue, 22 Jan 2013 03:38:17 -0500 Subject: staging: dgrp: check for a valid proc dir entry pointer while proc_create fails, the register_proc_table can do a derefernce of the null pointer causing to oops the system, instead check for a valid pointer at register and unregister Signed-off-by: Devendra Naga Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c index c214078..e09fc9c 100644 --- a/drivers/staging/dgrp/dgrp_specproc.c +++ b/drivers/staging/dgrp/dgrp_specproc.c @@ -181,13 +181,13 @@ static struct dgrp_proc_entry dgrp_dpa_table[] = { void dgrp_unregister_proc(void) { - unregister_proc_table(dgrp_table, dgrp_proc_dir_entry); net_entry_pointer = NULL; mon_entry_pointer = NULL; dpa_entry_pointer = NULL; ports_entry_pointer = NULL; if (dgrp_proc_dir_entry) { + unregister_proc_table(dgrp_table, dgrp_proc_dir_entry); remove_proc_entry(dgrp_proc_dir_entry->name, dgrp_proc_dir_entry->parent); dgrp_proc_dir_entry = NULL; @@ -231,6 +231,8 @@ static void register_proc_table(struct dgrp_proc_entry *table, if (table == NULL) return; + if (root == NULL) + return; for (; table->id; table++) { /* Can't do anything without a proc name. */ -- cgit v0.10.2 From c095454e4b6acc8a5e7908647ec60d6088be90c8 Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Tue, 22 Jan 2013 03:56:08 -0500 Subject: staging: sep: remove assignment to i and j in sep_crypto_setup the i and j are used in for loop and they assigned to zeros in the for loop, so no need to assign them to zeros again. Signed-off-by: Devendra Naga Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/sep/sep_crypto.c b/drivers/staging/sep/sep_crypto.c index 34710ce..861588f 100644 --- a/drivers/staging/sep/sep_crypto.c +++ b/drivers/staging/sep/sep_crypto.c @@ -3908,13 +3908,9 @@ int sep_crypto_setup(void) return -ENOMEM; } - i = 0; - j = 0; - spin_lock_init(&queue_lock); err = 0; - for (i = 0; i < ARRAY_SIZE(hash_algs); i++) { err = crypto_register_ahash(&hash_algs[i]); if (err) -- cgit v0.10.2 From c8b0a484ccf408cafa9e2ec6a2fad6701c8deec4 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Tue, 22 Jan 2013 14:29:47 +0000 Subject: staging: et131x: Fix endian bugs in et131x_get_regs() et131x_get_regs() calls et131x_mii_read(), passing the address of a u32 which is cast to a (u16 *). This works fine for little endian systems, but not for big endian. Change so that the types are cast, not pointers to the types. Reported-by: Dan Carpenter Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index 82508fb..d2fbe91 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -3456,6 +3456,7 @@ static void et131x_get_regs(struct net_device *netdev, struct address_map __iomem *aregs = adapter->regs; u32 *regs_buff = regs_data; u32 num = 0; + u16 tmp; memset(regs_data, 0, et131x_get_regs_len(netdev)); @@ -3463,44 +3464,68 @@ static void et131x_get_regs(struct net_device *netdev, adapter->pdev->device; /* PHY regs */ - et131x_mii_read(adapter, MII_BMCR, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_BMSR, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_PHYSID1, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_PHYSID2, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_ADVERTISE, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_LPA, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_EXPANSION, (u16 *)®s_buff[num++]); + et131x_mii_read(adapter, MII_BMCR, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_BMSR, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_PHYSID1, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_PHYSID2, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_ADVERTISE, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_LPA, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_EXPANSION, &tmp); + regs_buff[num++] = tmp; /* Autoneg next page transmit reg */ - et131x_mii_read(adapter, 0x07, (u16 *)®s_buff[num++]); + et131x_mii_read(adapter, 0x07, &tmp); + regs_buff[num++] = tmp; /* Link partner next page reg */ - et131x_mii_read(adapter, 0x08, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_CTRL1000, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_STAT1000, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, 0x0b, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, 0x0c, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_MMD_CTRL, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_MMD_DATA, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, MII_ESTATUS, (u16 *)®s_buff[num++]); - - et131x_mii_read(adapter, PHY_INDEX_REG, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_DATA_REG, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, - (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL, - (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL+1, - (u16 *)®s_buff[num++]); - - et131x_mii_read(adapter, PHY_REGISTER_MGMT_CONTROL, - (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_CONFIG, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_PHY_CONTROL, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_INTERRUPT_MASK, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_INTERRUPT_STATUS, - (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_PHY_STATUS, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_LED_1, (u16 *)®s_buff[num++]); - et131x_mii_read(adapter, PHY_LED_2, (u16 *)®s_buff[num++]); + et131x_mii_read(adapter, 0x08, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_CTRL1000, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_STAT1000, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, 0x0b, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, 0x0c, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_MMD_CTRL, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_MMD_DATA, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, MII_ESTATUS, &tmp); + regs_buff[num++] = tmp; + + et131x_mii_read(adapter, PHY_INDEX_REG, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_DATA_REG, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL + 1, &tmp); + regs_buff[num++] = tmp; + + et131x_mii_read(adapter, PHY_REGISTER_MGMT_CONTROL, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_CONFIG, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_PHY_CONTROL, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_INTERRUPT_MASK, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_INTERRUPT_STATUS, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_PHY_STATUS, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_LED_1, &tmp); + regs_buff[num++] = tmp; + et131x_mii_read(adapter, PHY_LED_2, &tmp); + regs_buff[num++] = tmp; /* Global regs */ regs_buff[num++] = readl(&aregs->global.txq_start_addr); -- cgit v0.10.2 From c655dee9298c68739de2fa6c80f258b434156d42 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Tue, 22 Jan 2013 14:29:48 +0000 Subject: staging: et131x: Trivial camel case fixes Checkpatch now highlights some camel case flag names. Fix these issues. Also fix some remaining lines > 80chars issues for completeness. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index d2fbe91..7adf0af 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -139,19 +139,19 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S #define NIC_SEND_HANG_THRESHOLD 0 /* MP_TCB flags */ -#define fMP_DEST_MULTI 0x00000001 -#define fMP_DEST_BROAD 0x00000002 +#define FMP_DEST_MULTI 0x00000001 +#define FMP_DEST_BROAD 0x00000002 /* MP_ADAPTER flags */ -#define fMP_ADAPTER_INTERRUPT_IN_USE 0x00000008 +#define FMP_ADAPTER_INTERRUPT_IN_USE 0x00000008 /* MP_SHARED flags */ -#define fMP_ADAPTER_LOWER_POWER 0x00200000 +#define FMP_ADAPTER_LOWER_POWER 0x00200000 -#define fMP_ADAPTER_NON_RECOVER_ERROR 0x00800000 -#define fMP_ADAPTER_HARDWARE_ERROR 0x04000000 +#define FMP_ADAPTER_NON_RECOVER_ERROR 0x00800000 +#define FMP_ADAPTER_HARDWARE_ERROR 0x04000000 -#define fMP_ADAPTER_FAIL_SEND_MASK 0x3ff00000 +#define FMP_ADAPTER_FAIL_SEND_MASK 0x3ff00000 /* Some offsets in PCI config space that are actually used. */ #define ET1310_PCI_MAC_ADDRESS 0xA4 @@ -1062,7 +1062,7 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) writel(ctl, &adapter->regs->txmac.ctl); /* Ready to start the RXDMA/TXDMA engine */ - if (adapter->flags & fMP_ADAPTER_LOWER_POWER) { + if (adapter->flags & FMP_ADAPTER_LOWER_POWER) { et131x_rx_dma_enable(adapter); et131x_tx_dma_enable(adapter); } @@ -2068,7 +2068,7 @@ static void et131x_enable_txrx(struct net_device *netdev) et131x_tx_dma_enable(adapter); /* Enable device interrupts */ - if (adapter->flags & fMP_ADAPTER_INTERRUPT_IN_USE) + if (adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE) et131x_enable_interrupts(adapter); /* We're ready to move some data, so start the queue */ @@ -2167,7 +2167,7 @@ static void et1310_enable_phy_coma(struct et131x_adapter *adapter) /* Stop sending packets. */ spin_lock_irqsave(&adapter->send_hw_lock, flags); - adapter->flags |= fMP_ADAPTER_LOWER_POWER; + adapter->flags |= FMP_ADAPTER_LOWER_POWER; spin_unlock_irqrestore(&adapter->send_hw_lock, flags); /* Wait for outstanding Receive packets */ @@ -2220,7 +2220,7 @@ static void et1310_disable_phy_coma(struct et131x_adapter *adapter) et131x_adapter_setup(adapter); /* Allow Tx to restart */ - adapter->flags &= ~fMP_ADAPTER_LOWER_POWER; + adapter->flags &= ~FMP_ADAPTER_LOWER_POWER; et131x_enable_txrx(adapter->netdev); } @@ -3041,13 +3041,15 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb) if (phydev && phydev->speed == SPEED_1000) { if (++adapter->tx_ring.since_irq == PARM_TX_NUM_BUFS_DEF) { /* Last element & Interrupt flag */ - desc[frag - 1].flags = TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; + desc[frag - 1].flags = + TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; adapter->tx_ring.since_irq = 0; } else { /* Last element */ desc[frag - 1].flags = TXDESC_FLAG_LASTPKT; } } else - desc[frag - 1].flags = TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; + desc[frag - 1].flags = + TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; desc[0].flags |= TXDESC_FLAG_FIRSTPKT; @@ -3168,9 +3170,9 @@ static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter) if ((shbufva[0] == 0xffff) && (shbufva[1] == 0xffff) && (shbufva[2] == 0xffff)) { - tcb->flags |= fMP_DEST_BROAD; + tcb->flags |= FMP_DEST_BROAD; } else if ((shbufva[0] & 0x3) == 0x0001) { - tcb->flags |= fMP_DEST_MULTI; + tcb->flags |= FMP_DEST_MULTI; } } @@ -3225,7 +3227,7 @@ static int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev) /* We need to see if the link is up; if it's not, make the * netif layer think we're good and drop the packet */ - if ((adapter->flags & fMP_ADAPTER_FAIL_SEND_MASK) || + if ((adapter->flags & FMP_ADAPTER_FAIL_SEND_MASK) || !netif_carrier_ok(netdev)) { dev_kfree_skb_any(skb); skb = NULL; @@ -3262,9 +3264,9 @@ static inline void free_send_packet(struct et131x_adapter *adapter, struct net_device_stats *stats = &adapter->net_stats; u64 dma_addr; - if (tcb->flags & fMP_DEST_BROAD) + if (tcb->flags & FMP_DEST_BROAD) atomic_inc(&adapter->stats.broadcast_pkts_xmtd); - else if (tcb->flags & fMP_DEST_MULTI) + else if (tcb->flags & FMP_DEST_MULTI) atomic_inc(&adapter->stats.multicast_pkts_xmtd); else atomic_inc(&adapter->stats.unicast_pkts_xmtd); @@ -4351,7 +4353,7 @@ static void et131x_isr_handler(struct work_struct *work) * to do is disable the interrupts and set the flag to cause us * to reset so we can solve this issue. */ - /* MP_SET_FLAG( adapter, fMP_ADAPTER_HARDWARE_ERROR); */ + /* MP_SET_FLAG( adapter, FMP_ADAPTER_HARDWARE_ERROR); */ dev_warn(&adapter->pdev->dev, "RXMAC interrupt, error 0x%08x. Requesting reset\n", @@ -4466,7 +4468,7 @@ static int et131x_open(struct net_device *netdev) return result; } - adapter->flags |= fMP_ADAPTER_INTERRUPT_IN_USE; + adapter->flags |= FMP_ADAPTER_INTERRUPT_IN_USE; et131x_up(netdev); @@ -4485,7 +4487,7 @@ static int et131x_close(struct net_device *netdev) et131x_down(netdev); - adapter->flags &= ~fMP_ADAPTER_INTERRUPT_IN_USE; + adapter->flags &= ~FMP_ADAPTER_INTERRUPT_IN_USE; free_irq(adapter->pdev->irq, netdev); /* Stop the error timer */ @@ -4695,17 +4697,17 @@ static void et131x_tx_timeout(struct net_device *netdev) unsigned long flags; /* If the device is closed, ignore the timeout */ - if (~(adapter->flags & fMP_ADAPTER_INTERRUPT_IN_USE)) + if (~(adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE)) return; /* Any nonrecoverable hardware error? * Checks adapter->flags for any failure in phy reading */ - if (adapter->flags & fMP_ADAPTER_NON_RECOVER_ERROR) + if (adapter->flags & FMP_ADAPTER_NON_RECOVER_ERROR) return; /* Hardware failure? */ - if (adapter->flags & fMP_ADAPTER_HARDWARE_ERROR) { + if (adapter->flags & FMP_ADAPTER_HARDWARE_ERROR) { dev_err(&adapter->pdev->dev, "hardware error - reset\n"); return; } -- cgit v0.10.2 From 26ef1021c1c7ba62a2790296546945022468e17d Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Tue, 22 Jan 2013 14:29:49 +0000 Subject: staging: et131x: Modify block comments to fit with networking style In preparation for moving et131x to drivers/net, fixup the block comments to match the preferred networking style - no /* on separate line, but */ are on a seperate line. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index 7adf0af..e38d701 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -1,5 +1,4 @@ -/* - * Agere Systems Inc. +/* Agere Systems Inc. * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs * * Copyright © 2005 Agere Systems Inc. @@ -50,7 +49,6 @@ * 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. - * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -102,8 +100,7 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S #define INTERNAL_MEM_RX_OFFSET 0x1FF /* 50% Tx, 50% Rx */ /* ISR defines */ -/* - * For interrupts, normal running is: +/* For interrupts, normal running is: * rxdma_xfr_done, phy_interrupt, mac_stat_interrupt, * watchdog_interrupt & txdma_xfer_done * @@ -245,8 +242,7 @@ struct pkt_stat_desc { /* Typedefs for the RX DMA status word */ -/* - * rx status word 0 holds part of the status bits of the Rx DMA engine +/* rx status word 0 holds part of the status bits of the Rx DMA engine * that get copied out to memory by the ET-1310. Word 0 is a 32 bit word * which contains the Free Buffer ring 0 and 1 available offset. * @@ -256,8 +252,7 @@ struct pkt_stat_desc { * bit 26 Wrap flag for FBR0 */ -/* - * RXSTAT_WORD1_t structure holds part of the status bits of the Rx DMA engine +/* RXSTAT_WORD1_t structure holds part of the status bits of the Rx DMA engine * that get copied out to memory by the ET-1310. Word 3 is a 32 bit word * which contains the Packet Status Ring available offset. * @@ -267,8 +262,7 @@ struct pkt_stat_desc { * bit 29-31 unused */ -/* - * struct rx_status_block is a structure representing the status of the Rx +/* struct rx_status_block is a structure representing the status of the Rx * DMA engine it sits in free memory, and is pointed to by 0x101c / 0x1020 */ struct rx_status_block { @@ -276,8 +270,7 @@ struct rx_status_block { u32 word1; }; -/* - * Structure for look-up table holding free buffer ring pointers, addresses +/* Structure for look-up table holding free buffer ring pointers, addresses * and state. */ struct fbr_lookup { @@ -293,8 +286,7 @@ struct fbr_lookup { dma_addr_t buffsize; }; -/* - * struct rx_ring is the sructure representing the adaptor's local +/* struct rx_ring is the sructure representing the adaptor's local * reference(s) to the rings */ struct rx_ring { @@ -317,8 +309,7 @@ struct rx_ring { }; /* TX defines */ -/* - * word 2 of the control bits in the Tx Descriptor ring for the ET-1310 +/* word 2 of the control bits in the Tx Descriptor ring for the ET-1310 * * 0-15: length of packet * 16-27: VLAN tag @@ -356,8 +347,7 @@ struct tx_desc { u32 flags; /* data (detailed above) */ }; -/* - * The status of the Tx DMA engine it sits in free memory, and is pointed to +/* The status of the Tx DMA engine it sits in free memory, and is pointed to * by 0x101c / 0x1020. This is a DMA10 type */ @@ -406,15 +396,13 @@ struct tx_ring { int since_irq; }; -/* - * Do not change these values: if changed, then change also in respective +/* Do not change these values: if changed, then change also in respective * TXdma and Rxdma engines */ #define NUM_DESC_PER_RING_TX 512 /* TX Do not change these values */ #define NUM_TCB 64 -/* - * These values are all superseded by registry entries to facilitate tuning. +/* These values are all superseded by registry entries to facilitate tuning. * Once the desired performance has been achieved, the optimal registry values * should be re-populated to these #defines: */ @@ -559,8 +547,7 @@ static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status) u32 reg; int i; - /* - * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and + /* 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and * bits 7,1:0 both equal to 1, at least once after reset. * Subsequent operations need only to check that bits 1:0 are equal * to 1 prior to starting a single byte read/write @@ -581,8 +568,7 @@ static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status) return -ETIMEDOUT; } -/** - * eeprom_write - Write a byte to the ET1310's EEPROM +/* eeprom_write - Write a byte to the ET1310's EEPROM * @adapter: pointer to our private adapter structure * @addr: the address to write * @data: the value to write @@ -600,8 +586,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) u32 status; u32 val = 0; - /* - * For an EEPROM, an I2C single byte write is defined as a START + /* For an EEPROM, an I2C single byte write is defined as a START * condition followed by the device address, EEPROM address, one byte * of data and a STOP condition. The STOP condition will trigger the * EEPROM's internally timed write cycle to the nonvolatile memory. @@ -613,12 +598,11 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) if (err) return err; - /* - * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0, - * and bits 1:0 both =0. Bit 5 should be set according to the - * type of EEPROM being accessed (1=two byte addressing, 0=one - * byte addressing). - */ + /* 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0, + * and bits 1:0 both =0. Bit 5 should be set according to the + * type of EEPROM being accessed (1=two byte addressing, 0=one + * byte addressing). + */ if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, LBCIF_CONTROL_LBCIF_ENABLE | LBCIF_CONTROL_I2C_WRITE)) return -EIO; @@ -631,14 +615,12 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) /* Write the address to the LBCIF Address Register */ if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr)) break; - /* - * Write the data to the LBCIF Data Register (the I2C write + /* Write the data to the LBCIF Data Register (the I2C write * will begin). */ if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER, data)) break; - /* - * Monitor bit 1:0 of the LBCIF Status Register. When bits + /* Monitor bit 1:0 of the LBCIF Status Register. When bits * 1:0 are both equal to 1, the I2C write has completed and the * internal write cycle of the EEPROM is about to start. * (bits 1:0 = 01 is a legal state while waiting from both @@ -649,8 +631,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) if (err < 0) return 0; - /* - * Check bit 3 of the LBCIF Status Register. If equal to 1, + /* Check bit 3 of the LBCIF Status Register. If equal to 1, * an error has occurred.Don't break here if we are revision * 1, this is so we do a blind write for load bug. */ @@ -658,8 +639,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) && adapter->pdev->revision == 0) break; - /* - * Check bit 2 of the LBCIF Status Register. If equal to 1 an + /* Check bit 2 of the LBCIF Status Register. If equal to 1 an * ACK error has occurred on the address phase of the write. * This could be due to an actual hardware failure or the * EEPROM may still be in its internal write cycle from a @@ -667,8 +647,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) *repeated later. */ if (status & LBCIF_STATUS_ACK_ERROR) { - /* - * This could be due to an actual hardware failure + /* This could be due to an actual hardware failure * or the EEPROM may still be in its internal write * cycle from a previous write. This write operation * was ignored and must be repeated later. @@ -681,8 +660,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) break; } - /* - * Set bit 6 of the LBCIF Control Register = 0. + /* Set bit 6 of the LBCIF Control Register = 0. */ udelay(10); @@ -711,8 +689,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) return writeok ? 0 : -EIO; } -/** - * eeprom_read - Read a byte from the ET1310's EEPROM +/* eeprom_read - Read a byte from the ET1310's EEPROM * @adapter: pointer to our private adapter structure * @addr: the address from which to read * @pdata: a pointer to a byte in which to store the value of the read @@ -727,16 +704,14 @@ static int eeprom_read(struct et131x_adapter *adapter, u32 addr, u8 *pdata) int err; u32 status; - /* - * A single byte read is similar to the single byte write, with the + /* A single byte read is similar to the single byte write, with the * exception of the data flow: */ err = eeprom_wait_ready(pdev, NULL); if (err) return err; - /* - * Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0, + /* Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0, * and bits 1:0 both =0. Bit 5 should be set according to the type * of EEPROM being accessed (1=two byte addressing, 0=one byte * addressing). @@ -744,27 +719,23 @@ static int eeprom_read(struct et131x_adapter *adapter, u32 addr, u8 *pdata) if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, LBCIF_CONTROL_LBCIF_ENABLE)) return -EIO; - /* - * Write the address to the LBCIF Address Register (I2C read will + /* Write the address to the LBCIF Address Register (I2C read will * begin). */ if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr)) return -EIO; - /* - * Monitor bit 0 of the LBCIF Status Register. When = 1, I2C read + /* Monitor bit 0 of the LBCIF Status Register. When = 1, I2C read * is complete. (if bit 1 =1 and bit 0 stays = 0, a hardware failure * has occurred). */ err = eeprom_wait_ready(pdev, &status); if (err < 0) return err; - /* - * Regardless of error status, read data byte from LBCIF Data + /* Regardless of error status, read data byte from LBCIF Data * Register. */ *pdata = err; - /* - * Check bit 2 of the LBCIF Status Register. If = 1, + /* Check bit 2 of the LBCIF Status Register. If = 1, * then an error has occurred. */ return (status & LBCIF_STATUS_ACK_ERROR) ? -EIO : 0; @@ -838,8 +809,7 @@ static int et131x_init_eeprom(struct et131x_adapter *adapter) return 0; } -/** - * et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310. +/* et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310. * @adapter: pointer to our adapter structure */ static void et131x_rx_dma_enable(struct et131x_adapter *adapter) @@ -875,8 +845,7 @@ static void et131x_rx_dma_enable(struct et131x_adapter *adapter) } } -/** - * et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310 +/* et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310 * @adapter: pointer to our adapter structure */ static void et131x_rx_dma_disable(struct et131x_adapter *adapter) @@ -896,8 +865,7 @@ static void et131x_rx_dma_disable(struct et131x_adapter *adapter) } } -/** - * et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310. +/* et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310. * @adapter: pointer to our adapter structure * * Mainly used after a return to the D0 (full-power) state from a lower state. @@ -921,8 +889,7 @@ static inline void add_12bit(u32 *v, int n) *v = INDEX12(*v + n) | (*v & ET_DMA12_WRAP); } -/** - * et1310_config_mac_regs1 - Initialize the first part of MAC regs +/* et1310_config_mac_regs1 - Initialize the first part of MAC regs * @adapter: pointer to our adapter structure */ static void et1310_config_mac_regs1(struct et131x_adapter *adapter) @@ -984,8 +951,7 @@ static void et1310_config_mac_regs1(struct et131x_adapter *adapter) writel(0, ¯egs->cfg1); } -/** - * et1310_config_mac_regs2 - Initialize the second part of MAC regs +/* et1310_config_mac_regs2 - Initialize the second part of MAC regs * @adapter: pointer to our adapter structure */ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) @@ -1026,7 +992,8 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) /* Now we need to initialize the MAC Configuration 2 register */ /* preamble 7, check length, huge frame off, pad crc, crc enable - full duplex off */ + * full duplex off + */ cfg2 |= 0x7 << ET_MAC_CFG2_PREAMBLE_SHIFT; cfg2 |= ET_MAC_CFG2_IFMODE_LEN_CHECK; cfg2 |= ET_MAC_CFG2_IFMODE_PAD_CRC; @@ -1068,8 +1035,7 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter) } } -/** - * et1310_in_phy_coma - check if the device is in phy coma +/* et1310_in_phy_coma - check if the device is in phy coma * @adapter: pointer to our adapter structure * * Returns 0 if the device is not in phy coma, 1 if it is in phy coma @@ -1383,8 +1349,7 @@ static void et1310_config_macstat_regs(struct et131x_adapter *adapter) writel(0xFFFE7E8B, &macstat->carry_reg2_mask); } -/** - * et131x_phy_mii_read - Read from the PHY through the MII Interface on the MAC +/* et131x_phy_mii_read - Read from the PHY through the MII Interface on the MAC * @adapter: pointer to our private adapter structure * @addr: the address of the transceiver * @reg: the register to read @@ -1433,7 +1398,8 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr, } /* If we hit here we were able to read the register and we need to - * return the value to the caller */ + * return the value to the caller + */ *value = readl(&mac->mii_mgmt_stat) & ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK; /* Stop the read operation */ @@ -1458,8 +1424,7 @@ static int et131x_mii_read(struct et131x_adapter *adapter, u8 reg, u16 *value) return et131x_phy_mii_read(adapter, phydev->addr, reg, value); } -/** - * et131x_mii_write - Write to a PHY register through the MII interface of the MAC +/* et131x_mii_write - Write to a PHY reg through the MII interface of the MAC * @adapter: pointer to our private adapter structure * @reg: the register to read * @value: 16-bit value to write @@ -1523,8 +1488,7 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 reg, u16 value) /* Stop the write operation */ writel(0, &mac->mii_mgmt_cmd); - /* - * set the registers we touched back to the state at which we entered + /* set the registers we touched back to the state at which we entered * this function */ writel(mii_addr, &mac->mii_mgmt_addr); @@ -1590,7 +1554,8 @@ static void et1310_config_flow_control(struct et131x_adapter *adapter) (remote_async_pause == TRUEPHY_BIT_CLEAR)) { adapter->flowcontrol = FLOW_NONE; } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT && - remote_async_pause == TRUEPHY_SET_BIT) */ + * remote_async_pause == TRUEPHY_SET_BIT) + */ if (adapter->wanted_flow == FLOW_BOTH) adapter->flowcontrol = FLOW_RXONLY; else @@ -1599,8 +1564,7 @@ static void et1310_config_flow_control(struct et131x_adapter *adapter) } } -/** - * et1310_update_macstat_host_counters - Update the local copy of the statistics +/* et1310_update_macstat_host_counters - Update the local copy of the statistics * @adapter: pointer to the adapter structure */ static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter) @@ -1627,8 +1591,7 @@ static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter) stats->rx_other_errs += readl(&macstat->rx_fragment_packets); } -/** - * et1310_handle_macstat_interrupt +/* et1310_handle_macstat_interrupt * @adapter: pointer to the adapter structure * * One of the MACSTAT counters has wrapped. Update the local copy of @@ -1719,8 +1682,7 @@ static int et131x_mdio_reset(struct mii_bus *bus) return 0; } -/** - * et1310_phy_power_down - PHY power control +/* et1310_phy_power_down - PHY power control * @adapter: device to control * @down: true for off/false for back on * @@ -1740,8 +1702,7 @@ static void et1310_phy_power_down(struct et131x_adapter *adapter, bool down) et131x_mii_write(adapter, MII_BMCR, data); } -/** - * et131x_xcvr_init - Init the phy if we are setting it into force mode +/* et131x_xcvr_init - Init the phy if we are setting it into force mode * @adapter: pointer to our private adapter structure * */ @@ -1772,8 +1733,7 @@ static void et131x_xcvr_init(struct et131x_adapter *adapter) } } -/** - * et131x_configure_global_regs - configure JAGCore global regs +/* et131x_configure_global_regs - configure JAGCore global regs * @adapter: pointer to our adapter structure * * Used to configure the global registers on the JAGCore @@ -1819,8 +1779,7 @@ static void et131x_configure_global_regs(struct et131x_adapter *adapter) writel(0, ®s->watchdog_timer); } -/** - * et131x_config_rx_dma_regs - Start of Rx_DMA init sequence +/* et131x_config_rx_dma_regs - Start of Rx_DMA init sequence * @adapter: pointer to our adapter structure */ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) @@ -1927,8 +1886,7 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) spin_unlock_irqrestore(&adapter->rcv_lock, flags); } -/** - * et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore. +/* et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore. * @adapter: pointer to our private adapter structure * * Configure the transmit engine with the ring buffers we have created @@ -1959,8 +1917,7 @@ static void et131x_config_tx_dma_regs(struct et131x_adapter *adapter) adapter->tx_ring.send_idx = 0; } -/** - * et131x_adapter_setup - Set the adapter up as per cassini+ documentation +/* et131x_adapter_setup - Set the adapter up as per cassini+ documentation * @adapter: pointer to our private adapter structure * * Returns 0 on success, errno on failure (as defined in errno.h) @@ -1988,8 +1945,7 @@ static void et131x_adapter_setup(struct et131x_adapter *adapter) et131x_xcvr_init(adapter); } -/** - * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310 +/* et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310 * @adapter: pointer to our private adapter structure */ static void et131x_soft_reset(struct et131x_adapter *adapter) @@ -2011,8 +1967,7 @@ static void et131x_soft_reset(struct et131x_adapter *adapter) writel(0, &adapter->regs->mac.cfg1); } -/** - * et131x_enable_interrupts - enable interrupt +/* et131x_enable_interrupts - enable interrupt * @adapter: et131x device * * Enable the appropriate interrupts on the ET131x according to our @@ -2032,8 +1987,7 @@ static void et131x_enable_interrupts(struct et131x_adapter *adapter) writel(mask, &adapter->regs->global.int_mask); } -/** - * et131x_disable_interrupts - interrupt disable +/* et131x_disable_interrupts - interrupt disable * @adapter: et131x device * * Block all interrupts from the et131x device at the device itself @@ -2044,8 +1998,7 @@ static void et131x_disable_interrupts(struct et131x_adapter *adapter) writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask); } -/** - * et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310 +/* et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310 * @adapter: pointer to our adapter structure */ static void et131x_tx_dma_disable(struct et131x_adapter *adapter) @@ -2055,8 +2008,7 @@ static void et131x_tx_dma_disable(struct et131x_adapter *adapter) &adapter->regs->txdma.csr); } -/** - * et131x_enable_txrx - Enable tx/rx queues +/* et131x_enable_txrx - Enable tx/rx queues * @netdev: device to be enabled */ static void et131x_enable_txrx(struct net_device *netdev) @@ -2075,8 +2027,7 @@ static void et131x_enable_txrx(struct net_device *netdev) netif_start_queue(netdev); } -/** - * et131x_disable_txrx - Disable tx/rx queues +/* et131x_disable_txrx - Disable tx/rx queues * @netdev: device to be disabled */ static void et131x_disable_txrx(struct net_device *netdev) @@ -2094,8 +2045,7 @@ static void et131x_disable_txrx(struct net_device *netdev) et131x_disable_interrupts(adapter); } -/** - * et131x_init_send - Initialize send data structures +/* et131x_init_send - Initialize send data structures * @adapter: pointer to our private adapter structure */ static void et131x_init_send(struct et131x_adapter *adapter) @@ -2128,8 +2078,7 @@ static void et131x_init_send(struct et131x_adapter *adapter) tx_ring->send_tail = NULL; } -/** - * et1310_enable_phy_coma - called when network cable is unplugged +/* et1310_enable_phy_coma - called when network cable is unplugged * @adapter: pointer to our adapter structure * * driver receive an phy status change interrupt while in D0 and check that @@ -2158,8 +2107,7 @@ static void et1310_enable_phy_coma(struct et131x_adapter *adapter) /* Save the GbE PHY speed and duplex modes. Need to restore this * when cable is plugged back in */ - /* - * TODO - when PM is re-enabled, check if we need to + /* TODO - when PM is re-enabled, check if we need to * perform a similar task as this - * adapter->pdown_speed = adapter->ai_force_speed; * adapter->pdown_duplex = adapter->ai_force_duplex; @@ -2183,8 +2131,7 @@ static void et1310_enable_phy_coma(struct et131x_adapter *adapter) writel(pmcsr, &adapter->regs->global.pm_csr); } -/** - * et1310_disable_phy_coma - Disable the Phy Coma Mode +/* et1310_disable_phy_coma - Disable the Phy Coma Mode * @adapter: pointer to our adapter structure */ static void et1310_disable_phy_coma(struct et131x_adapter *adapter) @@ -2230,9 +2177,10 @@ static inline u32 bump_free_buff_ring(u32 *free_buff_ring, u32 limit) u32 tmp_free_buff_ring = *free_buff_ring; tmp_free_buff_ring++; /* This works for all cases where limit < 1024. The 1023 case - works because 1023++ is 1024 which means the if condition is not - taken but the carry of the bit into the wrap bit toggles the wrap - value correctly */ + * works because 1023++ is 1024 which means the if condition is not + * taken but the carry of the bit into the wrap bit toggles the wrap + * value correctly + */ if ((tmp_free_buff_ring & ET_DMA10_MASK) > limit) { tmp_free_buff_ring &= ~ET_DMA10_MASK; tmp_free_buff_ring ^= ET_DMA10_WRAP; @@ -2243,8 +2191,7 @@ static inline u32 bump_free_buff_ring(u32 *free_buff_ring, u32 limit) return tmp_free_buff_ring; } -/** - * et131x_rx_dma_memory_alloc +/* et131x_rx_dma_memory_alloc * @adapter: pointer to our private adapter structure * * Returns 0 on success and errno on failure (as defined in errno.h) @@ -2384,8 +2331,7 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) pr_info("Packet Status Ring %llx\n", (unsigned long long) rx_ring->ps_ring_physaddr); - /* - * NOTE : dma_alloc_coherent(), used above to alloc DMA regions, + /* NOTE : dma_alloc_coherent(), used above to alloc DMA regions, * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses * are ever returned, make sure the high part is retrieved here before * storing the adjusted address. @@ -2411,8 +2357,7 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) return 0; } -/** - * et131x_rx_dma_memory_free - Free all memory allocated within this module. +/* et131x_rx_dma_memory_free - Free all memory allocated within this module. * @adapter: pointer to our private adapter structure */ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) @@ -2499,8 +2444,7 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) rx_ring->num_ready_recv = 0; } -/** - * et131x_init_recv - Initialize receive data structures. +/* et131x_init_recv - Initialize receive data structures. * @adapter: pointer to our private adapter structure * * Returns 0 on success and errno on failure (as defined in errno.h) @@ -2537,8 +2481,7 @@ static int et131x_init_recv(struct et131x_adapter *adapter) return 0; } -/** - * et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate. +/* et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate. * @adapter: pointer to our adapter structure */ static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter) @@ -2557,8 +2500,7 @@ static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter) } } -/** - * NICReturnRFD - Recycle a RFD and put it back onto the receive list +/* NICReturnRFD - Recycle a RFD and put it back onto the receive list * @adapter: pointer to our adapter * @rfd: pointer to the RFD */ @@ -2618,8 +2560,7 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd) WARN_ON(rx_local->num_ready_recv > rx_local->num_rfd); } -/** - * nic_rx_pkts - Checks the hardware for available packets +/* nic_rx_pkts - Checks the hardware for available packets * @adapter: pointer to our adapter * * Returns rfd, a pointer to our MPRFD. @@ -2802,8 +2743,7 @@ out: return rfd; } -/** - * et131x_handle_recv_interrupt - Interrupt handler for receive processing +/* et131x_handle_recv_interrupt - Interrupt handler for receive processing * @adapter: pointer to our adapter * * Assumption, Rcv spinlock has been acquired. @@ -2857,8 +2797,7 @@ static void et131x_handle_recv_interrupt(struct et131x_adapter *adapter) adapter->rx_ring.unfinished_receives = false; } -/** - * et131x_tx_dma_memory_alloc +/* et131x_tx_dma_memory_alloc * @adapter: pointer to our private adapter structure * * Returns 0 on success and errno on failure (as defined in errno.h). @@ -2914,8 +2853,7 @@ static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter) return 0; } -/** - * et131x_tx_dma_memory_free - Free all memory allocated within this module +/* et131x_tx_dma_memory_free - Free all memory allocated within this module * @adapter: pointer to our private adapter structure * * Returns 0 on success and errno on failure (as defined in errno.h). @@ -2947,8 +2885,7 @@ static void et131x_tx_dma_memory_free(struct et131x_adapter *adapter) kfree(adapter->tx_ring.tcb_ring); } -/** - * nic_send_packet - NIC specific send handler for version B silicon. +/* nic_send_packet - NIC specific send handler for version B silicon. * @adapter: pointer to our adapter * @tcb: pointer to struct tcb * @@ -2996,7 +2933,8 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb) */ if (skb_headlen(skb) <= 1514) { /* Low 16bits are length, high is vlan and - unused currently so zero */ + * unused currently so zero + */ desc[frag].len_vlan = skb_headlen(skb); dma_addr = dma_map_single(&adapter->pdev->dev, skb->data, @@ -3126,8 +3064,7 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb) return 0; } -/** - * send_packet - Do the work to send a packet +/* send_packet - Do the work to send a packet * @skb: the packet(s) to send * @adapter: a pointer to the device's private adapter structure * @@ -3198,8 +3135,7 @@ static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter) return 0; } -/** - * et131x_send_packets - This function is called by the OS to send packets +/* et131x_send_packets - This function is called by the OS to send packets * @skb: the packet(s) to send * @netdev:device on which to TX the above packet(s) * @@ -3248,8 +3184,7 @@ static int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev) return status; } -/** - * free_send_packet - Recycle a struct tcb +/* free_send_packet - Recycle a struct tcb * @adapter: pointer to our adapter * @tcb: pointer to struct tcb * @@ -3321,8 +3256,7 @@ static inline void free_send_packet(struct et131x_adapter *adapter, WARN_ON(adapter->tx_ring.used < 0); } -/** - * et131x_free_busy_send_packets - Free and complete the stopped active sends +/* et131x_free_busy_send_packets - Free and complete the stopped active sends * @adapter: pointer to our adapter * * Assumption - Send spinlock has been acquired @@ -3365,8 +3299,7 @@ static void et131x_free_busy_send_packets(struct et131x_adapter *adapter) adapter->tx_ring.used = 0; } -/** - * et131x_handle_send_interrupt - Interrupt handler for sending processing +/* et131x_handle_send_interrupt - Interrupt handler for sending processing * @adapter: pointer to our adapter * * Re-claim the send resources, complete sends and get more to send from @@ -3624,8 +3557,8 @@ static struct ethtool_ops et131x_ethtool_ops = { .get_regs = et131x_get_regs, .get_link = ethtool_op_get_link, }; -/** - * et131x_hwaddr_init - set up the MAC Address on the ET1310 + +/* et131x_hwaddr_init - set up the MAC Address on the ET1310 * @adapter: pointer to our private adapter structure */ static void et131x_hwaddr_init(struct et131x_adapter *adapter) @@ -3635,14 +3568,12 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter) * device */ if (is_zero_ether_addr(adapter->rom_addr)) { - /* - * We need to randomly generate the last octet so we + /* We need to randomly generate the last octet so we * decrease our chances of setting the mac address to * same as another one of our cards in the system */ get_random_bytes(&adapter->addr[5], 1); - /* - * We have the default value in the register we are + /* We have the default value in the register we are * working with so we need to copy the current * address into the permanent address */ @@ -3658,8 +3589,7 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter) } } -/** - * et131x_pci_init - initial PCI setup +/* et131x_pci_init - initial PCI setup * @adapter: pointer to our private adapter structure * @pdev: our PCI device * @@ -3751,8 +3681,7 @@ err_out: goto out; } -/** - * et131x_error_timer_handler +/* et131x_error_timer_handler * @data: timer-specific variable; here a pointer to our adapter structure * * The routine called when the error timer expires, to track the number of @@ -3766,7 +3695,8 @@ static void et131x_error_timer_handler(unsigned long data) if (et1310_in_phy_coma(adapter)) { /* Bring the device immediately out of coma, to * prevent it from sleeping indefinitely, this - * mechanism could be improved! */ + * mechanism could be improved! + */ et1310_disable_phy_coma(adapter); adapter->boot_coma = 20; } else { @@ -3792,8 +3722,7 @@ static void et131x_error_timer_handler(unsigned long data) mod_timer(&adapter->error_timer, jiffies + TX_ERROR_PERIOD * HZ / 1000); } -/** - * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx +/* et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx * @adapter: pointer to our private adapter structure */ static void et131x_adapter_memory_free(struct et131x_adapter *adapter) @@ -3803,8 +3732,7 @@ static void et131x_adapter_memory_free(struct et131x_adapter *adapter) et131x_rx_dma_memory_free(adapter); } -/** - * et131x_adapter_memory_alloc +/* et131x_adapter_memory_alloc * @adapter: pointer to our private adapter structure * * Returns 0 on success, errno on failure (as defined in errno.h). @@ -3847,8 +3775,7 @@ static void et131x_adjust_link(struct net_device *netdev) struct phy_device *phydev = adapter->phydev; if (phydev && phydev->link != adapter->link) { - /* - * Check to see if we are in coma mode and if + /* Check to see if we are in coma mode and if * so, disable it because we will not be able * to read PHY values until we are out. */ @@ -3861,8 +3788,7 @@ static void et131x_adjust_link(struct net_device *netdev) if (phydev->link) { adapter->boot_coma = 20; if (phydev && phydev->speed == SPEED_10) { - /* - * NOTE - Is there a way to query this without + /* NOTE - Is there a way to query this without * TruePHY? * && TRU_QueryCoreType(adapter->hTruePhy, 0)== * EMI_TRUEPHY_A13O) { @@ -3924,8 +3850,7 @@ static void et131x_adjust_link(struct net_device *netdev) /* Re-initialize the send structures */ et131x_init_send(adapter); - /* - * Bring the device back to the state it was during + /* Bring the device back to the state it was during * init prior to autonegotiation being complete. This * way, when we get the auto-neg complete interrupt, * we can complete init by calling config_mac_regs2. @@ -3955,7 +3880,7 @@ static int et131x_mii_probe(struct net_device *netdev) } phydev = phy_connect(netdev, dev_name(&phydev->dev), - &et131x_adjust_link, 0, PHY_INTERFACE_MODE_MII); + &et131x_adjust_link, 0, PHY_INTERFACE_MODE_MII); if (IS_ERR(phydev)) { dev_err(&adapter->pdev->dev, "Could not attach to PHY\n"); @@ -3982,8 +3907,7 @@ static int et131x_mii_probe(struct net_device *netdev) return 0; } -/** - * et131x_adapter_init +/* et131x_adapter_init * @adapter: pointer to the private adapter struct * @pdev: pointer to the PCI device * @@ -4020,8 +3944,7 @@ static struct et131x_adapter *et131x_adapter_init(struct net_device *netdev, return adapter; } -/** - * et131x_pci_remove +/* et131x_pci_remove * @pdev: a pointer to the device's pci_dev structure * * Registered in the pci_driver structure, this function is called when the @@ -4048,8 +3971,7 @@ static void et131x_pci_remove(struct pci_dev *pdev) pci_disable_device(pdev); } -/** - * et131x_up - Bring up a device for use. +/* et131x_up - Bring up a device for use. * @netdev: device to be opened */ static void et131x_up(struct net_device *netdev) @@ -4060,8 +3982,7 @@ static void et131x_up(struct net_device *netdev) phy_start(adapter->phydev); } -/** - * et131x_down - Bring down the device +/* et131x_down - Bring down the device * @netdev: device to be brought down */ static void et131x_down(struct net_device *netdev) @@ -4110,8 +4031,7 @@ static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume); #define ET131X_PM_OPS NULL #endif -/** - * et131x_isr - The Interrupt Service Routine for the driver. +/* et131x_isr - The Interrupt Service Routine for the driver. * @irq: the IRQ on which the interrupt was received. * @dev_id: device-specific info (here a pointer to a net_device struct) * @@ -4199,8 +4119,7 @@ out: return IRQ_RETVAL(handled); } -/** - * et131x_isr_handler - The ISR handler +/* et131x_isr_handler - The ISR handler * @p_adapter, a pointer to the device's private adapter structure * * scheduled to run in a deferred context by the ISR. This is where the ISR's @@ -4213,8 +4132,7 @@ static void et131x_isr_handler(struct work_struct *work) u32 status = adapter->stats.interrupt_status; struct address_map __iomem *iomem = adapter->regs; - /* - * These first two are by far the most common. Once handled, we clear + /* These first two are by far the most common. Once handled, we clear * their two bits in the status word. If the word is now zero, we * exit. */ @@ -4245,8 +4163,7 @@ static void et131x_isr_handler(struct work_struct *work) /* Handle Free Buffer Ring 0 and 1 Low interrupt */ if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) { - /* - * This indicates the number of unused buffers in RXDMA free + /* This indicates the number of unused buffers in RXDMA free * buffer ring 0 is <= the limit you programmed. Free buffer * resources need to be returned. Free buffers are consumed as * packets are passed from the network to the host. The host @@ -4258,16 +4175,14 @@ static void et131x_isr_handler(struct work_struct *work) * method of returning resources. */ - /* - * If the user has flow control on, then we will + /* If the user has flow control on, then we will * send a pause packet, otherwise just exit */ if (adapter->flowcontrol == FLOW_TXONLY || adapter->flowcontrol == FLOW_BOTH) { u32 pm_csr; - /* - * Tell the device to send a pause packet via the back + /* Tell the device to send a pause packet via the back * pressure register (bp req and bp xon/xoff) */ pm_csr = readl(&iomem->global.pm_csr); @@ -4278,8 +4193,7 @@ static void et131x_isr_handler(struct work_struct *work) /* Handle Packet Status Ring Low Interrupt */ if (status & ET_INTR_RXDMA_STAT_LOW) { - /* - * Same idea as with the two Free Buffer Rings. Packets going + /* Same idea as with the two Free Buffer Rings. Packets going * from the network to the host each consume a free buffer * resource and a packet status resource. These resoures are * passed to the OS. When the OS is done with the resources, @@ -4290,8 +4204,7 @@ static void et131x_isr_handler(struct work_struct *work) /* Handle RXDMA Error Interrupt */ if (status & ET_INTR_RXDMA_ERR) { - /* - * The rxdma_error interrupt is sent when a time-out on a + /* The rxdma_error interrupt is sent when a time-out on a * request issued by the JAGCore has occurred or a completion is * returned with an un-successful status. In both cases the * request is considered complete. The JAGCore will @@ -4314,8 +4227,7 @@ static void et131x_isr_handler(struct work_struct *work) /* Handle the Wake on LAN Event */ if (status & ET_INTR_WOL) { - /* - * This is a secondary interrupt for wake on LAN. The driver + /* This is a secondary interrupt for wake on LAN. The driver * should never see this, if it does, something serious is * wrong. We will TRAP the message when we are in DBG mode, * otherwise we will ignore it. @@ -4327,8 +4239,7 @@ static void et131x_isr_handler(struct work_struct *work) if (status & ET_INTR_TXMAC) { u32 err = readl(&iomem->txmac.err); - /* - * When any of the errors occur and TXMAC generates an + /* When any of the errors occur and TXMAC generates an * interrupt to report these errors, it usually means that * TXMAC has detected an error in the data stream retrieved * from the on-chip Tx Q. All of these errors are catastrophic @@ -4340,16 +4251,14 @@ static void et131x_isr_handler(struct work_struct *work) "TXMAC interrupt, error 0x%08x\n", err); - /* - * If we are debugging, we want to see this error, otherwise we + /* If we are debugging, we want to see this error, otherwise we * just want the device to be reset and continue */ } /* Handle RXMAC Interrupt */ if (status & ET_INTR_RXMAC) { - /* - * These interrupts are catastrophic to the device, what we need + /* These interrupts are catastrophic to the device, what we need * to do is disable the interrupts and set the flag to cause us * to reset so we can solve this issue. */ @@ -4364,16 +4273,14 @@ static void et131x_isr_handler(struct work_struct *work) readl(&iomem->rxmac.ctrl), readl(&iomem->rxmac.rxq_diag)); - /* - * If we are debugging, we want to see this error, otherwise we + /* If we are debugging, we want to see this error, otherwise we * just want the device to be reset and continue */ } /* Handle MAC_STAT Interrupt */ if (status & ET_INTR_MAC_STAT) { - /* - * This means at least one of the un-masked counters in the + /* This means at least one of the un-masked counters in the * MAC_STAT block has rolled over. Use this to maintain the top, * software managed bits of the counter(s). */ @@ -4382,8 +4289,7 @@ static void et131x_isr_handler(struct work_struct *work) /* Handle SLV Timeout Interrupt */ if (status & ET_INTR_SLV_TIMEOUT) { - /* - * This means a timeout has occurred on a read or write request + /* This means a timeout has occurred on a read or write request * to one of the JAGCore registers. The Global Resources block * has terminated the request and on a read request, returned a * "fake" value. The most likely reasons are: Bad Address or the @@ -4394,8 +4300,7 @@ out: et131x_enable_interrupts(adapter); } -/** - * et131x_stats - Return the current device statistics. +/* et131x_stats - Return the current device statistics. * @netdev: device whose stats are being queried * * Returns 0 on success, errno on failure (as defined in errno.h) @@ -4441,8 +4346,7 @@ static struct net_device_stats *et131x_stats(struct net_device *netdev) return stats; } -/** - * et131x_open - Open the device for use. +/* et131x_open - Open the device for use. * @netdev: device to be opened * * Returns 0 on success, errno on failure (as defined in errno.h) @@ -4475,8 +4379,7 @@ static int et131x_open(struct net_device *netdev) return result; } -/** - * et131x_close - Close the device +/* et131x_close - Close the device * @netdev: device to be closed * * Returns 0 on success, errno on failure (as defined in errno.h) @@ -4494,8 +4397,7 @@ static int et131x_close(struct net_device *netdev) return del_timer_sync(&adapter->error_timer); } -/** - * et131x_ioctl - The I/O Control handler for the driver +/* et131x_ioctl - The I/O Control handler for the driver * @netdev: device on which the control request is being made * @reqbuf: a pointer to the IOCTL request buffer * @cmd: the IOCTL command code @@ -4513,8 +4415,7 @@ static int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, return phy_mii_ioctl(adapter->phydev, reqbuf, cmd); } -/** - * et131x_set_packet_filter - Configures the Rx Packet filtering on the device +/* et131x_set_packet_filter - Configures the Rx Packet filtering on the device * @adapter: pointer to our private adapter structure * * FIXME: lot of dups with MAC code @@ -4542,8 +4443,7 @@ static int et131x_set_packet_filter(struct et131x_adapter *adapter) if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) pf_ctrl &= ~7; /* Clear filter bits */ else { - /* - * Set us up with Multicast packet filtering. Three cases are + /* Set us up with Multicast packet filtering. Three cases are * possible - (1) we have a multi-cast list, (2) we receive ALL * multicast entries or (3) we receive none. */ @@ -4579,8 +4479,7 @@ static int et131x_set_packet_filter(struct et131x_adapter *adapter) return status; } -/** - * et131x_multicast - The handler to configure multicasting on the interface +/* et131x_multicast - The handler to configure multicasting on the interface * @netdev: a pointer to a net_device struct representing the device */ static void et131x_multicast(struct net_device *netdev) @@ -4649,8 +4548,7 @@ static void et131x_multicast(struct net_device *netdev) spin_unlock_irqrestore(&adapter->lock, flags); } -/** - * et131x_tx - The handler to tx a packet on the device +/* et131x_tx - The handler to tx a packet on the device * @skb: data to be Tx'd * @netdev: device on which data is to be Tx'd * @@ -4682,8 +4580,7 @@ static int et131x_tx(struct sk_buff *skb, struct net_device *netdev) return status; } -/** - * et131x_tx_timeout - Timeout handler +/* et131x_tx_timeout - Timeout handler * @netdev: a pointer to a net_device struct representing the device * * The handler called when a Tx request times out. The timeout period is @@ -4741,8 +4638,7 @@ static void et131x_tx_timeout(struct net_device *netdev) spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); } -/** - * et131x_change_mtu - The handler called to change the MTU for the device +/* et131x_change_mtu - The handler called to change the MTU for the device * @netdev: device whose MTU is to be changed * @new_mtu: the desired MTU * @@ -4792,8 +4688,7 @@ static int et131x_change_mtu(struct net_device *netdev, int new_mtu) return result; } -/** - * et131x_set_mac_addr - handler to change the MAC address for the device +/* et131x_set_mac_addr - handler to change the MAC address for the device * @netdev: device whose MAC is to be changed * @new_mac: the desired MAC address * @@ -4866,8 +4761,7 @@ static const struct net_device_ops et131x_netdev_ops = { .ndo_do_ioctl = et131x_ioctl, }; -/** - * et131x_pci_setup - Perform device initialization +/* et131x_pci_setup - Perform device initialization * @pdev: a pointer to the device's pci_dev structure * @ent: this device's entry in the pci_device_id table * -- cgit v0.10.2 From dcf14779280215d1765141ce04c675df3e4301c5 Mon Sep 17 00:00:00 2001 From: Harvey Yang Date: Tue, 22 Jan 2013 13:31:30 +0800 Subject: staging: usbip: use interrupt safe spinlock to avoid potential deadlock. The function 'usbip_event_add()' may be called in interrupt context on the stub side: 'stub_complete'->'stub_enqueue_ret_unlink'->'usbip_event_add'. In this function it tries to get the lock 'ud->lock', so we should disable irq when we get this lock in process context. Signed-off-by: Harvey Yang Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c index ee36415..d36c69e 100644 --- a/drivers/staging/usbip/stub_dev.c +++ b/drivers/staging/usbip/stub_dev.c @@ -67,9 +67,9 @@ static ssize_t show_status(struct device *dev, struct device_attribute *attr, return -ENODEV; } - spin_lock(&sdev->ud.lock); + spin_lock_irq(&sdev->ud.lock); status = sdev->ud.status; - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); return snprintf(buf, PAGE_SIZE, "%d\n", status); } @@ -97,39 +97,39 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr, if (sockfd != -1) { dev_info(dev, "stub up\n"); - spin_lock(&sdev->ud.lock); + spin_lock_irq(&sdev->ud.lock); if (sdev->ud.status != SDEV_ST_AVAILABLE) { dev_err(dev, "not ready\n"); - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); return -EINVAL; } socket = sockfd_to_socket(sockfd); if (!socket) { - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); return -EINVAL; } sdev->ud.tcp_socket = socket; - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud, "stub_rx"); sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud, "stub_tx"); - spin_lock(&sdev->ud.lock); + spin_lock_irq(&sdev->ud.lock); sdev->ud.status = SDEV_ST_USED; - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); } else { dev_info(dev, "stub down\n"); - spin_lock(&sdev->ud.lock); + spin_lock_irq(&sdev->ud.lock); if (sdev->ud.status != SDEV_ST_USED) { - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); return -EINVAL; } - spin_unlock(&sdev->ud.lock); + spin_unlock_irq(&sdev->ud.lock); usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN); } @@ -241,9 +241,9 @@ static void stub_device_reset(struct usbip_device *ud) ret = usb_lock_device_for_reset(udev, sdev->interface); if (ret < 0) { dev_err(&udev->dev, "lock for reset\n"); - spin_lock(&ud->lock); + spin_lock_irq(&ud->lock); ud->status = SDEV_ST_ERROR; - spin_unlock(&ud->lock); + spin_unlock_irq(&ud->lock); return; } @@ -251,7 +251,7 @@ static void stub_device_reset(struct usbip_device *ud) ret = usb_reset_device(udev); usb_unlock_device(udev); - spin_lock(&ud->lock); + spin_lock_irq(&ud->lock); if (ret) { dev_err(&udev->dev, "device reset\n"); ud->status = SDEV_ST_ERROR; @@ -259,14 +259,14 @@ static void stub_device_reset(struct usbip_device *ud) dev_info(&udev->dev, "device reset\n"); ud->status = SDEV_ST_AVAILABLE; } - spin_unlock(&ud->lock); + spin_unlock_irq(&ud->lock); } static void stub_device_unusable(struct usbip_device *ud) { - spin_lock(&ud->lock); + spin_lock_irq(&ud->lock); ud->status = SDEV_ST_ERROR; - spin_unlock(&ud->lock); + spin_unlock_irq(&ud->lock); } /** diff --git a/drivers/staging/usbip/stub_rx.c b/drivers/staging/usbip/stub_rx.c index 0572a15..e7458e1 100644 --- a/drivers/staging/usbip/stub_rx.c +++ b/drivers/staging/usbip/stub_rx.c @@ -307,12 +307,12 @@ static int valid_request(struct stub_device *sdev, struct usbip_header *pdu) int valid = 0; if (pdu->base.devid == sdev->devid) { - spin_lock(&ud->lock); + spin_lock_irq(&ud->lock); if (ud->status == SDEV_ST_USED) { /* A request is valid. */ valid = 1; } - spin_unlock(&ud->lock); + spin_unlock_irq(&ud->lock); } return valid; diff --git a/drivers/staging/usbip/usbip_event.c b/drivers/staging/usbip/usbip_event.c index d332a34..82123be 100644 --- a/drivers/staging/usbip/usbip_event.c +++ b/drivers/staging/usbip/usbip_event.c @@ -105,10 +105,12 @@ EXPORT_SYMBOL_GPL(usbip_stop_eh); void usbip_event_add(struct usbip_device *ud, unsigned long event) { - spin_lock(&ud->lock); + unsigned long flags; + + spin_lock_irqsave(&ud->lock, flags); ud->event |= event; wake_up(&ud->eh_waitq); - spin_unlock(&ud->lock); + spin_unlock_irqrestore(&ud->lock, flags); } EXPORT_SYMBOL_GPL(usbip_event_add); -- cgit v0.10.2 From 50b66b5ce4ef40460b85ddc187225e26f91e22c5 Mon Sep 17 00:00:00 2001 From: Harvey Yang Date: Tue, 22 Jan 2013 13:31:31 +0800 Subject: staging: usbip: replace the interrupt safe spinlocks with common ones. On the client side, we have a virtual hcd driver, there actually no hardware interrupts, so we do not need worry about race conditions caused by irq with spinlock held. Turning off irq is not good for system performance after all. Just replace them with a non interrupt safe version. Signed-off-by: Harvey Yang Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c index c3aa219..216648d 100644 --- a/drivers/staging/usbip/vhci_hcd.c +++ b/drivers/staging/usbip/vhci_hcd.c @@ -121,11 +121,9 @@ static void dump_port_status_diff(u32 prev_status, u32 new_status) void rh_port_connect(int rhport, enum usb_device_speed speed) { - unsigned long flags; - usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); the_controller->port_status[rhport] |= USB_PORT_STAT_CONNECTION | (1 << USB_PORT_FEAT_C_CONNECTION); @@ -141,24 +139,22 @@ void rh_port_connect(int rhport, enum usb_device_speed speed) break; } - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); } static void rh_port_disconnect(int rhport) { - unsigned long flags; - usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION; the_controller->port_status[rhport] |= (1 << USB_PORT_FEAT_C_CONNECTION); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); } @@ -183,7 +179,6 @@ static void rh_port_disconnect(int rhport) static int vhci_hub_status(struct usb_hcd *hcd, char *buf) { struct vhci_hcd *vhci; - unsigned long flags; int retval; int rhport; int changed = 0; @@ -193,7 +188,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf) vhci = hcd_to_vhci(hcd); - spin_lock_irqsave(&vhci->lock, flags); + spin_lock(&vhci->lock); if (!HCD_HW_ACCESSIBLE(hcd)) { usbip_dbg_vhci_rh("hw accessible flag not on?\n"); goto done; @@ -216,7 +211,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf) usb_hcd_resume_root_hub(hcd); done: - spin_unlock_irqrestore(&vhci->lock, flags); + spin_unlock(&vhci->lock); return changed ? retval : 0; } @@ -237,7 +232,6 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, { struct vhci_hcd *dum; int retval = 0; - unsigned long flags; int rhport; u32 prev_port_status[VHCI_NPORTS]; @@ -257,7 +251,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, dum = hcd_to_vhci(hcd); - spin_lock_irqsave(&dum->lock, flags); + spin_lock(&dum->lock); /* store old status and compare now and old later */ if (usbip_dbg_flag_vhci_rh) { @@ -410,7 +404,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, } usbip_dbg_vhci_rh(" bye\n"); - spin_unlock_irqrestore(&dum->lock, flags); + spin_unlock(&dum->lock); return retval; } @@ -433,7 +427,6 @@ static void vhci_tx_urb(struct urb *urb) { struct vhci_device *vdev = get_vdev(urb->dev); struct vhci_priv *priv; - unsigned long flag; if (!vdev) { pr_err("could not get virtual device"); @@ -442,11 +435,11 @@ static void vhci_tx_urb(struct urb *urb) priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC); - spin_lock_irqsave(&vdev->priv_lock, flag); + spin_lock(&vdev->priv_lock); if (!priv) { dev_err(&urb->dev->dev, "malloc vhci_priv\n"); - spin_unlock_irqrestore(&vdev->priv_lock, flag); + spin_unlock(&vdev->priv_lock); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); return; } @@ -463,7 +456,7 @@ static void vhci_tx_urb(struct urb *urb) list_add_tail(&priv->list, &vdev->priv_tx); wake_up(&vdev->waitq_tx); - spin_unlock_irqrestore(&vdev->priv_lock, flag); + spin_unlock(&vdev->priv_lock); } static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, @@ -471,7 +464,6 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, { struct device *dev = &urb->dev->dev; int ret = 0; - unsigned long flags; struct vhci_device *vdev; usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n", @@ -480,11 +472,11 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, /* patch to usb_sg_init() is in 2.5.60 */ BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); if (urb->status != -EINPROGRESS) { dev_err(dev, "URB already unlinked!, status %d\n", urb->status); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); return urb->status; } @@ -496,7 +488,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, vdev->ud.status == VDEV_ST_ERROR) { dev_err(dev, "enqueue for inactive port %d\n", vdev->rhport); spin_unlock(&vdev->ud.lock); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); return -ENODEV; } spin_unlock(&vdev->ud.lock); @@ -571,14 +563,14 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, out: vhci_tx_urb(urb); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); return 0; no_need_xmit: usb_hcd_unlink_urb_from_ep(hcd, urb); no_need_unlink: - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); return ret; } @@ -631,19 +623,18 @@ no_need_unlink: */ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) { - unsigned long flags; struct vhci_priv *priv; struct vhci_device *vdev; pr_info("dequeue a urb %p\n", urb); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); priv = urb->hcpriv; if (!priv) { /* URB was never linked! or will be soon given back by * vhci_rx. */ - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); return 0; } @@ -651,7 +642,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) int ret = 0; ret = usb_hcd_check_unlink_urb(hcd, urb, status); if (ret) { - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); return ret; } } @@ -661,16 +652,14 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) if (!vdev->ud.tcp_socket) { /* tcp connection is closed */ - unsigned long flags2; - - spin_lock_irqsave(&vdev->priv_lock, flags2); + spin_lock(&vdev->priv_lock); pr_info("device %p seems to be disconnected\n", vdev); list_del(&priv->list); kfree(priv); urb->hcpriv = NULL; - spin_unlock_irqrestore(&vdev->priv_lock, flags2); + spin_unlock(&vdev->priv_lock); /* * If tcp connection is alive, we have sent CMD_UNLINK. @@ -681,24 +670,23 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) usb_hcd_unlink_urb_from_ep(hcd, urb); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); } else { /* tcp connection is alive */ - unsigned long flags2; struct vhci_unlink *unlink; - spin_lock_irqsave(&vdev->priv_lock, flags2); + spin_lock(&vdev->priv_lock); /* setup CMD_UNLINK pdu */ unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC); if (!unlink) { pr_err("malloc vhci_unlink\n"); - spin_unlock_irqrestore(&vdev->priv_lock, flags2); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&vdev->priv_lock); + spin_unlock(&the_controller->lock); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); return -ENOMEM; } @@ -716,10 +704,10 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) list_add_tail(&unlink->list, &vdev->unlink_tx); wake_up(&vdev->waitq_tx); - spin_unlock_irqrestore(&vdev->priv_lock, flags2); + spin_unlock(&vdev->priv_lock); } - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usbip_dbg_vhci_hc("leave\n"); return 0; @@ -957,9 +945,9 @@ static int vhci_bus_suspend(struct usb_hcd *hcd) dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); - spin_lock_irq(&vhci->lock); + spin_lock(&vhci->lock); hcd->state = HC_STATE_SUSPENDED; - spin_unlock_irq(&vhci->lock); + spin_unlock(&vhci->lock); return 0; } @@ -971,13 +959,13 @@ static int vhci_bus_resume(struct usb_hcd *hcd) dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); - spin_lock_irq(&vhci->lock); + spin_lock(&vhci->lock); if (!HCD_HW_ACCESSIBLE(hcd)) { rc = -ESHUTDOWN; } else { hcd->state = HC_STATE_RUNNING; } - spin_unlock_irq(&vhci->lock); + spin_unlock(&vhci->lock); return rc; } diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c index ba5f1c0..faf8e60 100644 --- a/drivers/staging/usbip/vhci_rx.c +++ b/drivers/staging/usbip/vhci_rx.c @@ -68,7 +68,6 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev, { struct usbip_device *ud = &vdev->ud; struct urb *urb; - unsigned long flags; spin_lock(&vdev->priv_lock); urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum); @@ -101,9 +100,9 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev, usbip_dbg_vhci_rx("now giveback urb %p\n", urb); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); @@ -141,7 +140,6 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev, { struct vhci_unlink *unlink; struct urb *urb; - unsigned long flags; usbip_dump_header(pdu); @@ -171,9 +169,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev, urb->status = pdu->u.ret_unlink.status; pr_info("urb->status %d\n", urb->status); - spin_lock_irqsave(&the_controller->lock, flags); + spin_lock(&the_controller->lock); usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); - spin_unlock_irqrestore(&the_controller->lock, flags); + spin_unlock(&the_controller->lock); usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); diff --git a/drivers/staging/usbip/vhci_tx.c b/drivers/staging/usbip/vhci_tx.c index b1f0dcd..409fd99 100644 --- a/drivers/staging/usbip/vhci_tx.c +++ b/drivers/staging/usbip/vhci_tx.c @@ -46,18 +46,17 @@ static void setup_cmd_submit_pdu(struct usbip_header *pdup, struct urb *urb) static struct vhci_priv *dequeue_from_priv_tx(struct vhci_device *vdev) { - unsigned long flags; struct vhci_priv *priv, *tmp; - spin_lock_irqsave(&vdev->priv_lock, flags); + spin_lock(&vdev->priv_lock); list_for_each_entry_safe(priv, tmp, &vdev->priv_tx, list) { list_move_tail(&priv->list, &vdev->priv_rx); - spin_unlock_irqrestore(&vdev->priv_lock, flags); + spin_unlock(&vdev->priv_lock); return priv; } - spin_unlock_irqrestore(&vdev->priv_lock, flags); + spin_unlock(&vdev->priv_lock); return NULL; } @@ -136,18 +135,17 @@ static int vhci_send_cmd_submit(struct vhci_device *vdev) static struct vhci_unlink *dequeue_from_unlink_tx(struct vhci_device *vdev) { - unsigned long flags; struct vhci_unlink *unlink, *tmp; - spin_lock_irqsave(&vdev->priv_lock, flags); + spin_lock(&vdev->priv_lock); list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { list_move_tail(&unlink->list, &vdev->unlink_rx); - spin_unlock_irqrestore(&vdev->priv_lock, flags); + spin_unlock(&vdev->priv_lock); return unlink; } - spin_unlock_irqrestore(&vdev->priv_lock, flags); + spin_unlock(&vdev->priv_lock); return NULL; } -- cgit v0.10.2 From c0594ee9ea20388310d2669a7c6122c5305dcf80 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Tue, 22 Jan 2013 17:10:10 +0000 Subject: staging: et131x: Fix all sparse warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dan Carpenter has pointed out that there are several sparse warnings from et131x.c, listed below. This patch fixes all these errors. drivers/staging/et131x/et131x.c:1870:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1870:33:    expected unsigned int [usertype] *num_des drivers/staging/et131x/et131x.c:1870:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1871:37: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1871:37:    expected unsigned int [usertype] *full_offset drivers/staging/et131x/et131x.c:1871:37:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1872:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1872:33:    expected unsigned int [usertype] *min_des drivers/staging/et131x/et131x.c:1872:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1873:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1873:33:    expected unsigned int [usertype] *base_hi drivers/staging/et131x/et131x.c:1873:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1874:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1874:33:    expected unsigned int [usertype] *base_lo drivers/staging/et131x/et131x.c:1874:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1876:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1876:33:    expected unsigned int [usertype] *num_des drivers/staging/et131x/et131x.c:1876:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1877:37: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1877:37:    expected unsigned int [usertype] *full_offset drivers/staging/et131x/et131x.c:1877:37:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1878:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1878:33:    expected unsigned int [usertype] *min_des drivers/staging/et131x/et131x.c:1878:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1879:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1879:33:    expected unsigned int [usertype] *base_hi drivers/staging/et131x/et131x.c:1879:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1880:33: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:1880:33:    expected unsigned int [usertype] *base_lo drivers/staging/et131x/et131x.c:1880:33:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:1898:24: warning: incorrect type in argument 2 (different address spaces) drivers/staging/et131x/et131x.c:1898:24:    expected void volatile [noderef] *addr drivers/staging/et131x/et131x.c:1898:24:    got unsigned int [usertype] *base_hi drivers/staging/et131x/et131x.c:1900:24: warning: incorrect type in argument 2 (different address spaces) drivers/staging/et131x/et131x.c:1900:24:    expected void volatile [noderef] *addr drivers/staging/et131x/et131x.c:1900:24:    got unsigned int [usertype] *base_lo drivers/staging/et131x/et131x.c:1901:60: warning: incorrect type in argument 2 (different address spaces) drivers/staging/et131x/et131x.c:1901:60:    expected void volatile [noderef] *addr drivers/staging/et131x/et131x.c:1901:60:    got unsigned int [usertype] *num_des drivers/staging/et131x/et131x.c:1902:39: warning: incorrect type in argument 2 (different address spaces) drivers/staging/et131x/et131x.c:1902:39:    expected void volatile [noderef] *addr drivers/staging/et131x/et131x.c:1902:39:    got unsigned int [usertype] *full_offset drivers/staging/et131x/et131x.c:1910:24: warning: incorrect type in argument 2 (different address spaces) drivers/staging/et131x/et131x.c:1910:24:    expected void volatile [noderef] *addr drivers/staging/et131x/et131x.c:1910:24:    got unsigned int [usertype] *min_des drivers/staging/et131x/et131x.c:2583:32: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:2583:32:    expected unsigned int [usertype] *offset drivers/staging/et131x/et131x.c:2583:32:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:2585:32: warning: incorrect type in assignment (different address spaces) drivers/staging/et131x/et131x.c:2585:32:    expected unsigned int [usertype] *offset drivers/staging/et131x/et131x.c:2585:32:    got unsigned int [noderef] * drivers/staging/et131x/et131x.c:2602:24: warning: incorrect type in argument 2 (different address spaces) drivers/staging/et131x/et131x.c:2602:24:    expected void volatile [noderef] *addr drivers/staging/et131x/et131x.c:2602:24:    got unsigned int [usertype] *offset drivers/staging/et131x/et131x.c:4093:13: warning: symbol 'et131x_isr' was not declared. Should it be static? Reported-by: Dan Carpenter Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index e38d701..4a7c302 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -1819,11 +1819,11 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) rx_local->local_psr_full = 0; for (id = 0; id < NUM_FBRS; id++) { - u32 *num_des; - u32 *full_offset; - u32 *min_des; - u32 *base_hi; - u32 *base_lo; + u32 __iomem *num_des; + u32 __iomem *full_offset; + u32 __iomem *min_des; + u32 __iomem *base_hi; + u32 __iomem *base_lo; if (id == 0) { num_des = &rx_dma->fbr0_num_des; @@ -2516,7 +2516,7 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd) * need to clean up OOB data */ if (buff_index < rx_local->fbr[ring_index]->num_entries) { - u32 *offset; + u32 __iomem *offset; struct fbr_desc *next; spin_lock_irqsave(&adapter->fbr_lock, flags); @@ -4037,7 +4037,7 @@ static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume); * * Returns a value indicating if the interrupt was handled. */ -irqreturn_t et131x_isr(int irq, void *dev_id) +static irqreturn_t et131x_isr(int irq, void *dev_id) { bool handled = true; struct net_device *netdev = (struct net_device *)dev_id; -- cgit v0.10.2 From e809c22b8fb0282048fc008cfcdd017186090dbc Mon Sep 17 00:00:00 2001 From: Jun Nakajima Date: Mon, 21 Jan 2013 23:48:07 +0000 Subject: goldfish: add the goldfish virtual bus This imports the current Google code and cleans it up slightly to use pr_ and to properly request its resources. Goldfish is an emulator used for Android development. It has a virtual bus where the emulator passes platform device information to the guest which then creates the appropriate devices. This part of the emulation is not architecture specific so should not be hiding in architecture trees as it does in the Google Android tree. The constants it uses do depend on the platform and the platform creates the bus device which then talks to the emulator to ascertain the actual devices present. Signed-off-by: Sheng Yang Signed-off-by: Yunhong Jiang Signed-off-by: Xiaohui Xin Signed-off-by: Jun Nakajima Signed-off-by: Bruce Beare [Moved out of x86, cleaned up headers] Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/platform/Makefile b/drivers/platform/Makefile index b17c16c..8a44a4c 100644 --- a/drivers/platform/Makefile +++ b/drivers/platform/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_X86) += x86/ obj-$(CONFIG_OLPC) += olpc/ +obj-$(CONFIG_GOLDFISH) += goldfish/ diff --git a/drivers/platform/goldfish/Makefile b/drivers/platform/goldfish/Makefile new file mode 100644 index 0000000..6c591f6 --- /dev/null +++ b/drivers/platform/goldfish/Makefile @@ -0,0 +1,4 @@ +# +# Makefile for Goldfish platform specific drivers +# +obj-$(CONFIG_GOLDFISH) += pdev_bus.o diff --git a/drivers/platform/goldfish/pdev_bus.c b/drivers/platform/goldfish/pdev_bus.c new file mode 100644 index 0000000..92cc4cf --- /dev/null +++ b/drivers/platform/goldfish/pdev_bus.c @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2007 Google, Inc. + * Copyright (C) 2011 Intel, Inc. + * Copyright (C) 2013 Intel, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#define PDEV_BUS_OP_DONE (0x00) +#define PDEV_BUS_OP_REMOVE_DEV (0x04) +#define PDEV_BUS_OP_ADD_DEV (0x08) + +#define PDEV_BUS_OP_INIT (0x00) + +#define PDEV_BUS_OP (0x00) +#define PDEV_BUS_GET_NAME (0x04) +#define PDEV_BUS_NAME_LEN (0x08) +#define PDEV_BUS_ID (0x0c) +#define PDEV_BUS_IO_BASE (0x10) +#define PDEV_BUS_IO_SIZE (0x14) +#define PDEV_BUS_IRQ (0x18) +#define PDEV_BUS_IRQ_COUNT (0x1c) + +struct pdev_bus_dev { + struct list_head list; + struct platform_device pdev; + struct resource resources[0]; +}; + +static void goldfish_pdev_worker(struct work_struct *work); + +static void __iomem *pdev_bus_base; +static unsigned long pdev_bus_addr; +static unsigned long pdev_bus_len; +static u32 pdev_bus_irq; +static LIST_HEAD(pdev_bus_new_devices); +static LIST_HEAD(pdev_bus_registered_devices); +static LIST_HEAD(pdev_bus_removed_devices); +static DECLARE_WORK(pdev_bus_worker, goldfish_pdev_worker); + + +static void goldfish_pdev_worker(struct work_struct *work) +{ + int ret; + struct pdev_bus_dev *pos, *n; + + list_for_each_entry_safe(pos, n, &pdev_bus_removed_devices, list) { + list_del(&pos->list); + platform_device_unregister(&pos->pdev); + kfree(pos); + } + list_for_each_entry_safe(pos, n, &pdev_bus_new_devices, list) { + list_del(&pos->list); + ret = platform_device_register(&pos->pdev); + if (ret) + pr_err("goldfish_pdev_worker failed to register device, %s\n", + pos->pdev.name); + list_add_tail(&pos->list, &pdev_bus_registered_devices); + } +} + +static void goldfish_pdev_remove(void) +{ + struct pdev_bus_dev *pos, *n; + u32 base; + + base = readl(pdev_bus_base + PDEV_BUS_IO_BASE); + + list_for_each_entry_safe(pos, n, &pdev_bus_new_devices, list) { + if (pos->resources[0].start == base) { + list_del(&pos->list); + kfree(pos); + return; + } + } + list_for_each_entry_safe(pos, n, &pdev_bus_registered_devices, list) { + if (pos->resources[0].start == base) { + list_del(&pos->list); + list_add_tail(&pos->list, &pdev_bus_removed_devices); + schedule_work(&pdev_bus_worker); + return; + } + }; + pr_err("goldfish_pdev_remove could not find device at %x\n", base); +} + +static int goldfish_new_pdev(void) +{ + struct pdev_bus_dev *dev; + u32 name_len; + u32 irq = -1, irq_count; + int resource_count = 2; + u32 base; + char *name; + + base = readl(pdev_bus_base + PDEV_BUS_IO_BASE); + + irq_count = readl(pdev_bus_base + PDEV_BUS_IRQ_COUNT); + name_len = readl(pdev_bus_base + PDEV_BUS_NAME_LEN); + if (irq_count) + resource_count++; + + dev = kzalloc(sizeof(*dev) + + sizeof(struct resource) * resource_count + + name_len + 1 + sizeof(*dev->pdev.dev.dma_mask), GFP_ATOMIC); + if (dev == NULL) + return -ENOMEM; + + dev->pdev.num_resources = resource_count; + dev->pdev.resource = (struct resource *)(dev + 1); + dev->pdev.name = name = (char *)(dev->pdev.resource + resource_count); + dev->pdev.dev.coherent_dma_mask = ~0; + dev->pdev.dev.dma_mask = (void *)(dev->pdev.name + name_len + 1); + *dev->pdev.dev.dma_mask = ~0; + + writel((unsigned long)name, pdev_bus_base + PDEV_BUS_GET_NAME); + name[name_len] = '\0'; + dev->pdev.id = readl(pdev_bus_base + PDEV_BUS_ID); + dev->pdev.resource[0].start = base; + dev->pdev.resource[0].end = base + + readl(pdev_bus_base + PDEV_BUS_IO_SIZE) - 1; + dev->pdev.resource[0].flags = IORESOURCE_MEM; + if (irq_count) { + irq = readl(pdev_bus_base + PDEV_BUS_IRQ); + dev->pdev.resource[1].start = irq; + dev->pdev.resource[1].end = irq + irq_count - 1; + dev->pdev.resource[1].flags = IORESOURCE_IRQ; + } + + pr_debug("goldfish_new_pdev %s at %x irq %d\n", name, base, irq); + list_add_tail(&dev->list, &pdev_bus_new_devices); + schedule_work(&pdev_bus_worker); + + return 0; +} + +static irqreturn_t goldfish_pdev_bus_interrupt(int irq, void *dev_id) +{ + irqreturn_t ret = IRQ_NONE; + while (1) { + u32 op = readl(pdev_bus_base + PDEV_BUS_OP); + switch (op) { + case PDEV_BUS_OP_DONE: + return IRQ_NONE; + + case PDEV_BUS_OP_REMOVE_DEV: + goldfish_pdev_remove(); + break; + + case PDEV_BUS_OP_ADD_DEV: + goldfish_new_pdev(); + break; + } + ret = IRQ_HANDLED; + } + return ret; +} + +static int goldfish_pdev_bus_probe(struct platform_device *pdev) +{ + int ret; + struct resource *r; + + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (r == NULL) + return -EINVAL; + + pdev_bus_addr = r->start; + pdev_bus_len = resource_size(r); + + if (request_mem_region(pdev_bus_addr, pdev_bus_len, "goldfish")) { + dev_err(&pdev->dev, "unable to reserve Goldfish MMIO.\n"); + return -EBUSY; + } + + pdev_bus_base = ioremap(pdev_bus_addr, pdev_bus_len); + if (pdev_bus_base == NULL) { + ret = -ENOMEM; + dev_err(&pdev->dev, "unable to map Goldfish MMIO.\n"); + goto free_resources; + } + + r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (r == NULL) { + ret = -ENOENT; + goto free_map; + } + + pdev_bus_irq = r->start; + + ret = request_irq(pdev_bus_irq, goldfish_pdev_bus_interrupt, + IRQF_SHARED, "goldfish_pdev_bus", pdev); + if (ret) { + dev_err(&pdev->dev, "unable to request Goldfish IRQ\n"); + goto free_map; + } + + writel(PDEV_BUS_OP_INIT, pdev_bus_base + PDEV_BUS_OP); + return 0; + +free_map: + iounmap(pdev_bus_base); +free_resources: + release_mem_region(pdev_bus_addr, pdev_bus_len); + return ret; +} + +static int goldfish_pdev_bus_remove(struct platform_device *pdev) +{ + iounmap(pdev_bus_base); + free_irq(pdev_bus_irq, pdev); + release_mem_region(pdev_bus_addr, pdev_bus_len); + return 0; +} + +static struct platform_driver goldfish_pdev_bus_driver = { + .probe = goldfish_pdev_bus_probe, + .remove = goldfish_pdev_bus_remove, + .driver = { + .name = "goldfish_pdev_bus" + } +}; + +module_platform_driver(goldfish_pdev_bus_driver); -- cgit v0.10.2 From c89f2750e9845aa115ca30c062edd569da619cad Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 21 Jan 2013 23:48:21 +0000 Subject: goldfish: add QEMU pipe driver A QEMU pipe is a very fast communication channel between the guest system and the emulator. Usage from the guest is simply something like; // connect to special device fd = open("/dev/qemu_pipe", O_RDWR); // tell which service we want to talk to (must be zero-terminated) write(fd, "pipeName", strlen("pipeName")+1); // do read()/write() through fd now ... // close channel close(fd); Signed-off-by: David 'Digit' Turner [Added support for parameter buffers for speed] igned-off-by: Xin, Xiaohui Signed-off-by: Jiang, Yunhong Signed-off-by: Nakajima, Jun [Ported to 3.6] Signed-off-by: Tom Keel [Ported to 3.7, moved to platform/goldfish] Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig index 8390dca..69616ae 100644 --- a/drivers/platform/Kconfig +++ b/drivers/platform/Kconfig @@ -1,3 +1,7 @@ if X86 source "drivers/platform/x86/Kconfig" endif +if GOLDFISH +source "drivers/platform/goldfish/Kconfig" +endif + diff --git a/drivers/platform/goldfish/Kconfig b/drivers/platform/goldfish/Kconfig new file mode 100644 index 0000000..635ef25 --- /dev/null +++ b/drivers/platform/goldfish/Kconfig @@ -0,0 +1,5 @@ +config GOLDFISH_PIPE + tristate "Goldfish virtual device for QEMU pipes" + ---help--- + This is a virtual device to drive the QEMU pipe interface used by + the Goldfish Android Virtual Device. diff --git a/drivers/platform/goldfish/Makefile b/drivers/platform/goldfish/Makefile index 6c591f6..a002239 100644 --- a/drivers/platform/goldfish/Makefile +++ b/drivers/platform/goldfish/Makefile @@ -2,3 +2,4 @@ # Makefile for Goldfish platform specific drivers # obj-$(CONFIG_GOLDFISH) += pdev_bus.o +obj-$(CONFIG_GOLDFISH_PIPE) += goldfish_pipe.o diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c new file mode 100644 index 0000000..58dae1f --- /dev/null +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -0,0 +1,611 @@ +/* + * Copyright (C) 2011 Google, Inc. + * Copyright (C) 2012 Intel, Inc. + * Copyright (C) 2013 Intel, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +/* This source file contains the implementation of a special device driver + * that intends to provide a *very* fast communication channel between the + * guest system and the QEMU emulator. + * + * Usage from the guest is simply the following (error handling simplified): + * + * int fd = open("/dev/qemu_pipe",O_RDWR); + * .... write() or read() through the pipe. + * + * This driver doesn't deal with the exact protocol used during the session. + * It is intended to be as simple as something like: + * + * // do this _just_ after opening the fd to connect to a specific + * // emulator service. + * const char* msg = ""; + * if (write(fd, msg, strlen(msg)+1) < 0) { + * ... could not connect to service + * close(fd); + * } + * + * // after this, simply read() and write() to communicate with the + * // service. Exact protocol details left as an exercise to the reader. + * + * This driver is very fast because it doesn't copy any data through + * intermediate buffers, since the emulator is capable of translating + * guest user addresses into host ones. + * + * Note that we must however ensure that each user page involved in the + * exchange is properly mapped during a transfer. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * IMPORTANT: The following constants must match the ones used and defined + * in external/qemu/hw/goldfish_pipe.c in the Android source tree. + */ + +/* pipe device registers */ +#define PIPE_REG_COMMAND 0x00 /* write: value = command */ +#define PIPE_REG_STATUS 0x04 /* read */ +#define PIPE_REG_CHANNEL 0x08 /* read/write: channel id */ +#define PIPE_REG_SIZE 0x0c /* read/write: buffer size */ +#define PIPE_REG_ADDRESS 0x10 /* write: physical address */ +#define PIPE_REG_WAKES 0x14 /* read: wake flags */ +#define PIPE_REG_PARAMS_ADDR_LOW 0x18 /* read/write: batch data address */ +#define PIPE_REG_PARAMS_ADDR_HIGH 0x1c /* read/write: batch data address */ +#define PIPE_REG_ACCESS_PARAMS 0x20 /* write: batch access */ + +/* list of commands for PIPE_REG_COMMAND */ +#define CMD_OPEN 1 /* open new channel */ +#define CMD_CLOSE 2 /* close channel (from guest) */ +#define CMD_POLL 3 /* poll read/write status */ + +/* List of bitflags returned in status of CMD_POLL command */ +#define PIPE_POLL_IN (1 << 0) +#define PIPE_POLL_OUT (1 << 1) +#define PIPE_POLL_HUP (1 << 2) + +/* The following commands are related to write operations */ +#define CMD_WRITE_BUFFER 4 /* send a user buffer to the emulator */ +#define CMD_WAKE_ON_WRITE 5 /* tell the emulator to wake us when writing + is possible */ + +/* The following commands are related to read operations, they must be + * listed in the same order than the corresponding write ones, since we + * will use (CMD_READ_BUFFER - CMD_WRITE_BUFFER) as a special offset + * in goldfish_pipe_read_write() below. + */ +#define CMD_READ_BUFFER 6 /* receive a user buffer from the emulator */ +#define CMD_WAKE_ON_READ 7 /* tell the emulator to wake us when reading + * is possible */ + +/* Possible status values used to signal errors - see goldfish_pipe_error_convert */ +#define PIPE_ERROR_INVAL -1 +#define PIPE_ERROR_AGAIN -2 +#define PIPE_ERROR_NOMEM -3 +#define PIPE_ERROR_IO -4 + +/* Bit-flags used to signal events from the emulator */ +#define PIPE_WAKE_CLOSED (1 << 0) /* emulator closed pipe */ +#define PIPE_WAKE_READ (1 << 1) /* pipe can now be read from */ +#define PIPE_WAKE_WRITE (1 << 2) /* pipe can now be written to */ + +struct access_params { + u32 channel; + u32 size; + u32 address; + u32 cmd; + u32 result; + /* reserved for future extension */ + u32 flags; +}; + +/* The global driver data. Holds a reference to the i/o page used to + * communicate with the emulator, and a wake queue for blocked tasks + * waiting to be awoken. + */ +struct goldfish_pipe_dev { + spinlock_t lock; + unsigned char __iomem *base; + struct access_params *aps; + int irq; +}; + +static struct goldfish_pipe_dev pipe_dev[1]; + +/* This data type models a given pipe instance */ +struct goldfish_pipe { + struct goldfish_pipe_dev *dev; + struct mutex lock; + unsigned long flags; + wait_queue_head_t wake_queue; +}; + + +/* Bit flags for the 'flags' field */ +enum { + BIT_CLOSED_ON_HOST = 0, /* pipe closed by host */ + BIT_WAKE_ON_WRITE = 1, /* want to be woken on writes */ + BIT_WAKE_ON_READ = 2, /* want to be woken on reads */ +}; + + +static u32 goldfish_cmd_status(struct goldfish_pipe *pipe, u32 cmd) +{ + unsigned long flags; + u32 status; + struct goldfish_pipe_dev *dev = pipe->dev; + + spin_lock_irqsave(&dev->lock, flags); + writel((u32)pipe, dev->base + PIPE_REG_CHANNEL); + writel(cmd, dev->base + PIPE_REG_COMMAND); + status = readl(dev->base + PIPE_REG_STATUS); + spin_unlock_irqrestore(&dev->lock, flags); + return status; +} + +static void goldfish_cmd(struct goldfish_pipe *pipe, u32 cmd) +{ + unsigned long flags; + struct goldfish_pipe_dev *dev = pipe->dev; + + spin_lock_irqsave(&dev->lock, flags); + writel((u32)pipe, dev->base + PIPE_REG_CHANNEL); + writel(cmd, dev->base + PIPE_REG_COMMAND); + spin_unlock_irqrestore(&dev->lock, flags); +} + +/* This function converts an error code returned by the emulator through + * the PIPE_REG_STATUS i/o register into a valid negative errno value. + */ +static int goldfish_pipe_error_convert(int status) +{ + switch (status) { + case PIPE_ERROR_AGAIN: + return -EAGAIN; + case PIPE_ERROR_NOMEM: + return -ENOMEM; + case PIPE_ERROR_IO: + return -EIO; + default: + return -EINVAL; + } +} + +/* + * Notice: QEMU will return 0 for un-known register access, indicating + * param_acess is supported or not + */ +static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev, + struct access_params *aps) +{ + u32 aph, apl; + u64 paddr; + aph = readl(dev->base + PIPE_REG_PARAMS_ADDR_HIGH); + apl = readl(dev->base + PIPE_REG_PARAMS_ADDR_LOW); + + paddr = ((u64)aph << 32) | apl; + if (paddr != (__pa(aps))) + return 0; + return 1; +} + +/* 0 on success */ +static int setup_access_params_addr(struct platform_device *pdev, + struct goldfish_pipe_dev *dev) +{ + u64 paddr; + struct access_params *aps; + + aps = devm_kzalloc(&pdev->dev, sizeof(struct access_params), GFP_KERNEL); + if (!aps) + return -1; + + /* FIXME */ + paddr = __pa(aps); + writel((u32)(paddr >> 32), dev->base + PIPE_REG_PARAMS_ADDR_HIGH); + writel((u32)paddr, dev->base + PIPE_REG_PARAMS_ADDR_LOW); + + if (valid_batchbuffer_addr(dev, aps)) { + dev->aps = aps; + return 0; + } else + return -1; +} + +/* A value that will not be set by qemu emulator */ +#define INITIAL_BATCH_RESULT (0xdeadbeaf) +static int access_with_param(struct goldfish_pipe_dev *dev, const int cmd, + unsigned long address, unsigned long avail, + struct goldfish_pipe *pipe, int *status) +{ + struct access_params *aps = dev->aps; + + if (aps == NULL) + return -1; + + aps->result = INITIAL_BATCH_RESULT; + aps->channel = (unsigned long)pipe; + aps->size = avail; + aps->address = address; + aps->cmd = cmd; + writel(cmd, dev->base + PIPE_REG_ACCESS_PARAMS); + /* + * If the aps->result has not changed, that means + * that the batch command failed + */ + if (aps->result == INITIAL_BATCH_RESULT) + return -1; + *status = aps->result; + return 0; +} + +/* This function is used for both reading from and writing to a given + * pipe. + */ +static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer, + size_t bufflen, int is_write) +{ + unsigned long irq_flags; + struct goldfish_pipe *pipe = filp->private_data; + struct goldfish_pipe_dev *dev = pipe->dev; + const int cmd_offset = is_write ? 0 + : (CMD_READ_BUFFER - CMD_WRITE_BUFFER); + unsigned long address, address_end; + int ret = 0; + + /* If the emulator already closed the pipe, no need to go further */ + if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) + return -EIO; + + /* Null reads or writes succeeds */ + if (unlikely(bufflen) == 0) + return 0; + + /* Check the buffer range for access */ + if (!access_ok(is_write ? VERIFY_WRITE : VERIFY_READ, + buffer, bufflen)) + return -EFAULT; + + /* Serialize access to the pipe */ + if (mutex_lock_interruptible(&pipe->lock)) + return -ERESTARTSYS; + + address = (unsigned long)(void *)buffer; + address_end = address + bufflen; + + while (address < address_end) { + unsigned long page_end = (address & PAGE_MASK) + PAGE_SIZE; + unsigned long next = page_end < address_end ? page_end + : address_end; + unsigned long avail = next - address; + int status, wakeBit; + + /* Ensure that the corresponding page is properly mapped */ + if (is_write) { + char c; + /* Ensure that the page is mapped and readable */ + if (__get_user(c, (char __user *)address)) { + if (!ret) + ret = -EFAULT; + break; + } + } else { + /* Ensure that the page is mapped and writable */ + if (__put_user(0, (char __user *)address)) { + if (!ret) + ret = -EFAULT; + break; + } + } + + /* Now, try to transfer the bytes in the current page */ + spin_lock_irqsave(&dev->lock, irq_flags); + if (access_with_param(dev, CMD_WRITE_BUFFER + cmd_offset, + address, avail, pipe, &status)) { + writel((u32)pipe, dev->base + PIPE_REG_CHANNEL); + writel(avail, dev->base + PIPE_REG_SIZE); + writel(address, dev->base + PIPE_REG_ADDRESS); + writel(CMD_WRITE_BUFFER + cmd_offset, + dev->base + PIPE_REG_COMMAND); + status = readl(dev->base + PIPE_REG_STATUS); + } + spin_unlock_irqrestore(&dev->lock, irq_flags); + + if (status > 0) { /* Correct transfer */ + ret += status; + address += status; + continue; + } + + if (status == 0) /* EOF */ + break; + + /* An error occured. If we already transfered stuff, just + * return with its count. We expect the next call to return + * an error code */ + if (ret > 0) + break; + + /* If the error is not PIPE_ERROR_AGAIN, or if we are not in + * non-blocking mode, just return the error code. + */ + if (status != PIPE_ERROR_AGAIN || + (filp->f_flags & O_NONBLOCK) != 0) { + ret = goldfish_pipe_error_convert(status); + break; + } + + /* We will have to wait until more data/space is available. + * First, mark the pipe as waiting for a specific wake signal. + */ + wakeBit = is_write ? BIT_WAKE_ON_WRITE : BIT_WAKE_ON_READ; + set_bit(wakeBit, &pipe->flags); + + /* Tell the emulator we're going to wait for a wake event */ + goldfish_cmd(pipe, CMD_WAKE_ON_WRITE + cmd_offset); + + /* Unlock the pipe, then wait for the wake signal */ + mutex_unlock(&pipe->lock); + + while (test_bit(wakeBit, &pipe->flags)) { + if (wait_event_interruptible( + pipe->wake_queue, + !test_bit(wakeBit, &pipe->flags))) + return -ERESTARTSYS; + + if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) + return -EIO; + } + + /* Try to re-acquire the lock */ + if (mutex_lock_interruptible(&pipe->lock)) + return -ERESTARTSYS; + + /* Try the transfer again */ + continue; + } + mutex_unlock(&pipe->lock); + return ret; +} + +static ssize_t goldfish_pipe_read(struct file *filp, char __user *buffer, + size_t bufflen, loff_t *ppos) +{ + return goldfish_pipe_read_write(filp, buffer, bufflen, 0); +} + +static ssize_t goldfish_pipe_write(struct file *filp, + const char __user *buffer, size_t bufflen, + loff_t *ppos) +{ + return goldfish_pipe_read_write(filp, (char __user *)buffer, + bufflen, 1); +} + + +static unsigned int goldfish_pipe_poll(struct file *filp, poll_table *wait) +{ + struct goldfish_pipe *pipe = filp->private_data; + unsigned int mask = 0; + int status; + + mutex_lock(&pipe->lock); + + poll_wait(filp, &pipe->wake_queue, wait); + + status = goldfish_cmd_status(pipe, CMD_POLL); + + mutex_unlock(&pipe->lock); + + if (status & PIPE_POLL_IN) + mask |= POLLIN | POLLRDNORM; + + if (status & PIPE_POLL_OUT) + mask |= POLLOUT | POLLWRNORM; + + if (status & PIPE_POLL_HUP) + mask |= POLLHUP; + + if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) + mask |= POLLERR; + + return mask; +} + +static irqreturn_t goldfish_pipe_interrupt(int irq, void *dev_id) +{ + struct goldfish_pipe_dev *dev = dev_id; + unsigned long irq_flags; + int count = 0; + + /* We're going to read from the emulator a list of (channel,flags) + * pairs corresponding to the wake events that occured on each + * blocked pipe (i.e. channel). + */ + spin_lock_irqsave(&dev->lock, irq_flags); + for (;;) { + /* First read the channel, 0 means the end of the list */ + struct goldfish_pipe *pipe; + unsigned long wakes; + unsigned long channel = readl(dev->base + PIPE_REG_CHANNEL); + + if (channel == 0) + break; + + /* Convert channel to struct pipe pointer + read wake flags */ + wakes = readl(dev->base + PIPE_REG_WAKES); + pipe = (struct goldfish_pipe *)(ptrdiff_t)channel; + + /* Did the emulator just closed a pipe? */ + if (wakes & PIPE_WAKE_CLOSED) { + set_bit(BIT_CLOSED_ON_HOST, &pipe->flags); + wakes |= PIPE_WAKE_READ | PIPE_WAKE_WRITE; + } + if (wakes & PIPE_WAKE_READ) + clear_bit(BIT_WAKE_ON_READ, &pipe->flags); + if (wakes & PIPE_WAKE_WRITE) + clear_bit(BIT_WAKE_ON_WRITE, &pipe->flags); + + wake_up_interruptible(&pipe->wake_queue); + count++; + } + spin_unlock_irqrestore(&dev->lock, irq_flags); + + return (count == 0) ? IRQ_NONE : IRQ_HANDLED; +} + +/** + * goldfish_pipe_open - open a channel to the AVD + * @inode: inode of device + * @file: file struct of opener + * + * Create a new pipe link between the emulator and the use application. + * Each new request produces a new pipe. + * + * Note: we use the pipe ID as a mux. All goldfish emulations are 32bit + * right now so this is fine. A move to 64bit will need this addressing + */ +static int goldfish_pipe_open(struct inode *inode, struct file *file) +{ + struct goldfish_pipe *pipe; + struct goldfish_pipe_dev *dev = pipe_dev; + int32_t status; + + /* Allocate new pipe kernel object */ + pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); + if (pipe == NULL) + return -ENOMEM; + + pipe->dev = dev; + mutex_init(&pipe->lock); + init_waitqueue_head(&pipe->wake_queue); + + /* + * Now, tell the emulator we're opening a new pipe. We use the + * pipe object's address as the channel identifier for simplicity. + */ + + status = goldfish_cmd_status(pipe, CMD_OPEN); + if (status < 0) { + kfree(pipe); + return status; + } + + /* All is done, save the pipe into the file's private data field */ + file->private_data = pipe; + return 0; +} + +static int goldfish_pipe_release(struct inode *inode, struct file *filp) +{ + struct goldfish_pipe *pipe = filp->private_data; + + /* The guest is closing the channel, so tell the emulator right now */ + goldfish_cmd(pipe, CMD_CLOSE); + kfree(pipe); + filp->private_data = NULL; + return 0; +} + +static const struct file_operations goldfish_pipe_fops = { + .owner = THIS_MODULE, + .read = goldfish_pipe_read, + .write = goldfish_pipe_write, + .poll = goldfish_pipe_poll, + .open = goldfish_pipe_open, + .release = goldfish_pipe_release, +}; + +static struct miscdevice goldfish_pipe_device = { + .minor = MISC_DYNAMIC_MINOR, + .name = "goldfish_pipe", + .fops = &goldfish_pipe_fops, +}; + +static int goldfish_pipe_probe(struct platform_device *pdev) +{ + int err; + struct resource *r; + struct goldfish_pipe_dev *dev = pipe_dev; + + /* not thread safe, but this should not happen */ + WARN_ON(dev->base != NULL); + + spin_lock_init(&dev->lock); + + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (r == NULL || resource_size(r) < PAGE_SIZE) { + dev_err(&pdev->dev, "can't allocate i/o page\n"); + return -EINVAL; + } + dev->base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); + if (dev->base == NULL) { + dev_err(&pdev->dev, "ioremap failed\n"); + return -EINVAL; + } + + r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (r == NULL) { + err = -EINVAL; + goto error; + } + dev->irq = r->start; + + err = devm_request_irq(&pdev->dev, dev->irq, goldfish_pipe_interrupt, + IRQF_SHARED, "goldfish_pipe", dev); + if (err) { + dev_err(&pdev->dev, "unable to allocate IRQ\n"); + goto error; + } + + err = misc_register(&goldfish_pipe_device); + if (err) { + dev_err(&pdev->dev, "unable to register device\n"); + goto error; + } + setup_access_params_addr(pdev, dev); + return 0; + +error: + dev->base = NULL; + return err; +} + +static int goldfish_pipe_remove(struct platform_device *pdev) +{ + struct goldfish_pipe_dev *dev = pipe_dev; + misc_deregister(&goldfish_pipe_device); + dev->base = NULL; + return 0; +} + +static struct platform_driver goldfish_pipe = { + .probe = goldfish_pipe_probe, + .remove = goldfish_pipe_remove, + .driver = { + .name = "goldfish_pipe" + } +}; + +module_platform_driver(goldfish_pipe); +MODULE_AUTHOR("David Turner "); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 17c4c9db4a33ae0a8dcfafab3dc59a83ccaf6076 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 23 Jan 2013 14:13:18 +0000 Subject: goldfish: Add a FIXME note to the pipe driver Note a point in the pipe driver that wants future attention Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index 58dae1f..4f5aa831 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -300,6 +300,7 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer, int status, wakeBit; /* Ensure that the corresponding page is properly mapped */ + /* FIXME: this isn't safe or sufficient - use get_user_pages */ if (is_write) { char c; /* Ensure that the page is mapped and readable */ -- cgit v0.10.2 From 2e82b83dc30e515ca3e03e79d4a398f30d796903 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 23 Jan 2013 14:13:52 +0000 Subject: goldfish: audio support (remove change to another file that escaped into the patch set) From: Mike Lockwood Provide a simple audio channel between the kernel and the emulator that host sit. Queued for staging right now as this ought to be an ALSA driver not just a dumb device of its own making. Signed-off-by: Mike A. Chan [x86 support] Signed-off-by: Sheng Yang Signed-off-by: Yunhong Jiang Signed-off-by: Xiaohui Xin Signed-off-by: Jun Nakajima Signed-off-by: Bruce Beare [Clean up] Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 0b47a06..3a7965d 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -140,4 +140,6 @@ source "drivers/staging/fwserial/Kconfig" source "drivers/staging/zcache/Kconfig" +source "drivers/staging/goldfish/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index b026ea3..5971865 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -62,3 +62,4 @@ obj-$(CONFIG_DGRP) += dgrp/ obj-$(CONFIG_SB105X) += sb105x/ obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ obj-$(CONFIG_ZCACHE) += zcache/ +obj-$(CONFIG_GOLDFISH) += goldfish/ diff --git a/drivers/staging/goldfish/Kconfig b/drivers/staging/goldfish/Kconfig new file mode 100644 index 0000000..1a3e576 --- /dev/null +++ b/drivers/staging/goldfish/Kconfig @@ -0,0 +1,6 @@ +config GOLDFISH_AUDIO + tristate "Goldfish AVD Audio Device" + depends on GOLDFISH + ---help--- + Emulated audio channel for the Goldfish Android Virtual Device + diff --git a/drivers/staging/goldfish/Makefile b/drivers/staging/goldfish/Makefile new file mode 100644 index 0000000..054eeb8 --- /dev/null +++ b/drivers/staging/goldfish/Makefile @@ -0,0 +1,5 @@ +# +# Makefile for the Goldfish audio driver +# + +obj-$(CONFIG_GOLDFISH_AUDIO) += goldfish_audio.o diff --git a/drivers/staging/goldfish/README b/drivers/staging/goldfish/README new file mode 100644 index 0000000..afa69bd --- /dev/null +++ b/drivers/staging/goldfish/README @@ -0,0 +1,2 @@ +- Move to using the ALSA framework not faking it +- Fix the wrong user page DMA (moving to ALSA may fix that too) diff --git a/drivers/staging/goldfish/goldfish_audio.c b/drivers/staging/goldfish/goldfish_audio.c new file mode 100644 index 0000000..d3bed21f --- /dev/null +++ b/drivers/staging/goldfish/goldfish_audio.c @@ -0,0 +1,363 @@ +/* drivers/misc/goldfish_audio.c + * + * Copyright (C) 2007 Google, Inc. + * Copyright (C) 2012 Intel, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MODULE_AUTHOR("Google, Inc."); +MODULE_DESCRIPTION("Android QEMU Audio Driver"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("1.0"); + +struct goldfish_audio { + char __iomem *reg_base; + int irq; + spinlock_t lock; + wait_queue_head_t wait; + + char __iomem *buffer_virt; /* combined buffer virtual address */ + unsigned long buffer_phys; /* combined buffer physical address */ + + char __iomem *write_buffer1; /* write buffer 1 virtual address */ + char __iomem *write_buffer2; /* write buffer 2 virtual address */ + char __iomem *read_buffer; /* read buffer virtual address */ + int buffer_status; + int read_supported; /* true if we have audio input support */ +}; + +/* We will allocate two read buffers and two write buffers. + Having two read buffers facilitate stereo -> mono conversion. + Having two write buffers facilitate interleaved IO. +*/ +#define READ_BUFFER_SIZE 16384 +#define WRITE_BUFFER_SIZE 16384 +#define COMBINED_BUFFER_SIZE ((2 * READ_BUFFER_SIZE) + \ + (2 * WRITE_BUFFER_SIZE)) + +#define AUDIO_READ(data, addr) (readl(data->reg_base + addr)) +#define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr)) + +/* temporary variable used between goldfish_audio_probe() and + goldfish_audio_open() */ +static struct goldfish_audio *audio_data; + +enum { + /* audio status register */ + AUDIO_INT_STATUS = 0x00, + /* set this to enable IRQ */ + AUDIO_INT_ENABLE = 0x04, + /* set these to specify buffer addresses */ + AUDIO_SET_WRITE_BUFFER_1 = 0x08, + AUDIO_SET_WRITE_BUFFER_2 = 0x0C, + /* set number of bytes in buffer to write */ + AUDIO_WRITE_BUFFER_1 = 0x10, + AUDIO_WRITE_BUFFER_2 = 0x14, + + /* true if audio input is supported */ + AUDIO_READ_SUPPORTED = 0x18, + /* buffer to use for audio input */ + AUDIO_SET_READ_BUFFER = 0x1C, + + /* driver writes number of bytes to read */ + AUDIO_START_READ = 0x20, + + /* number of bytes available in read buffer */ + AUDIO_READ_BUFFER_AVAILABLE = 0x24, + + /* AUDIO_INT_STATUS bits */ + + /* this bit set when it is safe to write more bytes to the buffer */ + AUDIO_INT_WRITE_BUFFER_1_EMPTY = 1U << 0, + AUDIO_INT_WRITE_BUFFER_2_EMPTY = 1U << 1, + AUDIO_INT_READ_BUFFER_FULL = 1U << 2, + + AUDIO_INT_MASK = AUDIO_INT_WRITE_BUFFER_1_EMPTY | + AUDIO_INT_WRITE_BUFFER_2_EMPTY | + AUDIO_INT_READ_BUFFER_FULL, +}; + + +static atomic_t open_count = ATOMIC_INIT(0); + + +static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, + size_t count, loff_t *pos) +{ + struct goldfish_audio *data = fp->private_data; + int length; + int result = 0; + + if (!data->read_supported) + return -ENODEV; + + while (count > 0) { + length = (count > READ_BUFFER_SIZE ? READ_BUFFER_SIZE : count); + AUDIO_WRITE(data, AUDIO_START_READ, length); + + wait_event_interruptible(data->wait, + (data->buffer_status & AUDIO_INT_READ_BUFFER_FULL)); + + length = AUDIO_READ(data, + AUDIO_READ_BUFFER_AVAILABLE); + + /* copy data to user space */ + if (copy_to_user(buf, data->read_buffer, length)) + return -EFAULT; + + result += length; + buf += length; + count -= length; + } + return result; +} + +static ssize_t goldfish_audio_write(struct file *fp, const char __user *buf, + size_t count, loff_t *pos) +{ + struct goldfish_audio *data = fp->private_data; + unsigned long irq_flags; + ssize_t result = 0; + char __iomem *kbuf; + + while (count > 0) { + ssize_t copy = count; + if (copy > WRITE_BUFFER_SIZE) + copy = WRITE_BUFFER_SIZE; + wait_event_interruptible(data->wait, (data->buffer_status & + (AUDIO_INT_WRITE_BUFFER_1_EMPTY | + AUDIO_INT_WRITE_BUFFER_2_EMPTY))); + + if ((data->buffer_status & AUDIO_INT_WRITE_BUFFER_1_EMPTY) != 0) + kbuf = data->write_buffer1; + else + kbuf = data->write_buffer2; + + /* copy from user space to the appropriate buffer */ + if (copy_from_user(kbuf, buf, copy)) { + result = -EFAULT; + break; + } + + spin_lock_irqsave(&data->lock, irq_flags); + /* clear the buffer empty flag, and signal the emulator + * to start writing the buffer */ + if (kbuf == data->write_buffer1) { + data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_1_EMPTY; + AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_1, copy); + } else { + data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_2_EMPTY; + AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_2, copy); + } + spin_unlock_irqrestore(&data->lock, irq_flags); + + buf += copy; + result += copy; + count -= copy; + } + return result; +} + +static int goldfish_audio_open(struct inode *ip, struct file *fp) +{ + if (!audio_data) + return -ENODEV; + + if (atomic_inc_return(&open_count) == 1) { + fp->private_data = audio_data; + audio_data->buffer_status = (AUDIO_INT_WRITE_BUFFER_1_EMPTY | + AUDIO_INT_WRITE_BUFFER_2_EMPTY); + AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, AUDIO_INT_MASK); + return 0; + } else { + atomic_dec(&open_count); + return -EBUSY; + } +} + +static int goldfish_audio_release(struct inode *ip, struct file *fp) +{ + atomic_dec(&open_count); + /* FIXME: surely this is wrong for the multi-opened case */ + AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, 0); + return 0; +} + +static long goldfish_audio_ioctl(struct file *fp, unsigned int cmd, + unsigned long arg) +{ + /* temporary workaround, until we switch to the ALSA API */ + if (cmd == 315) + return -1; + else + return 0; +} + +static irqreturn_t goldfish_audio_interrupt(int irq, void *dev_id) +{ + unsigned long irq_flags; + struct goldfish_audio *data = dev_id; + u32 status; + + spin_lock_irqsave(&data->lock, irq_flags); + + /* read buffer status flags */ + status = AUDIO_READ(data, AUDIO_INT_STATUS); + status &= AUDIO_INT_MASK; + /* if buffers are newly empty, wake up blocked + goldfish_audio_write() call */ + if (status) { + data->buffer_status = status; + wake_up(&data->wait); + } + + spin_unlock_irqrestore(&data->lock, irq_flags); + return status ? IRQ_HANDLED : IRQ_NONE; +} + +/* file operations for /dev/eac */ +static const struct file_operations goldfish_audio_fops = { + .owner = THIS_MODULE, + .read = goldfish_audio_read, + .write = goldfish_audio_write, + .open = goldfish_audio_open, + .release = goldfish_audio_release, + .unlocked_ioctl = goldfish_audio_ioctl, +}; + +static struct miscdevice goldfish_audio_device = { + .minor = MISC_DYNAMIC_MINOR, + .name = "eac", + .fops = &goldfish_audio_fops, +}; + +static int goldfish_audio_probe(struct platform_device *pdev) +{ + int ret; + struct resource *r; + struct goldfish_audio *data; + dma_addr_t buf_addr; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (data == NULL) { + ret = -ENOMEM; + goto err_data_alloc_failed; + } + spin_lock_init(&data->lock); + init_waitqueue_head(&data->wait); + platform_set_drvdata(pdev, data); + + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (r == NULL) { + dev_err(&pdev->dev, "platform_get_resource failed\n"); + ret = -ENODEV; + goto err_no_io_base; + } + data->reg_base = ioremap(r->start, PAGE_SIZE); + if (data->reg_base == NULL) { + ret = -ENOMEM; + goto err_no_io_base; + } + + data->irq = platform_get_irq(pdev, 0); + if (data->irq < 0) { + dev_err(&pdev->dev, "platform_get_irq failed\n"); + ret = -ENODEV; + goto err_no_irq; + } + data->buffer_virt = dma_alloc_coherent(&pdev->dev, + COMBINED_BUFFER_SIZE, &buf_addr, GFP_KERNEL); + if (data->buffer_virt == 0) { + ret = -ENOMEM; + dev_err(&pdev->dev, "allocate buffer failed\n"); + goto err_alloc_write_buffer_failed; + } + data->buffer_phys = buf_addr; + data->write_buffer1 = data->buffer_virt; + data->write_buffer2 = data->buffer_virt + WRITE_BUFFER_SIZE; + data->read_buffer = data->buffer_virt + 2 * WRITE_BUFFER_SIZE; + + ret = request_irq(data->irq, goldfish_audio_interrupt, + IRQF_SHARED, pdev->name, data); + if (ret) { + dev_err(&pdev->dev, "request_irq failed\n"); + goto err_request_irq_failed; + } + + ret = misc_register(&goldfish_audio_device); + if (ret) { + dev_err(&pdev->dev, + "misc_register returned %d in goldfish_audio_init\n", + ret); + goto err_misc_register_failed; + } + + AUDIO_WRITE(data, AUDIO_SET_WRITE_BUFFER_1, buf_addr); + AUDIO_WRITE(data, AUDIO_SET_WRITE_BUFFER_2, + buf_addr + WRITE_BUFFER_SIZE); + + data->read_supported = AUDIO_READ(data, AUDIO_READ_SUPPORTED); + if (data->read_supported) + AUDIO_WRITE(data, AUDIO_SET_READ_BUFFER, + buf_addr + 2 * WRITE_BUFFER_SIZE); + + audio_data = data; + return 0; + +err_misc_register_failed: +err_request_irq_failed: + dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE, + data->buffer_virt, data->buffer_phys); +err_alloc_write_buffer_failed: +err_no_irq: + iounmap(data->reg_base); +err_no_io_base: + kfree(data); +err_data_alloc_failed: + return ret; +} + +static int goldfish_audio_remove(struct platform_device *pdev) +{ + struct goldfish_audio *data = platform_get_drvdata(pdev); + + misc_deregister(&goldfish_audio_device); + free_irq(data->irq, data); + dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE, + data->buffer_virt, data->buffer_phys); + iounmap(data->reg_base); + kfree(data); + audio_data = NULL; + return 0; +} + +static struct platform_driver goldfish_audio_driver = { + .probe = goldfish_audio_probe, + .remove = goldfish_audio_remove, + .driver = { + .name = "goldfish_audio" + } +}; + +module_platform_driver(goldfish_audio_driver); -- cgit v0.10.2 From 8e404fffeac7d3985b193edbf860d9d73dec5b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= Date: Thu, 24 Jan 2013 17:50:00 +0000 Subject: goldfish: NAND flash driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fold together the NAND driver for Goldfish from Arve with cleanups by Jun Nakajima and a tidy up to 3.7 and checkpatch. This provides a virtual flash driver for the Goldfish Android Virtual Platform, and which is normally used as the root file system when testing emulated devices. Signed-off-by: Mike A. Chan Signed-off-by: Arve HjønnevÃ¥g [Ported to handle x86] Signed-off-by: Sheng Yang Signed-off-by: Yunhong Jiang Signed-off-by: Xiaohui Xin Signed-off-by: Jun Nakajima Signed-off-by: Bruce Beare [Ported to 3.4] Signed-off-by: Tom Keel [Ported to 3.7 and tided for checkpatch etc] Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/goldfish/Kconfig b/drivers/staging/goldfish/Kconfig index 1a3e576..d6c98d0 100644 --- a/drivers/staging/goldfish/Kconfig +++ b/drivers/staging/goldfish/Kconfig @@ -4,3 +4,9 @@ config GOLDFISH_AUDIO ---help--- Emulated audio channel for the Goldfish Android Virtual Device +config MTD_GOLDFISH_NAND + tristate "Goldfish NAND device" + depends on GOLDFISH + help + Drives the emulated NAND flash device on the Google Goldfish + Android virtual device. diff --git a/drivers/staging/goldfish/Makefile b/drivers/staging/goldfish/Makefile index 054eeb8..dec34ad 100644 --- a/drivers/staging/goldfish/Makefile +++ b/drivers/staging/goldfish/Makefile @@ -3,3 +3,4 @@ # obj-$(CONFIG_GOLDFISH_AUDIO) += goldfish_audio.o +obj-$(CONFIG_MTD_GOLDFISH_NAND) += goldfish_nand.o diff --git a/drivers/staging/goldfish/README b/drivers/staging/goldfish/README index afa69bd..93d65b0 100644 --- a/drivers/staging/goldfish/README +++ b/drivers/staging/goldfish/README @@ -1,2 +1,12 @@ +Audio +----- - Move to using the ALSA framework not faking it - Fix the wrong user page DMA (moving to ALSA may fix that too) + +NAND +---- +- Switch from spinlock to mutex +- Remove excess checking of parameters in calls +- Use dma coherent memory not kmalloc/__pa for the memory (this is just + a cleanliness issue not a correctness one) + diff --git a/drivers/staging/goldfish/goldfish_nand.c b/drivers/staging/goldfish/goldfish_nand.c new file mode 100644 index 0000000..1891d89 --- /dev/null +++ b/drivers/staging/goldfish/goldfish_nand.c @@ -0,0 +1,444 @@ +/* + * drivers/mtd/devices/goldfish_nand.c + * + * Copyright (C) 2007 Google, Inc. + * Copyright (C) 2012 Intel, Inc. + * Copyright (C) 2013 Intel, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "goldfish_nand_reg.h" + +struct goldfish_nand { + spinlock_t lock; + unsigned char __iomem *base; + struct cmd_params *cmd_params; + size_t mtd_count; + struct mtd_info mtd[0]; +}; + +static u32 goldfish_nand_cmd_with_params(struct mtd_info *mtd, + enum nand_cmd cmd, u64 addr, u32 len, + void *ptr, u32 *rv) +{ + u32 cmdp; + struct goldfish_nand *nand = mtd->priv; + struct cmd_params *cps = nand->cmd_params; + unsigned char __iomem *base = nand->base; + + if (cps == NULL) + return -1; + + switch (cmd) { + case NAND_CMD_ERASE: + cmdp = NAND_CMD_ERASE_WITH_PARAMS; + break; + case NAND_CMD_READ: + cmdp = NAND_CMD_READ_WITH_PARAMS; + break; + case NAND_CMD_WRITE: + cmdp = NAND_CMD_WRITE_WITH_PARAMS; + break; + default: + return -1; + } + cps->dev = mtd - nand->mtd; + cps->addr_high = (u32)(addr >> 32); + cps->addr_low = (u32)addr; + cps->transfer_size = len; + cps->data = (u32)ptr; + writel(cmdp, base + NAND_COMMAND); + *rv = cps->result; + return 0; +} + +static u32 goldfish_nand_cmd(struct mtd_info *mtd, enum nand_cmd cmd, + u64 addr, u32 len, void *ptr) +{ + struct goldfish_nand *nand = mtd->priv; + u32 rv; + unsigned long irq_flags; + unsigned char __iomem *base = nand->base; + + spin_lock_irqsave(&nand->lock, irq_flags); + if (goldfish_nand_cmd_with_params(mtd, cmd, addr, len, ptr, &rv)) { + writel(mtd - nand->mtd, base + NAND_DEV); + writel((u32)(addr >> 32), base + NAND_ADDR_HIGH); + writel((u32)addr, base + NAND_ADDR_LOW); + writel(len, base + NAND_TRANSFER_SIZE); + writel((u32)ptr, base + NAND_DATA); + writel(cmd, base + NAND_COMMAND); + rv = readl(base + NAND_RESULT); + } + spin_unlock_irqrestore(&nand->lock, irq_flags); + return rv; +} + +static int goldfish_nand_erase(struct mtd_info *mtd, struct erase_info *instr) +{ + loff_t ofs = instr->addr; + u32 len = instr->len; + u32 rem; + + if (ofs + len > mtd->size) + goto invalid_arg; + rem = do_div(ofs, mtd->writesize); + if (rem) + goto invalid_arg; + ofs *= (mtd->writesize + mtd->oobsize); + + if (len % mtd->writesize) + goto invalid_arg; + len = len / mtd->writesize * (mtd->writesize + mtd->oobsize); + + if (goldfish_nand_cmd(mtd, NAND_CMD_ERASE, ofs, len, NULL) != len) { + pr_err("goldfish_nand_erase: erase failed, start %llx, len %x, dev_size %llx, erase_size %x\n", + ofs, len, mtd->size, mtd->erasesize); + return -EIO; + } + + instr->state = MTD_ERASE_DONE; + mtd_erase_callback(instr); + + return 0; + +invalid_arg: + pr_err("goldfish_nand_erase: invalid erase, start %llx, len %x, dev_size %llx, erase_size %x\n", + ofs, len, mtd->size, mtd->erasesize); + return -EINVAL; +} + +static int goldfish_nand_read_oob(struct mtd_info *mtd, loff_t ofs, + struct mtd_oob_ops *ops) +{ + u32 rem; + + if (ofs + ops->len > mtd->size) + goto invalid_arg; + if (ops->datbuf && ops->len && ops->len != mtd->writesize) + goto invalid_arg; + if (ops->ooblen + ops->ooboffs > mtd->oobsize) + goto invalid_arg; + + rem = do_div(ofs, mtd->writesize); + if (rem) + goto invalid_arg; + ofs *= (mtd->writesize + mtd->oobsize); + + if (ops->datbuf) + ops->retlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, ofs, + ops->len, ops->datbuf); + ofs += mtd->writesize + ops->ooboffs; + if (ops->oobbuf) + ops->oobretlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, ofs, + ops->ooblen, ops->oobbuf); + return 0; + +invalid_arg: + pr_err("goldfish_nand_read_oob: invalid read, start %llx, len %x, ooblen %x, dev_size %llx, write_size %x\n", + ofs, ops->len, ops->ooblen, mtd->size, mtd->writesize); + return -EINVAL; +} + +static int goldfish_nand_write_oob(struct mtd_info *mtd, loff_t ofs, + struct mtd_oob_ops *ops) +{ + u32 rem; + + if (ofs + ops->len > mtd->size) + goto invalid_arg; + if (ops->len && ops->len != mtd->writesize) + goto invalid_arg; + if (ops->ooblen + ops->ooboffs > mtd->oobsize) + goto invalid_arg; + + rem = do_div(ofs, mtd->writesize); + if (rem) + goto invalid_arg; + ofs *= (mtd->writesize + mtd->oobsize); + + if (ops->datbuf) + ops->retlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, ofs, + ops->len, ops->datbuf); + ofs += mtd->writesize + ops->ooboffs; + if (ops->oobbuf) + ops->oobretlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, ofs, + ops->ooblen, ops->oobbuf); + return 0; + +invalid_arg: + pr_err("goldfish_nand_write_oob: invalid write, start %llx, len %x, ooblen %x, dev_size %llx, write_size %x\n", + ofs, ops->len, ops->ooblen, mtd->size, mtd->writesize); + return -EINVAL; +} + +static int goldfish_nand_read(struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, u_char *buf) +{ + u32 rem; + + if (from + len > mtd->size) + goto invalid_arg; + if (len != mtd->writesize) + goto invalid_arg; + + rem = do_div(from, mtd->writesize); + if (rem) + goto invalid_arg; + from *= (mtd->writesize + mtd->oobsize); + + *retlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, from, len, buf); + return 0; + +invalid_arg: + pr_err("goldfish_nand_read: invalid read, start %llx, len %x, dev_size %llx, write_size %x\n", + from, len, mtd->size, mtd->writesize); + return -EINVAL; +} + +static int goldfish_nand_write(struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u_char *buf) +{ + u32 rem; + + if (to + len > mtd->size) + goto invalid_arg; + if (len != mtd->writesize) + goto invalid_arg; + + rem = do_div(to, mtd->writesize); + if (rem) + goto invalid_arg; + to *= (mtd->writesize + mtd->oobsize); + + *retlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, to, len, (void *)buf); + return 0; + +invalid_arg: + pr_err("goldfish_nand_write: invalid write, start %llx, len %x, dev_size %llx, write_size %x\n", + to, len, mtd->size, mtd->writesize); + return -EINVAL; +} + +static int goldfish_nand_block_isbad(struct mtd_info *mtd, loff_t ofs) +{ + u32 rem; + + if (ofs >= mtd->size) + goto invalid_arg; + + rem = do_div(ofs, mtd->erasesize); + if (rem) + goto invalid_arg; + ofs *= mtd->erasesize / mtd->writesize; + ofs *= (mtd->writesize + mtd->oobsize); + + return goldfish_nand_cmd(mtd, NAND_CMD_BLOCK_BAD_GET, ofs, 0, NULL); + +invalid_arg: + pr_err("goldfish_nand_block_isbad: invalid arg, ofs %llx, dev_size %llx, write_size %x\n", + ofs, mtd->size, mtd->writesize); + return -EINVAL; +} + +static int goldfish_nand_block_markbad(struct mtd_info *mtd, loff_t ofs) +{ + u32 rem; + + if (ofs >= mtd->size) + goto invalid_arg; + + rem = do_div(ofs, mtd->erasesize); + if (rem) + goto invalid_arg; + ofs *= mtd->erasesize / mtd->writesize; + ofs *= (mtd->writesize + mtd->oobsize); + + if (goldfish_nand_cmd(mtd, NAND_CMD_BLOCK_BAD_SET, ofs, 0, NULL) != 1) + return -EIO; + return 0; + +invalid_arg: + pr_err("goldfish_nand_block_markbad: invalid arg, ofs %llx, dev_size %llx, write_size %x\n", + ofs, mtd->size, mtd->writesize); + return -EINVAL; +} + +static int nand_setup_cmd_params(struct platform_device *pdev, + struct goldfish_nand *nand) +{ + u64 paddr; + unsigned char __iomem *base = nand->base; + + nand->cmd_params = devm_kzalloc(&pdev->dev, + sizeof(struct cmd_params), GFP_KERNEL); + if (!nand->cmd_params) + return -1; + + paddr = __pa(nand->cmd_params); + writel((u32)(paddr >> 32), base + NAND_CMD_PARAMS_ADDR_HIGH); + writel((u32)paddr, base + NAND_CMD_PARAMS_ADDR_LOW); + return 0; +} + +static int goldfish_nand_init_device(struct platform_device *pdev, + struct goldfish_nand *nand, int id) +{ + u32 name_len; + u32 result; + u32 flags; + unsigned long irq_flags; + unsigned char __iomem *base = nand->base; + struct mtd_info *mtd = &nand->mtd[id]; + char *name; + + spin_lock_irqsave(&nand->lock, irq_flags); + writel(id, base + NAND_DEV); + flags = readl(base + NAND_DEV_FLAGS); + name_len = readl(base + NAND_DEV_NAME_LEN); + mtd->writesize = readl(base + NAND_DEV_PAGE_SIZE); + mtd->size = readl(base + NAND_DEV_SIZE_LOW); + mtd->size |= (u64)readl(base + NAND_DEV_SIZE_HIGH) << 32; + mtd->oobsize = readl(base + NAND_DEV_EXTRA_SIZE); + mtd->oobavail = mtd->oobsize; + mtd->erasesize = readl(base + NAND_DEV_ERASE_SIZE) / + (mtd->writesize + mtd->oobsize) * mtd->writesize; + do_div(mtd->size, mtd->writesize + mtd->oobsize); + mtd->size *= mtd->writesize; + dev_dbg(&pdev->dev, + "goldfish nand dev%d: size %llx, page %d, extra %d, erase %d\n", + id, mtd->size, mtd->writesize, mtd->oobsize, mtd->erasesize); + spin_unlock_irqrestore(&nand->lock, irq_flags); + + mtd->priv = nand; + + mtd->name = name = devm_kzalloc(&pdev->dev, name_len + 1, GFP_KERNEL); + if (name == NULL) + return -ENOMEM; + + result = goldfish_nand_cmd(mtd, NAND_CMD_GET_DEV_NAME, 0, name_len, + name); + if (result != name_len) { + dev_err(&pdev->dev, + "goldfish_nand_init_device failed to get dev name %d != %d\n", + result, name_len); + return -ENODEV; + } + ((char *) mtd->name)[name_len] = '\0'; + + /* Setup the MTD structure */ + mtd->type = MTD_NANDFLASH; + mtd->flags = MTD_CAP_NANDFLASH; + if (flags & NAND_DEV_FLAG_READ_ONLY) + mtd->flags &= ~MTD_WRITEABLE; + if (flags & NAND_DEV_FLAG_CMD_PARAMS_CAP) + nand_setup_cmd_params(pdev, nand); + + mtd->owner = THIS_MODULE; + mtd->_erase = goldfish_nand_erase; + mtd->_read = goldfish_nand_read; + mtd->_write = goldfish_nand_write; + mtd->_read_oob = goldfish_nand_read_oob; + mtd->_write_oob = goldfish_nand_write_oob; + mtd->_block_isbad = goldfish_nand_block_isbad; + mtd->_block_markbad = goldfish_nand_block_markbad; + + if (mtd_device_register(mtd, NULL, 0)) + return -EIO; + + return 0; +} + +static int goldfish_nand_probe(struct platform_device *pdev) +{ + u32 num_dev; + int i; + int err; + u32 num_dev_working; + u32 version; + struct resource *r; + struct goldfish_nand *nand; + unsigned char __iomem *base; + + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (r == NULL) + return -ENODEV; + + base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); + if (base == NULL) + return -ENOMEM; + + version = readl(base + NAND_VERSION); + if (version != NAND_VERSION_CURRENT) { + dev_err(&pdev->dev, + "goldfish_nand_init: version mismatch, got %d, expected %d\n", + version, NAND_VERSION_CURRENT); + return -ENODEV; + } + num_dev = readl(base + NAND_NUM_DEV); + if (num_dev == 0) + return -ENODEV; + + nand = devm_kzalloc(&pdev->dev, sizeof(*nand) + + sizeof(struct mtd_info) * num_dev, GFP_KERNEL); + if (nand == NULL) + return -ENOMEM; + + spin_lock_init(&nand->lock); + nand->base = base; + nand->mtd_count = num_dev; + platform_set_drvdata(pdev, nand); + + num_dev_working = 0; + for (i = 0; i < num_dev; i++) { + err = goldfish_nand_init_device(pdev, nand, i); + if (err == 0) + num_dev_working++; + } + if (num_dev_working == 0) + return -ENODEV; + return 0; +} + +static int goldfish_nand_remove(struct platform_device *pdev) +{ + struct goldfish_nand *nand = platform_get_drvdata(pdev); + int i; + for (i = 0; i < nand->mtd_count; i++) { + if (nand->mtd[i].name) + mtd_device_unregister(&nand->mtd[i]); + } + return 0; +} + +static struct platform_driver goldfish_nand_driver = { + .probe = goldfish_nand_probe, + .remove = goldfish_nand_remove, + .driver = { + .name = "goldfish_nand" + } +}; + +module_platform_driver(goldfish_nand_driver); +MODULE_LICENSE("GPL"); diff --git a/drivers/staging/goldfish/goldfish_nand_reg.h b/drivers/staging/goldfish/goldfish_nand_reg.h new file mode 100644 index 0000000..956c6c3 --- /dev/null +++ b/drivers/staging/goldfish/goldfish_nand_reg.h @@ -0,0 +1,72 @@ +/* drivers/mtd/devices/goldfish_nand_reg.h +** +** Copyright (C) 2007 Google, Inc. +** +** This software is licensed under the terms of the GNU General Public +** License version 2, as published by the Free Software Foundation, and +** may be copied, distributed, and modified under those terms. +** +** 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. +** +*/ + +#ifndef GOLDFISH_NAND_REG_H +#define GOLDFISH_NAND_REG_H + +enum nand_cmd { + NAND_CMD_GET_DEV_NAME, /* Write device name for NAND_DEV to NAND_DATA (vaddr) */ + NAND_CMD_READ, + NAND_CMD_WRITE, + NAND_CMD_ERASE, + NAND_CMD_BLOCK_BAD_GET, /* NAND_RESULT is 1 if block is bad, 0 if it is not */ + NAND_CMD_BLOCK_BAD_SET, + NAND_CMD_READ_WITH_PARAMS, + NAND_CMD_WRITE_WITH_PARAMS, + NAND_CMD_ERASE_WITH_PARAMS +}; + +enum nand_dev_flags { + NAND_DEV_FLAG_READ_ONLY = 0x00000001, + NAND_DEV_FLAG_CMD_PARAMS_CAP = 0x00000002, +}; + +#define NAND_VERSION_CURRENT (1) + +enum nand_reg { + /* Global */ + NAND_VERSION = 0x000, + NAND_NUM_DEV = 0x004, + NAND_DEV = 0x008, + + /* Dev info */ + NAND_DEV_FLAGS = 0x010, + NAND_DEV_NAME_LEN = 0x014, + NAND_DEV_PAGE_SIZE = 0x018, + NAND_DEV_EXTRA_SIZE = 0x01c, + NAND_DEV_ERASE_SIZE = 0x020, + NAND_DEV_SIZE_LOW = 0x028, + NAND_DEV_SIZE_HIGH = 0x02c, + + /* Command */ + NAND_RESULT = 0x040, + NAND_COMMAND = 0x044, + NAND_DATA = 0x048, + NAND_TRANSFER_SIZE = 0x04c, + NAND_ADDR_LOW = 0x050, + NAND_ADDR_HIGH = 0x054, + NAND_CMD_PARAMS_ADDR_LOW = 0x058, + NAND_CMD_PARAMS_ADDR_HIGH = 0x05c, +}; + +struct cmd_params { + uint32_t dev; + uint32_t addr_low; + uint32_t addr_high; + uint32_t transfer_size; + uint32_t data; + uint32_t result; +}; +#endif -- cgit v0.10.2 From d61ac98a4bd86b3217f0c6e058bd0b3a3282899b Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Tue, 22 Jan 2013 20:12:34 +0000 Subject: staging: vt6656: revert : 64 bit- Correctly address void structure. The patch is wrong and is partially reverted. The NULL check of pTransmitKey->pvKeyTable is kept. The problem was ultimately fixed by upstream commit. 1ee4c55fc9620451b2a825d793042a7e0775391b staging: vt6656: Fix inconsistent structure packing Reported-by: Ben Hutchings Signed-off-by: Malcolm Priestley Cc: stable@vger.kernel.org # 3.8 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index 536d314..92343f2 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -1232,7 +1232,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; if (bNeedEncryption && pTransmitKey->pvKeyTable) { - if (((PSKeyTable)&pTransmitKey->pvKeyTable)->bSoftWEP == TRUE) + if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == TRUE) bSoftWEP = TRUE; /* WEP 256 */ } -- cgit v0.10.2 From 392c6ff87f568d573239b763855160d1f06114de Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Tue, 22 Jan 2013 20:13:34 +0000 Subject: staging: vt6656: Revert: 64bit fixes: dpc.c incorrect addressing of void structure. The patch was totally wrong and is reverted. The problem was ultimately fixed by upstream commit. 1ee4c55fc9620451b2a825d793042a7e0775391b staging: vt6656: Fix inconsistent structure packing Reported-by: Ben Hutchings Signed-off-by: Malcolm Priestley Cc: stable@vger.kernel.org # 3.8 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index 6c98172..208be2c 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -1116,7 +1116,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, if (byDecMode == KEY_CTL_WEP) { // handle WEP if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || - (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE)) { + (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE)) { // Software WEP // 1. 3253A // 2. WEP 256 @@ -1213,7 +1213,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, // handle WEP DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n"); if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || - (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE) || + (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE) || (bOnFly == FALSE)) { // Software WEP // 1. 3253A -- cgit v0.10.2 From 96a8d14e875a017f9e9e71d93433414e9fb8863f Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 24 Jan 2013 09:41:43 +0300 Subject: staging: cxt1e1: buffer overflow in do_del_chan() If we don't restrict "cp.channum" to 3 digits then the sprintf() will overflow. I've added a check and changed the sprintf() to snprintf(). Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c index 0ff2865..a829b62 100644 --- a/drivers/staging/cxt1e1/linux.c +++ b/drivers/staging/cxt1e1/linux.c @@ -773,7 +773,9 @@ do_del_chan (struct net_device * musycc_dev, void *data) if (copy_from_user (&cp, data, sizeof (struct sbecom_chan_param))) return -EFAULT; - sprintf (buf, CHANNAME "%d", cp.channum); + if (cp.channum > 999) + return -EINVAL; + snprintf (buf, sizeof(buf), CHANNAME "%d", cp.channum); if (!(dev = dev_get_by_name (&init_net, buf))) return -ENOENT; dev_put (dev); -- cgit v0.10.2 From 8edca3fe9efb43ba41e22f182546e874227b92cb Mon Sep 17 00:00:00 2001 From: Chris Kelly Date: Thu, 24 Jan 2013 16:00:02 +0000 Subject: staging:ozwpan: Removed myself (Chris Kelly) as maintainer. Removed myself (ckelly@ozmodevices.com) as maintainer of ozwpan. Removed my email address from the TODO file. Signed-off-by: Greg Kroah-Hartman diff --git a/MAINTAINERS b/MAINTAINERS index fa309ab..49afc49 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7249,7 +7249,6 @@ F: drivers/staging/olpc_dcon/ STAGING - OZMO DEVICES USB OVER WIFI DRIVER M: Rupesh Gujare -M: Chris Kelly S: Maintained F: drivers/staging/ozwpan/ diff --git a/drivers/staging/ozwpan/TODO b/drivers/staging/ozwpan/TODO index b5db245..c71bd83 100644 --- a/drivers/staging/ozwpan/TODO +++ b/drivers/staging/ozwpan/TODO @@ -11,5 +11,4 @@ TODO: Please send any patches for this driver to Rupesh Gujare -Chris Kelly and Greg Kroah-Hartman . -- cgit v0.10.2 From c4048c641ad7769e4197ff114eaab01f4662cbca Mon Sep 17 00:00:00 2001 From: Rupesh Gujare Date: Thu, 24 Jan 2013 18:14:51 +0000 Subject: staging:ozwpan: Change email address. As part of transition caused due to acquisition of Ozmo Devices by Atmel, my email address is changed. Signed-off-by: Rupesh Gujare Signed-off-by: Greg Kroah-Hartman diff --git a/MAINTAINERS b/MAINTAINERS index 49afc49..3603fd3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7248,7 +7248,7 @@ S: Odd Fixes F: drivers/staging/olpc_dcon/ STAGING - OZMO DEVICES USB OVER WIFI DRIVER -M: Rupesh Gujare +M: Rupesh Gujare S: Maintained F: drivers/staging/ozwpan/ diff --git a/drivers/staging/ozwpan/TODO b/drivers/staging/ozwpan/TODO index c71bd83..b4febd7 100644 --- a/drivers/staging/ozwpan/TODO +++ b/drivers/staging/ozwpan/TODO @@ -10,5 +10,5 @@ TODO: - testing with as many devices as possible. Please send any patches for this driver to -Rupesh Gujare +Rupesh Gujare and Greg Kroah-Hartman . -- cgit v0.10.2 From e49ee36d2477e405da1fe0e6efbf4c122df3b300 Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Wed, 23 Jan 2013 13:46:30 -0800 Subject: staging: zcache: fix ppc64 and other arches where PAGE_SIZE!=4K Replace raw constant 12 with PAGE_SHIFT to fix non-x86 arches and provoke build failure if PAGE_SHIFT is too big Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zbud.c b/drivers/staging/zcache/zbud.c index a7c4361..6835fab 100644 --- a/drivers/staging/zcache/zbud.c +++ b/drivers/staging/zcache/zbud.c @@ -103,8 +103,8 @@ struct zbudpage { struct { unsigned long space_for_flags; struct { - unsigned zbud0_size:12; - unsigned zbud1_size:12; + unsigned zbud0_size: PAGE_SHIFT; + unsigned zbud1_size: PAGE_SHIFT; unsigned unevictable:2; }; struct list_head budlist; @@ -112,6 +112,9 @@ struct zbudpage { }; }; }; +#if (PAGE_SHIFT * 2) + 2 > BITS_PER_LONG +#error "zbud won't work for this arch, PAGE_SIZE is too large" +#endif struct zbudref { union { -- cgit v0.10.2 From ae59ecfd3ff45833c23913877d8c8d94eeb930d0 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 22 Jan 2013 21:07:32 +0100 Subject: staging/comedi: use comedi_usb_driver_(un)register for init/deinit Instead of coding calling comedi_driver_(un)register and usb_(de)register directly we can use the comedi_usb_driver_(un)register wrapper. This removes some boilerplate and is less error prone. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index 1767998..fc5b30c 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -1133,7 +1133,7 @@ static struct comedi_driver dt9812_comedi_driver = { static int __init usb_dt9812_init(void) { - int result, i; + int i; /* Initialize all driver slots */ for (i = 0; i < DT9812_NUM_SLOTS; i++) { @@ -1144,30 +1144,13 @@ static int __init usb_dt9812_init(void) } dt9812[12].serial = 0x0; - /* register with the USB subsystem */ - result = usb_register(&dt9812_usb_driver); - if (result) { - pr_err("usb_register failed. Error number %d\n", result); - return result; - } - /* register with comedi */ - result = comedi_driver_register(&dt9812_comedi_driver); - if (result) { - usb_deregister(&dt9812_usb_driver); - pr_err("comedi_driver_register failed. Error number %d\n", - result); - } - - return result; + return comedi_usb_driver_register(&dt9812_comedi_driver, + &dt9812_usb_driver); } static void __exit usb_dt9812_exit(void) { - /* unregister with comedi */ - comedi_driver_unregister(&dt9812_comedi_driver); - - /* deregister this driver with the USB subsystem */ - usb_deregister(&dt9812_usb_driver); + comedi_usb_driver_unregister(&dt9812_comedi_driver, &dt9812_usb_driver); } module_init(usb_dt9812_init); -- cgit v0.10.2 From 8861b456b8f800208e043b2d0d65985eca538dd9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:35:51 -0700 Subject: staging: comedi: addi_apci_3501: separate from addi_common.c This driver is for a simple analog output board with 4 or 8, 14-bit outputs. The board also has 4 digital i/o channels (2 out/2 in) as well as a watchdog or timer. Using the addi-data "common" code in this driver introduces a lot of bloat. Copy the code in addi_common.c to this driver and remove the #include that caused it to be compiled with the driver. This will allow removing the bloat. Rename the auto_attach and detach functions so they have namespace associated with this driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index ed297de..e2ea542 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -4,9 +4,12 @@ #include "addi-data/addi_common.h" +#ifndef COMEDI_SUBD_TTLIO +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#endif + #include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci3501.c" -#include "addi-data/addi_common.c" static const struct addi_board apci3501_boardtypes[] = { { @@ -35,17 +38,316 @@ static const struct addi_board apci3501_boardtypes[] = { }, }; -static DEFINE_PCI_DEVICE_TABLE(apci3501_pci_table) = { - { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3001) }, - { 0 } -}; -MODULE_DEVICE_TABLE(pci, apci3501_pci_table); +static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + const struct addi_board *this_board = comedi_board(dev); + struct addi_private *devpriv = dev->private; + unsigned short w_Address = CR_CHAN(insn->chanspec); + unsigned short w_Data; + + w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc, + this_board->pc_EepromChip, 2 * w_Address); + data[0] = w_Data; + + return insn->n; +} + +static irqreturn_t v_ADDI_Interrupt(int irq, void *d) +{ + struct comedi_device *dev = d; + const struct addi_board *this_board = comedi_board(dev); + + this_board->interrupt(irq, d); + return IRQ_RETVAL(1); +} + +static int i_ADDI_Reset(struct comedi_device *dev) +{ + const struct addi_board *this_board = comedi_board(dev); + + this_board->reset(dev); + return 0; +} + +static const void *addi_find_boardinfo(struct comedi_device *dev, + struct pci_dev *pcidev) +{ + const void *p = dev->driver->board_name; + const struct addi_board *this_board; + int i; + + for (i = 0; i < dev->driver->num_names; i++) { + this_board = p; + if (this_board->i_VendorId == pcidev->vendor && + this_board->i_DeviceId == pcidev->device) + return this_board; + p += dev->driver->offset; + } + return NULL; +} + +static int apci3501_auto_attach(struct comedi_device *dev, + unsigned long context_unused) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + const struct addi_board *this_board; + struct addi_private *devpriv; + struct comedi_subdevice *s; + int ret, n_subdevices; + unsigned int dw_Dummy; + + this_board = addi_find_boardinfo(dev, pcidev); + if (!this_board) + return -ENODEV; + dev->board_ptr = this_board; + dev->board_name = this_board->pc_DriverName; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + ret = comedi_pci_enable(pcidev, dev->board_name); + if (ret) + return ret; + + if (!this_board->pc_EepromChip || + strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { + /* board does not have an eeprom or is not ADDIDATA_9054 */ + if (this_board->i_IorangeBase1) + dev->iobase = pci_resource_start(pcidev, 1); + else + dev->iobase = pci_resource_start(pcidev, 0); + + devpriv->iobase = dev->iobase; + devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); + devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); + } else { + /* board has an ADDIDATA_9054 eeprom */ + dev->iobase = pci_resource_start(pcidev, 2); + devpriv->iobase = pci_resource_start(pcidev, 2); + devpriv->dw_AiBase = ioremap(pci_resource_start(pcidev, 3), + this_board->i_IorangeBase3); + } + devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); + + /* Initialize parameters that can be overridden in EEPROM */ + devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; + devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; + devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; + devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; + devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; + devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; + devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; + devpriv->s_EeParameters.i_Dma = this_board->i_Dma; + devpriv->s_EeParameters.i_Timer = this_board->i_Timer; + devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = + this_board->ui_MinAcquisitiontimeNs; + devpriv->s_EeParameters.ui_MinDelaytimeNs = + this_board->ui_MinDelaytimeNs; + + /* ## */ + + if (pcidev->irq > 0) { + ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, + dev->board_name, dev); + if (ret == 0) + dev->irq = pcidev->irq; + } + + /* Read eepeom and fill addi_board Structure */ + + if (this_board->i_PCIEeprom) { + if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { + /* Set 3 wait stait */ + if (!(strcmp(dev->board_name, "apci035"))) + outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); + else + outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); + + /* Enable the interrupt for the controller */ + dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); + outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); + } + addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); + } + + n_subdevices = 7; + ret = comedi_alloc_subdevices(dev, n_subdevices); + if (ret) + return ret; + + /* Allocate and Initialise AI Subdevice Structures */ + s = &dev->subdevices[0]; + if ((devpriv->s_EeParameters.i_NbrAiChannel) + || (this_board->i_NbrAiChannelDiff)) { + dev->read_subdev = s; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_COMMON | SDF_GROUND + | SDF_DIFF; + if (devpriv->s_EeParameters.i_NbrAiChannel) { + s->n_chan = + devpriv->s_EeParameters.i_NbrAiChannel; + devpriv->b_SingelDiff = 0; + } else { + s->n_chan = this_board->i_NbrAiChannelDiff; + devpriv->b_SingelDiff = 1; + } + s->maxdata = devpriv->s_EeParameters.i_AiMaxdata; + s->len_chanlist = this_board->i_AiChannelList; + s->range_table = this_board->pr_AiRangelist; + + /* Set the initialisation flag */ + devpriv->b_AiInitialisation = 1; + + s->insn_config = this_board->ai_config; + s->insn_read = this_board->ai_read; + s->insn_write = this_board->ai_write; + s->insn_bits = this_board->ai_bits; + s->do_cmdtest = this_board->ai_cmdtest; + s->do_cmd = this_board->ai_cmd; + s->cancel = this_board->ai_cancel; + + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise AO Subdevice Structures */ + s = &dev->subdevices[1]; + if (devpriv->s_EeParameters.i_NbrAoChannel) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; + s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrAoChannel; + s->range_table = this_board->pr_AoRangelist; + s->insn_config = this_board->ao_config; + s->insn_write = this_board->ao_write; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + /* Allocate and Initialise DI Subdevice Structures */ + s = &dev->subdevices[2]; + if (devpriv->s_EeParameters.i_NbrDiChannel) { + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel; + s->maxdata = 1; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrDiChannel; + s->range_table = &range_digital; + s->io_bits = 0; /* all bits input */ + s->insn_config = this_board->di_config; + s->insn_read = this_board->di_read; + s->insn_write = this_board->di_write; + s->insn_bits = this_board->di_bits; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + /* Allocate and Initialise DO Subdevice Structures */ + s = &dev->subdevices[3]; + if (devpriv->s_EeParameters.i_NbrDoChannel) { + s->type = COMEDI_SUBD_DO; + s->subdev_flags = + SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; + s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; + s->len_chanlist = + devpriv->s_EeParameters.i_NbrDoChannel; + s->range_table = &range_digital; + s->io_bits = 0xf; /* all bits output */ + + /* insn_config - for digital output memory */ + s->insn_config = this_board->do_config; + s->insn_write = this_board->do_write; + s->insn_bits = this_board->do_bits; + s->insn_read = this_board->do_read; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise Timer Subdevice Structures */ + s = &dev->subdevices[4]; + if (devpriv->s_EeParameters.i_Timer) { + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 1; + s->maxdata = 0; + s->len_chanlist = 1; + s->range_table = &range_digital; + + s->insn_write = this_board->timer_write; + s->insn_read = this_board->timer_read; + s->insn_config = this_board->timer_config; + s->insn_bits = this_board->timer_bits; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Allocate and Initialise TTL */ + s = &dev->subdevices[5]; + if (this_board->i_NbrTTLChannel) { + s->type = COMEDI_SUBD_TTLIO; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrTTLChannel; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->len_chanlist = this_board->i_NbrTTLChannel; + s->range_table = &range_digital; + s->insn_config = this_board->ttl_config; + s->insn_bits = this_board->ttl_bits; + s->insn_read = this_board->ttl_read; + s->insn_write = this_board->ttl_write; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* EEPROM */ + s = &dev->subdevices[6]; + if (this_board->i_PCIEeprom) { + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 256; + s->maxdata = 0xffff; + s->insn_read = i_ADDIDATA_InsnReadEeprom; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + i_ADDI_Reset(dev); + return 0; +} + +static void apci3501_detach(struct comedi_device *dev) +{ + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + struct addi_private *devpriv = dev->private; + + if (devpriv) { + if (dev->iobase) + i_ADDI_Reset(dev); + if (dev->irq) + free_irq(dev->irq, dev); + if (devpriv->dw_AiBase) + iounmap(devpriv->dw_AiBase); + } + if (pcidev) { + if (dev->iobase) + comedi_pci_disable(pcidev); + } +} static struct comedi_driver apci3501_driver = { .driver_name = "addi_apci_3501", .module = THIS_MODULE, - .auto_attach = addi_auto_attach, - .detach = i_ADDI_Detach, + .auto_attach = apci3501_auto_attach, + .detach = apci3501_detach, .num_names = ARRAY_SIZE(apci3501_boardtypes), .board_name = &apci3501_boardtypes[0].pc_DriverName, .offset = sizeof(struct addi_board), @@ -62,6 +364,12 @@ static void apci3501_pci_remove(struct pci_dev *dev) comedi_pci_auto_unconfig(dev); } +static DEFINE_PCI_DEVICE_TABLE(apci3501_pci_table) = { + { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3001) }, + { 0 } +}; +MODULE_DEVICE_TABLE(pci, apci3501_pci_table); + static struct pci_driver apci3501_pci_driver = { .name = "addi_apci_3501", .id_table = apci3501_pci_table, -- cgit v0.10.2 From 2a836ad74274e27b79e531f3399b8fc4220ea69d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:36:14 -0700 Subject: staging: comedi: addi_apci_3501: board does not have ttl i/o The board supported by this driver does not have ttl i/o. Remove the subdevice init for it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index e2ea542..772f035 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -4,10 +4,6 @@ #include "addi-data/addi_common.h" -#ifndef COMEDI_SUBD_TTLIO -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#endif - #include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci3501.c" @@ -291,22 +287,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* Allocate and Initialise TTL */ s = &dev->subdevices[5]; - if (this_board->i_NbrTTLChannel) { - s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = - SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrTTLChannel; - s->maxdata = 1; - s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; - s->range_table = &range_digital; - s->insn_config = this_board->ttl_config; - s->insn_bits = this_board->ttl_bits; - s->insn_read = this_board->ttl_read; - s->insn_write = this_board->ttl_write; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* EEPROM */ s = &dev->subdevices[6]; -- cgit v0.10.2 From 3d596e50ffbb183df6fb132a9a795a5ff8d7842c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:36:38 -0700 Subject: staging: comedi: addi_apci_3501: board has a timer The board supported by this driver has a timer device. Remove the conditional and always init the subdevice. Also, move the subdevice insn_* function pointers out of the boardinfo and use them to initialize the subdevice directly. Since devpriv->s_EeParameters.i_Timer is not longer being used, remove its initialization also. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 772f035..725bfde 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -21,16 +21,12 @@ static const struct addi_board apci3501_boardtypes[] = { .i_NbrDiChannel = 2, .i_NbrDoChannel = 2, .i_DoMaxdata = 0x3, - .i_Timer = 1, .interrupt = v_APCI3501_Interrupt, .reset = i_APCI3501_Reset, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, .di_bits = apci3501_di_insn_bits, .do_bits = apci3501_do_insn_bits, - .timer_config = i_APCI3501_ConfigTimerCounterWatchdog, - .timer_write = i_APCI3501_StartStopWriteTimerCounterWatchdog, - .timer_read = i_APCI3501_ReadTimerCounterWatchdog, }, }; @@ -139,7 +135,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; devpriv->s_EeParameters.i_Dma = this_board->i_Dma; - devpriv->s_EeParameters.i_Timer = this_board->i_Timer; devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = this_board->ui_MinAcquisitiontimeNs; devpriv->s_EeParameters.ui_MinDelaytimeNs = @@ -269,21 +264,15 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; - if (devpriv->s_EeParameters.i_Timer) { - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = 1; - s->maxdata = 0; - s->len_chanlist = 1; - s->range_table = &range_digital; - - s->insn_write = this_board->timer_write; - s->insn_read = this_board->timer_read; - s->insn_config = this_board->timer_config; - s->insn_bits = this_board->timer_bits; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 1; + s->maxdata = 0; + s->len_chanlist = 1; + s->range_table = &range_digital; + s->insn_write = i_APCI3501_StartStopWriteTimerCounterWatchdog; + s->insn_read = i_APCI3501_ReadTimerCounterWatchdog; + s->insn_config = i_APCI3501_ConfigTimerCounterWatchdog; /* Allocate and Initialise TTL */ s = &dev->subdevices[5]; -- cgit v0.10.2 From 953a36c45aa4ba23be687451df6311ad33d89538 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:37:16 -0700 Subject: staging: comedi: addi_apci_3501: cleanup the digital output subdevice The board supported by this driver has 2 digital outputs. Remove the conditional and always init the subdevice. Also, move the subdevice insn_bits function pointer as well as the n_chan out of the boardinfo and use them to initialize the subdevice directly. Since devpriv->s_EeParameters for the digital output subdevice are no longer being used, remove initialization of them also. Copy the apci3501_do_insn_bits() function from hwrdv_apci3501.c into the main driver file. Fix the subdev_flags for the subdevice. The only required flag is SDF_WRITEABLE. The SDF_GROUND and SDF_COMMON flags only have meaning for analog subdevices and the SDF_READABLE flag is not required. Fix the maxdata for the subdevice. Digital outputs can only be 1 or 0. Remove the len_chanlist initialization, it only has meaning for subdevices that support commands. Remove the io_bits initialization, it only has meaning for digital i/o subdevices that have configurable outputs. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 7a18ce7..c7abe85 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -96,28 +96,6 @@ static int apci3501_di_insn_bits(struct comedi_device *dev, return insn->n; } -static int apci3501_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - unsigned int mask = data[0]; - unsigned int bits = data[1]; - - s->state = inl(devpriv->iobase + APCI3501_DIGITAL_OP); - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - outl(s->state, devpriv->iobase + APCI3501_DIGITAL_OP); - } - - data[1] = s->state; - - return insn->n; -} - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ConfigAnalogOutput | diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 725bfde..8ea3838 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -19,17 +19,36 @@ static const struct addi_board apci3501_boardtypes[] = { .i_AoMaxdata = 16383, .pr_AoRangelist = &range_apci3501_ao, .i_NbrDiChannel = 2, - .i_NbrDoChannel = 2, - .i_DoMaxdata = 0x3, .interrupt = v_APCI3501_Interrupt, .reset = i_APCI3501_Reset, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, .di_bits = apci3501_di_insn_bits, - .do_bits = apci3501_do_insn_bits, }, }; +static int apci3501_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct addi_private *devpriv = dev->private; + unsigned int mask = data[0]; + unsigned int bits = data[1]; + + s->state = inl(devpriv->iobase + APCI3501_DIGITAL_OP); + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + outl(s->state, devpriv->iobase + APCI3501_DIGITAL_OP); + } + + data[1] = s->state; + + return insn->n; +} + static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -132,8 +151,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; - devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; - devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; devpriv->s_EeParameters.i_Dma = this_board->i_Dma; devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = this_board->ui_MinAcquisitiontimeNs; @@ -240,27 +257,15 @@ static int apci3501_auto_attach(struct comedi_device *dev, } else { s->type = COMEDI_SUBD_UNUSED; } - /* Allocate and Initialise DO Subdevice Structures */ - s = &dev->subdevices[3]; - if (devpriv->s_EeParameters.i_NbrDoChannel) { - s->type = COMEDI_SUBD_DO; - s->subdev_flags = - SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; - s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDoChannel; - s->range_table = &range_digital; - s->io_bits = 0xf; /* all bits output */ - /* insn_config - for digital output memory */ - s->insn_config = this_board->do_config; - s->insn_write = this_board->do_write; - s->insn_bits = this_board->do_bits; - s->insn_read = this_board->do_read; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + /* Initialize the digital output subdevice */ + s = &dev->subdevices[3]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 2; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci3501_do_insn_bits; /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4]; -- cgit v0.10.2 From 513192fc7e34d089d4b949a0e7ba6ccd4780f663 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:37:38 -0700 Subject: staging: comedi: addi_apci_3501: cleanup the digital input subdevice The board supported by this driver has 2 digital input. Remove the conditional and always init the subdevice. Also, move the subdevice insn_bits function pointer as well as the n_chan out of the boardinfo and use them to initialize the subdevice directly. Since devpriv->s_EeParameters.i_NbrDiChannel for the digital input subdevice is no longer being used, remove initialization of it also. Copy the apci3501_di_insn_bits() function from hwrdv_apci3501.c into the main driver file. Fix the subdev_flags for the subdevice. The only required flag is SDF_READABLE. The SDF_GROUND and SDF_COMMON flags only have meaning for analog subdevices. Remove the len_chanlist initialization, it only has meaning for subdevices that support commands. Remove the io_bits initialization, it only has meaning for digital i/o subdevices that have configurable outputs. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index c7abe85..4ecdb9e 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -84,18 +84,6 @@ static struct comedi_lrange range_apci3501_ao = { } }; -static int apci3501_di_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - - data[1] = inl(devpriv->iobase + APCI3501_DIGITAL_IP) & 0x3; - - return insn->n; -} - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ConfigAnalogOutput | diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 8ea3838..fa2b235 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -18,15 +18,25 @@ static const struct addi_board apci3501_boardtypes[] = { .pc_EepromChip = ADDIDATA_S5933, .i_AoMaxdata = 16383, .pr_AoRangelist = &range_apci3501_ao, - .i_NbrDiChannel = 2, .interrupt = v_APCI3501_Interrupt, .reset = i_APCI3501_Reset, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, - .di_bits = apci3501_di_insn_bits, }, }; +static int apci3501_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct addi_private *devpriv = dev->private; + + data[1] = inl(devpriv->iobase + APCI3501_DIGITAL_IP) & 0x3; + + return insn->n; +} + static int apci3501_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -150,7 +160,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; - devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; devpriv->s_EeParameters.i_Dma = this_board->i_Dma; devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = this_board->ui_MinAcquisitiontimeNs; @@ -241,22 +250,12 @@ static int apci3501_auto_attach(struct comedi_device *dev, } /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; - if (devpriv->s_EeParameters.i_NbrDiChannel) { - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel; - s->maxdata = 1; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDiChannel; - s->range_table = &range_digital; - s->io_bits = 0; /* all bits input */ - s->insn_config = this_board->di_config; - s->insn_read = this_board->di_read; - s->insn_write = this_board->di_write; - s->insn_bits = this_board->di_bits; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 2; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci3501_di_insn_bits; /* Initialize the digital output subdevice */ s = &dev->subdevices[3]; -- cgit v0.10.2 From e54ae8f6d4920a6734b909a44a601e0d722a84ac Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:37:59 -0700 Subject: staging: comedi: addi_apci_3501: board does not have analog inputs The board supported by this driver does not have analog inputs. Remove the subdevice init for it. Since the devpriv->s_EeParameters for the analog input subdevice are not used, remove the initialization of them also. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index fa2b235..5d14339 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -156,15 +156,9 @@ static int apci3501_auto_attach(struct comedi_device *dev, devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); /* Initialize parameters that can be overridden in EEPROM */ - devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel; devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; - devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; devpriv->s_EeParameters.i_Dma = this_board->i_Dma; - devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = - this_board->ui_MinAcquisitiontimeNs; - devpriv->s_EeParameters.ui_MinDelaytimeNs = - this_board->ui_MinDelaytimeNs; /* ## */ @@ -199,39 +193,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* Allocate and Initialise AI Subdevice Structures */ s = &dev->subdevices[0]; - if ((devpriv->s_EeParameters.i_NbrAiChannel) - || (this_board->i_NbrAiChannelDiff)) { - dev->read_subdev = s; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = - SDF_READABLE | SDF_COMMON | SDF_GROUND - | SDF_DIFF; - if (devpriv->s_EeParameters.i_NbrAiChannel) { - s->n_chan = - devpriv->s_EeParameters.i_NbrAiChannel; - devpriv->b_SingelDiff = 0; - } else { - s->n_chan = this_board->i_NbrAiChannelDiff; - devpriv->b_SingelDiff = 1; - } - s->maxdata = devpriv->s_EeParameters.i_AiMaxdata; - s->len_chanlist = this_board->i_AiChannelList; - s->range_table = this_board->pr_AiRangelist; - - /* Set the initialisation flag */ - devpriv->b_AiInitialisation = 1; - - s->insn_config = this_board->ai_config; - s->insn_read = this_board->ai_read; - s->insn_write = this_board->ai_write; - s->insn_bits = this_board->ai_bits; - s->do_cmdtest = this_board->ai_cmdtest; - s->do_cmd = this_board->ai_cmd; - s->cancel = this_board->ai_cancel; - - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* Allocate and Initialise AO Subdevice Structures */ s = &dev->subdevices[1]; -- cgit v0.10.2 From 678a4d3ab159b776a7cb9c8ca9fdaf5498f3423a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:38:21 -0700 Subject: staging: comedi: addi_apci_3501: absorb i_APCI3501_Reset() This driver only has one 'reset' function. Absorb the i_APCI3501_Reset() function from hwdrv_apci3501.c into the driver. Rename i_ADDI_Reset() to apci3501_reset() so that the function has namespace associated with the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 4ecdb9e..733c793 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -470,58 +470,6 @@ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, /* +----------------------------------------------------------------------------+ -| Function Name : int i_APCI3501_Reset(struct comedi_device *dev) | -| | -+----------------------------------------------------------------------------+ -| Task :Resets the registers of the card | -+----------------------------------------------------------------------------+ -| Input Parameters : | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : | -| | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI3501_Reset(struct comedi_device *dev) -{ - struct addi_private *devpriv = dev->private; - int i_Count = 0, i_temp = 0; - unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; - - outl(0x0, devpriv->iobase + APCI3501_DIGITAL_OP); - outl(1, devpriv->iobase + APCI3501_ANALOG_OUTPUT + - APCI3501_AO_VOLT_MODE); - - ul_Polarity = 0x80000000; - - for (i_Count = 0; i_Count <= 7; i_Count++) { - ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); - - while (ul_DAC_Ready == 0) { - ul_DAC_Ready = - inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); - ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; - } - - if (ul_DAC_Ready) { - /* Output the Value on the output channels. */ - ul_Command1 = - (unsigned int) ((unsigned int) (i_Count & 0xFF) | - (unsigned int) ((i_temp << 0x8) & 0x7FFFFF00L) | - (unsigned int) (ul_Polarity)); - outl(ul_Command1, - devpriv->iobase + APCI3501_ANALOG_OUTPUT + - APCI3501_AO_PROG); - } - } - - return 0; -} - -/* -+----------------------------------------------------------------------------+ | Function Name : static void v_APCI3501_Interrupt | | (int irq , void *d) | +----------------------------------------------------------------------------+ diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 5d14339..d6a96bd 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -19,7 +19,6 @@ static const struct addi_board apci3501_boardtypes[] = { .i_AoMaxdata = 16383, .pr_AoRangelist = &range_apci3501_ao, .interrupt = v_APCI3501_Interrupt, - .reset = i_APCI3501_Reset, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, }, @@ -85,11 +84,39 @@ static irqreturn_t v_ADDI_Interrupt(int irq, void *d) return IRQ_RETVAL(1); } -static int i_ADDI_Reset(struct comedi_device *dev) +static int apci3501_reset(struct comedi_device *dev) { - const struct addi_board *this_board = comedi_board(dev); + struct addi_private *devpriv = dev->private; + int i_Count = 0, i_temp = 0; + unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; + + outl(0x0, devpriv->iobase + APCI3501_DIGITAL_OP); + outl(1, devpriv->iobase + APCI3501_ANALOG_OUTPUT + + APCI3501_AO_VOLT_MODE); + + ul_Polarity = 0x80000000; + + for (i_Count = 0; i_Count <= 7; i_Count++) { + ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + + while (ul_DAC_Ready == 0) { + ul_DAC_Ready = + inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; + } + + if (ul_DAC_Ready) { + /* Output the Value on the output channels. */ + ul_Command1 = + (unsigned int) ((unsigned int) (i_Count & 0xFF) | + (unsigned int) ((i_temp << 0x8) & 0x7FFFFF00L) | + (unsigned int) (ul_Polarity)); + outl(ul_Command1, + devpriv->iobase + APCI3501_ANALOG_OUTPUT + + APCI3501_AO_PROG); + } + } - this_board->reset(dev); return 0; } @@ -256,7 +283,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_UNUSED; } - i_ADDI_Reset(dev); + apci3501_reset(dev); return 0; } @@ -267,7 +294,7 @@ static void apci3501_detach(struct comedi_device *dev) if (devpriv) { if (dev->iobase) - i_ADDI_Reset(dev); + apci3501_reset(dev); if (dev->irq) free_irq(dev->irq, dev); if (devpriv->dw_AiBase) -- cgit v0.10.2 From b2b82184c9c9a82553bfd49e7940ebc67fe655a8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:38:44 -0700 Subject: staging: comedi: addi_apci_3501: absorb v_APCI3501_Interrupt() This driver only has one 'interrupt' function. Absorb the v_APCI3501_Interrupt() function from hwdrv_apci3501.c into the driver. Rename v_ADDI_Interrupt() to apci3501_interrupt() so that the function has namespace associated with the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 733c793..74b6eac 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -467,59 +467,3 @@ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, } return insn->n; } - -/* -+----------------------------------------------------------------------------+ -| Function Name : static void v_APCI3501_Interrupt | -| (int irq , void *d) | -+----------------------------------------------------------------------------+ -| Task : Interrupt processing Routine | -+----------------------------------------------------------------------------+ -| Input Parameters : int irq : irq number | -| void *d : void pointer | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ -static void v_APCI3501_Interrupt(int irq, void *d) -{ - int i_temp; - struct comedi_device *dev = d; - struct addi_private *devpriv = dev->private; - unsigned int ui_Timer_AOWatchdog; - unsigned long ul_Command1; - - /* Disable Interrupt */ - ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - - ul_Command1 = (ul_Command1 & 0xFFFFF9FDul); - outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - - ui_Timer_AOWatchdog = - inl(devpriv->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_IRQ) & 0x1; - - if ((!ui_Timer_AOWatchdog)) { - comedi_error(dev, "IRQ from unknown source"); - return; - } - -/* -* Enable Interrupt Send a signal to from kernel to user space -*/ - send_sig(SIGIO, devpriv->tsk_Current, 0); - ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1); - outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - i_temp = inl(devpriv->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TRIG_STATUS) & 0x1; - return; -} diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index d6a96bd..3c82596 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -18,7 +18,6 @@ static const struct addi_board apci3501_boardtypes[] = { .pc_EepromChip = ADDIDATA_S5933, .i_AoMaxdata = 16383, .pr_AoRangelist = &range_apci3501_ao, - .interrupt = v_APCI3501_Interrupt, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, }, @@ -75,13 +74,42 @@ static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, return insn->n; } -static irqreturn_t v_ADDI_Interrupt(int irq, void *d) +static irqreturn_t apci3501_interrupt(int irq, void *d) { struct comedi_device *dev = d; - const struct addi_board *this_board = comedi_board(dev); + struct addi_private *devpriv = dev->private; + unsigned int ui_Timer_AOWatchdog; + unsigned long ul_Command1; + int i_temp; + + /* Disable Interrupt */ + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + + ul_Command1 = (ul_Command1 & 0xFFFFF9FDul); + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + + ui_Timer_AOWatchdog = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_IRQ) & 0x1; + + if ((!ui_Timer_AOWatchdog)) { + comedi_error(dev, "IRQ from unknown source"); + return IRQ_NONE; + } - this_board->interrupt(irq, d); - return IRQ_RETVAL(1); + /* Enable Interrupt Send a signal to from kernel to user space */ + send_sig(SIGIO, devpriv->tsk_Current, 0); + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1); + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + i_temp = inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TRIG_STATUS) & 0x1; + + return IRQ_HANDLED; } static int apci3501_reset(struct comedi_device *dev) @@ -190,7 +218,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* ## */ if (pcidev->irq > 0) { - ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, + ret = request_irq(pcidev->irq, apci3501_interrupt, IRQF_SHARED, dev->board_name, dev); if (ret == 0) dev->irq = pcidev->irq; -- cgit v0.10.2 From d5255afb932aca4d64fedfc791fd1142defdd5dd Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:39:06 -0700 Subject: staging: comedi: addi_apci_3501: simplify eeprom read This driver needs to read the on-board eeprom to determine the number of analog output channels (4 or 8) on the board. But, sinde we know the board has an eeprom and the PCI controller chip is an AMCC S5933, we can simplify the code and remove the code that sets the extra wait state neede for the AMCC S5920. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 3c82596..0c57d70 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -173,7 +173,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, struct addi_private *devpriv; struct comedi_subdevice *s; int ret, n_subdevices; - unsigned int dw_Dummy; this_board = addi_find_boardinfo(dev, pcidev); if (!this_board) @@ -224,22 +223,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - /* Read eepeom and fill addi_board Structure */ - - if (this_board->i_PCIEeprom) { - if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { - /* Set 3 wait stait */ - if (!(strcmp(dev->board_name, "apci035"))) - outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); - else - outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); - - /* Enable the interrupt for the controller */ - dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); - outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); - } - addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); - } + addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); -- cgit v0.10.2 From 1bdc840224f71768c6bbe41b211f07c0778330c8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:39:27 -0700 Subject: staging: comedi: addi_apci_3501: simplify the PCI bar reading The board supported by this driver has an eeprom connected to an AMCC S5933 PCI controller chip. Knowing this, we can simplify the code that reads the PCI bars to get the iobase addresses used in the driver. Also, since the dw_AiBase is not ioremap'ed, we can remove the iounmap in the detach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 0c57d70..3f8f26a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -189,24 +189,10 @@ static int apci3501_auto_attach(struct comedi_device *dev, if (ret) return ret; - if (!this_board->pc_EepromChip || - strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { - /* board does not have an eeprom or is not ADDIDATA_9054 */ - if (this_board->i_IorangeBase1) - dev->iobase = pci_resource_start(pcidev, 1); - else - dev->iobase = pci_resource_start(pcidev, 0); - - devpriv->iobase = dev->iobase; - devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); - } else { - /* board has an ADDIDATA_9054 eeprom */ - dev->iobase = pci_resource_start(pcidev, 2); - devpriv->iobase = pci_resource_start(pcidev, 2); - devpriv->dw_AiBase = ioremap(pci_resource_start(pcidev, 3), - this_board->i_IorangeBase3); - } + dev->iobase = pci_resource_start(pcidev, 1); + devpriv->iobase = dev->iobase; + devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); + devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); /* Initialize parameters that can be overridden in EEPROM */ @@ -309,8 +295,6 @@ static void apci3501_detach(struct comedi_device *dev) apci3501_reset(dev); if (dev->irq) free_irq(dev->irq, dev); - if (devpriv->dw_AiBase) - iounmap(devpriv->dw_AiBase); } if (pcidev) { if (dev->iobase) -- cgit v0.10.2 From 0b4d52e21c63ffda2e2f083fa928f854942e5740 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:39:47 -0700 Subject: staging: comedi: addi_apci_3501: remove devpriv->iobase usage The iobase address stored in devpriv->iobase is also stored in dev->iobase. Use that instead. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 74b6eac..41a3477 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -118,7 +118,7 @@ static int i_APCI3501_ConfigAnalogOutput(struct comedi_device *dev, struct addi_private *devpriv = dev->private; outl(data[0], - devpriv->iobase + APCI3501_ANALOG_OUTPUT + + dev->iobase + APCI3501_ANALOG_OUTPUT + APCI3501_AO_VOLT_MODE); if (data[0]) { @@ -181,10 +181,10 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); } /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */ - ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = inl(dev->iobase + APCI3501_ANALOG_OUTPUT); while (ul_DAC_Ready == 0) { - ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = inl(dev->iobase + APCI3501_ANALOG_OUTPUT); ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; } @@ -195,7 +195,7 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, (unsigned int) ((*data << 0x8) & 0x7FFFFF00L) | (unsigned int) (ul_Polarity)); outl(ul_Command1, - devpriv->iobase + APCI3501_ANALOG_OUTPUT + + dev->iobase + APCI3501_ANALOG_OUTPUT + APCI3501_AO_PROG); } @@ -242,67 +242,67 @@ static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev, devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; /* Disable the watchdog */ - outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Wa */ + outl(0x0, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Wa */ if (data[1] == 1) { /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ outl(0x02, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } else { - outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ + outl(0x0, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ } /* Loading the Timebase value */ outl(data[2], - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TIMEBASE); /* Loading the Reload value */ outl(data[3], - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_RELOAD_VALUE); /* Set the mode */ - ul_Command1 = inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG) | 0xFFF819E0UL; /* e2->e0 */ + ul_Command1 = inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG) | 0xFFF819E0UL; /* e2->e0 */ outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } /* end if(data[0]==ADDIDATA_WATCHDOG) */ else if (data[0] == ADDIDATA_TIMER) { /* First Stop The Timer */ ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* Stop The Timer */ + outl(ul_Command1, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* Stop The Timer */ devpriv->b_TimerSelectMode = ADDIDATA_TIMER; if (data[1] == 1) { /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ outl(0x02, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } else { - outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ + outl(0x0, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ } /* Loading Timebase */ outl(data[2], - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TIMEBASE); /* Loading the Reload value */ outl(data[3], - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_RELOAD_VALUE); - /* printk ("\nTimer Address :: %x\n", (devpriv->iobase+APCI3501_WATCHDOG)); */ + /* printk ("\nTimer Address :: %x\n", (dev->iobase + APCI3501_WATCHDOG)); */ ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; - outl(ul_Command1, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* mode 2 */ + outl(ul_Command1, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* mode 2 */ } /* end if(data[0]==ADDIDATA_TIMER) */ @@ -347,12 +347,12 @@ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *d if (data[1] == 1) { ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; /* Enable the Watchdog */ outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } @@ -360,19 +360,19 @@ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *d { /* Stop The Watchdog */ ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; outl(0x0, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } else if (data[1] == 2) { ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } /* if(data[1]==2) */ } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */ @@ -381,37 +381,37 @@ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *d if (data[1] == 1) { ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; /* Enable the Timer */ outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } else if (data[1] == 0) { /* Stop The Timer */ ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } else if (data[1] == 2) { /* Trigger the Timer */ ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); } } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */ - i_Temp = inl(devpriv->iobase + APCI3501_WATCHDOG + + i_Temp = inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS) & 0x1; return insn->n; } @@ -449,16 +449,16 @@ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { data[0] = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS) & 0x1; - data[1] = inl(devpriv->iobase + APCI3501_WATCHDOG); + data[1] = inl(dev->iobase + APCI3501_WATCHDOG); } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */ else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { data[0] = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS) & 0x1; - data[1] = inl(devpriv->iobase + APCI3501_WATCHDOG); + data[1] = inl(dev->iobase + APCI3501_WATCHDOG); } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */ else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER) diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 3f8f26a..16a348c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -28,9 +28,7 @@ static int apci3501_di_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; - - data[1] = inl(devpriv->iobase + APCI3501_DIGITAL_IP) & 0x3; + data[1] = inl(dev->iobase + APCI3501_DIGITAL_IP) & 0x3; return insn->n; } @@ -40,16 +38,15 @@ static int apci3501_do_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; unsigned int mask = data[0]; unsigned int bits = data[1]; - s->state = inl(devpriv->iobase + APCI3501_DIGITAL_OP); + s->state = inl(dev->iobase + APCI3501_DIGITAL_OP); if (mask) { s->state &= ~mask; s->state |= (bits & mask); - outl(s->state, devpriv->iobase + APCI3501_DIGITAL_OP); + outl(s->state, dev->iobase + APCI3501_DIGITAL_OP); } data[1] = s->state; @@ -84,14 +81,14 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) /* Disable Interrupt */ ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = (ul_Command1 & 0xFFFFF9FDul); outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ui_Timer_AOWatchdog = - inl(devpriv->iobase + APCI3501_WATCHDOG + + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_IRQ) & 0x1; if ((!ui_Timer_AOWatchdog)) { @@ -102,11 +99,11 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) /* Enable Interrupt Send a signal to from kernel to user space */ send_sig(SIGIO, devpriv->tsk_Current, 0); ul_Command1 = - inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1); outl(ul_Command1, - devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - i_temp = inl(devpriv->iobase + APCI3501_WATCHDOG + + dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + i_temp = inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS) & 0x1; return IRQ_HANDLED; @@ -114,22 +111,21 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) static int apci3501_reset(struct comedi_device *dev) { - struct addi_private *devpriv = dev->private; int i_Count = 0, i_temp = 0; unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; - outl(0x0, devpriv->iobase + APCI3501_DIGITAL_OP); - outl(1, devpriv->iobase + APCI3501_ANALOG_OUTPUT + + outl(0x0, dev->iobase + APCI3501_DIGITAL_OP); + outl(1, dev->iobase + APCI3501_ANALOG_OUTPUT + APCI3501_AO_VOLT_MODE); ul_Polarity = 0x80000000; for (i_Count = 0; i_Count <= 7; i_Count++) { - ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = inl(dev->iobase + APCI3501_ANALOG_OUTPUT); while (ul_DAC_Ready == 0) { ul_DAC_Ready = - inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + inl(dev->iobase + APCI3501_ANALOG_OUTPUT); ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; } @@ -140,7 +136,7 @@ static int apci3501_reset(struct comedi_device *dev) (unsigned int) ((i_temp << 0x8) & 0x7FFFFF00L) | (unsigned int) (ul_Polarity)); outl(ul_Command1, - devpriv->iobase + APCI3501_ANALOG_OUTPUT + + dev->iobase + APCI3501_ANALOG_OUTPUT + APCI3501_AO_PROG); } } @@ -190,7 +186,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, return ret; dev->iobase = pci_resource_start(pcidev, 1); - devpriv->iobase = dev->iobase; devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); -- cgit v0.10.2 From 0d14f610d2c6f28fbed2e45ef5525896a5498190 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:40:07 -0700 Subject: staging: comedi: addi_apci_3501: board does not support dma The board supported by this driver does not use dma. Remove the unnecessary initialization of devpriv->s_EeParameters.i_Dma. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 16a348c..0b7a500 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -193,9 +193,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* Initialize parameters that can be overridden in EEPROM */ devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; - devpriv->s_EeParameters.i_Dma = this_board->i_Dma; - - /* ## */ if (pcidev->irq > 0) { ret = request_irq(pcidev->irq, apci3501_interrupt, IRQF_SHARED, -- cgit v0.10.2 From 09680870a9b986862277cfaf9598b0d67108deaf Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:40:28 -0700 Subject: staging: comedi: addi_apci_3501: don't read the unused PCI bars This driver only uses PCI bar 0 and 1, don't bother reading the unused PCI bars. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 0b7a500..1408df3 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -187,8 +187,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 1); devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); - devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); /* Initialize parameters that can be overridden in EEPROM */ devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; -- cgit v0.10.2 From cfaa23de519b63ae4864a163fc9ba0a224c9f6b4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:40:50 -0700 Subject: staging: comedi: addi_apci_3501: analog output resolution is fixed The analog outputs of this board are always 14-bit. Remove this information from the boardinfo and just set the 'maxdata' directly in the subdevice init. Initialize with a hex value as that is more standard in the comedi drivers. Since devpriv->s_EeParameters.i_AoMaxdata is not longer being used, don't bother initializing it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 1408df3..469d4b8 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -16,7 +16,6 @@ static const struct addi_board apci3501_boardtypes[] = { .i_IorangeBase1 = APCI3501_ADDRESS_RANGE, .i_PCIEeprom = ADDIDATA_EEPROM, .pc_EepromChip = ADDIDATA_S5933, - .i_AoMaxdata = 16383, .pr_AoRangelist = &range_apci3501_ao, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, @@ -190,7 +189,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* Initialize parameters that can be overridden in EEPROM */ devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; - devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; if (pcidev->irq > 0) { ret = request_irq(pcidev->irq, apci3501_interrupt, IRQF_SHARED, @@ -216,7 +214,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; - s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; + s->maxdata = 0x3fff; s->len_chanlist = devpriv->s_EeParameters.i_NbrAoChannel; s->range_table = this_board->pr_AoRangelist; -- cgit v0.10.2 From 9f89ce8c62175e1f5bad495241ea34f288b2596c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:41:16 -0700 Subject: staging: comedi: addi_apci_3501: remove analog output boardinfo There is not need to pass the analog output subdevice information in the boardinfo. Just initialize the subdevice directly. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 469d4b8..2302e5a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -16,9 +16,6 @@ static const struct addi_board apci3501_boardtypes[] = { .i_IorangeBase1 = APCI3501_ADDRESS_RANGE, .i_PCIEeprom = ADDIDATA_EEPROM, .pc_EepromChip = ADDIDATA_S5933, - .pr_AoRangelist = &range_apci3501_ao, - .ao_config = i_APCI3501_ConfigAnalogOutput, - .ao_write = i_APCI3501_WriteAnalogOutput, }, }; @@ -217,9 +214,9 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->maxdata = 0x3fff; s->len_chanlist = devpriv->s_EeParameters.i_NbrAoChannel; - s->range_table = this_board->pr_AoRangelist; - s->insn_config = this_board->ao_config; - s->insn_write = this_board->ao_write; + s->range_table = &range_apci3501_ao; + s->insn_config = i_APCI3501_ConfigAnalogOutput; + s->insn_write = i_APCI3501_WriteAnalogOutput; } else { s->type = COMEDI_SUBD_UNUSED; } -- cgit v0.10.2 From 87c38fbed5bb706785be9171ed4a9b41faf17e13 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:41:36 -0700 Subject: staging: comedi: addi_apci_3501: board has an eeprom The board supported by this driver has an on-board eeprom. Since we need to read it to get the number of analog output channels, expose the eeprom as a readable subdevice to the user. Rename the i_ADDIDATA_InsnReadEeprom() function to give it namespace associated with the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 2302e5a..48f7c82 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -50,7 +50,7 @@ static int apci3501_do_insn_bits(struct comedi_device *dev, return insn->n; } -static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, +static int apci3501_eeprom_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -256,15 +256,11 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* EEPROM */ s = &dev->subdevices[6]; - if (this_board->i_PCIEeprom) { - s->type = COMEDI_SUBD_MEMORY; - s->subdev_flags = SDF_READABLE | SDF_INTERNAL; - s->n_chan = 256; - s->maxdata = 0xffff; - s->insn_read = i_ADDIDATA_InsnReadEeprom; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 256; + s->maxdata = 0xffff; + s->insn_read = apci3501_eeprom_insn_read; apci3501_reset(dev); return 0; -- cgit v0.10.2 From 25b9b873d3e3c1ed25cd5a7551bfee0b42d4ed1d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:42:02 -0700 Subject: staging: comedi: addi_apci_3501: simplify reading the eeprom The only value in the eeprom that is used by this driver is the number of analog output channels. Copy the necessary code from addi_eeprom.c to this driver and refactor it so that we can get the value needed. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 48f7c82..332e9a0 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -4,9 +4,28 @@ #include "addi-data/addi_common.h" -#include "addi-data/addi_eeprom.c" #include "addi-data/hwdrv_apci3501.c" +/* + * AMCC S5933 NVRAM + */ +#define NVRAM_USER_DATA_START 0x100 + +#define NVCMD_BEGIN_READ (0x7 << 5) +#define NVCMD_LOAD_LOW (0x4 << 5) +#define NVCMD_LOAD_HIGH (0x5 << 5) + +/* + * Function types stored in the eeprom + */ +#define EEPROM_DIGITALINPUT 0 +#define EEPROM_DIGITALOUTPUT 1 +#define EEPROM_ANALOGINPUT 2 +#define EEPROM_ANALOGOUTPUT 3 +#define EEPROM_TIMER 4 +#define EEPROM_WATCHDOG 5 +#define EEPROM_TIMER_WATCHDOG_COUNTER 10 + static const struct addi_board apci3501_boardtypes[] = { { .pc_DriverName = "apci3501", @@ -50,19 +69,90 @@ static int apci3501_do_insn_bits(struct comedi_device *dev, return insn->n; } +static void apci3501_eeprom_wait(unsigned long iobase) +{ + unsigned char val; + + do { + val = inb(iobase + AMCC_OP_REG_MCSR_NVCMD); + } while (val & 0x80); +} + +static unsigned short apci3501_eeprom_readw(unsigned long iobase, + unsigned short addr) +{ + unsigned short val = 0; + unsigned char tmp; + unsigned char i; + + /* Add the offset to the start of the user data */ + addr += NVRAM_USER_DATA_START; + + for (i = 0; i < 2; i++) { + /* Load the low 8 bit address */ + outb(NVCMD_LOAD_LOW, iobase + AMCC_OP_REG_MCSR_NVCMD); + apci3501_eeprom_wait(iobase); + outb((addr + i) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA); + apci3501_eeprom_wait(iobase); + + /* Load the high 8 bit address */ + outb(NVCMD_LOAD_HIGH, iobase + AMCC_OP_REG_MCSR_NVCMD); + apci3501_eeprom_wait(iobase); + outb(((addr + i) >> 8) & 0xff, + iobase + AMCC_OP_REG_MCSR_NVDATA); + apci3501_eeprom_wait(iobase); + + /* Read the eeprom data byte */ + outb(NVCMD_BEGIN_READ, iobase + AMCC_OP_REG_MCSR_NVCMD); + apci3501_eeprom_wait(iobase); + tmp = inb(iobase + AMCC_OP_REG_MCSR_NVDATA); + apci3501_eeprom_wait(iobase); + + if (i == 0) + val |= tmp; + else + val |= (tmp << 8); + } + + return val; +} + +static int apci3501_eeprom_get_ao_n_chan(struct comedi_device *dev) +{ + struct addi_private *devpriv = dev->private; + unsigned long iobase = devpriv->i_IobaseAmcc; + unsigned char nfuncs; + int i; + + nfuncs = apci3501_eeprom_readw(iobase, 10) & 0xff; + + /* Read functionality details */ + for (i = 0; i < nfuncs; i++) { + unsigned short offset = i * 4; + unsigned short addr; + unsigned char func; + unsigned short val; + + func = apci3501_eeprom_readw(iobase, 12 + offset) & 0x3f; + addr = apci3501_eeprom_readw(iobase, 14 + offset); + + if (func == EEPROM_ANALOGOUTPUT) { + val = apci3501_eeprom_readw(iobase, addr + 10); + return (val >> 4) & 0x3ff; + } + } + return 0; +} + static int apci3501_eeprom_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct addi_board *this_board = comedi_board(dev); struct addi_private *devpriv = dev->private; - unsigned short w_Address = CR_CHAN(insn->chanspec); - unsigned short w_Data; + unsigned short addr = CR_CHAN(insn->chanspec); - w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc, - this_board->pc_EepromChip, 2 * w_Address); - data[0] = w_Data; + data[0] = apci3501_eeprom_readw(devpriv->i_IobaseAmcc, 2 * addr); return insn->n; } @@ -164,6 +254,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, const struct addi_board *this_board; struct addi_private *devpriv; struct comedi_subdevice *s; + int ao_n_chan; int ret, n_subdevices; this_board = addi_find_boardinfo(dev, pcidev); @@ -184,8 +275,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, dev->iobase = pci_resource_start(pcidev, 1); devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - /* Initialize parameters that can be overridden in EEPROM */ - devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel; + ao_n_chan = apci3501_eeprom_get_ao_n_chan(dev); if (pcidev->irq > 0) { ret = request_irq(pcidev->irq, apci3501_interrupt, IRQF_SHARED, @@ -194,8 +284,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0)); - n_subdevices = 7; ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) @@ -207,19 +295,18 @@ static int apci3501_auto_attach(struct comedi_device *dev, /* Allocate and Initialise AO Subdevice Structures */ s = &dev->subdevices[1]; - if (devpriv->s_EeParameters.i_NbrAoChannel) { - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel; - s->maxdata = 0x3fff; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrAoChannel; - s->range_table = &range_apci3501_ao; - s->insn_config = i_APCI3501_ConfigAnalogOutput; - s->insn_write = i_APCI3501_WriteAnalogOutput; + if (ao_n_chan) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = ao_n_chan; + s->maxdata = 0x3fff; + s->range_table = &range_apci3501_ao; + s->insn_config = i_APCI3501_ConfigAnalogOutput; + s->insn_write = i_APCI3501_WriteAnalogOutput; } else { - s->type = COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_UNUSED; } + /* Allocate and Initialise DI Subdevice Structures */ s = &dev->subdevices[2]; s->type = COMEDI_SUBD_DI; -- cgit v0.10.2 From 94f68357f219b69173ea7b62ab4f903f8edf03c5 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:42:20 -0700 Subject: staging: comedi: addi_apci_3501: remove boardinfo With the eeprom support code now local to this driver, we can remove the boardinfo since it's not necessary. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 332e9a0..942386f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -26,18 +26,6 @@ #define EEPROM_WATCHDOG 5 #define EEPROM_TIMER_WATCHDOG_COUNTER 10 -static const struct addi_board apci3501_boardtypes[] = { - { - .pc_DriverName = "apci3501", - .i_VendorId = PCI_VENDOR_ID_ADDIDATA, - .i_DeviceId = 0x3001, - .i_IorangeBase0 = 64, - .i_IorangeBase1 = APCI3501_ADDRESS_RANGE, - .i_PCIEeprom = ADDIDATA_EEPROM, - .pc_EepromChip = ADDIDATA_S5933, - }, -}; - static int apci3501_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -230,38 +218,16 @@ static int apci3501_reset(struct comedi_device *dev) return 0; } -static const void *addi_find_boardinfo(struct comedi_device *dev, - struct pci_dev *pcidev) -{ - const void *p = dev->driver->board_name; - const struct addi_board *this_board; - int i; - - for (i = 0; i < dev->driver->num_names; i++) { - this_board = p; - if (this_board->i_VendorId == pcidev->vendor && - this_board->i_DeviceId == pcidev->device) - return this_board; - p += dev->driver->offset; - } - return NULL; -} - static int apci3501_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct addi_board *this_board; struct addi_private *devpriv; struct comedi_subdevice *s; int ao_n_chan; int ret, n_subdevices; - this_board = addi_find_boardinfo(dev, pcidev); - if (!this_board) - return -ENODEV; - dev->board_ptr = this_board; - dev->board_name = this_board->pc_DriverName; + dev->board_name = dev->driver->driver_name; devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); if (!devpriv) @@ -375,9 +341,6 @@ static struct comedi_driver apci3501_driver = { .module = THIS_MODULE, .auto_attach = apci3501_auto_attach, .detach = apci3501_detach, - .num_names = ARRAY_SIZE(apci3501_boardtypes), - .board_name = &apci3501_boardtypes[0].pc_DriverName, - .offset = sizeof(struct addi_board), }; static int apci3501_pci_probe(struct pci_dev *dev, -- cgit v0.10.2 From 694dcf501c35b6afcbc90ae3b4f3fea0b59f9888 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:42:39 -0700 Subject: staging: comedi: addi_apci_3501: only allocate needed subdevices The addi-data "common" code always allocated 7 subdevices. This driver only uses 5. Change the allocation and remove the unused subdevices. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 942386f..6e331d4 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -225,7 +225,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, struct addi_private *devpriv; struct comedi_subdevice *s; int ao_n_chan; - int ret, n_subdevices; + int ret; dev->board_name = dev->driver->driver_name; @@ -250,17 +250,12 @@ static int apci3501_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - n_subdevices = 7; - ret = comedi_alloc_subdevices(dev, n_subdevices); + ret = comedi_alloc_subdevices(dev, 5); if (ret) return ret; - /* Allocate and Initialise AI Subdevice Structures */ + /* Initialize the analog output subdevice */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_UNUSED; - - /* Allocate and Initialise AO Subdevice Structures */ - s = &dev->subdevices[1]; if (ao_n_chan) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; @@ -273,8 +268,8 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_UNUSED; } - /* Allocate and Initialise DI Subdevice Structures */ - s = &dev->subdevices[2]; + /* Initialize the digital input subdevice */ + s = &dev->subdevices[1]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 2; @@ -283,7 +278,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->insn_bits = apci3501_di_insn_bits; /* Initialize the digital output subdevice */ - s = &dev->subdevices[3]; + s = &dev->subdevices[2]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 2; @@ -291,8 +286,8 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->range_table = &range_digital; s->insn_bits = apci3501_do_insn_bits; - /* Allocate and Initialise Timer Subdevice Structures */ - s = &dev->subdevices[4]; + /* Initialize the timer/watchdog subdevice */ + s = &dev->subdevices[3]; s->type = COMEDI_SUBD_TIMER; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 1; @@ -303,12 +298,8 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->insn_read = i_APCI3501_ReadTimerCounterWatchdog; s->insn_config = i_APCI3501_ConfigTimerCounterWatchdog; - /* Allocate and Initialise TTL */ - s = &dev->subdevices[5]; - s->type = COMEDI_SUBD_UNUSED; - - /* EEPROM */ - s = &dev->subdevices[6]; + /* Initialize the eeprom subdevice */ + s = &dev->subdevices[4]; s->type = COMEDI_SUBD_MEMORY; s->subdev_flags = SDF_READABLE | SDF_INTERNAL; s->n_chan = 256; -- cgit v0.10.2 From 015aebe78d3f341fc6aa42f655e191f84bd1a7e5 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:43:14 -0700 Subject: staging: comedi: addi_apci_3501: remove dependency on addi_common.h Create a struct to hold the private data still used by this driver. This removes the last dependencies on the addi-data "common" code so we can also remove the #include of addi_common.h. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 41a3477..f709853 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -115,7 +115,7 @@ static int i_APCI3501_ConfigAnalogOutput(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; outl(data[0], dev->iobase + APCI3501_ANALOG_OUTPUT + @@ -157,7 +157,7 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0; ul_Channel_no = CR_CHAN(insn->chanspec); @@ -234,7 +234,7 @@ static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; unsigned int ul_Command1 = 0; devpriv->tsk_Current = current; @@ -339,7 +339,7 @@ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *d struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; unsigned int ul_Command1 = 0; int i_Temp; @@ -445,7 +445,7 @@ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { data[0] = diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 6e331d4..d345daa 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -2,7 +2,12 @@ #include "comedi_fc.h" #include "amcc_s5933.h" -#include "addi-data/addi_common.h" +struct apci3501_private { + int i_IobaseAmcc; + struct task_struct *tsk_Current; + unsigned char b_TimerSelectMode; + unsigned char b_InterruptMode; +}; #include "addi-data/hwdrv_apci3501.c" @@ -107,7 +112,7 @@ static unsigned short apci3501_eeprom_readw(unsigned long iobase, static int apci3501_eeprom_get_ao_n_chan(struct comedi_device *dev) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; unsigned long iobase = devpriv->i_IobaseAmcc; unsigned char nfuncs; int i; @@ -137,7 +142,7 @@ static int apci3501_eeprom_insn_read(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; unsigned short addr = CR_CHAN(insn->chanspec); data[0] = apci3501_eeprom_readw(devpriv->i_IobaseAmcc, 2 * addr); @@ -148,7 +153,7 @@ static int apci3501_eeprom_insn_read(struct comedi_device *dev, static irqreturn_t apci3501_interrupt(int irq, void *d) { struct comedi_device *dev = d; - struct addi_private *devpriv = dev->private; + struct apci3501_private *devpriv = dev->private; unsigned int ui_Timer_AOWatchdog; unsigned long ul_Command1; int i_temp; @@ -222,7 +227,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - struct addi_private *devpriv; + struct apci3501_private *devpriv; struct comedi_subdevice *s; int ao_n_chan; int ret; @@ -313,14 +318,11 @@ static int apci3501_auto_attach(struct comedi_device *dev, static void apci3501_detach(struct comedi_device *dev) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - struct addi_private *devpriv = dev->private; - if (devpriv) { - if (dev->iobase) - apci3501_reset(dev); - if (dev->irq) - free_irq(dev->irq, dev); - } + if (dev->iobase) + apci3501_reset(dev); + if (dev->irq) + free_irq(dev->irq, dev); if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); -- cgit v0.10.2 From 1bc5062a9796b2908f5c21c2bc3f50add7431fb8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:43:35 -0700 Subject: staging: comedi: addi_apci_3501: start defining i/o map Create, and use, defines for the analog output and digital i/o registers. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index f709853..bbdda4e 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -46,19 +46,7 @@ You should also find the complete GPL in the COPYING file accompanying this sour +----------+-----------+------------------------------------------------+ */ -/* Card Specific information */ -#define APCI3501_ADDRESS_RANGE 255 - -#define APCI3501_DIGITAL_IP 0x50 -#define APCI3501_DIGITAL_OP 0x40 -#define APCI3501_ANALOG_OUTPUT 0x00 - /* Analog Output related Defines */ -#define APCI3501_AO_VOLT_MODE 0 -#define APCI3501_AO_PROG 4 -#define APCI3501_AO_TRIG_SCS 8 -#define UNIPOLAR 0 -#define BIPOLAR 1 #define MODE0 0 #define MODE1 1 @@ -117,9 +105,7 @@ static int i_APCI3501_ConfigAnalogOutput(struct comedi_device *dev, { struct apci3501_private *devpriv = dev->private; - outl(data[0], - dev->iobase + APCI3501_ANALOG_OUTPUT + - APCI3501_AO_VOLT_MODE); + outl(data[0], dev->iobase + APCI3501_AO_CTRL_STATUS_REG); if (data[0]) { devpriv->b_InterruptMode = MODE1; @@ -181,10 +167,10 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); } /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */ - ul_DAC_Ready = inl(dev->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); while (ul_DAC_Ready == 0) { - ul_DAC_Ready = inl(dev->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; } @@ -194,9 +180,7 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, (unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) | (unsigned int) ((*data << 0x8) & 0x7FFFFF00L) | (unsigned int) (ul_Polarity)); - outl(ul_Command1, - dev->iobase + APCI3501_ANALOG_OUTPUT + - APCI3501_AO_PROG); + outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); } return insn->n; diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index d345daa..6207622 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -2,6 +2,17 @@ #include "comedi_fc.h" #include "amcc_s5933.h" +/* + * PCI bar 1 register I/O map + */ +#define APCI3501_AO_CTRL_STATUS_REG 0x00 +#define APCI3501_AO_CTRL_BIPOLAR (1 << 0) +#define APCI3501_AO_STATUS_READY (1 << 8) +#define APCI3501_AO_DATA_REG 0x04 +#define APCI3501_AO_TRIG_SCS_REG 0x08 +#define APCI3501_DO_REG 0x40 +#define APCI3501_DI_REG 0x50 + struct apci3501_private { int i_IobaseAmcc; struct task_struct *tsk_Current; @@ -36,7 +47,7 @@ static int apci3501_di_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - data[1] = inl(dev->iobase + APCI3501_DIGITAL_IP) & 0x3; + data[1] = inl(dev->iobase + APCI3501_DI_REG) & 0x3; return insn->n; } @@ -49,12 +60,12 @@ static int apci3501_do_insn_bits(struct comedi_device *dev, unsigned int mask = data[0]; unsigned int bits = data[1]; - s->state = inl(dev->iobase + APCI3501_DIGITAL_OP); + s->state = inl(dev->iobase + APCI3501_DO_REG); if (mask) { s->state &= ~mask; s->state |= (bits & mask); - outl(s->state, dev->iobase + APCI3501_DIGITAL_OP); + outl(s->state, dev->iobase + APCI3501_DO_REG); } data[1] = s->state; @@ -193,18 +204,17 @@ static int apci3501_reset(struct comedi_device *dev) int i_Count = 0, i_temp = 0; unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; - outl(0x0, dev->iobase + APCI3501_DIGITAL_OP); - outl(1, dev->iobase + APCI3501_ANALOG_OUTPUT + - APCI3501_AO_VOLT_MODE); + outl(0x0, dev->iobase + APCI3501_DO_REG); + outl(1, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); ul_Polarity = 0x80000000; for (i_Count = 0; i_Count <= 7; i_Count++) { - ul_DAC_Ready = inl(dev->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); while (ul_DAC_Ready == 0) { ul_DAC_Ready = - inl(dev->iobase + APCI3501_ANALOG_OUTPUT); + inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; } @@ -214,9 +224,7 @@ static int apci3501_reset(struct comedi_device *dev) (unsigned int) ((unsigned int) (i_Count & 0xFF) | (unsigned int) ((i_temp << 0x8) & 0x7FFFFF00L) | (unsigned int) (ul_Polarity)); - outl(ul_Command1, - dev->iobase + APCI3501_ANALOG_OUTPUT + - APCI3501_AO_PROG); + outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); } } -- cgit v0.10.2 From 53b28a23532f203f4b8287fad2461886088a9158 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:43:55 -0700 Subject: staging: comedi: addi_apci_3501: reorder code a bit Move the private struct definition and the #include of the low-level support code to prepare for merging the code in hwdrv_apci3501.c into the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 6207622..a7527a2 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -13,15 +13,6 @@ #define APCI3501_DO_REG 0x40 #define APCI3501_DI_REG 0x50 -struct apci3501_private { - int i_IobaseAmcc; - struct task_struct *tsk_Current; - unsigned char b_TimerSelectMode; - unsigned char b_InterruptMode; -}; - -#include "addi-data/hwdrv_apci3501.c" - /* * AMCC S5933 NVRAM */ @@ -42,6 +33,15 @@ struct apci3501_private { #define EEPROM_WATCHDOG 5 #define EEPROM_TIMER_WATCHDOG_COUNTER 10 +struct apci3501_private { + int i_IobaseAmcc; + struct task_struct *tsk_Current; + unsigned char b_TimerSelectMode; + unsigned char b_InterruptMode; +}; + +#include "addi-data/hwdrv_apci3501.c" + static int apci3501_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, -- cgit v0.10.2 From 99c9fa48b6bbc640066c414d6b413a1f1b4aa857 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:44:17 -0700 Subject: staging: comedi: addi_apci_3501: move range_apci3501_ao to driver Move the analog output range definition from hwdrv_apci3501.c into the main driver file. For aesthetic reasons, rename the range table so it has namespace associated with the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index bbdda4e..9739e8b 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -64,14 +64,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour #define ADDIDATA_TIMER 0 #define ADDIDATA_WATCHDOG 2 -/* ANALOG OUTPUT RANGE */ -static struct comedi_lrange range_apci3501_ao = { - 2, { - BIP_RANGE(10), - UNI_RANGE(10) - } -}; - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ConfigAnalogOutput | diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index a7527a2..b4679b2 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -40,6 +40,13 @@ struct apci3501_private { unsigned char b_InterruptMode; }; +static struct comedi_lrange apci3501_ao_range = { + 2, { + BIP_RANGE(10), + UNI_RANGE(10) + } +}; + #include "addi-data/hwdrv_apci3501.c" static int apci3501_di_insn_bits(struct comedi_device *dev, @@ -274,7 +281,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; s->n_chan = ao_n_chan; s->maxdata = 0x3fff; - s->range_table = &range_apci3501_ao; + s->range_table = &apci3501_ao_range; s->insn_config = i_APCI3501_ConfigAnalogOutput; s->insn_write = i_APCI3501_WriteAnalogOutput; } else { -- cgit v0.10.2 From 5458f3e7b5a8707a49948857d69b2eb2fa5931ac Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:44:40 -0700 Subject: staging: comedi: addi_apci_3501: introduce apci3501_wait_for_dac() Refactor the code that waits for the DAC to be ready into a helper function. A timeout of some sort should be added to this helper so code the users to expect the error condition. In i_APCI3501_WriteAnalogOutput() just return the error and don't actually write the new value to the DAC. In apci3501_reset() output a dev_warn() that the DAC was not ready. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 9739e8b..b057906 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -136,7 +136,8 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, unsigned int *data) { struct apci3501_private *devpriv = dev->private; - unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0; + unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity; + int ret; ul_Channel_no = CR_CHAN(insn->chanspec); @@ -159,21 +160,15 @@ static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); } /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */ - ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); + ret = apci3501_wait_for_dac(dev); + if (ret) + return ret; - while (ul_DAC_Ready == 0) { - ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); - ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; - } - - if (ul_DAC_Ready) { -/* Output the Value on the output channels. */ - ul_Command1 = - (unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) | + /* Output the Value on the output channels. */ + ul_Command1 = (unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) | (unsigned int) ((*data << 0x8) & 0x7FFFFF00L) | (unsigned int) (ul_Polarity)); - outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); - } + outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); return insn->n; } diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index b4679b2..906c37a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -47,6 +47,17 @@ static struct comedi_lrange apci3501_ao_range = { } }; +static int apci3501_wait_for_dac(struct comedi_device *dev) +{ + unsigned int status; + + do { + status = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); + } while (!(status & APCI3501_AO_STATUS_READY)); + + return 0; +} + #include "addi-data/hwdrv_apci3501.c" static int apci3501_di_insn_bits(struct comedi_device *dev, @@ -209,7 +220,8 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) static int apci3501_reset(struct comedi_device *dev) { int i_Count = 0, i_temp = 0; - unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; + unsigned int ul_Command1 = 0, ul_Polarity; + int ret; outl(0x0, dev->iobase + APCI3501_DO_REG); outl(1, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); @@ -217,15 +229,12 @@ static int apci3501_reset(struct comedi_device *dev) ul_Polarity = 0x80000000; for (i_Count = 0; i_Count <= 7; i_Count++) { - ul_DAC_Ready = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); - - while (ul_DAC_Ready == 0) { - ul_DAC_Ready = - inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG); - ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; - } - - if (ul_DAC_Ready) { + ret = apci3501_wait_for_dac(dev); + if (ret) { + dev_warn(dev->class_dev, + "%s: DAC not-ready for channel %i\n", + __func__, i_Count); + } else { /* Output the Value on the output channels. */ ul_Command1 = (unsigned int) ((unsigned int) (i_Count & 0xFF) | -- cgit v0.10.2 From 262736988d445cb1613aa936bfe343261627f899 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:45:01 -0700 Subject: staging: comedi: addi_apci_3501: cleanup apci3501_reset() Rename the CamelCase local variables. Refactor the code a bit to remove the need for some of the local variables. Add a couple defines to the register map to help make the code more concise. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 906c37a..d687081 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -9,6 +9,9 @@ #define APCI3501_AO_CTRL_BIPOLAR (1 << 0) #define APCI3501_AO_STATUS_READY (1 << 8) #define APCI3501_AO_DATA_REG 0x04 +#define APCI3501_AO_DATA_CHAN(x) ((x) << 0) +#define APCI3501_AO_DATA_VAL(x) ((x) << 8) +#define APCI3501_AO_DATA_BIPOLAR (1 << 31) #define APCI3501_AO_TRIG_SCS_REG 0x08 #define APCI3501_DO_REG 0x40 #define APCI3501_DI_REG 0x50 @@ -219,28 +222,28 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) static int apci3501_reset(struct comedi_device *dev) { - int i_Count = 0, i_temp = 0; - unsigned int ul_Command1 = 0, ul_Polarity; + unsigned int val; + int chan; int ret; + /* Reset all digital outputs to "0" */ outl(0x0, dev->iobase + APCI3501_DO_REG); - outl(1, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); - ul_Polarity = 0x80000000; + /* Default all analog outputs to 0V (bipolar) */ + outl(APCI3501_AO_CTRL_BIPOLAR, + dev->iobase + APCI3501_AO_CTRL_STATUS_REG); + val = APCI3501_AO_DATA_BIPOLAR | APCI3501_AO_DATA_VAL(0); - for (i_Count = 0; i_Count <= 7; i_Count++) { + /* Set all analog output channels */ + for (chan = 0; chan < 8; chan++) { ret = apci3501_wait_for_dac(dev); if (ret) { dev_warn(dev->class_dev, "%s: DAC not-ready for channel %i\n", - __func__, i_Count); + __func__, chan); } else { - /* Output the Value on the output channels. */ - ul_Command1 = - (unsigned int) ((unsigned int) (i_Count & 0xFF) | - (unsigned int) ((i_temp << 0x8) & 0x7FFFFF00L) | - (unsigned int) (ul_Polarity)); - outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); + outl(val | APCI3501_AO_DATA_CHAN(chan), + dev->iobase + APCI3501_AO_DATA_REG); } } -- cgit v0.10.2 From 298ab7de9ced3ecbe7961360ece58d5aa17aa3c1 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:45:21 -0700 Subject: staging: comedi: addi_apci_3501: rewrite the analog output support Currently the analog output subdevice has two support functions: (*insn_config) - i_APCI3501_ConfigAnalogOutput() (*insn_write) - i_APCI3501_WriteAnalogOutput() The (*insn_config) function is used to configure the analog outputs in either bipolar or unipolar mode. This function abuses the comedi API since it treats the data[0] value as a parameter instead of as the config "instruction". The (*insn_write) function then writes a single value to the desired analog output channel after doing some sanity checking on the channel number. The sanity checking is not required since the comedi core has already done it. Also, the (*insn_write) functions are supposed to write all the data, indicated by insn->n, to the channel not just a single value. Rewrite the support code so it works properly with the comedi API. The bipolar/unipolar configuration can be determine in the (*insn_write) by checking the passed insn->chanspec. Since the unipolar configuration only has 13-bit resolution, we need to check that the data is in range because the subdevice 'maxdata' is set to 14-bits for the bipolar mode. If the data is out of range, output a dev_warn() and return -EINVAL. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index b057906..7d8fbdf 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -46,10 +46,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour +----------+-----------+------------------------------------------------+ */ -/* Analog Output related Defines */ -#define MODE0 0 -#define MODE1 1 - /* Watchdog Related Defines */ #define APCI3501_WATCHDOG 0x20 @@ -66,115 +62,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour /* +----------------------------------------------------------------------------+ -| Function Name : int i_APCI3501_ConfigAnalogOutput | -| (struct comedi_device *dev,struct comedi_subdevice *s, | -| struct comedi_insn *insn,unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Configures The Analog Output Subdevice | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| struct comedi_subdevice *s : Subdevice Pointer | -| struct comedi_insn *insn : Insn Structure Pointer | -| unsigned int *data : Data Pointer contains | -| configuration parameters as below | -| | -| data[0] : Voltage Mode | -| 0:Mode 0 | -| 1:Mode 1 | -| | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3501_ConfigAnalogOutput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci3501_private *devpriv = dev->private; - - outl(data[0], dev->iobase + APCI3501_AO_CTRL_STATUS_REG); - - if (data[0]) { - devpriv->b_InterruptMode = MODE1; - } else { - devpriv->b_InterruptMode = MODE0; - } - return insn->n; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3501_WriteAnalogOutput | -| (struct comedi_device *dev,struct comedi_subdevice *s, | -| struct comedi_insn *insn,unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Writes To the Selected Anlog Output Channel | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| struct comedi_subdevice *s : Subdevice Pointer | -| struct comedi_insn *insn : Insn Structure Pointer | -| unsigned int *data : Data Pointer contains | -| configuration parameters as below | -| | -| | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci3501_private *devpriv = dev->private; - unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity; - int ret; - - ul_Channel_no = CR_CHAN(insn->chanspec); - - if (devpriv->b_InterruptMode == MODE1) { - ul_Polarity = 0x80000000; - if ((*data < 0) || (*data > 16384)) { - printk("\nIn WriteAnalogOutput :: Not Valid Data\n"); - } - - } /* end if(devpriv->b_InterruptMode==MODE1) */ - else { - ul_Polarity = 0; - if ((*data < 0) || (*data > 8192)) { - printk("\nIn WriteAnalogOutput :: Not Valid Data\n"); - } - - } /* end else */ - - if ((ul_Channel_no < 0) || (ul_Channel_no > 7)) { - printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); - } /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */ - - ret = apci3501_wait_for_dac(dev); - if (ret) - return ret; - - /* Output the Value on the output channels. */ - ul_Command1 = (unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) | - (unsigned int) ((*data << 0x8) & 0x7FFFFF00L) | - (unsigned int) (ul_Polarity)); - outl(ul_Command1, dev->iobase + APCI3501_AO_DATA_REG); - - return insn->n; -} - -/* -+----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ConfigTimerCounterWatchdog | | (struct comedi_device *dev,struct comedi_subdevice *s, | | struct comedi_insn *insn,unsigned int *data) | diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index d687081..7fedf15 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -40,7 +40,6 @@ struct apci3501_private { int i_IobaseAmcc; struct task_struct *tsk_Current; unsigned char b_TimerSelectMode; - unsigned char b_InterruptMode; }; static struct comedi_lrange apci3501_ao_range = { @@ -61,6 +60,53 @@ static int apci3501_wait_for_dac(struct comedi_device *dev) return 0; } +static int apci3501_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val = 0; + int i; + int ret; + + /* + * All analog output channels have the same output range. + * 14-bit bipolar: 0-10V + * 13-bit unipolar: +/-10V + * Changing the range of one channel changes all of them! + */ + if (range) { + outl(0, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); + } else { + val |= APCI3501_AO_DATA_BIPOLAR; + outl(APCI3501_AO_CTRL_BIPOLAR, + dev->iobase + APCI3501_AO_CTRL_STATUS_REG); + } + + val |= APCI3501_AO_DATA_CHAN(chan); + + for (i = 0; i < insn->n; i++) { + if (range == 1) { + if (data[i] > 0x1fff) { + dev_err(dev->class_dev, + "Unipolar resolution is only 13-bits\n"); + return -EINVAL; + } + } + + ret = apci3501_wait_for_dac(dev); + if (ret) + return ret; + + outl(val | APCI3501_AO_DATA_VAL(data[i]), + dev->iobase + APCI3501_AO_DATA_REG); + } + + return insn->n; +} + #include "addi-data/hwdrv_apci3501.c" static int apci3501_di_insn_bits(struct comedi_device *dev, @@ -294,8 +340,7 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->n_chan = ao_n_chan; s->maxdata = 0x3fff; s->range_table = &apci3501_ao_range; - s->insn_config = i_APCI3501_ConfigAnalogOutput; - s->insn_write = i_APCI3501_WriteAnalogOutput; + s->insn_write = apci3501_ao_insn_write; } else { s->type = COMEDI_SUBD_UNUSED; } -- cgit v0.10.2 From 027f58c637cda26ba4492b782a08f697f99a1e23 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:45:42 -0700 Subject: staging: comedi: addi_apci_3501: move the copyright information Move the copyright information from hwrdv_apci3501.c to the main driver file. Reformat it to fix the > 80 char lines. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Cc: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 7d8fbdf..aeaa533 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -1,51 +1,3 @@ -/** -@verbatim - -Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. - - ADDI-DATA GmbH - Dieselstrasse 3 - D-77833 Ottersweier - Tel: +19(0)7223/9493-0 - Fax: +49(0)7223/9493-92 - http://www.addi-data.com - info@addi-data.com - -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - -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. - -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - -@endverbatim -*/ -/*. - - +-----------------------------------------------------------------------+ - | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier | - +-----------------------------------------------------------------------+ - | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | - | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | - +-------------------------------+---------------------------------------+ - | Project : APCI-3501 | Compiler : GCC | - | Module name : hwdrv_apci3501.c| Version : 2.96 | - +-------------------------------+---------------------------------------+ - | Project manager: Eric Stolz | Date : 02/12/2002 | - +-------------------------------+---------------------------------------+ - | Description : Hardware Layer Access For APCI-3501 | - +-----------------------------------------------------------------------+ - | UPDATES | - +----------+-----------+------------------------------------------------+ - | Date | Author | Description of updates | - +----------+-----------+------------------------------------------------+ - | | | | - | | | | - | | | | - +----------+-----------+------------------------------------------------+ -*/ - /* Watchdog Related Defines */ #define APCI3501_WATCHDOG 0x20 diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 7fedf15..9dd6bff 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -1,3 +1,34 @@ +/* + * addi_apci_3501.c + * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. + * Project manager: Eric Stolz + * + * ADDI-DATA GmbH + * Dieselstrasse 3 + * D-77833 Ottersweier + * Tel: +19(0)7223/9493-0 + * Fax: +49(0)7223/9493-92 + * http://www.addi-data.com + * info@addi-data.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * You should also find the complete GPL in the COPYING file accompanying + * this source code. + */ + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" -- cgit v0.10.2 From 6ff35881e882f744a4a9954fbf838296a36fe7c2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:46:01 -0700 Subject: staging: comedi: addi_apci_3501: change the MODULE_DESCRIPTION Change the MODULE_DESCRIPTION to something more useful than the generic "Comedi low-level driver" so that modinfo provides a better description of the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 9dd6bff..72292ab 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -464,6 +464,6 @@ static struct pci_driver apci3501_pci_driver = { }; module_comedi_pci_driver(apci3501_driver, apci3501_pci_driver); +MODULE_DESCRIPTION("ADDI-DATA APCI-3501 Analog output board"); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 9798df7269a44fb148d1815542abb844b0dac435 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:46:22 -0700 Subject: staging: comedi: addi_apci_3501: define the timer i/o registers Create, and use, defines for the i/o registers used with the timer subdevice. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index aeaa533..3dbe99d 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -1,14 +1,5 @@ /* Watchdog Related Defines */ -#define APCI3501_WATCHDOG 0x20 -#define APCI3501_TCW_SYNC_ENABLEDISABLE 0 -#define APCI3501_TCW_RELOAD_VALUE 4 -#define APCI3501_TCW_TIMEBASE 8 -#define APCI3501_TCW_PROG 12 -#define APCI3501_TCW_TRIG_STATUS 16 -#define APCI3501_TCW_IRQ 20 -#define APCI3501_TCW_WARN_TIMEVAL 24 -#define APCI3501_TCW_WARN_TIMEBASE 28 #define ADDIDATA_TIMER 0 #define ADDIDATA_WATCHDOG 2 @@ -52,69 +43,47 @@ static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev, devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; /* Disable the watchdog */ - outl(0x0, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Wa */ + outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG); if (data[1] == 1) { /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ - outl(0x02, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG); } else { - outl(0x0, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ + /* disable Timer interrupt */ + outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG); } - /* Loading the Timebase value */ - outl(data[2], - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TIMEBASE); + outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG); + outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG); - /* Loading the Reload value */ - outl(data[3], - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_RELOAD_VALUE); - /* Set the mode */ - ul_Command1 = inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG) | 0xFFF819E0UL; /* e2->e0 */ - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); - } /* end if(data[0]==ADDIDATA_WATCHDOG) */ + /* Set the mode (e2->e0) */ + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG) | 0xFFF819E0UL; + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); + } else if (data[0] == ADDIDATA_TIMER) { /* First Stop The Timer */ - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* Stop The Timer */ + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); devpriv->b_TimerSelectMode = ADDIDATA_TIMER; if (data[1] == 1) { /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ - outl(0x02, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG); } else { - outl(0x0, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ + /* disable Timer interrupt */ + outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG); } - /* Loading Timebase */ - outl(data[2], - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TIMEBASE); - - /* Loading the Reload value */ - outl(data[3], - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_RELOAD_VALUE); + outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG); + outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG); - /* printk ("\nTimer Address :: %x\n", (dev->iobase + APCI3501_WATCHDOG)); */ - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + /* mode 2 */ + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; - outl(ul_Command1, dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* mode 2 */ - - } /* end if(data[0]==ADDIDATA_TIMER) */ + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); + } return insn->n; } @@ -156,73 +125,48 @@ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *d if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { if (data[1] == 1) { - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; /* Enable the Watchdog */ - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); } else if (data[1] == 0) /* Stop The Watchdog */ { /* Stop The Watchdog */ - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; - outl(0x0, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG); } else if (data[1] == 2) { - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); - } /* if(data[1]==2) */ - } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */ + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); + } + } if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { if (data[1] == 1) { - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; /* Enable the Timer */ - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); } else if (data[1] == 0) { /* Stop The Timer */ - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); } else if (data[1] == 2) { /* Trigger the Timer */ - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_PROG); + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); } + } - } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */ - i_Temp = inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TRIG_STATUS) & 0x1; + i_Temp = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; return insn->n; } @@ -258,18 +202,14 @@ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, struct apci3501_private *devpriv = dev->private; if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { - data[0] = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TRIG_STATUS) & 0x1; - data[1] = inl(dev->iobase + APCI3501_WATCHDOG); - } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */ + data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; + data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG); + } else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { - data[0] = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TRIG_STATUS) & 0x1; - data[1] = inl(dev->iobase + APCI3501_WATCHDOG); - } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */ + data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; + data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG); + } else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)) { diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 72292ab..0fdcbe2 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -44,6 +44,14 @@ #define APCI3501_AO_DATA_VAL(x) ((x) << 8) #define APCI3501_AO_DATA_BIPOLAR (1 << 31) #define APCI3501_AO_TRIG_SCS_REG 0x08 +#define APCI3501_TIMER_SYNC_REG 0x20 +#define APCI3501_TIMER_RELOAD_REG 0x24 +#define APCI3501_TIMER_TIMEBASE_REG 0x28 +#define APCI3501_TIMER_CTRL_REG 0x2c +#define APCI3501_TIMER_STATUS_REG 0x30 +#define APCI3501_TIMER_IRQ_REG 0x34 +#define APCI3501_TIMER_WARN_RELOAD_REG 0x38 +#define APCI3501_TIMER_WARN_TIMEBASE_REG 0x3c #define APCI3501_DO_REG 0x40 #define APCI3501_DI_REG 0x50 @@ -268,17 +276,11 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) int i_temp; /* Disable Interrupt */ - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = (ul_Command1 & 0xFFFFF9FDul); - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - - ui_Timer_AOWatchdog = - inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_IRQ) & 0x1; + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); + ui_Timer_AOWatchdog = inl(dev->iobase + APCI3501_TIMER_IRQ_REG) & 0x1; if ((!ui_Timer_AOWatchdog)) { comedi_error(dev, "IRQ from unknown source"); return IRQ_NONE; @@ -286,13 +288,10 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) /* Enable Interrupt Send a signal to from kernel to user space */ send_sig(SIGIO, devpriv->tsk_Current, 0); - ul_Command1 = - inl(dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1); - outl(ul_Command1, - dev->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); - i_temp = inl(dev->iobase + APCI3501_WATCHDOG + - APCI3501_TCW_TRIG_STATUS) & 0x1; + outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); + i_temp = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; return IRQ_HANDLED; } -- cgit v0.10.2 From 1ef0cfb192905d0e8d03d15a69b446c26d54c81f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:46:45 -0700 Subject: staging: comedi: addi_apci_3501: cleanup comments in hwdrv_apci3501.c The watchdog/timer subdevice in this driver is basically broke. The subdevice functions abuse the comedi API and the (*insn_config) simply doesn't work due to it's treating data[0] as a parameter and not as the config "instruction". For now, cleanup the comments for the functions so they are at least readable. Then we can figure out how to fix the subdevice. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 3dbe99d..ebc1534 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -4,32 +4,18 @@ #define ADDIDATA_WATCHDOG 2 /* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3501_ConfigTimerCounterWatchdog | -| (struct comedi_device *dev,struct comedi_subdevice *s, | -| struct comedi_insn *insn,unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Configures The Timer , Counter or Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| unsigned int *data : Data Pointer contains | -| configuration parameters as below | -| | -| data[0] : 0 Configure As Timer | -| 1 Configure As Counter | -| 2 Configure As Watchdog | -| data[1] : 1 Enable Interrupt | -| 0 Disable Interrupt | -| data[2] : Time Unit | -| data[3] : Reload Value | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ + * (*insn_config) for the timer subdevice + * + * Configures The Timer, Counter or Watchdog + * Data Pointer contains configuration parameters as below + * data[0] : 0 Configure As Timer + * 1 Configure As Counter + * 2 Configure As Watchdog + * data[1] : 1 Enable Interrupt + * 0 Disable Interrupt + * data[2] : Time Unit + * data[3] : Reload Value + */ static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -89,30 +75,17 @@ static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev, } /* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3501_StartStopWriteTimerCounterWatchdog | -| (struct comedi_device *dev,struct comedi_subdevice *s, | -| struct comedi_insn *insn,unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Start / Stop The Selected Timer , Counter or Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| unsigned int *data : Data Pointer contains | -| configuration parameters as below | -| | -| data[0] : 0 Timer | -| 1 Counter | -| 2 Watchdog | | data[1] : 1 Start | -| 0 Stop | 2 Trigger | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - + * (*insn_write) for the timer subdevice + * + * Start / Stop The Selected Timer , Counter or Watchdog + * Data Pointer contains configuration parameters as below + * data[0] : 0 Timer + * 1 Counter + * 2 Watchdog + * data[1] : 1 Start + * 0 Stop + * 2 Trigger + */ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -171,29 +144,15 @@ static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *d } /* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3501_ReadTimerCounterWatchdog | -| (struct comedi_device *dev,struct comedi_subdevice *s, | -| struct comedi_insn *insn,unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Read The Selected Timer , Counter or Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev : Driver handle | -| unsigned int *data : Data Pointer contains | -| configuration parameters as below | -| | -| data[0] : 0 Timer | -| 1 Counter | -| 2 Watchdog | | data[1] : Timer Counter Watchdog Number | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - + * (*insn_read) for the timer subdevice + * + * Read The Selected Timer, Counter or Watchdog + * Data Pointer contains configuration parameters as below + * data[0] : 0 Timer + * 1 Counter + * 2 Watchdog + * data[1] : Timer Counter Watchdog Number + */ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, -- cgit v0.10.2 From c2f90a20c9166bf9effb064703903039a49324e3 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 23 Jan 2013 00:03:30 +0100 Subject: staging/comedi: Move comedi_pci_auto_unconfig to drivers.c Since comedi_pci_auto_unconfig cannot be inlined anymore after staging/comedi: Use comedi_pci_auto_unconfig directly for pci_driver.remove is applied, it makes sense to move it drivers.c Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 6211d44..e2b7d60 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -484,10 +484,7 @@ static inline int comedi_pci_auto_config(struct pci_dev *pcidev, return comedi_auto_config(&pcidev->dev, driver, 0); } -static inline void comedi_pci_auto_unconfig(struct pci_dev *pcidev) -{ - comedi_auto_unconfig(&pcidev->dev); -} +void comedi_pci_auto_unconfig(struct pci_dev *pcidev); static inline int comedi_usb_auto_config(struct usb_interface *intf, struct comedi_driver *driver) diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 1c7d4da..87eeee5 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -558,6 +558,12 @@ void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver, } EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister); +void comedi_pci_auto_unconfig(struct pci_dev *pcidev) +{ + comedi_auto_unconfig(&pcidev->dev); +} +EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig); + #if IS_ENABLED(CONFIG_PCMCIA) int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, struct pcmcia_driver *pcmcia_driver) -- cgit v0.10.2 From 9901a4d75d007686e8f6473189cafc4b216b7449 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 22 Jan 2013 23:40:03 +0100 Subject: staging/comedi: Use comedi_pci_auto_unconfig directly for pci_driver.remove (Almost) all comedi pci drivers have some wrapper for their pci_driver.remove function which simply calls comedi_pci_auto_unconfig which has the same function prototype as the wrapper. -> we can remove these wrappers and call comedi_pci_auto_unconfig directly. This removes a lot some boilerplate code and saves some bytes. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index e0a7952..87fe96d 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -314,11 +314,6 @@ static int pci_8255_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &pci_8255_driver); } -static void pci_8255_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(pci_8255_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7224) }, { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7248) }, @@ -342,7 +337,7 @@ static struct pci_driver pci_8255_pci_driver = { .name = "8255_pci", .id_table = pci_8255_pci_table, .probe = pci_8255_pci_probe, - .remove = pci_8255_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_035.c b/drivers/staging/comedi/drivers/addi_apci_035.c index c981d4b..d69d6ec 100644 --- a/drivers/staging/comedi/drivers/addi_apci_035.c +++ b/drivers/staging/comedi/drivers/addi_apci_035.c @@ -53,11 +53,6 @@ static int apci035_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci035_driver); } -static void apci035_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci035_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x0300) }, { 0 } @@ -68,7 +63,7 @@ static struct pci_driver apci035_pci_driver = { .name = "addi_apci_035", .id_table = apci035_pci_table, .probe = apci035_pci_probe, - .remove = apci035_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci035_driver, apci035_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index 7f94242..d2abfc2 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -375,11 +375,6 @@ static int apci1032_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci1032_driver); } -static void apci1032_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci1032_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1003) }, { 0 } @@ -390,7 +385,7 @@ static struct pci_driver apci1032_pci_driver = { .name = "addi_apci_1032", .id_table = apci1032_pci_table, .probe = apci1032_pci_probe, - .remove = apci1032_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci1032_driver, apci1032_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_1500.c b/drivers/staging/comedi/drivers/addi_apci_1500.c index 8e686a9..1ac4062 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1500.c +++ b/drivers/staging/comedi/drivers/addi_apci_1500.c @@ -53,11 +53,6 @@ static int apci1500_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci1500_driver); } -static void apci1500_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci1500_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x80fc) }, { 0 } @@ -68,7 +63,7 @@ static struct pci_driver apci1500_pci_driver = { .name = "addi_apci_1500", .id_table = apci1500_pci_table, .probe = apci1500_pci_probe, - .remove = apci1500_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci1500_driver, apci1500_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c index 8fef04b..0911516 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1516.c +++ b/drivers/staging/comedi/drivers/addi_apci_1516.c @@ -323,11 +323,6 @@ static int apci1516_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci1516_driver); } -static void apci1516_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci1516_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1016) }, { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1516) }, @@ -340,7 +335,7 @@ static struct pci_driver apci1516_pci_driver = { .name = "addi_apci_1516", .id_table = apci1516_pci_table, .probe = apci1516_pci_probe, - .remove = apci1516_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci1516_driver, apci1516_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c index 513e536..3556c61 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1564.c +++ b/drivers/staging/comedi/drivers/addi_apci_1564.c @@ -50,11 +50,6 @@ static int apci1564_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci1564_driver); } -static void apci1564_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci1564_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1006) }, { 0 } @@ -65,7 +60,7 @@ static struct pci_driver apci1564_pci_driver = { .name = "addi_apci_1564", .id_table = apci1564_pci_table, .probe = apci1564_pci_probe, - .remove = apci1564_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci1564_driver, apci1564_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index a04d66c..8b88503 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -228,11 +228,6 @@ static int apci16xx_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci16xx_driver); } -static void apci16xx_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci16xx_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1648) }, { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1696) }, @@ -244,7 +239,7 @@ static struct pci_driver apci16xx_pci_driver = { .name = "addi_apci_16xx", .id_table = apci16xx_pci_table, .probe = apci16xx_pci_probe, - .remove = apci16xx_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci16xx_driver, apci16xx_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_1710.c b/drivers/staging/comedi/drivers/addi_apci_1710.c index 152e7ef..7eb03b1 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1710.c +++ b/drivers/staging/comedi/drivers/addi_apci_1710.c @@ -128,11 +128,6 @@ static int apci1710_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci1710_driver); } -static void apci1710_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci1710_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, APCI1710_BOARD_DEVICE_ID) }, { 0 } @@ -143,7 +138,7 @@ static struct pci_driver apci1710_pci_driver = { .name = "addi_apci_1710", .id_table = apci1710_pci_table, .probe = apci1710_pci_probe, - .remove = apci1710_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci1710_driver, apci1710_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 4660ec7..5ad9db9 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -376,11 +376,6 @@ static int apci2032_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci2032_driver); } -static void apci2032_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci2032_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1004) }, { 0 } @@ -391,7 +386,7 @@ static struct pci_driver apci2032_pci_driver = { .name = "addi_apci_2032", .id_table = apci2032_pci_table, .probe = apci2032_pci_probe, - .remove = apci2032_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci2032_driver, apci2032_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 4092faa..a9891b4 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -153,11 +153,6 @@ static int apci2200_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci2200_driver); } -static void apci2200_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) }, { 0 } @@ -168,7 +163,7 @@ static struct pci_driver apci2200_pci_driver = { .name = "addi_apci_2200", .id_table = apci2200_pci_table, .probe = apci2200_pci_probe, - .remove = apci2200_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c index fec2962..8cad18f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3120.c +++ b/drivers/staging/comedi/drivers/addi_apci_3120.c @@ -251,11 +251,6 @@ static int apci3120_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci3120_driver); } -static void apci3120_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci3120_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x818d) }, { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x828d) }, @@ -267,7 +262,7 @@ static struct pci_driver apci3120_pci_driver = { .name = "addi_apci_3120", .id_table = apci3120_pci_table, .probe = apci3120_pci_probe, - .remove = apci3120_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci3120_driver, apci3120_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_3200.c b/drivers/staging/comedi/drivers/addi_apci_3200.c index 9085b77..c11bf4b 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3200.c +++ b/drivers/staging/comedi/drivers/addi_apci_3200.c @@ -106,15 +106,10 @@ static int apci3200_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci3200_driver); } -static void apci3200_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver apci3200_pci_driver = { .name = "addi_apci_3200", .id_table = apci3200_pci_table, .probe = apci3200_pci_probe, - .remove = apci3200_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci3200_driver, apci3200_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 0fdcbe2..8920b96 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -444,11 +444,6 @@ static int apci3501_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci3501_driver); } -static void apci3501_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci3501_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3001) }, { 0 } @@ -459,7 +454,7 @@ static struct pci_driver apci3501_pci_driver = { .name = "addi_apci_3501", .id_table = apci3501_pci_table, .probe = apci3501_pci_probe, - .remove = apci3501_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci3501_driver, apci3501_pci_driver); diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index 1562347..69f5bf4 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -751,11 +751,6 @@ static int apci3xxx_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &apci3xxx_driver); } -static void apci3xxx_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(apci3xxx_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3010) }, { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x300f) }, @@ -790,7 +785,7 @@ static struct pci_driver apci3xxx_pci_driver = { .name = "addi_apci_3xxx", .id_table = apci3xxx_pci_table, .probe = apci3xxx_pci_probe, - .remove = apci3xxx_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(apci3xxx_driver, apci3xxx_pci_driver); diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c index 9a56eed..41df010 100644 --- a/drivers/staging/comedi/drivers/adl_pci6208.c +++ b/drivers/staging/comedi/drivers/adl_pci6208.c @@ -270,11 +270,6 @@ static int adl_pci6208_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adl_pci6208_driver); } -static void adl_pci6208_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6208) }, { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6216) }, @@ -286,7 +281,7 @@ static struct pci_driver adl_pci6208_pci_driver = { .name = "adl_pci6208", .id_table = adl_pci6208_pci_table, .probe = adl_pci6208_pci_probe, - .remove = adl_pci6208_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver); diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c index 772edc0..2a8bc98 100644 --- a/drivers/staging/comedi/drivers/adl_pci7x3x.c +++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c @@ -302,11 +302,6 @@ static int adl_pci7x3x_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adl_pci7x3x_driver); } -static void adl_pci7x3x_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adl_pci7x3x_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) }, { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7233) }, @@ -322,7 +317,7 @@ static struct pci_driver adl_pci7x3x_pci_driver = { .name = "adl_pci7x3x", .id_table = adl_pci7x3x_pci_table, .probe = adl_pci7x3x_pci_probe, - .remove = adl_pci7x3x_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adl_pci7x3x_driver, adl_pci7x3x_pci_driver); diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index 4dd9d70..bfa71e0 100644 --- a/drivers/staging/comedi/drivers/adl_pci8164.c +++ b/drivers/staging/comedi/drivers/adl_pci8164.c @@ -298,11 +298,6 @@ static int adl_pci8164_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adl_pci8164_driver); } -static void adl_pci8164_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) }, {0} @@ -313,7 +308,7 @@ static struct pci_driver adl_pci8164_pci_driver = { .name = "adl_pci8164", .id_table = adl_pci8164_pci_table, .probe = adl_pci8164_pci_probe, - .remove = adl_pci8164_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adl_pci8164_driver, adl_pci8164_pci_driver); diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c index a339b9d..1a31e91 100644 --- a/drivers/staging/comedi/drivers/adl_pci9111.c +++ b/drivers/staging/comedi/drivers/adl_pci9111.c @@ -963,11 +963,6 @@ static int pci9111_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adl_pci9111_driver); } -static void pci9111_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID) }, /* { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID) }, */ @@ -979,7 +974,7 @@ static struct pci_driver adl_pci9111_pci_driver = { .name = "adl_pci9111", .id_table = pci9111_pci_table, .probe = pci9111_pci_probe, - .remove = pci9111_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adl_pci9111_driver, adl_pci9111_pci_driver); diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index b6dda80..d21dfe6 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -2225,11 +2225,6 @@ static int adl_pci9118_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adl_pci9118_driver); } -static void adl_pci9118_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adl_pci9118_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_AMCC, 0x80d9) }, { 0 } @@ -2240,7 +2235,7 @@ static struct pci_driver adl_pci9118_pci_driver = { .name = "adl_pci9118", .id_table = adl_pci9118_pci_table, .probe = adl_pci9118_pci_probe, - .remove = adl_pci9118_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adl_pci9118_driver, adl_pci9118_pci_driver); diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c index a6fd8c2..d232d0c 100644 --- a/drivers/staging/comedi/drivers/adv_pci1710.c +++ b/drivers/staging/comedi/drivers/adv_pci1710.c @@ -1402,11 +1402,6 @@ static int adv_pci1710_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adv_pci1710_driver); } -static void adv_pci1710_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adv_pci1710_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1710) }, { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1711) }, @@ -1421,7 +1416,7 @@ static struct pci_driver adv_pci1710_pci_driver = { .name = "adv_pci1710", .id_table = adv_pci1710_pci_table, .probe = adv_pci1710_pci_probe, - .remove = adv_pci1710_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adv_pci1710_driver, adv_pci1710_pci_driver); diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c index 5af7314..1be8902 100644 --- a/drivers/staging/comedi/drivers/adv_pci1723.c +++ b/drivers/staging/comedi/drivers/adv_pci1723.c @@ -327,11 +327,6 @@ static int adv_pci1723_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adv_pci1723_driver); } -static void adv_pci1723_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adv_pci1723_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1723) }, { 0 } @@ -342,7 +337,7 @@ static struct pci_driver adv_pci1723_pci_driver = { .name = "adv_pci1723", .id_table = adv_pci1723_pci_table, .probe = adv_pci1723_pci_probe, - .remove = adv_pci1723_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver); diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index 05a663e..35887e4 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -1206,11 +1206,6 @@ static int adv_pci_dio_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &adv_pci_dio_driver); } -static void adv_pci_dio_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(adv_pci_dio_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) }, { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) }, @@ -1234,7 +1229,7 @@ static struct pci_driver adv_pci_dio_pci_driver = { .name = "adv_pci_dio", .id_table = adv_pci_dio_pci_table, .probe = adv_pci_dio_pci_probe, - .remove = adv_pci_dio_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(adv_pci_dio_driver, adv_pci_dio_pci_driver); diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c index b09269d..1fadf5d 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.c +++ b/drivers/staging/comedi/drivers/amplc_dio200.c @@ -2078,16 +2078,11 @@ static int amplc_dio200_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &lc_dio200_driver); } -static void amplc_dio200_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver amplc_dio200_pci_driver = { .name = DIO200_DRIVER_NAME, .id_table = dio200_pci_table, .probe = &lc_dio200_pci_probe, - .remove = &lc_dio200_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(amplc_dio200_driver, amplc_dio200_pci_driver); #else diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c index 2898354..5011016 100644 --- a/drivers/staging/comedi/drivers/amplc_pc236.c +++ b/drivers/staging/comedi/drivers/amplc_pc236.c @@ -614,16 +614,11 @@ static int amplc_pc236_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &lc_pc236_driver); } -static void amplc_pc236_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver amplc_pc236_pci_driver = { .name = PC236_DRIVER_NAME, .id_table = pc236_pci_table, .probe = &lc_pc236_pci_probe, - .remove = &lc_pc236_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(amplc_pc236_driver, amplc_pc236_pci_driver); diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c index dfbff77..c34bb00 100644 --- a/drivers/staging/comedi/drivers/amplc_pc263.c +++ b/drivers/staging/comedi/drivers/amplc_pc263.c @@ -372,16 +372,11 @@ static int amplc_pc263_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &lc_pc263_driver); } -static void amplc_pc263_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver amplc_pc263_pci_driver = { .name = PC263_DRIVER_NAME, .id_table = pc263_pci_table, .probe = &lc_pc263_pci_probe, - .remove = &lc_pc263_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(amplc_pc263_driver, amplc_pc263_pci_driver); #else diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c index 6e2566a..24794f4 100644 --- a/drivers/staging/comedi/drivers/amplc_pci224.c +++ b/drivers/staging/comedi/drivers/amplc_pci224.c @@ -1512,11 +1512,6 @@ static int amplc_pci224_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &lc_pci224_driver); } -static void amplc_pci224_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(amplc_pci224_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224) }, { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234) }, @@ -1528,7 +1523,7 @@ static struct pci_driver amplc_pci224_pci_driver = { .name = "amplc_pci224", .id_table = amplc_pci224_pci_table, .probe = amplc_pci224_pci_probe, - .remove = amplc_pci224_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(amplc_pci224_driver, amplc_pci224_pci_driver); diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 366c68b..2440596 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -2863,11 +2863,6 @@ static int amplc_pci230_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &lc_pci230_driver); } -static void amplc_pci230_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(amplc_pci230_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230) }, { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260) }, @@ -2879,7 +2874,7 @@ static struct pci_driver amplc_pci230_pci_driver = { .name = "amplc_pci230", .id_table = amplc_pci230_pci_table, .probe = amplc_pci230_pci_probe, - .remove = amplc_pci230_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(amplc_pci230_driver, amplc_pci230_pci_driver); diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index aed6863..0fd6fcf 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -1632,11 +1632,6 @@ static int cb_pcidas_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &cb_pcidas_driver); } -static void cb_pcidas_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) }, { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) }, @@ -1654,7 +1649,7 @@ static struct pci_driver cb_pcidas_pci_driver = { .name = "cb_pcidas", .id_table = cb_pcidas_pci_table, .probe = cb_pcidas_pci_probe, - .remove = cb_pcidas_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(cb_pcidas_driver, cb_pcidas_pci_driver); diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c index d72b46c..e7d2977 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas64.c +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c @@ -4220,11 +4220,6 @@ static int cb_pcidas64_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &cb_pcidas64_driver); } -static void cb_pcidas64_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(cb_pcidas64_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001d) }, { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001e) }, @@ -4253,7 +4248,7 @@ static struct pci_driver cb_pcidas64_pci_driver = { .name = "cb_pcidas64", .id_table = cb_pcidas64_pci_table, .probe = cb_pcidas64_pci_probe, - .remove = cb_pcidas64_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(cb_pcidas64_driver, cb_pcidas64_pci_driver); diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index 7c6029a..04be8c6 100644 --- a/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/drivers/staging/comedi/drivers/cb_pcidda.c @@ -438,11 +438,6 @@ static int cb_pcidda_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &cb_pcidda_driver); } -static void cb_pcidda_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA02_12) }, { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA04_12) }, @@ -458,7 +453,7 @@ static struct pci_driver cb_pcidda_pci_driver = { .name = "cb_pcidda", .id_table = cb_pcidda_pci_table, .probe = cb_pcidda_pci_probe, - .remove = cb_pcidda_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(cb_pcidda_driver, cb_pcidda_pci_driver); diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c index b43a5f8..709c5c6 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdas.c +++ b/drivers/staging/comedi/drivers/cb_pcimdas.c @@ -299,11 +299,6 @@ static int cb_pcimdas_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &cb_pcimdas_driver); } -static void cb_pcimdas_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) }, { 0 } @@ -314,7 +309,7 @@ static struct pci_driver cb_pcimdas_pci_driver = { .name = "cb_pcimdas", .id_table = cb_pcimdas_pci_table, .probe = cb_pcimdas_pci_probe, - .remove = cb_pcimdas_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver); diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index 699b84f..74aa4e0 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c @@ -222,11 +222,6 @@ static int cb_pcimdda_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &cb_pcimdda_driver); } -static void cb_pcimdda_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) }, { 0 } @@ -237,7 +232,7 @@ static struct pci_driver cb_pcimdda_driver_pci_driver = { .name = "cb_pcimdda", .id_table = cb_pcimdda_pci_table, .probe = cb_pcimdda_pci_probe, - .remove = cb_pcimdda_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver); diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c index 1a18fa3..e0273c4 100644 --- a/drivers/staging/comedi/drivers/contec_pci_dio.c +++ b/drivers/staging/comedi/drivers/contec_pci_dio.c @@ -130,11 +130,6 @@ static int contec_pci_dio_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &contec_pci_dio_driver); } -static void contec_pci_dio_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) }, { 0 } @@ -145,7 +140,7 @@ static struct pci_driver contec_pci_dio_pci_driver = { .name = "contec_pci_dio", .id_table = contec_pci_dio_pci_table, .probe = contec_pci_dio_pci_probe, - .remove = contec_pci_dio_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver); diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index d206c7b..d1fc190 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -799,11 +799,6 @@ static int daqboard2000_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &daqboard2000_driver); } -static void daqboard2000_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) }, { 0 } @@ -814,7 +809,7 @@ static struct pci_driver daqboard2000_pci_driver = { .name = "daqboard2000", .id_table = daqboard2000_pci_table, .probe = daqboard2000_pci_probe, - .remove = daqboard2000_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(daqboard2000_driver, daqboard2000_pci_driver); diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c index b15e058..37f03c2 100644 --- a/drivers/staging/comedi/drivers/das08.c +++ b/drivers/staging/comedi/drivers/das08.c @@ -891,16 +891,11 @@ static int das08_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &das08_driver); } -static void das08_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver das08_pci_driver = { .id_table = das08_pci_table, .name = DRV_NAME, .probe = &das08_pci_probe, - .remove = &das08_pci_remove + .remove = comedi_pci_auto_unconfig, }; #endif /* DO_PCI */ diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index 960da8d..1fabe88 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -856,11 +856,6 @@ static int dt3000_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &dt3000_driver); } -static void dt3000_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(dt3000_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001) }, { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001_PGL) }, @@ -877,7 +872,7 @@ static struct pci_driver dt3000_pci_driver = { .name = "dt3000", .id_table = dt3000_pci_table, .probe = dt3000_pci_probe, - .remove = dt3000_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(dt3000_driver, dt3000_pci_driver); diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c index 8497a36..5aa695e 100644 --- a/drivers/staging/comedi/drivers/dyna_pci10xx.c +++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c @@ -276,11 +276,6 @@ static int dyna_pci10xx_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &dyna_pci10xx_driver); } -static void dyna_pci10xx_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(dyna_pci10xx_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) }, { 0 } @@ -291,7 +286,7 @@ static struct pci_driver dyna_pci10xx_pci_driver = { .name = "dyna_pci10xx", .id_table = dyna_pci10xx_pci_table, .probe = dyna_pci10xx_pci_probe, - .remove = dyna_pci10xx_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver); diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c index 154598f..6d88b72 100644 --- a/drivers/staging/comedi/drivers/gsc_hpdi.c +++ b/drivers/staging/comedi/drivers/gsc_hpdi.c @@ -946,11 +946,6 @@ static int gsc_hpdi_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &gsc_hpdi_driver); } -static void gsc_hpdi_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(gsc_hpdi_pci_table) = { { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX, 0x2400, 0, 0, 0}, @@ -962,7 +957,7 @@ static struct pci_driver gsc_hpdi_pci_driver = { .name = "gsc_hpdi", .id_table = gsc_hpdi_pci_table, .probe = gsc_hpdi_pci_probe, - .remove = gsc_hpdi_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(gsc_hpdi_driver, gsc_hpdi_pci_driver); diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c index a91a448..0174295 100644 --- a/drivers/staging/comedi/drivers/icp_multi.c +++ b/drivers/staging/comedi/drivers/icp_multi.c @@ -623,11 +623,6 @@ static int icp_multi_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &icp_multi_driver); } -static void icp_multi_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(icp_multi_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_ICP, PCI_DEVICE_ID_ICP_MULTI) }, { 0 } @@ -638,7 +633,7 @@ static struct pci_driver icp_multi_pci_driver = { .name = "icp_multi", .id_table = icp_multi_pci_table, .probe = icp_multi_pci_probe, - .remove = icp_multi_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(icp_multi_driver, icp_multi_pci_driver); diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c index c756a35..8d79c76 100644 --- a/drivers/staging/comedi/drivers/jr3_pci.c +++ b/drivers/staging/comedi/drivers/jr3_pci.c @@ -844,11 +844,6 @@ static int jr3_pci_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &jr3_pci_driver); } -static void jr3_pci_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL) }, { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW) }, @@ -863,7 +858,7 @@ static struct pci_driver jr3_pci_pci_driver = { .name = "jr3_pci", .id_table = jr3_pci_pci_table, .probe = jr3_pci_pci_probe, - .remove = jr3_pci_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(jr3_pci_driver, jr3_pci_pci_driver); diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index 19c9428..535800a 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c @@ -152,11 +152,6 @@ static int ke_counter_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ke_counter_driver); } -static void ke_counter_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) }, { 0 } @@ -167,7 +162,7 @@ static struct pci_driver ke_counter_pci_driver = { .name = "ke_counter", .id_table = ke_counter_pci_table, .probe = ke_counter_pci_probe, - .remove = ke_counter_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver); diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 3c4b022..4312b37 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -1734,11 +1734,6 @@ static int me4000_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &me4000_driver); } -static void me4000_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(me4000_pci_table) = { {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4650)}, {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660)}, @@ -1761,7 +1756,7 @@ static struct pci_driver me4000_pci_driver = { .name = "me4000", .id_table = me4000_pci_table, .probe = me4000_pci_probe, - .remove = me4000_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(me4000_driver, me4000_pci_driver); diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index ce8e3d3..ee8bafc 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -619,11 +619,6 @@ static int me_daq_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &me_daq_driver); } -static void me_daq_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(me_daq_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) }, { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) }, @@ -635,7 +630,7 @@ static struct pci_driver me_daq_pci_driver = { .name = "me_daq", .id_table = me_daq_pci_table, .probe = me_daq_pci_probe, - .remove = me_daq_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(me_daq_driver, me_daq_pci_driver); diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c index 5196b460..67aa6f4 100644 --- a/drivers/staging/comedi/drivers/ni_6527.c +++ b/drivers/staging/comedi/drivers/ni_6527.c @@ -452,16 +452,11 @@ static int ni6527_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ni6527_driver); } -static void ni6527_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver ni6527_pci_driver = { .name = DRIVER_NAME, .id_table = ni6527_pci_table, .probe = ni6527_pci_probe, - .remove = ni6527_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ni6527_driver, ni6527_pci_driver); diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index 2fb4b77..fb7e8b8 100644 --- a/drivers/staging/comedi/drivers/ni_65xx.c +++ b/drivers/staging/comedi/drivers/ni_65xx.c @@ -787,16 +787,11 @@ static int ni_65xx_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ni_65xx_driver); } -static void ni_65xx_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver ni_65xx_pci_driver = { .name = "ni_65xx", .id_table = ni_65xx_pci_table, .probe = ni_65xx_pci_probe, - .remove = ni_65xx_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ni_65xx_driver, ni_65xx_pci_driver); diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c index 26baf9c..bdef2e4 100644 --- a/drivers/staging/comedi/drivers/ni_660x.c +++ b/drivers/staging/comedi/drivers/ni_660x.c @@ -1327,11 +1327,6 @@ static int ni_660x_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ni_660x_driver); } -static void ni_660x_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(ni_660x_pci_table) = { {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c60)}, {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1310)}, @@ -1345,7 +1340,7 @@ static struct pci_driver ni_660x_pci_driver = { .name = "ni_660x", .id_table = ni_660x_pci_table, .probe = ni_660x_pci_probe, - .remove = ni_660x_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ni_660x_driver, ni_660x_pci_driver); diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c index 272caeb..6f3c090 100644 --- a/drivers/staging/comedi/drivers/ni_670x.c +++ b/drivers/staging/comedi/drivers/ni_670x.c @@ -309,11 +309,6 @@ static int ni_670x_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ni_670x_driver); } -static void ni_670x_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(ni_670x_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c90) }, { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1920) }, @@ -325,7 +320,7 @@ static struct pci_driver ni_670x_pci_driver = { .name = "ni_670x", .id_table = ni_670x_pci_table, .probe = ni_670x_pci_probe, - .remove = ni_670x_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ni_670x_driver, ni_670x_pci_driver); diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index d29c4d7..dedb2ab 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -2116,16 +2116,11 @@ static int labpc_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &labpc_driver); } -static void labpc_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver labpc_pci_driver = { .name = DRV_NAME, .id_table = labpc_pci_table, .probe = labpc_pci_probe, - .remove = labpc_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(labpc_driver, labpc_pci_driver); #else diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c index 084ebea..ba8c2f2 100644 --- a/drivers/staging/comedi/drivers/ni_pcidio.c +++ b/drivers/staging/comedi/drivers/ni_pcidio.c @@ -1224,11 +1224,6 @@ static int ni_pcidio_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ni_pcidio_driver); } -static void ni_pcidio_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150) }, { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320) }, @@ -1241,7 +1236,7 @@ static struct pci_driver ni_pcidio_pci_driver = { .name = "ni_pcidio", .id_table = ni_pcidio_pci_table, .probe = ni_pcidio_pci_probe, - .remove = ni_pcidio_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ni_pcidio_driver, ni_pcidio_pci_driver); diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c index fd1662b..26a870c 100644 --- a/drivers/staging/comedi/drivers/ni_pcimio.c +++ b/drivers/staging/comedi/drivers/ni_pcimio.c @@ -1791,11 +1791,6 @@ static int ni_pcimio_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &ni_pcimio_driver); } -static void ni_pcimio_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(ni_pcimio_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162) }, { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170) }, @@ -1858,7 +1853,7 @@ static struct pci_driver ni_pcimio_pci_driver = { .name = "ni_pcimio", .id_table = ni_pcimio_pci_table, .probe = ni_pcimio_pci_probe, - .remove = ni_pcimio_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(ni_pcimio_driver, ni_pcimio_pci_driver); diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c index 8d7c948..5581452 100644 --- a/drivers/staging/comedi/drivers/rtd520.c +++ b/drivers/staging/comedi/drivers/rtd520.c @@ -1420,11 +1420,6 @@ static int rtd520_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &rtd520_driver); } -static void rtd520_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static DEFINE_PCI_DEVICE_TABLE(rtd520_pci_table) = { { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x7520) }, { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x4520) }, @@ -1436,7 +1431,7 @@ static struct pci_driver rtd520_pci_driver = { .name = "rtd520", .id_table = rtd520_pci_table, .probe = rtd520_pci_probe, - .remove = rtd520_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(rtd520_driver, rtd520_pci_driver); diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 6dc1d28..0c7221c 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -2836,11 +2836,6 @@ static int s626_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &s626_driver); } -static void s626_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - /* * For devices with vendor:device id == 0x1131:0x7146 you must specify * also subvendor:subdevice ids, because otherwise it will conflict with @@ -2857,7 +2852,7 @@ static struct pci_driver s626_pci_driver = { .name = "s626", .id_table = s626_pci_table, .probe = s626_pci_probe, - .remove = s626_pci_remove, + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(s626_driver, s626_pci_driver); diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c index 48178ca..0aad815 100644 --- a/drivers/staging/comedi/drivers/skel.c +++ b/drivers/staging/comedi/drivers/skel.c @@ -707,16 +707,11 @@ static int skel_pci_probe(struct pci_dev *dev, return comedi_pci_auto_config(dev, &skel_driver); } -static void skel_pci_remove(struct pci_dev *dev) -{ - comedi_pci_auto_unconfig(dev); -} - static struct pci_driver skel_pci_driver = { .name = "dummy", .id_table = skel_pci_table, .probe = &skel_pci_probe, - .remove = &skel_pci_remove + .remove = comedi_pci_auto_unconfig, }; module_comedi_pci_driver(skel_driver, skel_pci_driver); #else -- cgit v0.10.2 From 1445ea1545e07faf91ce05c470024b4ee74f0251 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 16:51:01 -0700 Subject: staging: comedi: addi_apci_1516: use addi_watchdog module Use the addi_watchdog module to provide support for the watchdog subdevice. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Cc: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 815c20a..4c80ac9 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -599,6 +599,7 @@ config COMEDI_ADDI_APCI_1500 config COMEDI_ADDI_APCI_1516 tristate "ADDI-DATA APCI-1016/1516/2016 support" + select COMEDI_ADDI_WATCHDOG ---help--- Enable support for ADDI-DATA APCI-1016, APCI-1516 and APCI-2016 boards. These are 16 channel, optically isolated, digital I/O boards. The 1516 diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c index 0911516..1721ba7 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1516.c +++ b/drivers/staging/comedi/drivers/addi_apci_1516.c @@ -30,6 +30,7 @@ */ #include "../comedidev.h" +#include "addi_watchdog.h" #include "comedi_fc.h" /* @@ -49,13 +50,6 @@ * PCI bar 2 I/O Register map - Watchdog (APCI-1516 and APCI-2016) */ #define APCI1516_WDOG_REG 0x00 -#define APCI1516_WDOG_RELOAD_REG 0x04 -#define APCI1516_WDOG_CTRL_REG 0x0c -#define APCI1516_WDOG_CTRL_ENABLE (1 << 0) -#define APCI1516_WDOG_CTRL_SW_TRIG (1 << 9) -#define APCI1516_WDOG_STATUS_REG 0x10 -#define APCI1516_WDOG_STATUS_ENABLED (1 << 0) -#define APCI1516_WDOG_STATUS_SW_TRIG (1 << 1) struct apci1516_boardinfo { const char *name; @@ -86,7 +80,6 @@ static const struct apci1516_boardinfo apci1516_boardtypes[] = { struct apci1516_private { unsigned long wdog_iobase; - unsigned int ctrl; }; static int apci1516_di_insn_bits(struct comedi_device *dev, @@ -120,82 +113,6 @@ static int apci1516_do_insn_bits(struct comedi_device *dev, return insn->n; } -/* - * The watchdog subdevice is configured with two INSN_CONFIG instructions: - * - * Enable the watchdog and set the reload timeout: - * data[0] = INSN_CONFIG_ARM - * data[1] = timeout reload value - * - * Disable the watchdog: - * data[0] = INSN_CONFIG_DISARM - */ -static int apci1516_wdog_insn_config(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci1516_private *devpriv = dev->private; - unsigned int reload; - - switch (data[0]) { - case INSN_CONFIG_ARM: - devpriv->ctrl = APCI1516_WDOG_CTRL_ENABLE; - reload = data[1] & s->maxdata; - outw(reload, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG); - - /* Time base is 20ms, let the user know the timeout */ - dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n", - 20 * reload + 20); - break; - case INSN_CONFIG_DISARM: - devpriv->ctrl = 0; - break; - default: - return -EINVAL; - } - - outw(devpriv->ctrl, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG); - - return insn->n; -} - -static int apci1516_wdog_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci1516_private *devpriv = dev->private; - int i; - - if (devpriv->ctrl == 0) { - dev_warn(dev->class_dev, "watchdog is disabled\n"); - return -EINVAL; - } - - /* "ping" the watchdog */ - for (i = 0; i < insn->n; i++) { - outw(devpriv->ctrl | APCI1516_WDOG_CTRL_SW_TRIG, - devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG); - } - - return insn->n; -} - -static int apci1516_wdog_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct apci1516_private *devpriv = dev->private; - int i; - - for (i = 0; i < insn->n; i++) - data[i] = inw(devpriv->wdog_iobase + APCI1516_WDOG_STATUS_REG); - - return insn->n; -} - static int apci1516_reset(struct comedi_device *dev) { const struct apci1516_boardinfo *this_board = comedi_board(dev); @@ -205,8 +122,8 @@ static int apci1516_reset(struct comedi_device *dev) return 0; outw(0x0, dev->iobase + APCI1516_DO_REG); - outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG); - outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG); + + addi_watchdog_reset(devpriv->wdog_iobase); return 0; } @@ -285,13 +202,9 @@ static int apci1516_auto_attach(struct comedi_device *dev, /* Initialize the watchdog subdevice */ s = &dev->subdevices[2]; if (this_board->has_wdog) { - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 1; - s->maxdata = 0xff; - s->insn_write = apci1516_wdog_insn_write; - s->insn_read = apci1516_wdog_insn_read; - s->insn_config = apci1516_wdog_insn_config; + ret = addi_watchdog_init(s, devpriv->wdog_iobase); + if (ret) + return ret; } else { s->type = COMEDI_SUBD_UNUSED; } @@ -304,10 +217,12 @@ static void apci1516_detach(struct comedi_device *dev) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - if (dev->iobase) { + if (dev->iobase) apci1516_reset(dev); + if (dev->subdevices) + addi_watchdog_cleanup(&dev->subdevices[2]); + if (dev->iobase) comedi_pci_disable(pcidev); - } } static struct comedi_driver apci1516_driver = { -- cgit v0.10.2 From c0cd2da16b431a2007ea83865f3dd1530c1643a5 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 17:02:31 -0700 Subject: staging: comedi: addi_watchdog: all i/o registers are 32-bit All the i/o registers used by the watchdog device on the addi-data boards are 32-bit. Make sure all the i/o commands use outl/inl to access the registers. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Cc: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c index b944503..375ab66 100644 --- a/drivers/staging/comedi/drivers/addi_watchdog.c +++ b/drivers/staging/comedi/drivers/addi_watchdog.c @@ -65,7 +65,7 @@ static int addi_watchdog_insn_config(struct comedi_device *dev, case INSN_CONFIG_ARM: spriv->wdog_ctrl = ADDI_WDOG_CTRL_ENABLE; reload = data[1] & s->maxdata; - outw(reload, spriv->iobase + ADDI_WDOG_RELOAD_REG); + outl(reload, spriv->iobase + ADDI_WDOG_RELOAD_REG); /* Time base is 20ms, let the user know the timeout */ dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n", @@ -78,7 +78,7 @@ static int addi_watchdog_insn_config(struct comedi_device *dev, return -EINVAL; } - outw(spriv->wdog_ctrl, spriv->iobase + ADDI_WDOG_CTRL_REG); + outl(spriv->wdog_ctrl, spriv->iobase + ADDI_WDOG_CTRL_REG); return insn->n; } @@ -112,7 +112,7 @@ static int addi_watchdog_insn_write(struct comedi_device *dev, /* "ping" the watchdog */ for (i = 0; i < insn->n; i++) { - outw(spriv->wdog_ctrl | ADDI_WDOG_CTRL_SW_TRIG, + outl(spriv->wdog_ctrl | ADDI_WDOG_CTRL_SW_TRIG, spriv->iobase + ADDI_WDOG_CTRL_REG); } -- cgit v0.10.2 From 8a9f645fc15b4bb49a1c8133df9db0ccd67e3f76 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Thu, 10 Jan 2013 17:29:00 +0000 Subject: iio: fix Kconfig for max1363 ERROR: "iio_triggered_buffer_setup" [drivers/iio/adc/max1363.ko] undefined! ERROR: "iio_triggered_buffer_cleanup" [drivers/iio/adc/max1363.ko] undefined! add select IIO_TRIGGERED_BUFFER IIO_TRIGGERED_BUFFER in turn selects IIO_TRIGGER and IIO_KFIFO_BUF, so drop those MAX1363_RING_BUFFER is not used anymore Signed-off-by: Peter Meerwald Reported-by: Fengguang Wu Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index fe822a1..e372257 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -100,10 +100,8 @@ config LP8788_ADC config MAX1363 tristate "Maxim max1363 ADC driver" depends on I2C - select IIO_TRIGGER - select MAX1363_RING_BUFFER select IIO_BUFFER - select IIO_KFIFO_BUF + select IIO_TRIGGERED_BUFFER help Say yes here to build support for many Maxim i2c analog to digital converters (ADC). (max1361, max1362, max1363, max1364, max1036, -- cgit v0.10.2 From 2b4ff03895e4451719400e9ac50980b9d14af37d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 11 Jan 2013 10:49:00 +0000 Subject: staging:iio:gyro: Remove stale Makefile entry Commit a301d425e ("staging:iio:gyro remove adis16251 driver as now supported by adis16260 driver") removed the adis16251, but left its Makefile entry intact. This patch removes the unused Makefile entry. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile index 1303569..79bef4e 100644 --- a/drivers/staging/iio/gyro/Makefile +++ b/drivers/staging/iio/gyro/Makefile @@ -14,8 +14,5 @@ obj-$(CONFIG_ADIS16130) += adis16130.o adis16260-y := adis16260_core.o obj-$(CONFIG_ADIS16260) += adis16260.o -adis16251-y := adis16251_core.o -obj-$(CONFIG_ADIS16251) += adis16251.o - adxrs450-y := adxrs450_core.o obj-$(CONFIG_ADXRS450) += adxrs450.o -- cgit v0.10.2 From 06ddd353f5c8678238d519dcecf9d557e5e1f7a6 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 11 Jan 2013 23:35:00 +0000 Subject: iio: mxs: Implement support for touchscreen This patch implements support for sampling of a touchscreen into the MXS LRADC driver. The LRADC block allows configuring some of it's channels into special mode where they either output the drive voltage or sample it, allowing it to operate a 4-wire or 5-wire resistive touchscreen. In case the touchscreen mode is enabled, the LRADC slot #7 is reserved for touchscreen only, therefore it is not possible to sample 8 LRADC channels at time, but only 7 channels. The touchscreen controller is configured such that the PENDOWN event disables touchscreen interrupts and triggers execution of worker thread, which then polls the touchscreen controller for X, Y and Pressure values. This reduces the overhead of interrupt-driven operation. Upon the PENUP event, the worker thread re-enables the PENDOWN detection interrupt and exits. Signed-off-by: Marek Vasut Acked-by: Dmitry Torokhov Signed-off-by: Jonathan Cameron diff --git a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt index 801d58c..4688205 100644 --- a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt +++ b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt @@ -5,6 +5,12 @@ Required properties: - reg: Address and length of the register set for the device - interrupts: Should contain the LRADC interrupts +Optional properties: +- fsl,lradc-touchscreen-wires: Number of wires used to connect the touchscreen + to LRADC. Valid value is either 4 or 5. If this + property is not present, then the touchscreen is + disabled. + Examples: lradc@80050000 { diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index eca0704..e472871 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -59,6 +61,21 @@ #define LRADC_DELAY_TIMER_PER 200 #define LRADC_DELAY_TIMER_LOOP 5 +/* + * Once the pen touches the touchscreen, the touchscreen switches from + * IRQ-driven mode to polling mode to prevent interrupt storm. The polling + * is realized by worker thread, which is called every 20 or so milliseconds. + * This gives the touchscreen enough fluence and does not strain the system + * too much. + */ +#define LRADC_TS_SAMPLE_DELAY_MS 5 + +/* + * The LRADC reads the following amount of samples from each touchscreen + * channel and the driver then computes avarage of these. + */ +#define LRADC_TS_SAMPLE_AMOUNT 4 + static const char * const mxs_lradc_irq_name[] = { "mxs-lradc-touchscreen", "mxs-lradc-thresh0", @@ -75,6 +92,12 @@ static const char * const mxs_lradc_irq_name[] = { "mxs-lradc-button1", }; +enum mxs_lradc_ts { + MXS_LRADC_TOUCHSCREEN_NONE = 0, + MXS_LRADC_TOUCHSCREEN_4WIRE, + MXS_LRADC_TOUCHSCREEN_5WIRE, +}; + struct mxs_lradc { struct device *dev; void __iomem *base; @@ -86,21 +109,69 @@ struct mxs_lradc { struct mutex lock; struct completion completion; + + /* + * Touchscreen LRADC channels receives a private slot in the CTRL4 + * register, the slot #7. Therefore only 7 slots instead of 8 in the + * CTRL4 register can be mapped to LRADC channels when using the + * touchscreen. + * + * Furthermore, certain LRADC channels are shared between touchscreen + * and/or touch-buttons and generic LRADC block. Therefore when using + * either of these, these channels are not available for the regular + * sampling. The shared channels are as follows: + * + * CH0 -- Touch button #0 + * CH1 -- Touch button #1 + * CH2 -- Touch screen XPUL + * CH3 -- Touch screen YPLL + * CH4 -- Touch screen XNUL + * CH5 -- Touch screen YNLR + * CH6 -- Touch screen WIPER (5-wire only) + * + * The bitfields below represents which parts of the LRADC block are + * switched into special mode of operation. These channels can not + * be sampled as regular LRADC channels. The driver will refuse any + * attempt to sample these channels. + */ +#define CHAN_MASK_TOUCHBUTTON (0x3 << 0) +#define CHAN_MASK_TOUCHSCREEN_4WIRE (0xf << 2) +#define CHAN_MASK_TOUCHSCREEN_5WIRE (0x1f << 2) + enum mxs_lradc_ts use_touchscreen; + bool stop_touchscreen; + bool use_touchbutton; + + struct input_dev *ts_input; + struct work_struct ts_work; }; #define LRADC_CTRL0 0x00 -#define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23) -#define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22) +#define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23) +#define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22) +#define LRADC_CTRL0_YNNSW /* YM */ (1 << 21) +#define LRADC_CTRL0_YPNSW /* YP */ (1 << 20) +#define LRADC_CTRL0_YPPSW /* YP */ (1 << 19) +#define LRADC_CTRL0_XNNSW /* XM */ (1 << 18) +#define LRADC_CTRL0_XNPSW /* XM */ (1 << 17) +#define LRADC_CTRL0_XPPSW /* XP */ (1 << 16) +#define LRADC_CTRL0_PLATE_MASK (0x3f << 16) #define LRADC_CTRL1 0x10 -#define LRADC_CTRL1_LRADC_IRQ(n) (1 << (n)) -#define LRADC_CTRL1_LRADC_IRQ_MASK 0x1fff +#define LRADC_CTRL1_TOUCH_DETECT_IRQ_EN (1 << 24) #define LRADC_CTRL1_LRADC_IRQ_EN(n) (1 << ((n) + 16)) #define LRADC_CTRL1_LRADC_IRQ_EN_MASK (0x1fff << 16) +#define LRADC_CTRL1_LRADC_IRQ_EN_OFFSET 16 +#define LRADC_CTRL1_TOUCH_DETECT_IRQ (1 << 8) +#define LRADC_CTRL1_LRADC_IRQ(n) (1 << (n)) +#define LRADC_CTRL1_LRADC_IRQ_MASK 0x1fff +#define LRADC_CTRL1_LRADC_IRQ_OFFSET 0 #define LRADC_CTRL2 0x20 #define LRADC_CTRL2_TEMPSENSE_PWD (1 << 15) +#define LRADC_STATUS 0x40 +#define LRADC_STATUS_TOUCH_DETECT_RAW (1 << 0) + #define LRADC_CH(n) (0x50 + (0x10 * (n))) #define LRADC_CH_ACCUMULATE (1 << 29) #define LRADC_CH_NUM_SAMPLES_MASK (0x1f << 24) @@ -132,6 +203,7 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev, { struct mxs_lradc *lradc = iio_priv(iio_dev); int ret; + unsigned long mask; if (m != IIO_CHAN_INFO_RAW) return -EINVAL; @@ -140,6 +212,12 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev, if (chan->channel > LRADC_MAX_TOTAL_CHANS) return -EINVAL; + /* Validate the channel if it doesn't intersect with reserved chans. */ + bitmap_set(&mask, chan->channel, 1); + ret = iio_validate_scan_mask_onehot(iio_dev, &mask); + if (ret) + return -EINVAL; + /* * See if there is no buffered operation in progess. If there is, simply * bail out. This can be improved to support both buffered and raw IO at @@ -161,7 +239,11 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev, lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); - writel(chan->channel, lradc->base + LRADC_CTRL4); + /* Clean the slot's previous content, then set new one. */ + writel(LRADC_CTRL4_LRADCSELECT_MASK(0), + lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR); + writel(chan->channel, lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET); + writel(0, lradc->base + LRADC_CH(0)); /* Enable the IRQ and start sampling the channel. */ @@ -195,6 +277,269 @@ static const struct iio_info mxs_lradc_iio_info = { }; /* + * Touchscreen handling + */ +enum lradc_ts_plate { + LRADC_SAMPLE_X, + LRADC_SAMPLE_Y, + LRADC_SAMPLE_PRESSURE, +}; + +static int mxs_lradc_ts_touched(struct mxs_lradc *lradc) +{ + uint32_t reg; + + /* Enable touch detection. */ + writel(LRADC_CTRL0_PLATE_MASK, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); + writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); + + msleep(LRADC_TS_SAMPLE_DELAY_MS); + + reg = readl(lradc->base + LRADC_STATUS); + + return reg & LRADC_STATUS_TOUCH_DETECT_RAW; +} + +static int32_t mxs_lradc_ts_sample(struct mxs_lradc *lradc, + enum lradc_ts_plate plate, int change) +{ + unsigned long delay, jiff; + uint32_t reg, ctrl0 = 0, chan = 0; + /* The touchscreen always uses CTRL4 slot #7. */ + const uint8_t slot = 7; + uint32_t val; + + /* + * There are three correct configurations of the controller sampling + * the touchscreen, each of these configuration provides different + * information from the touchscreen. + * + * The following table describes the sampling configurations: + * +-------------+-------+-------+-------+ + * | Wire \ Axis | X | Y | Z | + * +---------------------+-------+-------+ + * | X+ (CH2) | HI | TS | TS | + * +-------------+-------+-------+-------+ + * | X- (CH4) | LO | SH | HI | + * +-------------+-------+-------+-------+ + * | Y+ (CH3) | SH | HI | HI | + * +-------------+-------+-------+-------+ + * | Y- (CH5) | TS | LO | SH | + * +-------------+-------+-------+-------+ + * + * HI ... strong '1' ; LO ... strong '0' + * SH ... sample here ; TS ... tri-state + * + * There are a few other ways of obtaining the Z coordinate + * (aka. pressure), but the one in the table seems to be the + * most reliable one. + */ + switch (plate) { + case LRADC_SAMPLE_X: + ctrl0 = LRADC_CTRL0_XPPSW | LRADC_CTRL0_XNNSW; + chan = 3; + break; + case LRADC_SAMPLE_Y: + ctrl0 = LRADC_CTRL0_YPPSW | LRADC_CTRL0_YNNSW; + chan = 4; + break; + case LRADC_SAMPLE_PRESSURE: + ctrl0 = LRADC_CTRL0_YPPSW | LRADC_CTRL0_XNNSW; + chan = 5; + break; + } + + if (change) { + writel(LRADC_CTRL0_PLATE_MASK, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); + writel(ctrl0, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); + + writel(LRADC_CTRL4_LRADCSELECT_MASK(slot), + lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR); + writel(chan << LRADC_CTRL4_LRADCSELECT_OFFSET(slot), + lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET); + } + + writel(0xffffffff, lradc->base + LRADC_CH(slot) + STMP_OFFSET_REG_CLR); + writel(1 << slot, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); + + delay = jiffies + msecs_to_jiffies(LRADC_TS_SAMPLE_DELAY_MS); + do { + jiff = jiffies; + reg = readl_relaxed(lradc->base + LRADC_CTRL1); + if (reg & LRADC_CTRL1_LRADC_IRQ(slot)) + break; + } while (time_before(jiff, delay)); + + writel(LRADC_CTRL1_LRADC_IRQ(slot), + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); + + if (time_after_eq(jiff, delay)) + return -ETIMEDOUT; + + val = readl(lradc->base + LRADC_CH(slot)); + val &= LRADC_CH_VALUE_MASK; + + return val; +} + +static int32_t mxs_lradc_ts_sample_filter(struct mxs_lradc *lradc, + enum lradc_ts_plate plate) +{ + int32_t val, tot = 0; + int i; + + val = mxs_lradc_ts_sample(lradc, plate, 1); + + /* Delay a bit so the touchscreen is stable. */ + mdelay(2); + + for (i = 0; i < LRADC_TS_SAMPLE_AMOUNT; i++) { + val = mxs_lradc_ts_sample(lradc, plate, 0); + tot += val; + } + + return tot / LRADC_TS_SAMPLE_AMOUNT; +} + +static void mxs_lradc_ts_work(struct work_struct *ts_work) +{ + struct mxs_lradc *lradc = container_of(ts_work, + struct mxs_lradc, ts_work); + int val_x, val_y, val_p; + bool valid = false; + + while (mxs_lradc_ts_touched(lradc)) { + /* Disable touch detector so we can sample the touchscreen. */ + writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); + + if (likely(valid)) { + input_report_abs(lradc->ts_input, ABS_X, val_x); + input_report_abs(lradc->ts_input, ABS_Y, val_y); + input_report_abs(lradc->ts_input, ABS_PRESSURE, val_p); + input_report_key(lradc->ts_input, BTN_TOUCH, 1); + input_sync(lradc->ts_input); + } + + valid = false; + + val_x = mxs_lradc_ts_sample_filter(lradc, LRADC_SAMPLE_X); + if (val_x < 0) + continue; + val_y = mxs_lradc_ts_sample_filter(lradc, LRADC_SAMPLE_Y); + if (val_y < 0) + continue; + val_p = mxs_lradc_ts_sample_filter(lradc, LRADC_SAMPLE_PRESSURE); + if (val_p < 0) + continue; + + valid = true; + } + + input_report_abs(lradc->ts_input, ABS_PRESSURE, 0); + input_report_key(lradc->ts_input, BTN_TOUCH, 0); + input_sync(lradc->ts_input); + + /* Do not restart the TS IRQ if the driver is shutting down. */ + if (lradc->stop_touchscreen) + return; + + /* Restart the touchscreen interrupts. */ + writel(LRADC_CTRL1_TOUCH_DETECT_IRQ, + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); + writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); +} + +static int mxs_lradc_ts_open(struct input_dev *dev) +{ + struct mxs_lradc *lradc = input_get_drvdata(dev); + + /* The touchscreen is starting. */ + lradc->stop_touchscreen = false; + + /* Enable the touch-detect circuitry. */ + writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); + + /* Enable the touch-detect IRQ. */ + writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); + + return 0; +} + +static void mxs_lradc_ts_close(struct input_dev *dev) +{ + struct mxs_lradc *lradc = input_get_drvdata(dev); + + /* Indicate the touchscreen is stopping. */ + lradc->stop_touchscreen = true; + mb(); + + /* Wait until touchscreen thread finishes any possible remnants. */ + cancel_work_sync(&lradc->ts_work); + + /* Disable touchscreen touch-detect IRQ. */ + writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); + + /* Power-down touchscreen touch-detect circuitry. */ + writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); +} + +static int mxs_lradc_ts_register(struct mxs_lradc *lradc) +{ + struct input_dev *input; + struct device *dev = lradc->dev; + int ret; + + if (!lradc->use_touchscreen) + return 0; + + input = input_allocate_device(); + if (!input) { + dev_err(dev, "Failed to allocate TS device!\n"); + return -ENOMEM; + } + + input->name = DRIVER_NAME; + input->id.bustype = BUS_HOST; + input->dev.parent = dev; + input->open = mxs_lradc_ts_open; + input->close = mxs_lradc_ts_close; + + __set_bit(EV_ABS, input->evbit); + __set_bit(EV_KEY, input->evbit); + __set_bit(BTN_TOUCH, input->keybit); + input_set_abs_params(input, ABS_X, 0, LRADC_CH_VALUE_MASK, 0, 0); + input_set_abs_params(input, ABS_Y, 0, LRADC_CH_VALUE_MASK, 0, 0); + input_set_abs_params(input, ABS_PRESSURE, 0, LRADC_CH_VALUE_MASK, 0, 0); + + lradc->ts_input = input; + input_set_drvdata(input, lradc); + ret = input_register_device(input); + if (ret) + input_free_device(lradc->ts_input); + + return ret; +} + +static void mxs_lradc_ts_unregister(struct mxs_lradc *lradc) +{ + if (!lradc->use_touchscreen) + return; + + cancel_work_sync(&lradc->ts_work); + + input_unregister_device(lradc->ts_input); +} + +/* * IRQ Handling */ static irqreturn_t mxs_lradc_handle_irq(int irq, void *data) @@ -202,14 +547,24 @@ static irqreturn_t mxs_lradc_handle_irq(int irq, void *data) struct iio_dev *iio = data; struct mxs_lradc *lradc = iio_priv(iio); unsigned long reg = readl(lradc->base + LRADC_CTRL1); + const uint32_t ts_irq_mask = + LRADC_CTRL1_TOUCH_DETECT_IRQ_EN | + LRADC_CTRL1_TOUCH_DETECT_IRQ; if (!(reg & LRADC_CTRL1_LRADC_IRQ_MASK)) return IRQ_NONE; /* - * Touchscreen IRQ handling code shall probably have priority - * and therefore shall be placed here. + * Touchscreen IRQ handling code has priority and therefore + * is placed here. In case touchscreen IRQ arrives, disable + * it ASAP */ + if (reg & LRADC_CTRL1_TOUCH_DETECT_IRQ) { + writel(ts_irq_mask, + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); + if (!lradc->stop_touchscreen) + schedule_work(&lradc->ts_work); + } if (iio_buffer_enabled(iio)) iio_trigger_poll(iio->trig, iio_get_time_ns()); @@ -305,8 +660,10 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio) { struct mxs_lradc *lradc = iio_priv(iio); struct iio_buffer *buffer = iio->buffer; - int ret = 0, chan, ofs = 0, enable = 0; - uint32_t ctrl4 = 0; + int ret = 0, chan, ofs = 0; + unsigned long enable = 0; + uint32_t ctrl4_set = 0; + uint32_t ctrl4_clr = 0; uint32_t ctrl1_irq = 0; const uint32_t chan_value = LRADC_CH_ACCUMULATE | ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET); @@ -338,17 +695,20 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio) writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); for_each_set_bit(chan, buffer->scan_mask, LRADC_MAX_TOTAL_CHANS) { - ctrl4 |= chan << LRADC_CTRL4_LRADCSELECT_OFFSET(ofs); + ctrl4_set |= chan << LRADC_CTRL4_LRADCSELECT_OFFSET(ofs); + ctrl4_clr |= LRADC_CTRL4_LRADCSELECT_MASK(ofs); ctrl1_irq |= LRADC_CTRL1_LRADC_IRQ_EN(ofs); writel(chan_value, lradc->base + LRADC_CH(ofs)); - enable |= 1 << ofs; + bitmap_set(&enable, ofs, 1); ofs++; } writel(LRADC_DELAY_TRIGGER_LRADCS_MASK | LRADC_DELAY_KICK, lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_CLR); - writel(ctrl4, lradc->base + LRADC_CTRL4); + writel(ctrl4_clr, lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR); + writel(ctrl4_set, lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET); + writel(ctrl1_irq, lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); writel(enable << LRADC_DELAY_TRIGGER_LRADCS_OFFSET, @@ -383,9 +743,33 @@ static int mxs_lradc_buffer_postdisable(struct iio_dev *iio) static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio, const unsigned long *mask) { - const int mw = bitmap_weight(mask, iio->masklength); - - return mw <= LRADC_MAX_MAPPED_CHANS; + struct mxs_lradc *lradc = iio_priv(iio); + const int len = iio->masklength; + const int map_chans = bitmap_weight(mask, len); + int rsvd_chans = 0; + unsigned long rsvd_mask = 0; + + if (lradc->use_touchbutton) + rsvd_mask |= CHAN_MASK_TOUCHBUTTON; + if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_4WIRE) + rsvd_mask |= CHAN_MASK_TOUCHSCREEN_4WIRE; + if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE) + rsvd_mask |= CHAN_MASK_TOUCHSCREEN_5WIRE; + + if (lradc->use_touchbutton) + rsvd_chans++; + if (lradc->use_touchscreen) + rsvd_chans++; + + /* Test for attempts to map channels with special mode of operation. */ + if (bitmap_intersects(mask, &rsvd_mask, len)) + return false; + + /* Test for attempts to map more channels then available slots. */ + if (map_chans + rsvd_chans > LRADC_MAX_MAPPED_CHANS) + return false; + + return true; } static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = { @@ -434,15 +818,29 @@ static const struct iio_chan_spec mxs_lradc_chan_spec[] = { static void mxs_lradc_hw_init(struct mxs_lradc *lradc) { - int i; - const uint32_t cfg = + /* The ADC always uses DELAY CHANNEL 0. */ + const uint32_t adc_cfg = + (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + 0)) | (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET); stmp_reset_block(lradc->base); - for (i = 0; i < LRADC_MAX_DELAY_CHANS; i++) - writel(cfg | (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + i)), - lradc->base + LRADC_DELAY(i)); + /* Configure DELAY CHANNEL 0 for generic ADC sampling. */ + writel(adc_cfg, lradc->base + LRADC_DELAY(0)); + + /* Disable remaining DELAY CHANNELs */ + writel(0, lradc->base + LRADC_DELAY(1)); + writel(0, lradc->base + LRADC_DELAY(2)); + writel(0, lradc->base + LRADC_DELAY(3)); + + /* Configure the touchscreen type */ + writel(LRADC_CTRL0_TOUCH_SCREEN_TYPE, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); + + if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE) { + writel(LRADC_CTRL0_TOUCH_SCREEN_TYPE, + lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); + } /* Start internal temperature sensing. */ writel(0, lradc->base + LRADC_CTRL2); @@ -462,9 +860,11 @@ static void mxs_lradc_hw_stop(struct mxs_lradc *lradc) static int mxs_lradc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; struct mxs_lradc *lradc; struct iio_dev *iio; struct resource *iores; + uint32_t ts_wires = 0; int ret = 0; int i; @@ -486,6 +886,21 @@ static int mxs_lradc_probe(struct platform_device *pdev) goto err_addr; } + INIT_WORK(&lradc->ts_work, mxs_lradc_ts_work); + + /* Check if touchscreen is enabled in DT. */ + ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires", + &ts_wires); + if (ret) + dev_info(dev, "Touchscreen not enabled.\n"); + else if (ts_wires == 4) + lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_4WIRE; + else if (ts_wires == 5) + lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_5WIRE; + else + dev_warn(dev, "Unsupported number of touchscreen wires (%d)\n", + ts_wires); + /* Grab all IRQ sources */ for (i = 0; i < 13; i++) { lradc->irq[i] = platform_get_irq(pdev, i); @@ -523,11 +938,16 @@ static int mxs_lradc_probe(struct platform_device *pdev) if (ret) goto err_trig; + /* Register the touchscreen input device. */ + ret = mxs_lradc_ts_register(lradc); + if (ret) + goto err_dev; + /* Register IIO device. */ ret = iio_device_register(iio); if (ret) { dev_err(dev, "Failed to register IIO device\n"); - goto err_dev; + goto err_ts; } /* Configure the hardware. */ @@ -535,6 +955,8 @@ static int mxs_lradc_probe(struct platform_device *pdev) return 0; +err_ts: + mxs_lradc_ts_unregister(lradc); err_dev: mxs_lradc_trigger_remove(iio); err_trig: @@ -549,6 +971,8 @@ static int mxs_lradc_remove(struct platform_device *pdev) struct iio_dev *iio = platform_get_drvdata(pdev); struct mxs_lradc *lradc = iio_priv(iio); + mxs_lradc_ts_unregister(lradc); + mxs_lradc_hw_stop(lradc); iio_device_unregister(iio); -- cgit v0.10.2 From 3f6a0bad61e34c648fd08ff8dcbfdd58148963d2 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 10 Jan 2013 16:18:00 +0000 Subject: staging:iio:tsl2x7x: Use iio_str_to_fixedpoint instead of open-coding it The tsl2x7x driver has a copy'n'pasted version of the iio_str_to_fixedpoint() function from the IIO core. Replace this custom copy and use iio_str_to_fixedpoint instead. The patch also introduces a slight functional change in that it makes sure that in case of a parsing error the error is reported back to userspace instead of silently ignoring it. Signed-off-by: Lars-Peter Clausen Acked-by: Jon Brenner Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c index 9e50fbb..a58731e 100644 --- a/drivers/staging/iio/light/tsl2x7x_core.c +++ b/drivers/staging/iio/light/tsl2x7x_core.c @@ -292,59 +292,6 @@ static const u8 device_channel_config[] = { }; /** - * tsl2x7x_parse_buffer() - parse a decimal result from a buffer. - * @*buf: pointer to char buffer to parse - * @*result: pointer to buffer to contain - * resulting interger / decimal as ints. - * - */ -static int -tsl2x7x_parse_buffer(const char *buf, struct tsl2x7x_parse_result *result) -{ - int integer = 0, fract = 0, fract_mult = 100000; - bool integer_part = true, negative = false; - - if (buf[0] == '-') { - negative = true; - buf++; - } - - while (*buf) { - if ('0' <= *buf && *buf <= '9') { - if (integer_part) - integer = integer*10 + *buf - '0'; - else { - fract += fract_mult*(*buf - '0'); - if (fract_mult == 1) - break; - fract_mult /= 10; - } - } else if (*buf == '\n') { - if (*(buf + 1) == '\0') - break; - else - return -EINVAL; - } else if (*buf == '.') { - integer_part = false; - } else { - return -EINVAL; - } - buf++; - } - if (negative) { - if (integer) - integer = -integer; - else - fract = -fract; - } - - result->integer = integer; - result->fract = fract; - - return 0; -} - -/** * tsl2x7x_i2c_read() - Read a byte from a register. * @client: i2c client * @reg: device register to read from @@ -1036,13 +983,12 @@ static ssize_t tsl2x7x_als_time_store(struct device *dev, struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev); struct tsl2x7x_parse_result result; + int ret; - result.integer = 0; - result.fract = 0; - - tsl2x7x_parse_buffer(buf, &result); + ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); + if (ret) + return ret; - result.fract /= 1000; result.fract /= 3; chip->tsl2x7x_settings.als_time = (TSL2X7X_MAX_TIMER_CNT - (u8)result.fract); @@ -1109,12 +1055,12 @@ static ssize_t tsl2x7x_als_persistence_store(struct device *dev, struct tsl2X7X_chip *chip = iio_priv(indio_dev); struct tsl2x7x_parse_result result; int y, z, filter_delay; + int ret; - result.integer = 0; - result.fract = 0; - tsl2x7x_parse_buffer(buf, &result); + ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); + if (ret) + return ret; - result.fract /= 1000; y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1; z = y * TSL2X7X_MIN_ITIME; @@ -1155,12 +1101,12 @@ static ssize_t tsl2x7x_prox_persistence_store(struct device *dev, struct tsl2X7X_chip *chip = iio_priv(indio_dev); struct tsl2x7x_parse_result result; int y, z, filter_delay; + int ret; - result.integer = 0; - result.fract = 0; - tsl2x7x_parse_buffer(buf, &result); + ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); + if (ret) + return ret; - result.fract /= 1000; y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1; z = y * TSL2X7X_MIN_ITIME; -- cgit v0.10.2 From 06220b89f2284f910f925676d757fd3331138dc6 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Don't pass 0 to ilog2 ilog2 is not defined for 0, so we need to handle the case where the requested frequency is larger than the base sampling rate. In this case we'll round down and set the sampling rate to the base sampling rate. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index 9c8f5ab..cb66225 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -178,7 +178,11 @@ static int adis16334_set_freq(struct iio_dev *indio_dev, unsigned int freq) { unsigned int t; - t = ilog2(8192 / (freq * 10)); + freq *= 10; + if (freq < 8192) + t = ilog2(8192 / freq); + else + t = 0; if (t > 0x31) t = 0x31; -- cgit v0.10.2 From bdb20bdb8c1ea55c9a2f744cc5b2c7f66148a41b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Fix and cleanup 3db filter setting The 3db divisors table is partially wrong and incomplete. Also the code rounds up to the next higher frequency if the requested frequency would matches one of the available frequencies. These two issues are fixed by this patch. The patch also changes the driver to round down the filter frequency if it is larger than the largest supported frequency instead of rejecting it as an invalid value. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index cb66225..7114de9 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -242,33 +242,32 @@ static ssize_t adis16400_read_frequency(struct device *dev, static const unsigned adis16400_3db_divisors[] = { [0] = 2, /* Special case */ - [1] = 5, - [2] = 10, - [3] = 50, - [4] = 200, + [1] = 6, + [2] = 12, + [3] = 25, + [4] = 50, + [5] = 100, + [6] = 200, + [7] = 200, /* Not a valid setting */ }; static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) { int i, ret; u16 val16; - for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 0; i--) - if (sps/adis16400_3db_divisors[i] > val) + + for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { + if (sps / adis16400_3db_divisors[i] >= val) break; - if (i == -1) - ret = -EINVAL; - else { - ret = adis16400_spi_read_reg_16(indio_dev, - ADIS16400_SENS_AVG, + } + + ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SENS_AVG, &val16); - if (ret < 0) - goto error_ret; + if (ret < 0) + return ret; - ret = adis16400_spi_write_reg_16(indio_dev, - ADIS16400_SENS_AVG, - (val16 & ~0x03) | i); - } -error_ret: + ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_SENS_AVG, + (val16 & ~0x07) | i); return ret; } @@ -653,9 +652,9 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, mutex_unlock(&indio_dev->mlock); return ret; } - val16 = st->variant->get_freq(indio_dev); - if (ret > 0) - *val = ret/adis16400_3db_divisors[val16 & 0x03]; + ret = st->variant->get_freq(indio_dev); + if (ret >= 0) + *val = ret / adis16400_3db_divisors[val16 & 0x07]; *val2 = 0; mutex_unlock(&indio_dev->mlock); if (ret < 0) -- cgit v0.10.2 From ca6907df6b5d86d848eac706f28c7a89126f3875 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Remove unused default_scan_mask The chip_info struct for contains a defaul_scan_mask field. But it is never actually used in the code, so remove it from the chip_info struct. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/staging/iio/imu/adis16400.h index 7a105e9..3efafcb 100644 --- a/drivers/staging/iio/imu/adis16400.h +++ b/drivers/staging/iio/imu/adis16400.h @@ -145,7 +145,6 @@ struct adis16400_chip_info { unsigned int accel_scale_micro; int temp_scale_nano; int temp_offset; - unsigned long default_scan_mask; int (*set_freq)(struct iio_dev *indio_dev, unsigned int freq); int (*get_freq)(struct iio_dev *indio_dev); }; diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index 7114de9..24fca10 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -1116,12 +1116,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .accel_scale_micro = 5884, .temp_scale_nano = 140000000, /* 0.14 C */ .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ - .default_scan_mask = (1 << ADIS16400_SCAN_SUPPLY) | - (1 << ADIS16400_SCAN_GYRO_X) | (1 << ADIS16400_SCAN_ACC_X) | - (1 << ADIS16400_SCAN_ACC_Y) | (1 << ADIS16400_SCAN_ACC_Z) | - (1 << ADIS16400_SCAN_TEMP) | (1 << ADIS16400_SCAN_ADC_0) | - (1 << ADIS16300_SCAN_INCLI_X) | (1 << ADIS16300_SCAN_INCLI_Y) | - (1 << 14), .set_freq = adis16400_set_freq, .get_freq = adis16400_get_freq, }, @@ -1133,10 +1127,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ .temp_scale_nano = 67850000, /* 0.06785 C */ .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */ - .default_scan_mask = (1 << ADIS16400_SCAN_GYRO_X) | - (1 << ADIS16400_SCAN_GYRO_Y) | (1 << ADIS16400_SCAN_GYRO_Z) | - (1 << ADIS16400_SCAN_ACC_X) | (1 << ADIS16400_SCAN_ACC_Y) | - (1 << ADIS16400_SCAN_ACC_Z), .set_freq = adis16334_set_freq, .get_freq = adis16334_get_freq, }, @@ -1147,7 +1137,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */ .temp_scale_nano = 145300000, /* 0.1453 C */ .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */ - .default_scan_mask = 0x7FF, .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE, .set_freq = adis16400_set_freq, .get_freq = adis16400_get_freq, @@ -1160,7 +1149,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .default_scan_mask = 0x7FF, .set_freq = adis16400_set_freq, .get_freq = adis16400_get_freq, }, @@ -1172,7 +1160,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .default_scan_mask = 0x7FF, .set_freq = adis16400_set_freq, .get_freq = adis16400_get_freq, }, @@ -1184,7 +1171,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .default_scan_mask = 0x7FF, .set_freq = adis16400_set_freq, .get_freq = adis16400_get_freq, }, @@ -1194,7 +1180,6 @@ static struct adis16400_chip_info adis16400_chips[] = { .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ - .default_scan_mask = 0xFFF, .temp_scale_nano = 140000000, /* 0.14 C */ .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ .set_freq = adis16400_set_freq, -- cgit v0.10.2 From cd888a17f95fb170f6463990a6a24b4cd5fedea6 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Use adis library Use the new adis library for the adis16400 driver. This allows us to completely scrap the adis16400 trigger code and more than half of the core driver code. For now we can not make use of the generic adis buffer implementation since the adis16400 driver has special requirements due to its burst mode support. But we will eventually get to this. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/Kconfig b/drivers/staging/iio/imu/Kconfig index 2c2f47d..096afc8 100644 --- a/drivers/staging/iio/imu/Kconfig +++ b/drivers/staging/iio/imu/Kconfig @@ -6,8 +6,8 @@ menu "Inertial measurement units" config ADIS16400 tristate "Analog Devices ADIS16400 and similar IMU SPI driver" depends on SPI - select IIO_SW_RING if IIO_BUFFER - select IIO_TRIGGER if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16300, adis16344, adis16350, adis16354, adis16355, adis16360, adis16362, adis16364, diff --git a/drivers/staging/iio/imu/Makefile b/drivers/staging/iio/imu/Makefile index 3400a13..c9988f6 100644 --- a/drivers/staging/iio/imu/Makefile +++ b/drivers/staging/iio/imu/Makefile @@ -3,5 +3,5 @@ # adis16400-y := adis16400_core.o -adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o adis16400_trigger.o +adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o obj-$(CONFIG_ADIS16400) += adis16400.o diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/staging/iio/imu/adis16400.h index 3efafcb..ce63ced 100644 --- a/drivers/staging/iio/imu/adis16400.h +++ b/drivers/staging/iio/imu/adis16400.h @@ -17,12 +17,11 @@ #ifndef SPI_ADIS16400_H_ #define SPI_ADIS16400_H_ +#include + #define ADIS16400_STARTUP_DELAY 290 /* ms */ #define ADIS16400_MTEST_DELAY 90 /* ms */ -#define ADIS16400_READ_REG(a) a -#define ADIS16400_WRITE_REG(a) ((a) | 0x80) - #define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */ #define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */ #define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */ @@ -96,21 +95,21 @@ #define ADIS16400_SMPL_PRD_DIV_MASK 0x7F /* DIAG_STAT */ -#define ADIS16400_DIAG_STAT_ZACCL_FAIL (1<<15) -#define ADIS16400_DIAG_STAT_YACCL_FAIL (1<<14) -#define ADIS16400_DIAG_STAT_XACCL_FAIL (1<<13) -#define ADIS16400_DIAG_STAT_XGYRO_FAIL (1<<12) -#define ADIS16400_DIAG_STAT_YGYRO_FAIL (1<<11) -#define ADIS16400_DIAG_STAT_ZGYRO_FAIL (1<<10) -#define ADIS16400_DIAG_STAT_ALARM2 (1<<9) -#define ADIS16400_DIAG_STAT_ALARM1 (1<<8) -#define ADIS16400_DIAG_STAT_FLASH_CHK (1<<6) -#define ADIS16400_DIAG_STAT_SELF_TEST (1<<5) -#define ADIS16400_DIAG_STAT_OVERFLOW (1<<4) -#define ADIS16400_DIAG_STAT_SPI_FAIL (1<<3) -#define ADIS16400_DIAG_STAT_FLASH_UPT (1<<2) -#define ADIS16400_DIAG_STAT_POWER_HIGH (1<<1) -#define ADIS16400_DIAG_STAT_POWER_LOW (1<<0) +#define ADIS16400_DIAG_STAT_ZACCL_FAIL 15 +#define ADIS16400_DIAG_STAT_YACCL_FAIL 14 +#define ADIS16400_DIAG_STAT_XACCL_FAIL 13 +#define ADIS16400_DIAG_STAT_XGYRO_FAIL 12 +#define ADIS16400_DIAG_STAT_YGYRO_FAIL 11 +#define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10 +#define ADIS16400_DIAG_STAT_ALARM2 9 +#define ADIS16400_DIAG_STAT_ALARM1 8 +#define ADIS16400_DIAG_STAT_FLASH_CHK 6 +#define ADIS16400_DIAG_STAT_SELF_TEST 5 +#define ADIS16400_DIAG_STAT_OVERFLOW 4 +#define ADIS16400_DIAG_STAT_SPI_FAIL 3 +#define ADIS16400_DIAG_STAT_FLASH_UPT 2 +#define ADIS16400_DIAG_STAT_POWER_HIGH 1 +#define ADIS16400_DIAG_STAT_POWER_LOW 0 /* GLOB_CMD */ #define ADIS16400_GLOB_CMD_SW_RESET (1<<7) @@ -126,9 +125,6 @@ #define ADIS16334_RATE_DIV_SHIFT 8 #define ADIS16334_RATE_INT_CLK BIT(0) -#define ADIS16400_MAX_TX 24 -#define ADIS16400_MAX_RX 24 - #define ADIS16400_SPI_SLOW (u32)(300 * 1000) #define ADIS16400_SPI_BURST (u32)(1000 * 1000) #define ADIS16400_SPI_FAST (u32)(2000 * 1000) @@ -137,6 +133,8 @@ #define ADIS16400_NO_BURST BIT(1) #define ADIS16400_HAS_SLOW_MODE BIT(2) +struct adis16400_state; + struct adis16400_chip_info { const struct iio_chan_spec *channels; const int num_channels; @@ -145,58 +143,47 @@ struct adis16400_chip_info { unsigned int accel_scale_micro; int temp_scale_nano; int temp_offset; - int (*set_freq)(struct iio_dev *indio_dev, unsigned int freq); - int (*get_freq)(struct iio_dev *indio_dev); + int (*set_freq)(struct adis16400_state *st, unsigned int freq); + int (*get_freq)(struct adis16400_state *st); }; /** * struct adis16400_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @tx: transmit buffer - * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx - * @filt_int: integer part of requested filter frequency + * @variant: chip variant info + * @filt_int: integer part of requested filter frequency + * @adis: adis device **/ struct adis16400_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; struct adis16400_chip_info *variant; int filt_int; - u8 tx[ADIS16400_MAX_TX] ____cacheline_aligned; - u8 rx[ADIS16400_MAX_RX] ____cacheline_aligned; + struct adis adis; }; -int adis16400_set_irq(struct iio_dev *indio_dev, bool enable); - /* At the moment triggers are only used for ring buffer * filling. This may change! */ -#define ADIS16400_SCAN_SUPPLY 0 -#define ADIS16400_SCAN_GYRO_X 1 -#define ADIS16400_SCAN_GYRO_Y 2 -#define ADIS16400_SCAN_GYRO_Z 3 -#define ADIS16400_SCAN_ACC_X 4 -#define ADIS16400_SCAN_ACC_Y 5 -#define ADIS16400_SCAN_ACC_Z 6 -#define ADIS16400_SCAN_MAGN_X 7 -#define ADIS16350_SCAN_TEMP_X 7 -#define ADIS16400_SCAN_MAGN_Y 8 -#define ADIS16350_SCAN_TEMP_Y 8 -#define ADIS16400_SCAN_MAGN_Z 9 -#define ADIS16350_SCAN_TEMP_Z 9 -#define ADIS16400_SCAN_TEMP 10 -#define ADIS16350_SCAN_ADC_0 10 -#define ADIS16400_SCAN_ADC_0 11 -#define ADIS16300_SCAN_INCLI_X 12 -#define ADIS16300_SCAN_INCLI_Y 13 +enum { + ADIS16400_SCAN_SUPPLY, + ADIS16400_SCAN_GYRO_X, + ADIS16400_SCAN_GYRO_Y, + ADIS16400_SCAN_GYRO_Z, + ADIS16400_SCAN_ACC_X, + ADIS16400_SCAN_ACC_Y, + ADIS16400_SCAN_ACC_Z, + ADIS16400_SCAN_MAGN_X, + ADIS16400_SCAN_MAGN_Y, + ADIS16400_SCAN_MAGN_Z, + ADIS16350_SCAN_TEMP_X, + ADIS16350_SCAN_TEMP_Y, + ADIS16350_SCAN_TEMP_Z, + ADIS16300_SCAN_INCLI_X, + ADIS16300_SCAN_INCLI_Y, + ADIS16400_SCAN_ADC, +}; #ifdef CONFIG_IIO_BUFFER -void adis16400_remove_trigger(struct iio_dev *indio_dev); -int adis16400_probe_trigger(struct iio_dev *indio_dev); ssize_t adis16400_read_data_from_ring(struct device *dev, struct device_attribute *attr, @@ -208,15 +195,6 @@ void adis16400_unconfigure_ring(struct iio_dev *indio_dev); #else /* CONFIG_IIO_BUFFER */ -static inline void adis16400_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16400_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - static inline ssize_t adis16400_read_data_from_ring(struct device *dev, struct device_attribute *attr, @@ -235,4 +213,5 @@ static inline void adis16400_unconfigure_ring(struct iio_dev *indio_dev) } #endif /* CONFIG_IIO_BUFFER */ + #endif /* SPI_ADIS16400_H_ */ diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index 24fca10..a948472 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -29,6 +29,7 @@ #include #include #include + #include "adis16400.h" enum adis16400_chip_variant { @@ -41,131 +42,12 @@ enum adis16400_chip_variant { ADIS16400, }; -/** - * adis16400_spi_write_reg_8() - write single byte to a register - * @dev: device associated with child of actual device (iio_dev or iio_trig) - * @reg_address: the address of the register to be written - * @val: the value to write - */ -static int adis16400_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16400_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16400_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16400_spi_write_reg_16() - write 2 bytes to a pair of registers - * @dev: device associated with child of actual device (iio_dev or iio_trig) - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - * - * At the moment the spi framework doesn't allow global setting of cs_change. - * This means that use cannot be made of spi_write. - */ -static int adis16400_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16400_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16400_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16400_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16400_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - * - * At the moment the spi framework doesn't allow global setting of cs_change. - * This means that use cannot be made of spi_read. - **/ -static int adis16400_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16400_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16400_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, - "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static int adis16334_get_freq(struct iio_dev *indio_dev) +static int adis16334_get_freq(struct adis16400_state *st) { int ret; u16 t; - ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SMPL_PRD, &t); + ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); if (ret < 0) return ret; @@ -174,7 +56,7 @@ static int adis16334_get_freq(struct iio_dev *indio_dev) return (8192 >> t) / 10; } -static int adis16334_set_freq(struct iio_dev *indio_dev, unsigned int freq) +static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) { unsigned int t; @@ -190,15 +72,15 @@ static int adis16334_set_freq(struct iio_dev *indio_dev, unsigned int freq) t <<= ADIS16334_RATE_DIV_SHIFT; t |= ADIS16334_RATE_INT_CLK; - return adis16400_spi_write_reg_16(indio_dev, ADIS16400_SMPL_PRD, t); + return adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t); } -static int adis16400_get_freq(struct iio_dev *indio_dev) +static int adis16400_get_freq(struct adis16400_state *st) { int sps, ret; u16 t; - ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SMPL_PRD, &t); + ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); if (ret < 0) return ret; sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; @@ -207,9 +89,8 @@ static int adis16400_get_freq(struct iio_dev *indio_dev) return sps; } -static int adis16400_set_freq(struct iio_dev *indio_dev, unsigned int freq) +static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) { - struct adis16400_state *st = iio_priv(indio_dev); unsigned int t; t = 1638 / freq; @@ -217,12 +98,11 @@ static int adis16400_set_freq(struct iio_dev *indio_dev, unsigned int freq) t--; t &= ADIS16400_SMPL_PRD_DIV_MASK; if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) - st->us->max_speed_hz = ADIS16400_SPI_SLOW; + st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; else - st->us->max_speed_hz = ADIS16400_SPI_FAST; + st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; - return adis16400_spi_write_reg_8(indio_dev, - ADIS16400_SMPL_PRD, t); + return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, t); } static ssize_t adis16400_read_frequency(struct device *dev, @@ -233,7 +113,7 @@ static ssize_t adis16400_read_frequency(struct device *dev, struct adis16400_state *st = iio_priv(indio_dev); int ret, len = 0; - ret = st->variant->get_freq(indio_dev); + ret = st->variant->get_freq(st); if (ret < 0) return ret; len = sprintf(buf, "%d SPS\n", ret); @@ -253,6 +133,7 @@ static const unsigned adis16400_3db_divisors[] = { static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) { + struct adis16400_state *st = iio_priv(indio_dev); int i, ret; u16 val16; @@ -261,12 +142,11 @@ static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) break; } - ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SENS_AVG, - &val16); + ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); if (ret < 0) return ret; - ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_SENS_AVG, + ret = adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG, (val16 & ~0x07) | i); return ret; } @@ -289,7 +169,7 @@ static ssize_t adis16400_write_frequency(struct device *dev, mutex_lock(&indio_dev->mlock); - st->variant->set_freq(indio_dev, val); + st->variant->set_freq(st, val); /* Also update the filter */ mutex_unlock(&indio_dev->mlock); @@ -297,48 +177,14 @@ static ssize_t adis16400_write_frequency(struct device *dev, return ret ? ret : len; } -static int adis16400_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16400_spi_write_reg_8(indio_dev, - ADIS16400_GLOB_CMD, - ADIS16400_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - -int adis16400_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret; - u16 msc; - - ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH; - if (enable) - msc |= ADIS16400_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16400_MSC_CTRL_DATA_RDY_EN; - - ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_MSC_CTRL, msc); - if (ret) - goto error_ret; - -error_ret: - return ret; -} - /* Power down the device */ static int adis16400_stop_device(struct iio_dev *indio_dev) { + struct adis16400_state *st = iio_priv(indio_dev); int ret; u16 val = ADIS16400_SLP_CNT_POWER_OFF; - ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_SLP_CNT, val); + ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, val); if (ret) dev_err(&indio_dev->dev, "problem with turning device off: SLP_CNT"); @@ -346,73 +192,6 @@ static int adis16400_stop_device(struct iio_dev *indio_dev) return ret; } -static int adis16400_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - struct device *dev = &indio_dev->dev; - - ret = adis16400_spi_read_reg_16(indio_dev, - ADIS16400_DIAG_STAT, &status); - - if (ret < 0) { - dev_err(dev, "Reading status failed\n"); - goto error_ret; - } - ret = status; - if (status & ADIS16400_DIAG_STAT_ZACCL_FAIL) - dev_err(dev, "Z-axis accelerometer self-test failure\n"); - if (status & ADIS16400_DIAG_STAT_YACCL_FAIL) - dev_err(dev, "Y-axis accelerometer self-test failure\n"); - if (status & ADIS16400_DIAG_STAT_XACCL_FAIL) - dev_err(dev, "X-axis accelerometer self-test failure\n"); - if (status & ADIS16400_DIAG_STAT_XGYRO_FAIL) - dev_err(dev, "X-axis gyroscope self-test failure\n"); - if (status & ADIS16400_DIAG_STAT_YGYRO_FAIL) - dev_err(dev, "Y-axis gyroscope self-test failure\n"); - if (status & ADIS16400_DIAG_STAT_ZGYRO_FAIL) - dev_err(dev, "Z-axis gyroscope self-test failure\n"); - if (status & ADIS16400_DIAG_STAT_ALARM2) - dev_err(dev, "Alarm 2 active\n"); - if (status & ADIS16400_DIAG_STAT_ALARM1) - dev_err(dev, "Alarm 1 active\n"); - if (status & ADIS16400_DIAG_STAT_FLASH_CHK) - dev_err(dev, "Flash checksum error\n"); - if (status & ADIS16400_DIAG_STAT_SELF_TEST) - dev_err(dev, "Self test error\n"); - if (status & ADIS16400_DIAG_STAT_OVERFLOW) - dev_err(dev, "Sensor overrange\n"); - if (status & ADIS16400_DIAG_STAT_SPI_FAIL) - dev_err(dev, "SPI failure\n"); - if (status & ADIS16400_DIAG_STAT_FLASH_UPT) - dev_err(dev, "Flash update failed\n"); - if (status & ADIS16400_DIAG_STAT_POWER_HIGH) - dev_err(dev, "Power supply above 5.25V\n"); - if (status & ADIS16400_DIAG_STAT_POWER_LOW) - dev_err(dev, "Power supply below 4.75V\n"); - -error_ret: - return ret; -} - -static int adis16400_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16400_spi_write_reg_16(indio_dev, - ADIS16400_MSC_CTRL, - ADIS16400_MSC_CTRL_MEM_TEST); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - msleep(ADIS16400_MTEST_DELAY); - adis16400_check_status(indio_dev); - -err_ret: - return ret; -} - static int adis16400_initial_setup(struct iio_dev *indio_dev) { int ret; @@ -422,37 +201,18 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev) /* use low spi speed for init if the device has a slow mode */ if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) - st->us->max_speed_hz = ADIS16400_SPI_SLOW; + st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; else - st->us->max_speed_hz = ADIS16400_SPI_FAST; - st->us->mode = SPI_MODE_3; - spi_setup(st->us); - - ret = adis16400_set_irq(indio_dev, false); - if (ret) { - dev_err(&indio_dev->dev, "disable irq failed"); - goto err_ret; - } + st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; + st->adis.spi->mode = SPI_MODE_3; + spi_setup(st->adis.spi); - ret = adis16400_self_test(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "self test failure"); - goto err_ret; - } + ret = adis_initial_startup(&st->adis); + if (ret) + return ret; - ret = adis16400_check_status(indio_dev); - if (ret) { - adis16400_reset(indio_dev); - dev_err(&indio_dev->dev, "device not playing ball -> reset"); - msleep(ADIS16400_STARTUP_DELAY); - ret = adis16400_check_status(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "giving up"); - goto err_ret; - } - } if (st->variant->flags & ADIS16400_HAS_PROD_ID) { - ret = adis16400_spi_read_reg_16(indio_dev, + ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id); if (ret) goto err_ret; @@ -465,18 +225,17 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev) dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", indio_dev->name, prod_id, - st->us->chip_select, st->us->irq); + st->adis.spi->chip_select, st->adis.spi->irq); } /* use high spi speed if possible */ if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { - ret = adis16400_spi_read_reg_16(indio_dev, - ADIS16400_SMPL_PRD, &smp_prd); + ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd); if (ret) goto err_ret; if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { - st->us->max_speed_hz = ADIS16400_SPI_FAST; - spi_setup(st->us); + st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; + spi_setup(st->adis.spi); } } @@ -490,47 +249,15 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("409 546 819 1638"); -enum adis16400_chan { - in_supply, - gyro_x, - gyro_y, - gyro_z, - accel_x, - accel_y, - accel_z, - magn_x, - magn_y, - magn_z, - temp, - temp0, temp1, temp2, - in1, - in2, - incli_x, - incli_y, -}; - -static u8 adis16400_addresses[18][2] = { - [in_supply] = { ADIS16400_SUPPLY_OUT }, - [gyro_x] = { ADIS16400_XGYRO_OUT, ADIS16400_XGYRO_OFF }, - [gyro_y] = { ADIS16400_YGYRO_OUT, ADIS16400_YGYRO_OFF }, - [gyro_z] = { ADIS16400_ZGYRO_OUT, ADIS16400_ZGYRO_OFF }, - [accel_x] = { ADIS16400_XACCL_OUT, ADIS16400_XACCL_OFF }, - [accel_y] = { ADIS16400_YACCL_OUT, ADIS16400_YACCL_OFF }, - [accel_z] = { ADIS16400_ZACCL_OUT, ADIS16400_ZACCL_OFF }, - [magn_x] = { ADIS16400_XMAGN_OUT }, - [magn_y] = { ADIS16400_YMAGN_OUT }, - [magn_z] = { ADIS16400_ZMAGN_OUT }, - [temp] = { ADIS16400_TEMP_OUT }, - [temp0] = { ADIS16350_XTEMP_OUT }, - [temp1] = { ADIS16350_YTEMP_OUT }, - [temp2] = { ADIS16350_ZTEMP_OUT }, - [in1] = { ADIS16300_AUX_ADC }, - [in2] = { ADIS16400_AUX_ADC }, - [incli_x] = { ADIS16300_PITCH_OUT }, - [incli_y] = { ADIS16300_ROLL_OUT } +static const u8 adis16400_addresses[] = { + [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, + [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, + [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF, + [ADIS16400_SCAN_ACC_X] = ADIS16400_XACCL_OFF, + [ADIS16400_SCAN_ACC_Y] = ADIS16400_YACCL_OFF, + [ADIS16400_SCAN_ACC_Z] = ADIS16400_ZACCL_OFF, }; - static int adis16400_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, @@ -543,9 +270,8 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_CALIBBIAS: mutex_lock(&indio_dev->mlock); - ret = adis16400_spi_write_reg_16(indio_dev, - adis16400_addresses[chan->address][1], - val); + ret = adis_write_reg_16(&st->adis, + adis16400_addresses[chan->scan_index], val); mutex_unlock(&indio_dev->mlock); return ret; case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: @@ -554,7 +280,7 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, mutex_lock(&indio_dev->mlock); st->filt_int = val; /* Work out update to current value */ - sps = st->variant->get_freq(indio_dev); + sps = st->variant->get_freq(st); if (sps < 0) { mutex_unlock(&indio_dev->mlock); return sps; @@ -575,27 +301,12 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, long mask) { struct adis16400_state *st = iio_priv(indio_dev); - int ret, shift; + int ret; s16 val16; switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - ret = adis16400_spi_read_reg_16(indio_dev, - adis16400_addresses[chan->address][0], - &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - val16 &= (1 << chan->scan_type.realbits) - 1; - if (chan->scan_type.sign == 's') { - shift = 16 - chan->scan_type.realbits; - val16 = (s16)(val16 << shift) >> shift; - } - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, 0, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ANGL_VEL: @@ -629,9 +340,8 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, } case IIO_CHAN_INFO_CALIBBIAS: mutex_lock(&indio_dev->mlock); - ret = adis16400_spi_read_reg_16(indio_dev, - adis16400_addresses[chan->address][1], - &val16); + ret = adis_read_reg_16(&st->adis, + adis16400_addresses[chan->scan_index], &val16); mutex_unlock(&indio_dev->mlock); if (ret) return ret; @@ -645,14 +355,14 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: mutex_lock(&indio_dev->mlock); /* Need both the number of taps and the sampling frequency */ - ret = adis16400_spi_read_reg_16(indio_dev, + ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); if (ret < 0) { mutex_unlock(&indio_dev->mlock); return ret; } - ret = st->variant->get_freq(indio_dev); + ret = st->variant->get_freq(st); if (ret >= 0) *val = ret / adis16400_3db_divisors[val16 & 0x07]; *val2 = 0; @@ -673,7 +383,7 @@ static const struct iio_chan_spec adis16400_channels[] = { .extend_name = "supply", .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, + .address = ADIS16400_SUPPLY_OUT, .scan_index = ADIS16400_SCAN_SUPPLY, .scan_type = IIO_ST('u', 14, 16, 0), }, { @@ -684,7 +394,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_x, + .address = ADIS16400_XGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -695,7 +405,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_y, + .address = ADIS16400_YGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -706,7 +416,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_z, + .address = ADIS16400_ZGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -717,7 +427,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_x, + .address = ADIS16400_XACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -728,7 +438,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_y, + .address = ADIS16400_YACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -739,7 +449,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_z, + .address = ADIS16400_ZACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -749,7 +459,7 @@ static const struct iio_chan_spec adis16400_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = magn_x, + .address = ADIS16400_XMAGN_OUT, .scan_index = ADIS16400_SCAN_MAGN_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -759,7 +469,7 @@ static const struct iio_chan_spec adis16400_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = magn_y, + .address = ADIS16400_YMAGN_OUT, .scan_index = ADIS16400_SCAN_MAGN_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -769,7 +479,7 @@ static const struct iio_chan_spec adis16400_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = magn_z, + .address = ADIS16400_ZMAGN_OUT, .scan_index = ADIS16400_SCAN_MAGN_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -779,8 +489,8 @@ static const struct iio_chan_spec adis16400_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = temp, - .scan_index = ADIS16400_SCAN_TEMP, + .address = ADIS16400_TEMP_OUT, + .scan_index = ADIS16350_SCAN_TEMP_X, .scan_type = IIO_ST('s', 12, 16, 0), }, { .type = IIO_VOLTAGE, @@ -788,8 +498,8 @@ static const struct iio_chan_spec adis16400_channels[] = { .channel = 1, .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in2, - .scan_index = ADIS16400_SCAN_ADC_0, + .address = ADIS16400_AUX_ADC, + .scan_index = ADIS16400_SCAN_ADC, .scan_type = IIO_ST('s', 12, 16, 0), }, IIO_CHAN_SOFT_TIMESTAMP(12) @@ -803,7 +513,7 @@ static const struct iio_chan_spec adis16350_channels[] = { .extend_name = "supply", .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, + .address = ADIS16400_SUPPLY_OUT, .scan_index = ADIS16400_SCAN_SUPPLY, .scan_type = IIO_ST('u', 12, 16, 0), }, { @@ -814,7 +524,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_x, + .address = ADIS16400_XGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -825,7 +535,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_y, + .address = ADIS16400_YGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -836,7 +546,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_z, + .address = ADIS16400_ZGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -847,7 +557,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_x, + .address = ADIS16400_XACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -858,7 +568,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_y, + .address = ADIS16400_YACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -869,7 +579,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_z, + .address = ADIS16400_ZACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -881,7 +591,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = temp0, + .address = ADIS16350_XTEMP_OUT, .scan_index = ADIS16350_SCAN_TEMP_X, .scan_type = IIO_ST('s', 12, 16, 0), }, { @@ -893,7 +603,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = temp1, + .address = ADIS16350_YTEMP_OUT, .scan_index = ADIS16350_SCAN_TEMP_Y, .scan_type = IIO_ST('s', 12, 16, 0), }, { @@ -904,7 +614,7 @@ static const struct iio_chan_spec adis16350_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = temp2, + .address = ADIS16350_ZTEMP_OUT, .scan_index = ADIS16350_SCAN_TEMP_Z, .scan_type = IIO_ST('s', 12, 16, 0), }, { @@ -913,8 +623,8 @@ static const struct iio_chan_spec adis16350_channels[] = { .channel = 1, .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in1, - .scan_index = ADIS16350_SCAN_ADC_0, + .address = ADIS16300_AUX_ADC, + .scan_index = ADIS16400_SCAN_ADC, .scan_type = IIO_ST('s', 12, 16, 0), }, IIO_CHAN_SOFT_TIMESTAMP(11) @@ -928,7 +638,7 @@ static const struct iio_chan_spec adis16300_channels[] = { .extend_name = "supply", .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, + .address = ADIS16400_SUPPLY_OUT, .scan_index = ADIS16400_SCAN_SUPPLY, .scan_type = IIO_ST('u', 12, 16, 0), }, { @@ -939,7 +649,7 @@ static const struct iio_chan_spec adis16300_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_x, + .address = ADIS16400_XGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -950,7 +660,7 @@ static const struct iio_chan_spec adis16300_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_x, + .address = ADIS16400_XACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -961,7 +671,7 @@ static const struct iio_chan_spec adis16300_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_y, + .address = ADIS16400_YACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -972,7 +682,7 @@ static const struct iio_chan_spec adis16300_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_z, + .address = ADIS16400_ZACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -982,8 +692,8 @@ static const struct iio_chan_spec adis16300_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = temp0, - .scan_index = ADIS16400_SCAN_TEMP, + .address = ADIS16350_XTEMP_OUT, + .scan_index = ADIS16350_SCAN_TEMP_X, .scan_type = IIO_ST('s', 12, 16, 0), }, { .type = IIO_VOLTAGE, @@ -991,8 +701,8 @@ static const struct iio_chan_spec adis16300_channels[] = { .channel = 1, .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in1, - .scan_index = ADIS16350_SCAN_ADC_0, + .address = ADIS16300_AUX_ADC, + .scan_index = ADIS16400_SCAN_ADC, .scan_type = IIO_ST('s', 12, 16, 0), }, { .type = IIO_INCLI, @@ -1000,7 +710,7 @@ static const struct iio_chan_spec adis16300_channels[] = { .channel2 = IIO_MOD_X, .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = incli_x, + .address = ADIS16300_PITCH_OUT, .scan_index = ADIS16300_SCAN_INCLI_X, .scan_type = IIO_ST('s', 13, 16, 0), }, { @@ -1009,7 +719,7 @@ static const struct iio_chan_spec adis16300_channels[] = { .channel2 = IIO_MOD_Y, .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = incli_y, + .address = ADIS16300_ROLL_OUT, .scan_index = ADIS16300_SCAN_INCLI_Y, .scan_type = IIO_ST('s', 13, 16, 0), }, @@ -1025,7 +735,7 @@ static const struct iio_chan_spec adis16334_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_x, + .address = ADIS16400_XGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -1036,7 +746,7 @@ static const struct iio_chan_spec adis16334_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_y, + .address = ADIS16400_YGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -1047,7 +757,7 @@ static const struct iio_chan_spec adis16334_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = gyro_z, + .address = ADIS16400_ZGYRO_OUT, .scan_index = ADIS16400_SCAN_GYRO_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -1058,7 +768,7 @@ static const struct iio_chan_spec adis16334_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_x, + .address = ADIS16400_XACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_X, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -1069,7 +779,7 @@ static const struct iio_chan_spec adis16334_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_y, + .address = ADIS16400_YACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Y, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -1080,7 +790,7 @@ static const struct iio_chan_spec adis16334_channels[] = { IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = accel_z, + .address = ADIS16400_ZACCL_OUT, .scan_index = ADIS16400_SCAN_ACC_Z, .scan_type = IIO_ST('s', 14, 16, 0), }, { @@ -1090,8 +800,8 @@ static const struct iio_chan_spec adis16334_channels[] = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = temp0, - .scan_index = ADIS16400_SCAN_TEMP, + .address = ADIS16350_XTEMP_OUT, + .scan_index = ADIS16350_SCAN_TEMP_X, .scan_type = IIO_ST('s', 14, 16, 0), }, IIO_CHAN_SOFT_TIMESTAMP(12) @@ -1194,6 +904,53 @@ static const struct iio_info adis16400_info = { .attrs = &adis16400_attribute_group, }; +static const char * const adis16400_status_error_msgs[] = { + [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure", + [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure", + [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure", + [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure", + [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure", + [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure", + [ADIS16400_DIAG_STAT_ALARM2] = "Alarm 2 active", + [ADIS16400_DIAG_STAT_ALARM1] = "Alarm 1 active", + [ADIS16400_DIAG_STAT_FLASH_CHK] = "Flash checksum error", + [ADIS16400_DIAG_STAT_SELF_TEST] = "Self test error", + [ADIS16400_DIAG_STAT_OVERFLOW] = "Sensor overrange", + [ADIS16400_DIAG_STAT_SPI_FAIL] = "SPI failure", + [ADIS16400_DIAG_STAT_FLASH_UPT] = "Flash update failed", + [ADIS16400_DIAG_STAT_POWER_HIGH] = "Power supply above 5.25V", + [ADIS16400_DIAG_STAT_POWER_LOW] = "Power supply below 4.75V", +}; + +static const struct adis_data adis16400_data = { + .msc_ctrl_reg = ADIS16400_MSC_CTRL, + .glob_cmd_reg = ADIS16400_GLOB_CMD, + .diag_stat_reg = ADIS16400_DIAG_STAT, + + .read_delay = 50, + .write_delay = 50, + + .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, + .startup_delay = ADIS16400_STARTUP_DELAY, + + .status_error_msgs = adis16400_status_error_msgs, + .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | + BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | + BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | + BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | + BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | + BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | + BIT(ADIS16400_DIAG_STAT_ALARM2) | + BIT(ADIS16400_DIAG_STAT_ALARM1) | + BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | + BIT(ADIS16400_DIAG_STAT_SELF_TEST) | + BIT(ADIS16400_DIAG_STAT_OVERFLOW) | + BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | + BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | + BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | + BIT(ADIS16400_DIAG_STAT_POWER_LOW), +}; + static int adis16400_probe(struct spi_device *spi) { int ret; @@ -1207,9 +964,6 @@ static int adis16400_probe(struct spi_device *spi) /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - /* setup the industrialio driver allocated elements */ st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; indio_dev->dev.parent = &spi->dev; @@ -1219,6 +973,10 @@ static int adis16400_probe(struct spi_device *spi) indio_dev->info = &adis16400_info; indio_dev->modes = INDIO_DIRECT_MODE; + ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); + if (ret) + goto error_free_dev; + ret = adis16400_configure_ring(indio_dev); if (ret) goto error_free_dev; @@ -1232,7 +990,7 @@ static int adis16400_probe(struct spi_device *spi) } if (spi->irq) { - ret = adis16400_probe_trigger(indio_dev); + ret = adis_probe_trigger(&st->adis, indio_dev); if (ret) goto error_uninitialize_ring; } @@ -1249,7 +1007,7 @@ static int adis16400_probe(struct spi_device *spi) error_remove_trigger: if (spi->irq) - adis16400_remove_trigger(indio_dev); + adis_remove_trigger(&st->adis); error_uninitialize_ring: iio_buffer_unregister(indio_dev); error_unreg_ring_funcs: @@ -1264,13 +1022,16 @@ error_ret: static int adis16400_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis16400_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); adis16400_stop_device(indio_dev); - adis16400_remove_trigger(indio_dev); + if (spi->irq) + adis_remove_trigger(&st->adis); iio_buffer_unregister(indio_dev); adis16400_unconfigure_ring(indio_dev); + iio_device_free(indio_dev); return 0; diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c index d46c1e3..6c5b0be 100644 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ b/drivers/staging/iio/imu/adis16400_ring.c @@ -9,6 +9,7 @@ #include #include "../ring_sw.h" #include + #include "adis16400.h" /** @@ -20,12 +21,12 @@ static int adis16400_spi_read_burst(struct iio_dev *indio_dev, u8 *rx) { struct spi_message msg; struct adis16400_state *st = iio_priv(indio_dev); - u32 old_speed_hz = st->us->max_speed_hz; + u32 old_speed_hz = st->adis.spi->max_speed_hz; int ret; struct spi_transfer xfers[] = { { - .tx_buf = st->tx, + .tx_buf = st->adis.tx, .bits_per_word = 8, .len = 2, }, { @@ -35,39 +36,39 @@ static int adis16400_spi_read_burst(struct iio_dev *indio_dev, u8 *rx) }, }; - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16400_READ_REG(ADIS16400_GLOB_CMD); - st->tx[1] = 0; + mutex_lock(&st->adis.txrx_lock); + st->adis.tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD); + st->adis.tx[1] = 0; spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); spi_message_add_tail(&xfers[1], &msg); - st->us->max_speed_hz = min(ADIS16400_SPI_BURST, old_speed_hz); - spi_setup(st->us); + st->adis.spi->max_speed_hz = min(ADIS16400_SPI_BURST, old_speed_hz); + spi_setup(st->adis.spi); - ret = spi_sync(st->us, &msg); + ret = spi_sync(st->adis.spi, &msg); if (ret) - dev_err(&st->us->dev, "problem when burst reading"); + dev_err(&st->adis.spi->dev, "problem when burst reading"); - st->us->max_speed_hz = old_speed_hz; - spi_setup(st->us); - mutex_unlock(&st->buf_lock); + st->adis.spi->max_speed_hz = old_speed_hz; + spi_setup(st->adis.spi); + mutex_unlock(&st->adis.txrx_lock); return ret; } static const u16 read_all_tx_array[] = { - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_SUPPLY_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_XGYRO_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_YGYRO_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_ZGYRO_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_XACCL_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_YACCL_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_ZACCL_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16350_XTEMP_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16350_YTEMP_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16350_ZTEMP_OUT)), - cpu_to_be16(ADIS16400_READ_REG(ADIS16400_AUX_ADC)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_SUPPLY_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_XGYRO_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_YGYRO_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_ZGYRO_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_XACCL_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_YACCL_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_ZACCL_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16350_XTEMP_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16350_YTEMP_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16350_ZTEMP_OUT)), + cpu_to_be16(ADIS_READ_REG(ADIS16400_AUX_ADC)), }; static int adis16350_spi_read_all(struct iio_dev *indio_dev, u8 *rx) @@ -100,7 +101,7 @@ static int adis16350_spi_read_all(struct iio_dev *indio_dev, u8 *rx) for (j = 0; j < scan_count + 1; j++) spi_message_add_tail(&xfers[j], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync(st->adis.spi, &msg); kfree(xfers); return ret; @@ -123,26 +124,26 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) indio_dev->masklength); data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); + dev_err(&st->adis.spi->dev, "memory alloc failed in ring bh"); goto done; } if (scan_count) { if (st->variant->flags & ADIS16400_NO_BURST) { - ret = adis16350_spi_read_all(indio_dev, st->rx); + ret = adis16350_spi_read_all(indio_dev, st->adis.rx); if (ret < 0) goto done; for (; i < scan_count; i++) - data[i] = *(s16 *)(st->rx + i*2); + data[i] = *(s16 *)(st->adis.rx + i*2); } else { - ret = adis16400_spi_read_burst(indio_dev, st->rx); + ret = adis16400_spi_read_burst(indio_dev, st->adis.rx); if (ret < 0) goto done; for (; i < scan_count; i++) { j = __ffs(mask); mask &= ~(1 << j); data[i] = be16_to_cpup( - (__be16 *)&(st->rx[j*2])); + (__be16 *)&(st->adis.rx[j*2])); } } } diff --git a/drivers/staging/iio/imu/adis16400_trigger.c b/drivers/staging/iio/imu/adis16400_trigger.c deleted file mode 100644 index 42a678e..0000000 --- a/drivers/staging/iio/imu/adis16400_trigger.c +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include "adis16400.h" - -/** - * adis16400_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16400_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16400_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16400_data_rdy_trigger_set_state, -}; - -int adis16400_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16400_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("%s-dev%d", - indio_dev->name, - indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - ret = request_irq(st->us->irq, - &iio_trigger_generic_data_rdy_poll, - IRQF_TRIGGER_RISING, - "adis16400", - st->trig); - if (ret) - goto error_free_trig; - st->trig->dev.parent = &st->us->dev; - st->trig->private_data = indio_dev; - st->trig->ops = &adis16400_trigger_ops; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16400_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16400_state *st = iio_priv(indio_dev); - - iio_trigger_unregister(st->trig); - free_irq(st->us->irq, st->trig); - iio_trigger_free(st->trig); -} -- cgit v0.10.2 From 1ffe2e7ac000b7a7c01b22cd64cc3d4ef01a9def Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Use triggered buffer setup helper function Use the triggered buffer helper functions to setup and tear down the buffer for the adis16400 instead of doing this manually. This also means that we switch away from the deprecated sw_ring buffer and use the kfifo buffer now instead. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index a948472..c545cd9 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -981,18 +981,10 @@ static int adis16400_probe(struct spi_device *spi) if (ret) goto error_free_dev; - ret = iio_buffer_register(indio_dev, - st->variant->channels, - st->variant->num_channels); - if (ret) { - dev_err(&spi->dev, "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } - if (spi->irq) { ret = adis_probe_trigger(&st->adis, indio_dev); if (ret) - goto error_uninitialize_ring; + goto error_unreg_ring_funcs; } /* Get the device into a sane initial state */ @@ -1008,8 +1000,6 @@ static int adis16400_probe(struct spi_device *spi) error_remove_trigger: if (spi->irq) adis_remove_trigger(&st->adis); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); error_unreg_ring_funcs: adis16400_unconfigure_ring(indio_dev); error_free_dev: @@ -1029,7 +1019,6 @@ static int adis16400_remove(struct spi_device *spi) if (spi->irq) adis_remove_trigger(&st->adis); - iio_buffer_unregister(indio_dev); adis16400_unconfigure_ring(indio_dev); iio_device_free(indio_dev); diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c index 6c5b0be..e421278 100644 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ b/drivers/staging/iio/imu/adis16400_ring.c @@ -7,7 +7,8 @@ #include #include -#include "../ring_sw.h" +#include +#include #include #include "adis16400.h" @@ -159,47 +160,13 @@ done: return IRQ_HANDLED; } -void adis16400_unconfigure_ring(struct iio_dev *indio_dev) +int adis16400_configure_ring(struct iio_dev *indio_dev) { - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + &adis16400_trigger_handler, NULL); } -static const struct iio_buffer_setup_ops adis16400_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16400_configure_ring(struct iio_dev *indio_dev) +void adis16400_unconfigure_ring(struct iio_dev *indio_dev) { - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16400_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16400_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - indio_dev->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; + iio_triggered_buffer_cleanup(indio_dev); } -- cgit v0.10.2 From 599acfbb974dbce63c3f33f169c74fffdadcfa72 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Add helper macros for channel declaration Most of the channels declared in the adis16400 driver look quite similar. This patch adds a bunch of helper macros to initialize the channel spec for this driver. This allows us to drastically reduce the number of lines of code needed for the channel spec declaration. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index c545cd9..f1d747a 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -375,436 +375,159 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, } } +#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = 0, \ + .extend_name = name, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .address = (addr), \ + .scan_index = (si), \ + .scan_type = IIO_ST('u', (bits), 16, 0), \ +} + +#define ADIS16400_SUPPLY_CHAN(addr, bits) \ + ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY) + +#define ADIS16400_AUX_ADC_CHAN(addr, bits) \ + ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC) + +#define ADIS16400_GYRO_CHAN(mod, addr, bits) { \ + .type = IIO_ANGL_VEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = addr, \ + .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ + .scan_type = IIO_ST('s', (bits), 16, 0), \ +} + +#define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ + .scan_type = IIO_ST('s', (bits), 16, 0), \ +} + +#define ADIS16400_MAGN_CHAN(mod, addr, bits) { \ + .type = IIO_MAGN, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ + .scan_type = IIO_ST('s', (bits), 16, 0), \ +} + +#define ADIS16400_MOD_TEMP_NAME_X "x" +#define ADIS16400_MOD_TEMP_NAME_Y "y" +#define ADIS16400_MOD_TEMP_NAME_Z "z" + +#define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .channel = 0, \ + .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ + .scan_type = IIO_ST('s', (bits), 16, 0), \ +} + +#define ADIS16400_TEMP_CHAN(addr, bits) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .channel = 0, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .address = (addr), \ + .scan_index = ADIS16350_SCAN_TEMP_X, \ + .scan_type = IIO_ST('s', (bits), 16, 0), \ +} + +#define ADIS16400_INCLI_CHAN(mod, addr, bits) { \ + .type = IIO_INCLI, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ + .scan_type = IIO_ST('s', (bits), 16, 0), \ +} + static const struct iio_chan_spec adis16400_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16400_SUPPLY_OUT, - .scan_index = ADIS16400_SCAN_SUPPLY, - .scan_type = IIO_ST('u', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_MAGN, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XMAGN_OUT, - .scan_index = ADIS16400_SCAN_MAGN_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_MAGN, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YMAGN_OUT, - .scan_index = ADIS16400_SCAN_MAGN_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_MAGN, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZMAGN_OUT, - .scan_index = ADIS16400_SCAN_MAGN_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16400_TEMP_OUT, - .scan_index = ADIS16350_SCAN_TEMP_X, - .scan_type = IIO_ST('s', 12, 16, 0), - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16400_AUX_ADC, - .scan_index = ADIS16400_SCAN_ADC, - .scan_type = IIO_ST('s', 12, 16, 0), - }, + ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 14), + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), + ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12), + ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12), IIO_CHAN_SOFT_TIMESTAMP(12) }; static const struct iio_chan_spec adis16350_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16400_SUPPLY_OUT, - .scan_index = ADIS16400_SCAN_SUPPLY, - .scan_type = IIO_ST('u', 12, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .extend_name = "x", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16350_XTEMP_OUT, - .scan_index = ADIS16350_SCAN_TEMP_X, - .scan_type = IIO_ST('s', 12, 16, 0), - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 1, - .extend_name = "y", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16350_YTEMP_OUT, - .scan_index = ADIS16350_SCAN_TEMP_Y, - .scan_type = IIO_ST('s', 12, 16, 0), - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 2, - .extend_name = "z", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16350_ZTEMP_OUT, - .scan_index = ADIS16350_SCAN_TEMP_Z, - .scan_type = IIO_ST('s', 12, 16, 0), - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16300_AUX_ADC, - .scan_index = ADIS16400_SCAN_ADC, - .scan_type = IIO_ST('s', 12, 16, 0), - }, + ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), + ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), + ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12), + ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12), + ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12), IIO_CHAN_SOFT_TIMESTAMP(11) }; static const struct iio_chan_spec adis16300_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16400_SUPPLY_OUT, - .scan_index = ADIS16400_SCAN_SUPPLY, - .scan_type = IIO_ST('u', 12, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16350_XTEMP_OUT, - .scan_index = ADIS16350_SCAN_TEMP_X, - .scan_type = IIO_ST('s', 12, 16, 0), - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16300_AUX_ADC, - .scan_index = ADIS16400_SCAN_ADC, - .scan_type = IIO_ST('s', 12, 16, 0), - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = ADIS16300_PITCH_OUT, - .scan_index = ADIS16300_SCAN_INCLI_X, - .scan_type = IIO_ST('s', 13, 16, 0), - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = ADIS16300_ROLL_OUT, - .scan_index = ADIS16300_SCAN_INCLI_Y, - .scan_type = IIO_ST('s', 13, 16, 0), - }, + ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), + ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), + ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13), + ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13), IIO_CHAN_SOFT_TIMESTAMP(14) }; static const struct iio_chan_spec adis16334_channels[] = { - { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZGYRO_OUT, - .scan_index = ADIS16400_SCAN_GYRO_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_XACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_YACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Y, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, - .address = ADIS16400_ZACCL_OUT, - .scan_index = ADIS16400_SCAN_ACC_Z, - .scan_type = IIO_ST('s', 14, 16, 0), - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = ADIS16350_XTEMP_OUT, - .scan_index = ADIS16350_SCAN_TEMP_X, - .scan_type = IIO_ST('s', 14, 16, 0), - }, - IIO_CHAN_SOFT_TIMESTAMP(12) + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), + IIO_CHAN_SOFT_TIMESTAMP(8) }; static struct attribute *adis16400_attributes[] = { -- cgit v0.10.2 From 5eda3550a3cc1987a495e9f85e5998a76d15a0aa Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Preallocate transfer message Similar to like we already did for the generic adis library preallocate and pre-construct the SPI transfer message for the adis16400. For devices which do not support burst mode sampling does not differ from other adis devices and so we use the generic functions of the adis library in this case. In burst mode we can only sample all channels at once, so use the IIO cores demux facility instead of doing this manually. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/staging/iio/imu/adis16400.h index ce63ced..a3b9e56 100644 --- a/drivers/staging/iio/imu/adis16400.h +++ b/drivers/staging/iio/imu/adis16400.h @@ -190,27 +190,14 @@ ssize_t adis16400_read_data_from_ring(struct device *dev, char *buf); -int adis16400_configure_ring(struct iio_dev *indio_dev); -void adis16400_unconfigure_ring(struct iio_dev *indio_dev); +int adis16400_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask); +irqreturn_t adis16400_trigger_handler(int irq, void *p); #else /* CONFIG_IIO_BUFFER */ -static inline ssize_t -adis16400_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16400_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16400_unconfigure_ring(struct iio_dev *indio_dev) -{ -} +#define adis16400_update_scan_mode NULL +#define adis16400_trigger_handler NULL #endif /* CONFIG_IIO_BUFFER */ diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index f1d747a..aa4ffcf 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -384,7 +384,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ .address = (addr), \ .scan_index = (si), \ - .scan_type = IIO_ST('u', (bits), 16, 0), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } #define ADIS16400_SUPPLY_CHAN(addr, bits) \ @@ -403,7 +409,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ .address = addr, \ .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ - .scan_type = IIO_ST('s', (bits), 16, 0), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } #define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \ @@ -416,7 +428,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ .address = (addr), \ .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ - .scan_type = IIO_ST('s', (bits), 16, 0), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } #define ADIS16400_MAGN_CHAN(mod, addr, bits) { \ @@ -428,7 +446,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ .address = (addr), \ .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ - .scan_type = IIO_ST('s', (bits), 16, 0), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } #define ADIS16400_MOD_TEMP_NAME_X "x" @@ -446,7 +470,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ .address = (addr), \ .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ - .scan_type = IIO_ST('s', (bits), 16, 0), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } #define ADIS16400_TEMP_CHAN(addr, bits) { \ @@ -458,7 +488,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ .address = (addr), \ .scan_index = ADIS16350_SCAN_TEMP_X, \ - .scan_type = IIO_ST('s', (bits), 16, 0), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } #define ADIS16400_INCLI_CHAN(mod, addr, bits) { \ @@ -469,7 +505,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, IIO_CHAN_INFO_SCALE_SHARED_BIT, \ .address = (addr), \ .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ - .scan_type = IIO_ST('s', (bits), 16, 0), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ } static const struct iio_chan_spec adis16400_channels[] = { @@ -625,6 +667,12 @@ static const struct iio_info adis16400_info = { .read_raw = &adis16400_read_raw, .write_raw = &adis16400_write_raw, .attrs = &adis16400_attribute_group, + .update_scan_mode = adis16400_update_scan_mode, +}; + +static const unsigned long adis16400_burst_scan_mask[] = { + ~0UL, + 0, }; static const char * const adis16400_status_error_msgs[] = { @@ -696,35 +744,30 @@ static int adis16400_probe(struct spi_device *spi) indio_dev->info = &adis16400_info; indio_dev->modes = INDIO_DIRECT_MODE; + if (!(st->variant->flags & ADIS16400_NO_BURST)) + indio_dev->available_scan_masks = adis16400_burst_scan_mask; + ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); if (ret) goto error_free_dev; - ret = adis16400_configure_ring(indio_dev); + ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, + adis16400_trigger_handler); if (ret) goto error_free_dev; - if (spi->irq) { - ret = adis_probe_trigger(&st->adis, indio_dev); - if (ret) - goto error_unreg_ring_funcs; - } - /* Get the device into a sane initial state */ ret = adis16400_initial_setup(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer; ret = iio_device_register(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer; return 0; -error_remove_trigger: - if (spi->irq) - adis_remove_trigger(&st->adis); -error_unreg_ring_funcs: - adis16400_unconfigure_ring(indio_dev); +error_cleanup_buffer: + adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: @@ -740,9 +783,7 @@ static int adis16400_remove(struct spi_device *spi) iio_device_unregister(indio_dev); adis16400_stop_device(indio_dev); - if (spi->irq) - adis_remove_trigger(&st->adis); - adis16400_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); iio_device_free(indio_dev); diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c index e421278..054c01d 100644 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ b/drivers/staging/iio/imu/adis16400_ring.c @@ -13,160 +13,84 @@ #include "adis16400.h" -/** - * adis16400_spi_read_burst() - read all data registers - * @indio_dev: the IIO device - * @rx: somewhere to pass back the value read (min size is 24 bytes) - **/ -static int adis16400_spi_read_burst(struct iio_dev *indio_dev, u8 *rx) +int adis16400_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask) { - struct spi_message msg; struct adis16400_state *st = iio_priv(indio_dev); - u32 old_speed_hz = st->adis.spi->max_speed_hz; - int ret; + struct adis *adis = &st->adis; + uint16_t *tx, *rx; - struct spi_transfer xfers[] = { - { - .tx_buf = st->adis.tx, - .bits_per_word = 8, - .len = 2, - }, { - .rx_buf = rx, - .bits_per_word = 8, - .len = 24, - }, - }; - - mutex_lock(&st->adis.txrx_lock); - st->adis.tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD); - st->adis.tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - - st->adis.spi->max_speed_hz = min(ADIS16400_SPI_BURST, old_speed_hz); - spi_setup(st->adis.spi); - - ret = spi_sync(st->adis.spi, &msg); - if (ret) - dev_err(&st->adis.spi->dev, "problem when burst reading"); + if (st->variant->flags & ADIS16400_NO_BURST) + return adis_update_scan_mode(indio_dev, scan_mask); - st->adis.spi->max_speed_hz = old_speed_hz; - spi_setup(st->adis.spi); - mutex_unlock(&st->adis.txrx_lock); - return ret; -} - -static const u16 read_all_tx_array[] = { - cpu_to_be16(ADIS_READ_REG(ADIS16400_SUPPLY_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_XGYRO_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_YGYRO_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_ZGYRO_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_XACCL_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_YACCL_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_ZACCL_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16350_XTEMP_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16350_YTEMP_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16350_ZTEMP_OUT)), - cpu_to_be16(ADIS_READ_REG(ADIS16400_AUX_ADC)), -}; - -static int adis16350_spi_read_all(struct iio_dev *indio_dev, u8 *rx) -{ - struct adis16400_state *st = iio_priv(indio_dev); + kfree(adis->xfer); + kfree(adis->buffer); - struct spi_message msg; - int i, j = 0, ret; - struct spi_transfer *xfers; - int scan_count = bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); + adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL); + if (!adis->xfer) + return -ENOMEM; - xfers = kzalloc(sizeof(*xfers)*(scan_count + 1), - GFP_KERNEL); - if (xfers == NULL) + adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16), + GFP_KERNEL); + if (!adis->buffer) return -ENOMEM; - for (i = 0; i < ARRAY_SIZE(read_all_tx_array); i++) - if (test_bit(i, indio_dev->active_scan_mask)) { - xfers[j].tx_buf = &read_all_tx_array[i]; - xfers[j].bits_per_word = 16; - xfers[j].len = 2; - xfers[j + 1].rx_buf = rx + j*2; - j++; - } - xfers[j].bits_per_word = 16; - xfers[j].len = 2; - - spi_message_init(&msg); - for (j = 0; j < scan_count + 1; j++) - spi_message_add_tail(&xfers[j], &msg); - - ret = spi_sync(st->adis.spi, &msg); - kfree(xfers); - - return ret; + rx = adis->buffer; + tx = adis->buffer + indio_dev->scan_bytes; + + tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD); + tx[1] = 0; + + adis->xfer[0].tx_buf = tx; + adis->xfer[0].bits_per_word = 8; + adis->xfer[0].len = 2; + adis->xfer[1].tx_buf = tx; + adis->xfer[1].bits_per_word = 8; + adis->xfer[1].len = indio_dev->scan_bytes; + + spi_message_init(&adis->msg); + spi_message_add_tail(&adis->xfer[0], &adis->msg); + spi_message_add_tail(&adis->xfer[1], &adis->msg); + + return 0; } -/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device - * specific to be rolled into the core. - */ -static irqreturn_t adis16400_trigger_handler(int irq, void *p) +irqreturn_t adis16400_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct adis16400_state *st = iio_priv(indio_dev); - int i = 0, j, ret = 0; - s16 *data; - - /* Asumption that long is enough for maximum channels */ - unsigned long mask = *indio_dev->active_scan_mask; - int scan_count = bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->adis.spi->dev, "memory alloc failed in ring bh"); - goto done; + struct adis *adis = &st->adis; + u32 old_speed_hz = st->adis.spi->max_speed_hz; + int ret; + + if (!adis->buffer) + return -ENOMEM; + + if (!(st->variant->flags & ADIS16400_NO_BURST) && + st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) { + st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST; + spi_setup(st->adis.spi); } - if (scan_count) { - if (st->variant->flags & ADIS16400_NO_BURST) { - ret = adis16350_spi_read_all(indio_dev, st->adis.rx); - if (ret < 0) - goto done; - for (; i < scan_count; i++) - data[i] = *(s16 *)(st->adis.rx + i*2); - } else { - ret = adis16400_spi_read_burst(indio_dev, st->adis.rx); - if (ret < 0) - goto done; - for (; i < scan_count; i++) { - j = __ffs(mask); - mask &= ~(1 << j); - data[i] = be16_to_cpup( - (__be16 *)&(st->adis.rx[j*2])); - } - } + ret = spi_sync(adis->spi, &adis->msg); + if (ret) + dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); + + if (!(st->variant->flags & ADIS16400_NO_BURST)) { + st->adis.spi->max_speed_hz = old_speed_hz; + spi_setup(st->adis.spi); } + /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - iio_push_to_buffers(indio_dev, (u8 *) data); + if (indio_dev->scan_timestamp) { + void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64); + *(s64 *)b = pf->timestamp; + } + + iio_push_to_buffers(indio_dev, adis->buffer); -done: - kfree(data); iio_trigger_notify_done(indio_dev->trig); return IRQ_HANDLED; } - -int adis16400_configure_ring(struct iio_dev *indio_dev) -{ - return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, - &adis16400_trigger_handler, NULL); -} - -void adis16400_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); -} -- cgit v0.10.2 From 5eaf4ad9d72b619e4a171b80eaaffce69c8cf791 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Remove unit suffix from samplerate attribute To be compliant to the IIO specification we should not include the "SPS" suffix in the "samplerate" attribute contents. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index aa4ffcf..9429072 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -116,7 +116,7 @@ static ssize_t adis16400_read_frequency(struct device *dev, ret = st->variant->get_freq(st); if (ret < 0) return ret; - len = sprintf(buf, "%d SPS\n", ret); + len = sprintf(buf, "%d\n", ret); return len; } -- cgit v0.10.2 From 6634ccae6f703a113a9f8515c0d8ce39706355b6 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Remove samplerate_available attribute While the samplerate supported by the devices which are supported by this driver is not continuous it supports a wide range, much more than currently listed in the samplerate_available attribute. Also it accepts all values written to the samplerate attribute and will round-up them to the nearest supported sample rate. So remove the samplerate_available attribute. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index 9429072..c08490b 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -247,8 +247,6 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, adis16400_read_frequency, adis16400_write_frequency); -static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("409 546 819 1638"); - static const u8 adis16400_addresses[] = { [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, @@ -574,7 +572,6 @@ static const struct iio_chan_spec adis16334_channels[] = { static struct attribute *adis16400_attributes[] = { &iio_dev_attr_sampling_frequency.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, NULL }; -- cgit v0.10.2 From f4c6d64bcf5b4bd868c53c6943d9b9bdd65eaa48 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio:adis16400: Code style cleanup Do a set of minor miscellaneous code style cleanups for the adis16400 before moving it out of staging. Delete outdated comments, removed excess whitespace, add missing whitespace, replace u{8,16} with uint{8,16}_t. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index c08490b..1bbe5ee 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -45,7 +45,7 @@ enum adis16400_chip_variant { static int adis16334_get_freq(struct adis16400_state *st) { int ret; - u16 t; + uint16_t t; ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); if (ret < 0) @@ -78,12 +78,13 @@ static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) static int adis16400_get_freq(struct adis16400_state *st) { int sps, ret; - u16 t; + uint16_t t; ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); if (ret < 0) return ret; - sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; + + sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; return sps; @@ -97,6 +98,7 @@ static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) if (t > 0) t--; t &= ADIS16400_SMPL_PRD_DIV_MASK; + if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; else @@ -111,13 +113,13 @@ static ssize_t adis16400_read_frequency(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct adis16400_state *st = iio_priv(indio_dev); - int ret, len = 0; + int ret; ret = st->variant->get_freq(st); if (ret < 0) return ret; - len = sprintf(buf, "%d\n", ret); - return len; + + return sprintf(buf, "%d\n", ret); } static const unsigned adis16400_3db_divisors[] = { @@ -134,8 +136,8 @@ static const unsigned adis16400_3db_divisors[] = { static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) { struct adis16400_state *st = iio_priv(indio_dev); + uint16_t val16; int i, ret; - u16 val16; for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { if (sps / adis16400_3db_divisors[i] >= val) @@ -152,26 +154,22 @@ static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) } static ssize_t adis16400_write_frequency(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct adis16400_state *st = iio_priv(indio_dev); long val; int ret; - ret = strict_strtol(buf, 10, &val); + ret = kstrtol(buf, 10, &val); if (ret) return ret; + if (val == 0) return -EINVAL; mutex_lock(&indio_dev->mlock); - st->variant->set_freq(st, val); - - /* Also update the filter */ mutex_unlock(&indio_dev->mlock); return ret ? ret : len; @@ -182,9 +180,9 @@ static int adis16400_stop_device(struct iio_dev *indio_dev) { struct adis16400_state *st = iio_priv(indio_dev); int ret; - u16 val = ADIS16400_SLP_CNT_POWER_OFF; - ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, val); + ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, + ADIS16400_SLP_CNT_POWER_OFF); if (ret) dev_err(&indio_dev->dev, "problem with turning device off: SLP_CNT"); @@ -194,10 +192,10 @@ static int adis16400_stop_device(struct iio_dev *indio_dev) static int adis16400_initial_setup(struct iio_dev *indio_dev) { - int ret; - u16 prod_id, smp_prd; - unsigned int device_id; struct adis16400_state *st = iio_priv(indio_dev); + uint16_t prod_id, smp_prd; + unsigned int device_id; + int ret; /* use low spi speed for init if the device has a slow mode */ if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) @@ -224,8 +222,8 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev) device_id, prod_id); dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", - indio_dev->name, prod_id, - st->adis.spi->chip_select, st->adis.spi->irq); + indio_dev->name, prod_id, + st->adis.spi->chip_select, st->adis.spi->irq); } /* use high spi speed if possible */ if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { @@ -247,7 +245,7 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, adis16400_read_frequency, adis16400_write_frequency); -static const u8 adis16400_addresses[] = { +static const uint8_t adis16400_addresses[] = { [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF, @@ -257,15 +255,12 @@ static const u8 adis16400_addresses[] = { }; static int adis16400_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) + struct iio_chan_spec const *chan, int val, int val2, long info) { struct adis16400_state *st = iio_priv(indio_dev); int ret, sps; - switch (mask) { + switch (info) { case IIO_CHAN_INFO_CALIBBIAS: mutex_lock(&indio_dev->mlock); ret = adis_write_reg_16(&st->adis, @@ -273,8 +268,10 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, mutex_unlock(&indio_dev->mlock); return ret; case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - /* Need to cache values so we can update if the frequency - changes */ + /* + * Need to cache values so we can update if the frequency + * changes. + */ mutex_lock(&indio_dev->mlock); st->filt_int = val; /* Work out update to current value */ @@ -293,16 +290,13 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, } static int adis16400_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long mask) + struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct adis16400_state *st = iio_priv(indio_dev); + int16_t val16; int ret; - s16 val16; - switch (mask) { + switch (info) { case IIO_CHAN_INFO_RAW: return adis_single_conversion(indio_dev, chan, 0, val); case IIO_CHAN_INFO_SCALE: @@ -721,13 +715,14 @@ static const struct adis_data adis16400_data = { static int adis16400_probe(struct spi_device *spi) { - int ret; struct adis16400_state *st; - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } + struct iio_dev *indio_dev; + int ret; + + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) + return -ENOMEM; + st = iio_priv(indio_dev); /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); @@ -767,14 +762,12 @@ error_cleanup_buffer: adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); error_free_dev: iio_device_free(indio_dev); -error_ret: return ret; } -/* fixme, confirm ordering in this function */ static int adis16400_remove(struct spi_device *spi) { - struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct iio_dev *indio_dev = spi_get_drvdata(spi); struct adis16400_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); -- cgit v0.10.2 From d6b09bd85d57752395c6407bd8a9b32eb7b279ff Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: staging:iio: Move adis16400 out of staging This adis16400 driver is in pretty good shape now, so move it out of staging. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig index 3d79a40..47f66ed 100644 --- a/drivers/iio/imu/Kconfig +++ b/drivers/iio/imu/Kconfig @@ -3,6 +3,17 @@ # menu "Inertial measurement units" +config ADIS16400 + tristate "Analog Devices ADIS16400 and similar IMU SPI driver" + depends on SPI + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER + help + Say yes here to build support for Analog Devices adis16300, adis16344, + adis16350, adis16354, adis16355, adis16360, adis16362, adis16364, + adis16365, adis16400 and adis16405 triaxial inertial sensors + (adis16400 series also have magnetometers). + config ADIS16480 tristate "Analog Devices ADIS16480 and similar IMU driver" depends on SPI diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile index cfe5763..019b717 100644 --- a/drivers/iio/imu/Makefile +++ b/drivers/iio/imu/Makefile @@ -2,6 +2,9 @@ # Makefile for Inertial Measurement Units # +adis16400-y := adis16400_core.o +adis16400-$(CONFIG_IIO_BUFFER) += adis16400_buffer.o +obj-$(CONFIG_ADIS16400) += adis16400.o obj-$(CONFIG_ADIS16480) += adis16480.o adis_lib-y += adis.o diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h new file mode 100644 index 0000000..a3b9e56 --- /dev/null +++ b/drivers/iio/imu/adis16400.h @@ -0,0 +1,204 @@ +/* + * adis16400.h support Analog Devices ADIS16400 + * 3d 18g accelerometers, + * 3d gyroscopes, + * 3d 2.5gauss magnetometers via SPI + * + * Copyright (c) 2009 Manuel Stahl + * Copyright (c) 2007 Jonathan Cameron + * + * Loosely based upon lis3l02dq.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef SPI_ADIS16400_H_ +#define SPI_ADIS16400_H_ + +#include + +#define ADIS16400_STARTUP_DELAY 290 /* ms */ +#define ADIS16400_MTEST_DELAY 90 /* ms */ + +#define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */ +#define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */ +#define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */ +#define ADIS16400_YGYRO_OUT 0x06 /* Y-axis gyroscope output */ +#define ADIS16400_ZGYRO_OUT 0x08 /* Z-axis gyroscope output */ +#define ADIS16400_XACCL_OUT 0x0A /* X-axis accelerometer output */ +#define ADIS16400_YACCL_OUT 0x0C /* Y-axis accelerometer output */ +#define ADIS16400_ZACCL_OUT 0x0E /* Z-axis accelerometer output */ +#define ADIS16400_XMAGN_OUT 0x10 /* X-axis magnetometer measurement */ +#define ADIS16400_YMAGN_OUT 0x12 /* Y-axis magnetometer measurement */ +#define ADIS16400_ZMAGN_OUT 0x14 /* Z-axis magnetometer measurement */ +#define ADIS16400_TEMP_OUT 0x16 /* Temperature output */ +#define ADIS16400_AUX_ADC 0x18 /* Auxiliary ADC measurement */ + +#define ADIS16350_XTEMP_OUT 0x10 /* X-axis gyroscope temperature measurement */ +#define ADIS16350_YTEMP_OUT 0x12 /* Y-axis gyroscope temperature measurement */ +#define ADIS16350_ZTEMP_OUT 0x14 /* Z-axis gyroscope temperature measurement */ + +#define ADIS16300_PITCH_OUT 0x12 /* X axis inclinometer output measurement */ +#define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */ +#define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */ + +/* Calibration parameters */ +#define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */ +#define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */ +#define ADIS16400_ZGYRO_OFF 0x1E /* Z-axis gyroscope bias offset factor */ +#define ADIS16400_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */ +#define ADIS16400_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */ +#define ADIS16400_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */ +#define ADIS16400_XMAGN_HIF 0x26 /* X-axis magnetometer, hard-iron factor */ +#define ADIS16400_YMAGN_HIF 0x28 /* Y-axis magnetometer, hard-iron factor */ +#define ADIS16400_ZMAGN_HIF 0x2A /* Z-axis magnetometer, hard-iron factor */ +#define ADIS16400_XMAGN_SIF 0x2C /* X-axis magnetometer, soft-iron factor */ +#define ADIS16400_YMAGN_SIF 0x2E /* Y-axis magnetometer, soft-iron factor */ +#define ADIS16400_ZMAGN_SIF 0x30 /* Z-axis magnetometer, soft-iron factor */ + +#define ADIS16400_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */ +#define ADIS16400_MSC_CTRL 0x34 /* Miscellaneous control */ +#define ADIS16400_SMPL_PRD 0x36 /* Internal sample period (rate) control */ +#define ADIS16400_SENS_AVG 0x38 /* Dynamic range and digital filter control */ +#define ADIS16400_SLP_CNT 0x3A /* Sleep mode control */ +#define ADIS16400_DIAG_STAT 0x3C /* System status */ + +/* Alarm functions */ +#define ADIS16400_GLOB_CMD 0x3E /* System command */ +#define ADIS16400_ALM_MAG1 0x40 /* Alarm 1 amplitude threshold */ +#define ADIS16400_ALM_MAG2 0x42 /* Alarm 2 amplitude threshold */ +#define ADIS16400_ALM_SMPL1 0x44 /* Alarm 1 sample size */ +#define ADIS16400_ALM_SMPL2 0x46 /* Alarm 2 sample size */ +#define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ +#define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ + +#define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ + +#define ADIS16400_ERROR_ACTIVE (1<<14) +#define ADIS16400_NEW_DATA (1<<14) + +/* MSC_CTRL */ +#define ADIS16400_MSC_CTRL_MEM_TEST (1<<11) +#define ADIS16400_MSC_CTRL_INT_SELF_TEST (1<<10) +#define ADIS16400_MSC_CTRL_NEG_SELF_TEST (1<<9) +#define ADIS16400_MSC_CTRL_POS_SELF_TEST (1<<8) +#define ADIS16400_MSC_CTRL_GYRO_BIAS (1<<7) +#define ADIS16400_MSC_CTRL_ACCL_ALIGN (1<<6) +#define ADIS16400_MSC_CTRL_DATA_RDY_EN (1<<2) +#define ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1) +#define ADIS16400_MSC_CTRL_DATA_RDY_DIO2 (1<<0) + +/* SMPL_PRD */ +#define ADIS16400_SMPL_PRD_TIME_BASE (1<<7) +#define ADIS16400_SMPL_PRD_DIV_MASK 0x7F + +/* DIAG_STAT */ +#define ADIS16400_DIAG_STAT_ZACCL_FAIL 15 +#define ADIS16400_DIAG_STAT_YACCL_FAIL 14 +#define ADIS16400_DIAG_STAT_XACCL_FAIL 13 +#define ADIS16400_DIAG_STAT_XGYRO_FAIL 12 +#define ADIS16400_DIAG_STAT_YGYRO_FAIL 11 +#define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10 +#define ADIS16400_DIAG_STAT_ALARM2 9 +#define ADIS16400_DIAG_STAT_ALARM1 8 +#define ADIS16400_DIAG_STAT_FLASH_CHK 6 +#define ADIS16400_DIAG_STAT_SELF_TEST 5 +#define ADIS16400_DIAG_STAT_OVERFLOW 4 +#define ADIS16400_DIAG_STAT_SPI_FAIL 3 +#define ADIS16400_DIAG_STAT_FLASH_UPT 2 +#define ADIS16400_DIAG_STAT_POWER_HIGH 1 +#define ADIS16400_DIAG_STAT_POWER_LOW 0 + +/* GLOB_CMD */ +#define ADIS16400_GLOB_CMD_SW_RESET (1<<7) +#define ADIS16400_GLOB_CMD_P_AUTO_NULL (1<<4) +#define ADIS16400_GLOB_CMD_FLASH_UPD (1<<3) +#define ADIS16400_GLOB_CMD_DAC_LATCH (1<<2) +#define ADIS16400_GLOB_CMD_FAC_CALIB (1<<1) +#define ADIS16400_GLOB_CMD_AUTO_NULL (1<<0) + +/* SLP_CNT */ +#define ADIS16400_SLP_CNT_POWER_OFF (1<<8) + +#define ADIS16334_RATE_DIV_SHIFT 8 +#define ADIS16334_RATE_INT_CLK BIT(0) + +#define ADIS16400_SPI_SLOW (u32)(300 * 1000) +#define ADIS16400_SPI_BURST (u32)(1000 * 1000) +#define ADIS16400_SPI_FAST (u32)(2000 * 1000) + +#define ADIS16400_HAS_PROD_ID BIT(0) +#define ADIS16400_NO_BURST BIT(1) +#define ADIS16400_HAS_SLOW_MODE BIT(2) + +struct adis16400_state; + +struct adis16400_chip_info { + const struct iio_chan_spec *channels; + const int num_channels; + const long flags; + unsigned int gyro_scale_micro; + unsigned int accel_scale_micro; + int temp_scale_nano; + int temp_offset; + int (*set_freq)(struct adis16400_state *st, unsigned int freq); + int (*get_freq)(struct adis16400_state *st); +}; + +/** + * struct adis16400_state - device instance specific data + * @variant: chip variant info + * @filt_int: integer part of requested filter frequency + * @adis: adis device + **/ +struct adis16400_state { + struct adis16400_chip_info *variant; + int filt_int; + + struct adis adis; +}; + +/* At the moment triggers are only used for ring buffer + * filling. This may change! + */ + +enum { + ADIS16400_SCAN_SUPPLY, + ADIS16400_SCAN_GYRO_X, + ADIS16400_SCAN_GYRO_Y, + ADIS16400_SCAN_GYRO_Z, + ADIS16400_SCAN_ACC_X, + ADIS16400_SCAN_ACC_Y, + ADIS16400_SCAN_ACC_Z, + ADIS16400_SCAN_MAGN_X, + ADIS16400_SCAN_MAGN_Y, + ADIS16400_SCAN_MAGN_Z, + ADIS16350_SCAN_TEMP_X, + ADIS16350_SCAN_TEMP_Y, + ADIS16350_SCAN_TEMP_Z, + ADIS16300_SCAN_INCLI_X, + ADIS16300_SCAN_INCLI_Y, + ADIS16400_SCAN_ADC, +}; + +#ifdef CONFIG_IIO_BUFFER + +ssize_t adis16400_read_data_from_ring(struct device *dev, + struct device_attribute *attr, + char *buf); + + +int adis16400_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask); +irqreturn_t adis16400_trigger_handler(int irq, void *p); + +#else /* CONFIG_IIO_BUFFER */ + +#define adis16400_update_scan_mode NULL +#define adis16400_trigger_handler NULL + +#endif /* CONFIG_IIO_BUFFER */ + +#endif /* SPI_ADIS16400_H_ */ diff --git a/drivers/iio/imu/adis16400_buffer.c b/drivers/iio/imu/adis16400_buffer.c new file mode 100644 index 0000000..054c01d --- /dev/null +++ b/drivers/iio/imu/adis16400_buffer.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "adis16400.h" + +int adis16400_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask) +{ + struct adis16400_state *st = iio_priv(indio_dev); + struct adis *adis = &st->adis; + uint16_t *tx, *rx; + + if (st->variant->flags & ADIS16400_NO_BURST) + return adis_update_scan_mode(indio_dev, scan_mask); + + kfree(adis->xfer); + kfree(adis->buffer); + + adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL); + if (!adis->xfer) + return -ENOMEM; + + adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16), + GFP_KERNEL); + if (!adis->buffer) + return -ENOMEM; + + rx = adis->buffer; + tx = adis->buffer + indio_dev->scan_bytes; + + tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD); + tx[1] = 0; + + adis->xfer[0].tx_buf = tx; + adis->xfer[0].bits_per_word = 8; + adis->xfer[0].len = 2; + adis->xfer[1].tx_buf = tx; + adis->xfer[1].bits_per_word = 8; + adis->xfer[1].len = indio_dev->scan_bytes; + + spi_message_init(&adis->msg); + spi_message_add_tail(&adis->xfer[0], &adis->msg); + spi_message_add_tail(&adis->xfer[1], &adis->msg); + + return 0; +} + +irqreturn_t adis16400_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct adis16400_state *st = iio_priv(indio_dev); + struct adis *adis = &st->adis; + u32 old_speed_hz = st->adis.spi->max_speed_hz; + int ret; + + if (!adis->buffer) + return -ENOMEM; + + if (!(st->variant->flags & ADIS16400_NO_BURST) && + st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) { + st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST; + spi_setup(st->adis.spi); + } + + ret = spi_sync(adis->spi, &adis->msg); + if (ret) + dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); + + if (!(st->variant->flags & ADIS16400_NO_BURST)) { + st->adis.spi->max_speed_hz = old_speed_hz; + spi_setup(st->adis.spi); + } + + /* Guaranteed to be aligned with 8 byte boundary */ + if (indio_dev->scan_timestamp) { + void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64); + *(s64 *)b = pf->timestamp; + } + + iio_push_to_buffers(indio_dev, adis->buffer); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c new file mode 100644 index 0000000..1bbe5ee --- /dev/null +++ b/drivers/iio/imu/adis16400_core.c @@ -0,0 +1,812 @@ +/* + * adis16400.c support Analog Devices ADIS16400/5 + * 3d 2g Linear Accelerometers, + * 3d Gyroscopes, + * 3d Magnetometers via SPI + * + * Copyright (c) 2009 Manuel Stahl + * Copyright (c) 2007 Jonathan Cameron + * Copyright (c) 2011 Analog Devices Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "adis16400.h" + +enum adis16400_chip_variant { + ADIS16300, + ADIS16334, + ADIS16350, + ADIS16360, + ADIS16362, + ADIS16364, + ADIS16400, +}; + +static int adis16334_get_freq(struct adis16400_state *st) +{ + int ret; + uint16_t t; + + ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); + if (ret < 0) + return ret; + + t >>= ADIS16334_RATE_DIV_SHIFT; + + return (8192 >> t) / 10; +} + +static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) +{ + unsigned int t; + + freq *= 10; + if (freq < 8192) + t = ilog2(8192 / freq); + else + t = 0; + + if (t > 0x31) + t = 0x31; + + t <<= ADIS16334_RATE_DIV_SHIFT; + t |= ADIS16334_RATE_INT_CLK; + + return adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t); +} + +static int adis16400_get_freq(struct adis16400_state *st) +{ + int sps, ret; + uint16_t t; + + ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); + if (ret < 0) + return ret; + + sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; + sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; + + return sps; +} + +static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) +{ + unsigned int t; + + t = 1638 / freq; + if (t > 0) + t--; + t &= ADIS16400_SMPL_PRD_DIV_MASK; + + if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) + st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; + else + st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; + + return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, t); +} + +static ssize_t adis16400_read_frequency(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adis16400_state *st = iio_priv(indio_dev); + int ret; + + ret = st->variant->get_freq(st); + if (ret < 0) + return ret; + + return sprintf(buf, "%d\n", ret); +} + +static const unsigned adis16400_3db_divisors[] = { + [0] = 2, /* Special case */ + [1] = 6, + [2] = 12, + [3] = 25, + [4] = 50, + [5] = 100, + [6] = 200, + [7] = 200, /* Not a valid setting */ +}; + +static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) +{ + struct adis16400_state *st = iio_priv(indio_dev); + uint16_t val16; + int i, ret; + + for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { + if (sps / adis16400_3db_divisors[i] >= val) + break; + } + + ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); + if (ret < 0) + return ret; + + ret = adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG, + (val16 & ~0x07) | i); + return ret; +} + +static ssize_t adis16400_write_frequency(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adis16400_state *st = iio_priv(indio_dev); + long val; + int ret; + + ret = kstrtol(buf, 10, &val); + if (ret) + return ret; + + if (val == 0) + return -EINVAL; + + mutex_lock(&indio_dev->mlock); + st->variant->set_freq(st, val); + mutex_unlock(&indio_dev->mlock); + + return ret ? ret : len; +} + +/* Power down the device */ +static int adis16400_stop_device(struct iio_dev *indio_dev) +{ + struct adis16400_state *st = iio_priv(indio_dev); + int ret; + + ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, + ADIS16400_SLP_CNT_POWER_OFF); + if (ret) + dev_err(&indio_dev->dev, + "problem with turning device off: SLP_CNT"); + + return ret; +} + +static int adis16400_initial_setup(struct iio_dev *indio_dev) +{ + struct adis16400_state *st = iio_priv(indio_dev); + uint16_t prod_id, smp_prd; + unsigned int device_id; + int ret; + + /* use low spi speed for init if the device has a slow mode */ + if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) + st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; + else + st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; + st->adis.spi->mode = SPI_MODE_3; + spi_setup(st->adis.spi); + + ret = adis_initial_startup(&st->adis); + if (ret) + return ret; + + if (st->variant->flags & ADIS16400_HAS_PROD_ID) { + ret = adis_read_reg_16(&st->adis, + ADIS16400_PRODUCT_ID, &prod_id); + if (ret) + goto err_ret; + + sscanf(indio_dev->name, "adis%u\n", &device_id); + + if (prod_id != device_id) + dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", + device_id, prod_id); + + dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", + indio_dev->name, prod_id, + st->adis.spi->chip_select, st->adis.spi->irq); + } + /* use high spi speed if possible */ + if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { + ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd); + if (ret) + goto err_ret; + + if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { + st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; + spi_setup(st->adis.spi); + } + } + +err_ret: + return ret; +} + +static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, + adis16400_read_frequency, + adis16400_write_frequency); + +static const uint8_t adis16400_addresses[] = { + [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, + [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, + [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF, + [ADIS16400_SCAN_ACC_X] = ADIS16400_XACCL_OFF, + [ADIS16400_SCAN_ACC_Y] = ADIS16400_YACCL_OFF, + [ADIS16400_SCAN_ACC_Z] = ADIS16400_ZACCL_OFF, +}; + +static int adis16400_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, long info) +{ + struct adis16400_state *st = iio_priv(indio_dev); + int ret, sps; + + switch (info) { + case IIO_CHAN_INFO_CALIBBIAS: + mutex_lock(&indio_dev->mlock); + ret = adis_write_reg_16(&st->adis, + adis16400_addresses[chan->scan_index], val); + mutex_unlock(&indio_dev->mlock); + return ret; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + /* + * Need to cache values so we can update if the frequency + * changes. + */ + mutex_lock(&indio_dev->mlock); + st->filt_int = val; + /* Work out update to current value */ + sps = st->variant->get_freq(st); + if (sps < 0) { + mutex_unlock(&indio_dev->mlock); + return sps; + } + + ret = adis16400_set_filter(indio_dev, sps, val); + mutex_unlock(&indio_dev->mlock); + return ret; + default: + return -EINVAL; + } +} + +static int adis16400_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, int *val2, long info) +{ + struct adis16400_state *st = iio_priv(indio_dev); + int16_t val16; + int ret; + + switch (info) { + case IIO_CHAN_INFO_RAW: + return adis_single_conversion(indio_dev, chan, 0, val); + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = 0; + *val2 = st->variant->gyro_scale_micro; + return IIO_VAL_INT_PLUS_MICRO; + case IIO_VOLTAGE: + *val = 0; + if (chan->channel == 0) { + *val = 2; + *val2 = 418000; /* 2.418 mV */ + } else { + *val = 0; + *val2 = 805800; /* 805.8 uV */ + } + return IIO_VAL_INT_PLUS_MICRO; + case IIO_ACCEL: + *val = 0; + *val2 = st->variant->accel_scale_micro; + return IIO_VAL_INT_PLUS_MICRO; + case IIO_MAGN: + *val = 0; + *val2 = 500; /* 0.5 mgauss */ + return IIO_VAL_INT_PLUS_MICRO; + case IIO_TEMP: + *val = st->variant->temp_scale_nano / 1000000; + *val2 = (st->variant->temp_scale_nano % 1000000); + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_CALIBBIAS: + mutex_lock(&indio_dev->mlock); + ret = adis_read_reg_16(&st->adis, + adis16400_addresses[chan->scan_index], &val16); + mutex_unlock(&indio_dev->mlock); + if (ret) + return ret; + val16 = ((val16 & 0xFFF) << 4) >> 4; + *val = val16; + return IIO_VAL_INT; + case IIO_CHAN_INFO_OFFSET: + /* currently only temperature */ + *val = st->variant->temp_offset; + return IIO_VAL_INT; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + mutex_lock(&indio_dev->mlock); + /* Need both the number of taps and the sampling frequency */ + ret = adis_read_reg_16(&st->adis, + ADIS16400_SENS_AVG, + &val16); + if (ret < 0) { + mutex_unlock(&indio_dev->mlock); + return ret; + } + ret = st->variant->get_freq(st); + if (ret >= 0) + *val = ret / adis16400_3db_divisors[val16 & 0x07]; + *val2 = 0; + mutex_unlock(&indio_dev->mlock); + if (ret < 0) + return ret; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = 0, \ + .extend_name = name, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .address = (addr), \ + .scan_index = (si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +#define ADIS16400_SUPPLY_CHAN(addr, bits) \ + ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY) + +#define ADIS16400_AUX_ADC_CHAN(addr, bits) \ + ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC) + +#define ADIS16400_GYRO_CHAN(mod, addr, bits) { \ + .type = IIO_ANGL_VEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = addr, \ + .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +#define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +#define ADIS16400_MAGN_CHAN(mod, addr, bits) { \ + .type = IIO_MAGN, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +#define ADIS16400_MOD_TEMP_NAME_X "x" +#define ADIS16400_MOD_TEMP_NAME_Y "y" +#define ADIS16400_MOD_TEMP_NAME_Z "z" + +#define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .channel = 0, \ + .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ + IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +#define ADIS16400_TEMP_CHAN(addr, bits) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .channel = 0, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .address = (addr), \ + .scan_index = ADIS16350_SCAN_TEMP_X, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +#define ADIS16400_INCLI_CHAN(mod, addr, bits) { \ + .type = IIO_INCLI, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT, \ + .address = (addr), \ + .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ +} + +static const struct iio_chan_spec adis16400_channels[] = { + ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 14), + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), + ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12), + ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12), + IIO_CHAN_SOFT_TIMESTAMP(12) +}; + +static const struct iio_chan_spec adis16350_channels[] = { + ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), + ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), + ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), + ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12), + ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12), + ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12), + IIO_CHAN_SOFT_TIMESTAMP(11) +}; + +static const struct iio_chan_spec adis16300_channels[] = { + ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), + ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), + ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13), + ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13), + IIO_CHAN_SOFT_TIMESTAMP(14) +}; + +static const struct iio_chan_spec adis16334_channels[] = { + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), + ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), + IIO_CHAN_SOFT_TIMESTAMP(8) +}; + +static struct attribute *adis16400_attributes[] = { + &iio_dev_attr_sampling_frequency.dev_attr.attr, + NULL +}; + +static const struct attribute_group adis16400_attribute_group = { + .attrs = adis16400_attributes, +}; + +static struct adis16400_chip_info adis16400_chips[] = { + [ADIS16300] = { + .channels = adis16300_channels, + .num_channels = ARRAY_SIZE(adis16300_channels), + .flags = ADIS16400_HAS_SLOW_MODE, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ + .accel_scale_micro = 5884, + .temp_scale_nano = 140000000, /* 0.14 C */ + .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, + }, + [ADIS16334] = { + .channels = adis16334_channels, + .num_channels = ARRAY_SIZE(adis16334_channels), + .flags = ADIS16400_HAS_PROD_ID, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ + .temp_scale_nano = 67850000, /* 0.06785 C */ + .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */ + .set_freq = adis16334_set_freq, + .get_freq = adis16334_get_freq, + }, + [ADIS16350] = { + .channels = adis16350_channels, + .num_channels = ARRAY_SIZE(adis16350_channels), + .gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */ + .temp_scale_nano = 145300000, /* 0.1453 C */ + .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */ + .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE, + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, + }, + [ADIS16360] = { + .channels = adis16350_channels, + .num_channels = ARRAY_SIZE(adis16350_channels), + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ + .temp_scale_nano = 136000000, /* 0.136 C */ + .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, + }, + [ADIS16362] = { + .channels = adis16350_channels, + .num_channels = ARRAY_SIZE(adis16350_channels), + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ + .temp_scale_nano = 136000000, /* 0.136 C */ + .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, + }, + [ADIS16364] = { + .channels = adis16350_channels, + .num_channels = ARRAY_SIZE(adis16350_channels), + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ + .temp_scale_nano = 136000000, /* 0.136 C */ + .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, + }, + [ADIS16400] = { + .channels = adis16400_channels, + .num_channels = ARRAY_SIZE(adis16400_channels), + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ + .temp_scale_nano = 140000000, /* 0.14 C */ + .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, + } +}; + +static const struct iio_info adis16400_info = { + .driver_module = THIS_MODULE, + .read_raw = &adis16400_read_raw, + .write_raw = &adis16400_write_raw, + .attrs = &adis16400_attribute_group, + .update_scan_mode = adis16400_update_scan_mode, +}; + +static const unsigned long adis16400_burst_scan_mask[] = { + ~0UL, + 0, +}; + +static const char * const adis16400_status_error_msgs[] = { + [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure", + [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure", + [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure", + [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure", + [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure", + [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure", + [ADIS16400_DIAG_STAT_ALARM2] = "Alarm 2 active", + [ADIS16400_DIAG_STAT_ALARM1] = "Alarm 1 active", + [ADIS16400_DIAG_STAT_FLASH_CHK] = "Flash checksum error", + [ADIS16400_DIAG_STAT_SELF_TEST] = "Self test error", + [ADIS16400_DIAG_STAT_OVERFLOW] = "Sensor overrange", + [ADIS16400_DIAG_STAT_SPI_FAIL] = "SPI failure", + [ADIS16400_DIAG_STAT_FLASH_UPT] = "Flash update failed", + [ADIS16400_DIAG_STAT_POWER_HIGH] = "Power supply above 5.25V", + [ADIS16400_DIAG_STAT_POWER_LOW] = "Power supply below 4.75V", +}; + +static const struct adis_data adis16400_data = { + .msc_ctrl_reg = ADIS16400_MSC_CTRL, + .glob_cmd_reg = ADIS16400_GLOB_CMD, + .diag_stat_reg = ADIS16400_DIAG_STAT, + + .read_delay = 50, + .write_delay = 50, + + .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, + .startup_delay = ADIS16400_STARTUP_DELAY, + + .status_error_msgs = adis16400_status_error_msgs, + .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | + BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | + BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | + BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | + BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | + BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | + BIT(ADIS16400_DIAG_STAT_ALARM2) | + BIT(ADIS16400_DIAG_STAT_ALARM1) | + BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | + BIT(ADIS16400_DIAG_STAT_SELF_TEST) | + BIT(ADIS16400_DIAG_STAT_OVERFLOW) | + BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | + BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | + BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | + BIT(ADIS16400_DIAG_STAT_POWER_LOW), +}; + +static int adis16400_probe(struct spi_device *spi) +{ + struct adis16400_state *st; + struct iio_dev *indio_dev; + int ret; + + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) + return -ENOMEM; + + st = iio_priv(indio_dev); + /* this is only used for removal purposes */ + spi_set_drvdata(spi, indio_dev); + + /* setup the industrialio driver allocated elements */ + st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->channels = st->variant->channels; + indio_dev->num_channels = st->variant->num_channels; + indio_dev->info = &adis16400_info; + indio_dev->modes = INDIO_DIRECT_MODE; + + if (!(st->variant->flags & ADIS16400_NO_BURST)) + indio_dev->available_scan_masks = adis16400_burst_scan_mask; + + ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); + if (ret) + goto error_free_dev; + + ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, + adis16400_trigger_handler); + if (ret) + goto error_free_dev; + + /* Get the device into a sane initial state */ + ret = adis16400_initial_setup(indio_dev); + if (ret) + goto error_cleanup_buffer; + ret = iio_device_register(indio_dev); + if (ret) + goto error_cleanup_buffer; + + return 0; + +error_cleanup_buffer: + adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); +error_free_dev: + iio_device_free(indio_dev); + return ret; +} + +static int adis16400_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis16400_state *st = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + adis16400_stop_device(indio_dev); + + adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); + + iio_device_free(indio_dev); + + return 0; +} + +static const struct spi_device_id adis16400_id[] = { + {"adis16300", ADIS16300}, + {"adis16334", ADIS16334}, + {"adis16350", ADIS16350}, + {"adis16354", ADIS16350}, + {"adis16355", ADIS16350}, + {"adis16360", ADIS16360}, + {"adis16362", ADIS16362}, + {"adis16364", ADIS16364}, + {"adis16365", ADIS16360}, + {"adis16400", ADIS16400}, + {"adis16405", ADIS16400}, + {} +}; +MODULE_DEVICE_TABLE(spi, adis16400_id); + +static struct spi_driver adis16400_driver = { + .driver = { + .name = "adis16400", + .owner = THIS_MODULE, + }, + .id_table = adis16400_id, + .probe = adis16400_probe, + .remove = adis16400_remove, +}; +module_spi_driver(adis16400_driver); + +MODULE_AUTHOR("Manuel Stahl "); +MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig index ca56c75..94d60d5 100644 --- a/drivers/staging/iio/Kconfig +++ b/drivers/staging/iio/Kconfig @@ -32,7 +32,6 @@ source "drivers/staging/iio/cdc/Kconfig" source "drivers/staging/iio/frequency/Kconfig" source "drivers/staging/iio/gyro/Kconfig" source "drivers/staging/iio/impedance-analyzer/Kconfig" -source "drivers/staging/iio/imu/Kconfig" source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/magnetometer/Kconfig" source "drivers/staging/iio/meter/Kconfig" diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile index fa6937d..468b7f8 100644 --- a/drivers/staging/iio/Makefile +++ b/drivers/staging/iio/Makefile @@ -20,7 +20,6 @@ obj-y += cdc/ obj-y += frequency/ obj-y += gyro/ obj-y += impedance-analyzer/ -obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += meter/ diff --git a/drivers/staging/iio/imu/Kconfig b/drivers/staging/iio/imu/Kconfig deleted file mode 100644 index 096afc8..0000000 --- a/drivers/staging/iio/imu/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# -# IIO imu drivers configuration -# -menu "Inertial measurement units" - -config ADIS16400 - tristate "Analog Devices ADIS16400 and similar IMU SPI driver" - depends on SPI - select IIO_ADIS_LIB - select IIO_ADIS_LIB_BUFFER if IIO_BUFFER - help - Say yes here to build support for Analog Devices adis16300, adis16344, - adis16350, adis16354, adis16355, adis16360, adis16362, adis16364, - adis16365, adis16400 and adis16405 triaxial inertial sensors - (adis16400 series also have magnetometers). - -endmenu diff --git a/drivers/staging/iio/imu/Makefile b/drivers/staging/iio/imu/Makefile deleted file mode 100644 index c9988f6..0000000 --- a/drivers/staging/iio/imu/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# -# Makefile for Inertial Measurement Units -# - -adis16400-y := adis16400_core.o -adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o -obj-$(CONFIG_ADIS16400) += adis16400.o diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/staging/iio/imu/adis16400.h deleted file mode 100644 index a3b9e56..0000000 --- a/drivers/staging/iio/imu/adis16400.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * adis16400.h support Analog Devices ADIS16400 - * 3d 18g accelerometers, - * 3d gyroscopes, - * 3d 2.5gauss magnetometers via SPI - * - * Copyright (c) 2009 Manuel Stahl - * Copyright (c) 2007 Jonathan Cameron - * - * Loosely based upon lis3l02dq.h - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#ifndef SPI_ADIS16400_H_ -#define SPI_ADIS16400_H_ - -#include - -#define ADIS16400_STARTUP_DELAY 290 /* ms */ -#define ADIS16400_MTEST_DELAY 90 /* ms */ - -#define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */ -#define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */ -#define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */ -#define ADIS16400_YGYRO_OUT 0x06 /* Y-axis gyroscope output */ -#define ADIS16400_ZGYRO_OUT 0x08 /* Z-axis gyroscope output */ -#define ADIS16400_XACCL_OUT 0x0A /* X-axis accelerometer output */ -#define ADIS16400_YACCL_OUT 0x0C /* Y-axis accelerometer output */ -#define ADIS16400_ZACCL_OUT 0x0E /* Z-axis accelerometer output */ -#define ADIS16400_XMAGN_OUT 0x10 /* X-axis magnetometer measurement */ -#define ADIS16400_YMAGN_OUT 0x12 /* Y-axis magnetometer measurement */ -#define ADIS16400_ZMAGN_OUT 0x14 /* Z-axis magnetometer measurement */ -#define ADIS16400_TEMP_OUT 0x16 /* Temperature output */ -#define ADIS16400_AUX_ADC 0x18 /* Auxiliary ADC measurement */ - -#define ADIS16350_XTEMP_OUT 0x10 /* X-axis gyroscope temperature measurement */ -#define ADIS16350_YTEMP_OUT 0x12 /* Y-axis gyroscope temperature measurement */ -#define ADIS16350_ZTEMP_OUT 0x14 /* Z-axis gyroscope temperature measurement */ - -#define ADIS16300_PITCH_OUT 0x12 /* X axis inclinometer output measurement */ -#define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */ -#define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */ - -/* Calibration parameters */ -#define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */ -#define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */ -#define ADIS16400_ZGYRO_OFF 0x1E /* Z-axis gyroscope bias offset factor */ -#define ADIS16400_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */ -#define ADIS16400_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */ -#define ADIS16400_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */ -#define ADIS16400_XMAGN_HIF 0x26 /* X-axis magnetometer, hard-iron factor */ -#define ADIS16400_YMAGN_HIF 0x28 /* Y-axis magnetometer, hard-iron factor */ -#define ADIS16400_ZMAGN_HIF 0x2A /* Z-axis magnetometer, hard-iron factor */ -#define ADIS16400_XMAGN_SIF 0x2C /* X-axis magnetometer, soft-iron factor */ -#define ADIS16400_YMAGN_SIF 0x2E /* Y-axis magnetometer, soft-iron factor */ -#define ADIS16400_ZMAGN_SIF 0x30 /* Z-axis magnetometer, soft-iron factor */ - -#define ADIS16400_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */ -#define ADIS16400_MSC_CTRL 0x34 /* Miscellaneous control */ -#define ADIS16400_SMPL_PRD 0x36 /* Internal sample period (rate) control */ -#define ADIS16400_SENS_AVG 0x38 /* Dynamic range and digital filter control */ -#define ADIS16400_SLP_CNT 0x3A /* Sleep mode control */ -#define ADIS16400_DIAG_STAT 0x3C /* System status */ - -/* Alarm functions */ -#define ADIS16400_GLOB_CMD 0x3E /* System command */ -#define ADIS16400_ALM_MAG1 0x40 /* Alarm 1 amplitude threshold */ -#define ADIS16400_ALM_MAG2 0x42 /* Alarm 2 amplitude threshold */ -#define ADIS16400_ALM_SMPL1 0x44 /* Alarm 1 sample size */ -#define ADIS16400_ALM_SMPL2 0x46 /* Alarm 2 sample size */ -#define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ -#define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ - -#define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ - -#define ADIS16400_ERROR_ACTIVE (1<<14) -#define ADIS16400_NEW_DATA (1<<14) - -/* MSC_CTRL */ -#define ADIS16400_MSC_CTRL_MEM_TEST (1<<11) -#define ADIS16400_MSC_CTRL_INT_SELF_TEST (1<<10) -#define ADIS16400_MSC_CTRL_NEG_SELF_TEST (1<<9) -#define ADIS16400_MSC_CTRL_POS_SELF_TEST (1<<8) -#define ADIS16400_MSC_CTRL_GYRO_BIAS (1<<7) -#define ADIS16400_MSC_CTRL_ACCL_ALIGN (1<<6) -#define ADIS16400_MSC_CTRL_DATA_RDY_EN (1<<2) -#define ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1) -#define ADIS16400_MSC_CTRL_DATA_RDY_DIO2 (1<<0) - -/* SMPL_PRD */ -#define ADIS16400_SMPL_PRD_TIME_BASE (1<<7) -#define ADIS16400_SMPL_PRD_DIV_MASK 0x7F - -/* DIAG_STAT */ -#define ADIS16400_DIAG_STAT_ZACCL_FAIL 15 -#define ADIS16400_DIAG_STAT_YACCL_FAIL 14 -#define ADIS16400_DIAG_STAT_XACCL_FAIL 13 -#define ADIS16400_DIAG_STAT_XGYRO_FAIL 12 -#define ADIS16400_DIAG_STAT_YGYRO_FAIL 11 -#define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10 -#define ADIS16400_DIAG_STAT_ALARM2 9 -#define ADIS16400_DIAG_STAT_ALARM1 8 -#define ADIS16400_DIAG_STAT_FLASH_CHK 6 -#define ADIS16400_DIAG_STAT_SELF_TEST 5 -#define ADIS16400_DIAG_STAT_OVERFLOW 4 -#define ADIS16400_DIAG_STAT_SPI_FAIL 3 -#define ADIS16400_DIAG_STAT_FLASH_UPT 2 -#define ADIS16400_DIAG_STAT_POWER_HIGH 1 -#define ADIS16400_DIAG_STAT_POWER_LOW 0 - -/* GLOB_CMD */ -#define ADIS16400_GLOB_CMD_SW_RESET (1<<7) -#define ADIS16400_GLOB_CMD_P_AUTO_NULL (1<<4) -#define ADIS16400_GLOB_CMD_FLASH_UPD (1<<3) -#define ADIS16400_GLOB_CMD_DAC_LATCH (1<<2) -#define ADIS16400_GLOB_CMD_FAC_CALIB (1<<1) -#define ADIS16400_GLOB_CMD_AUTO_NULL (1<<0) - -/* SLP_CNT */ -#define ADIS16400_SLP_CNT_POWER_OFF (1<<8) - -#define ADIS16334_RATE_DIV_SHIFT 8 -#define ADIS16334_RATE_INT_CLK BIT(0) - -#define ADIS16400_SPI_SLOW (u32)(300 * 1000) -#define ADIS16400_SPI_BURST (u32)(1000 * 1000) -#define ADIS16400_SPI_FAST (u32)(2000 * 1000) - -#define ADIS16400_HAS_PROD_ID BIT(0) -#define ADIS16400_NO_BURST BIT(1) -#define ADIS16400_HAS_SLOW_MODE BIT(2) - -struct adis16400_state; - -struct adis16400_chip_info { - const struct iio_chan_spec *channels; - const int num_channels; - const long flags; - unsigned int gyro_scale_micro; - unsigned int accel_scale_micro; - int temp_scale_nano; - int temp_offset; - int (*set_freq)(struct adis16400_state *st, unsigned int freq); - int (*get_freq)(struct adis16400_state *st); -}; - -/** - * struct adis16400_state - device instance specific data - * @variant: chip variant info - * @filt_int: integer part of requested filter frequency - * @adis: adis device - **/ -struct adis16400_state { - struct adis16400_chip_info *variant; - int filt_int; - - struct adis adis; -}; - -/* At the moment triggers are only used for ring buffer - * filling. This may change! - */ - -enum { - ADIS16400_SCAN_SUPPLY, - ADIS16400_SCAN_GYRO_X, - ADIS16400_SCAN_GYRO_Y, - ADIS16400_SCAN_GYRO_Z, - ADIS16400_SCAN_ACC_X, - ADIS16400_SCAN_ACC_Y, - ADIS16400_SCAN_ACC_Z, - ADIS16400_SCAN_MAGN_X, - ADIS16400_SCAN_MAGN_Y, - ADIS16400_SCAN_MAGN_Z, - ADIS16350_SCAN_TEMP_X, - ADIS16350_SCAN_TEMP_Y, - ADIS16350_SCAN_TEMP_Z, - ADIS16300_SCAN_INCLI_X, - ADIS16300_SCAN_INCLI_Y, - ADIS16400_SCAN_ADC, -}; - -#ifdef CONFIG_IIO_BUFFER - -ssize_t adis16400_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - - -int adis16400_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *scan_mask); -irqreturn_t adis16400_trigger_handler(int irq, void *p); - -#else /* CONFIG_IIO_BUFFER */ - -#define adis16400_update_scan_mode NULL -#define adis16400_trigger_handler NULL - -#endif /* CONFIG_IIO_BUFFER */ - -#endif /* SPI_ADIS16400_H_ */ diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c deleted file mode 100644 index 1bbe5ee..0000000 --- a/drivers/staging/iio/imu/adis16400_core.c +++ /dev/null @@ -1,812 +0,0 @@ -/* - * adis16400.c support Analog Devices ADIS16400/5 - * 3d 2g Linear Accelerometers, - * 3d Gyroscopes, - * 3d Magnetometers via SPI - * - * Copyright (c) 2009 Manuel Stahl - * Copyright (c) 2007 Jonathan Cameron - * Copyright (c) 2011 Analog Devices Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "adis16400.h" - -enum adis16400_chip_variant { - ADIS16300, - ADIS16334, - ADIS16350, - ADIS16360, - ADIS16362, - ADIS16364, - ADIS16400, -}; - -static int adis16334_get_freq(struct adis16400_state *st) -{ - int ret; - uint16_t t; - - ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); - if (ret < 0) - return ret; - - t >>= ADIS16334_RATE_DIV_SHIFT; - - return (8192 >> t) / 10; -} - -static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) -{ - unsigned int t; - - freq *= 10; - if (freq < 8192) - t = ilog2(8192 / freq); - else - t = 0; - - if (t > 0x31) - t = 0x31; - - t <<= ADIS16334_RATE_DIV_SHIFT; - t |= ADIS16334_RATE_INT_CLK; - - return adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t); -} - -static int adis16400_get_freq(struct adis16400_state *st) -{ - int sps, ret; - uint16_t t; - - ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); - if (ret < 0) - return ret; - - sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; - sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; - - return sps; -} - -static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) -{ - unsigned int t; - - t = 1638 / freq; - if (t > 0) - t--; - t &= ADIS16400_SMPL_PRD_DIV_MASK; - - if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) - st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; - else - st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; - - return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, t); -} - -static ssize_t adis16400_read_frequency(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct adis16400_state *st = iio_priv(indio_dev); - int ret; - - ret = st->variant->get_freq(st); - if (ret < 0) - return ret; - - return sprintf(buf, "%d\n", ret); -} - -static const unsigned adis16400_3db_divisors[] = { - [0] = 2, /* Special case */ - [1] = 6, - [2] = 12, - [3] = 25, - [4] = 50, - [5] = 100, - [6] = 200, - [7] = 200, /* Not a valid setting */ -}; - -static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) -{ - struct adis16400_state *st = iio_priv(indio_dev); - uint16_t val16; - int i, ret; - - for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { - if (sps / adis16400_3db_divisors[i] >= val) - break; - } - - ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); - if (ret < 0) - return ret; - - ret = adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG, - (val16 & ~0x07) | i); - return ret; -} - -static ssize_t adis16400_write_frequency(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct adis16400_state *st = iio_priv(indio_dev); - long val; - int ret; - - ret = kstrtol(buf, 10, &val); - if (ret) - return ret; - - if (val == 0) - return -EINVAL; - - mutex_lock(&indio_dev->mlock); - st->variant->set_freq(st, val); - mutex_unlock(&indio_dev->mlock); - - return ret ? ret : len; -} - -/* Power down the device */ -static int adis16400_stop_device(struct iio_dev *indio_dev) -{ - struct adis16400_state *st = iio_priv(indio_dev); - int ret; - - ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, - ADIS16400_SLP_CNT_POWER_OFF); - if (ret) - dev_err(&indio_dev->dev, - "problem with turning device off: SLP_CNT"); - - return ret; -} - -static int adis16400_initial_setup(struct iio_dev *indio_dev) -{ - struct adis16400_state *st = iio_priv(indio_dev); - uint16_t prod_id, smp_prd; - unsigned int device_id; - int ret; - - /* use low spi speed for init if the device has a slow mode */ - if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) - st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; - else - st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; - st->adis.spi->mode = SPI_MODE_3; - spi_setup(st->adis.spi); - - ret = adis_initial_startup(&st->adis); - if (ret) - return ret; - - if (st->variant->flags & ADIS16400_HAS_PROD_ID) { - ret = adis_read_reg_16(&st->adis, - ADIS16400_PRODUCT_ID, &prod_id); - if (ret) - goto err_ret; - - sscanf(indio_dev->name, "adis%u\n", &device_id); - - if (prod_id != device_id) - dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", - device_id, prod_id); - - dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", - indio_dev->name, prod_id, - st->adis.spi->chip_select, st->adis.spi->irq); - } - /* use high spi speed if possible */ - if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { - ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd); - if (ret) - goto err_ret; - - if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { - st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; - spi_setup(st->adis.spi); - } - } - -err_ret: - return ret; -} - -static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, - adis16400_read_frequency, - adis16400_write_frequency); - -static const uint8_t adis16400_addresses[] = { - [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, - [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, - [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF, - [ADIS16400_SCAN_ACC_X] = ADIS16400_XACCL_OFF, - [ADIS16400_SCAN_ACC_Y] = ADIS16400_YACCL_OFF, - [ADIS16400_SCAN_ACC_Z] = ADIS16400_ZACCL_OFF, -}; - -static int adis16400_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, int val, int val2, long info) -{ - struct adis16400_state *st = iio_priv(indio_dev); - int ret, sps; - - switch (info) { - case IIO_CHAN_INFO_CALIBBIAS: - mutex_lock(&indio_dev->mlock); - ret = adis_write_reg_16(&st->adis, - adis16400_addresses[chan->scan_index], val); - mutex_unlock(&indio_dev->mlock); - return ret; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - /* - * Need to cache values so we can update if the frequency - * changes. - */ - mutex_lock(&indio_dev->mlock); - st->filt_int = val; - /* Work out update to current value */ - sps = st->variant->get_freq(st); - if (sps < 0) { - mutex_unlock(&indio_dev->mlock); - return sps; - } - - ret = adis16400_set_filter(indio_dev, sps, val); - mutex_unlock(&indio_dev->mlock); - return ret; - default: - return -EINVAL; - } -} - -static int adis16400_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, int *val, int *val2, long info) -{ - struct adis16400_state *st = iio_priv(indio_dev); - int16_t val16; - int ret; - - switch (info) { - case IIO_CHAN_INFO_RAW: - return adis_single_conversion(indio_dev, chan, 0, val); - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_ANGL_VEL: - *val = 0; - *val2 = st->variant->gyro_scale_micro; - return IIO_VAL_INT_PLUS_MICRO; - case IIO_VOLTAGE: - *val = 0; - if (chan->channel == 0) { - *val = 2; - *val2 = 418000; /* 2.418 mV */ - } else { - *val = 0; - *val2 = 805800; /* 805.8 uV */ - } - return IIO_VAL_INT_PLUS_MICRO; - case IIO_ACCEL: - *val = 0; - *val2 = st->variant->accel_scale_micro; - return IIO_VAL_INT_PLUS_MICRO; - case IIO_MAGN: - *val = 0; - *val2 = 500; /* 0.5 mgauss */ - return IIO_VAL_INT_PLUS_MICRO; - case IIO_TEMP: - *val = st->variant->temp_scale_nano / 1000000; - *val2 = (st->variant->temp_scale_nano % 1000000); - return IIO_VAL_INT_PLUS_MICRO; - default: - return -EINVAL; - } - case IIO_CHAN_INFO_CALIBBIAS: - mutex_lock(&indio_dev->mlock); - ret = adis_read_reg_16(&st->adis, - adis16400_addresses[chan->scan_index], &val16); - mutex_unlock(&indio_dev->mlock); - if (ret) - return ret; - val16 = ((val16 & 0xFFF) << 4) >> 4; - *val = val16; - return IIO_VAL_INT; - case IIO_CHAN_INFO_OFFSET: - /* currently only temperature */ - *val = st->variant->temp_offset; - return IIO_VAL_INT; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - mutex_lock(&indio_dev->mlock); - /* Need both the number of taps and the sampling frequency */ - ret = adis_read_reg_16(&st->adis, - ADIS16400_SENS_AVG, - &val16); - if (ret < 0) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - ret = st->variant->get_freq(st); - if (ret >= 0) - *val = ret / adis16400_3db_divisors[val16 & 0x07]; - *val2 = 0; - mutex_unlock(&indio_dev->mlock); - if (ret < 0) - return ret; - return IIO_VAL_INT_PLUS_MICRO; - default: - return -EINVAL; - } -} - -#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = 0, \ - .extend_name = name, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ - .address = (addr), \ - .scan_index = (si), \ - .scan_type = { \ - .sign = 'u', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -#define ADIS16400_SUPPLY_CHAN(addr, bits) \ - ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY) - -#define ADIS16400_AUX_ADC_CHAN(addr, bits) \ - ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC) - -#define ADIS16400_GYRO_CHAN(mod, addr, bits) { \ - .type = IIO_ANGL_VEL, \ - .modified = 1, \ - .channel2 = IIO_MOD_ ## mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT | \ - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ - .address = addr, \ - .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ - .scan_type = { \ - .sign = 's', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -#define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \ - .type = IIO_ACCEL, \ - .modified = 1, \ - .channel2 = IIO_MOD_ ## mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT | \ - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ - .address = (addr), \ - .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ - .scan_type = { \ - .sign = 's', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -#define ADIS16400_MAGN_CHAN(mod, addr, bits) { \ - .type = IIO_MAGN, \ - .modified = 1, \ - .channel2 = IIO_MOD_ ## mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT | \ - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ - .address = (addr), \ - .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ - .scan_type = { \ - .sign = 's', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -#define ADIS16400_MOD_TEMP_NAME_X "x" -#define ADIS16400_MOD_TEMP_NAME_Y "y" -#define ADIS16400_MOD_TEMP_NAME_Z "z" - -#define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \ - .type = IIO_TEMP, \ - .indexed = 1, \ - .channel = 0, \ - .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ - IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ - .address = (addr), \ - .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ - .scan_type = { \ - .sign = 's', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -#define ADIS16400_TEMP_CHAN(addr, bits) { \ - .type = IIO_TEMP, \ - .indexed = 1, \ - .channel = 0, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ - .address = (addr), \ - .scan_index = ADIS16350_SCAN_TEMP_X, \ - .scan_type = { \ - .sign = 's', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -#define ADIS16400_INCLI_CHAN(mod, addr, bits) { \ - .type = IIO_INCLI, \ - .modified = 1, \ - .channel2 = IIO_MOD_ ## mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT, \ - .address = (addr), \ - .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ - .scan_type = { \ - .sign = 's', \ - .realbits = (bits), \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ -} - -static const struct iio_chan_spec adis16400_channels[] = { - ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 14), - ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), - ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), - ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), - ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), - ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), - ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), - ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), - ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12), - ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12), - IIO_CHAN_SOFT_TIMESTAMP(12) -}; - -static const struct iio_chan_spec adis16350_channels[] = { - ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), - ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), - ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), - ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), - ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), - ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), - ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), - ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), - ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), - ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12), - ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12), - ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12), - IIO_CHAN_SOFT_TIMESTAMP(11) -}; - -static const struct iio_chan_spec adis16300_channels[] = { - ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), - ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), - ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), - ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), - ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), - ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13), - ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13), - IIO_CHAN_SOFT_TIMESTAMP(14) -}; - -static const struct iio_chan_spec adis16334_channels[] = { - ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), - ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), - ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), - ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), - ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), - ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), - IIO_CHAN_SOFT_TIMESTAMP(8) -}; - -static struct attribute *adis16400_attributes[] = { - &iio_dev_attr_sampling_frequency.dev_attr.attr, - NULL -}; - -static const struct attribute_group adis16400_attribute_group = { - .attrs = adis16400_attributes, -}; - -static struct adis16400_chip_info adis16400_chips[] = { - [ADIS16300] = { - .channels = adis16300_channels, - .num_channels = ARRAY_SIZE(adis16300_channels), - .flags = ADIS16400_HAS_SLOW_MODE, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = 5884, - .temp_scale_nano = 140000000, /* 0.14 C */ - .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ - .set_freq = adis16400_set_freq, - .get_freq = adis16400_get_freq, - }, - [ADIS16334] = { - .channels = adis16334_channels, - .num_channels = ARRAY_SIZE(adis16334_channels), - .flags = ADIS16400_HAS_PROD_ID, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ - .temp_scale_nano = 67850000, /* 0.06785 C */ - .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */ - .set_freq = adis16334_set_freq, - .get_freq = adis16334_get_freq, - }, - [ADIS16350] = { - .channels = adis16350_channels, - .num_channels = ARRAY_SIZE(adis16350_channels), - .gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */ - .temp_scale_nano = 145300000, /* 0.1453 C */ - .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */ - .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE, - .set_freq = adis16400_set_freq, - .get_freq = adis16400_get_freq, - }, - [ADIS16360] = { - .channels = adis16350_channels, - .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ - .temp_scale_nano = 136000000, /* 0.136 C */ - .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .set_freq = adis16400_set_freq, - .get_freq = adis16400_get_freq, - }, - [ADIS16362] = { - .channels = adis16350_channels, - .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ - .temp_scale_nano = 136000000, /* 0.136 C */ - .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .set_freq = adis16400_set_freq, - .get_freq = adis16400_get_freq, - }, - [ADIS16364] = { - .channels = adis16350_channels, - .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ - .temp_scale_nano = 136000000, /* 0.136 C */ - .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .set_freq = adis16400_set_freq, - .get_freq = adis16400_get_freq, - }, - [ADIS16400] = { - .channels = adis16400_channels, - .num_channels = ARRAY_SIZE(adis16400_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ - .temp_scale_nano = 140000000, /* 0.14 C */ - .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ - .set_freq = adis16400_set_freq, - .get_freq = adis16400_get_freq, - } -}; - -static const struct iio_info adis16400_info = { - .driver_module = THIS_MODULE, - .read_raw = &adis16400_read_raw, - .write_raw = &adis16400_write_raw, - .attrs = &adis16400_attribute_group, - .update_scan_mode = adis16400_update_scan_mode, -}; - -static const unsigned long adis16400_burst_scan_mask[] = { - ~0UL, - 0, -}; - -static const char * const adis16400_status_error_msgs[] = { - [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure", - [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure", - [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure", - [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure", - [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure", - [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure", - [ADIS16400_DIAG_STAT_ALARM2] = "Alarm 2 active", - [ADIS16400_DIAG_STAT_ALARM1] = "Alarm 1 active", - [ADIS16400_DIAG_STAT_FLASH_CHK] = "Flash checksum error", - [ADIS16400_DIAG_STAT_SELF_TEST] = "Self test error", - [ADIS16400_DIAG_STAT_OVERFLOW] = "Sensor overrange", - [ADIS16400_DIAG_STAT_SPI_FAIL] = "SPI failure", - [ADIS16400_DIAG_STAT_FLASH_UPT] = "Flash update failed", - [ADIS16400_DIAG_STAT_POWER_HIGH] = "Power supply above 5.25V", - [ADIS16400_DIAG_STAT_POWER_LOW] = "Power supply below 4.75V", -}; - -static const struct adis_data adis16400_data = { - .msc_ctrl_reg = ADIS16400_MSC_CTRL, - .glob_cmd_reg = ADIS16400_GLOB_CMD, - .diag_stat_reg = ADIS16400_DIAG_STAT, - - .read_delay = 50, - .write_delay = 50, - - .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, - .startup_delay = ADIS16400_STARTUP_DELAY, - - .status_error_msgs = adis16400_status_error_msgs, - .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | - BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | - BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | - BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | - BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | - BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | - BIT(ADIS16400_DIAG_STAT_ALARM2) | - BIT(ADIS16400_DIAG_STAT_ALARM1) | - BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | - BIT(ADIS16400_DIAG_STAT_SELF_TEST) | - BIT(ADIS16400_DIAG_STAT_OVERFLOW) | - BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | - BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | - BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | - BIT(ADIS16400_DIAG_STAT_POWER_LOW), -}; - -static int adis16400_probe(struct spi_device *spi) -{ - struct adis16400_state *st; - struct iio_dev *indio_dev; - int ret; - - indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) - return -ENOMEM; - - st = iio_priv(indio_dev); - /* this is only used for removal purposes */ - spi_set_drvdata(spi, indio_dev); - - /* setup the industrialio driver allocated elements */ - st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; - indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->channels = st->variant->channels; - indio_dev->num_channels = st->variant->num_channels; - indio_dev->info = &adis16400_info; - indio_dev->modes = INDIO_DIRECT_MODE; - - if (!(st->variant->flags & ADIS16400_NO_BURST)) - indio_dev->available_scan_masks = adis16400_burst_scan_mask; - - ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); - if (ret) - goto error_free_dev; - - ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, - adis16400_trigger_handler); - if (ret) - goto error_free_dev; - - /* Get the device into a sane initial state */ - ret = adis16400_initial_setup(indio_dev); - if (ret) - goto error_cleanup_buffer; - ret = iio_device_register(indio_dev); - if (ret) - goto error_cleanup_buffer; - - return 0; - -error_cleanup_buffer: - adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); -error_free_dev: - iio_device_free(indio_dev); - return ret; -} - -static int adis16400_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct adis16400_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - adis16400_stop_device(indio_dev); - - adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); - - iio_device_free(indio_dev); - - return 0; -} - -static const struct spi_device_id adis16400_id[] = { - {"adis16300", ADIS16300}, - {"adis16334", ADIS16334}, - {"adis16350", ADIS16350}, - {"adis16354", ADIS16350}, - {"adis16355", ADIS16350}, - {"adis16360", ADIS16360}, - {"adis16362", ADIS16362}, - {"adis16364", ADIS16364}, - {"adis16365", ADIS16360}, - {"adis16400", ADIS16400}, - {"adis16405", ADIS16400}, - {} -}; -MODULE_DEVICE_TABLE(spi, adis16400_id); - -static struct spi_driver adis16400_driver = { - .driver = { - .name = "adis16400", - .owner = THIS_MODULE, - }, - .id_table = adis16400_id, - .probe = adis16400_probe, - .remove = adis16400_remove, -}; -module_spi_driver(adis16400_driver); - -MODULE_AUTHOR("Manuel Stahl "); -MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c deleted file mode 100644 index 054c01d..0000000 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "adis16400.h" - -int adis16400_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *scan_mask) -{ - struct adis16400_state *st = iio_priv(indio_dev); - struct adis *adis = &st->adis; - uint16_t *tx, *rx; - - if (st->variant->flags & ADIS16400_NO_BURST) - return adis_update_scan_mode(indio_dev, scan_mask); - - kfree(adis->xfer); - kfree(adis->buffer); - - adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL); - if (!adis->xfer) - return -ENOMEM; - - adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16), - GFP_KERNEL); - if (!adis->buffer) - return -ENOMEM; - - rx = adis->buffer; - tx = adis->buffer + indio_dev->scan_bytes; - - tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD); - tx[1] = 0; - - adis->xfer[0].tx_buf = tx; - adis->xfer[0].bits_per_word = 8; - adis->xfer[0].len = 2; - adis->xfer[1].tx_buf = tx; - adis->xfer[1].bits_per_word = 8; - adis->xfer[1].len = indio_dev->scan_bytes; - - spi_message_init(&adis->msg); - spi_message_add_tail(&adis->xfer[0], &adis->msg); - spi_message_add_tail(&adis->xfer[1], &adis->msg); - - return 0; -} - -irqreturn_t adis16400_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16400_state *st = iio_priv(indio_dev); - struct adis *adis = &st->adis; - u32 old_speed_hz = st->adis.spi->max_speed_hz; - int ret; - - if (!adis->buffer) - return -ENOMEM; - - if (!(st->variant->flags & ADIS16400_NO_BURST) && - st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) { - st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST; - spi_setup(st->adis.spi); - } - - ret = spi_sync(adis->spi, &adis->msg); - if (ret) - dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); - - if (!(st->variant->flags & ADIS16400_NO_BURST)) { - st->adis.spi->max_speed_hz = old_speed_hz; - spi_setup(st->adis.spi); - } - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) { - void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64); - *(s64 *)b = pf->timestamp; - } - - iio_push_to_buffers(indio_dev, adis->buffer); - - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} -- cgit v0.10.2 From b24150e31ab27ffcd2aa9b33dca42c2070526054 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: iio:adis16400: Increase samplerate precession The devices supported by this drivers support sample rates with less than one sample per second. To support this increase the samplerate precession to allow setting (and reading) the samplerate with a milli-HZ precession. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index 1bbe5ee..8551fde 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -53,16 +53,15 @@ static int adis16334_get_freq(struct adis16400_state *st) t >>= ADIS16334_RATE_DIV_SHIFT; - return (8192 >> t) / 10; + return 819200 >> t; } static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) { unsigned int t; - freq *= 10; - if (freq < 8192) - t = ilog2(8192 / freq); + if (freq < 819200) + t = ilog2(819200 / freq); else t = 0; @@ -84,7 +83,7 @@ static int adis16400_get_freq(struct adis16400_state *st) if (ret < 0) return ret; - sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; + sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 52851 : 1638404; sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; return sps; @@ -94,7 +93,7 @@ static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) { unsigned int t; - t = 1638 / freq; + t = 1638404 / freq; if (t > 0) t--; t &= ADIS16400_SMPL_PRD_DIV_MASK; @@ -119,7 +118,7 @@ static ssize_t adis16400_read_frequency(struct device *dev, if (ret < 0) return ret; - return sprintf(buf, "%d\n", ret); + return sprintf(buf, "%d.%.3d\n", ret / 1000, ret % 1000); } static const unsigned adis16400_3db_divisors[] = { @@ -158,14 +157,16 @@ static ssize_t adis16400_write_frequency(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct adis16400_state *st = iio_priv(indio_dev); - long val; + int i, f, val; int ret; - ret = kstrtol(buf, 10, &val); + ret = iio_str_to_fixpoint(buf, 100, &i, &f); if (ret) return ret; - if (val == 0) + val = i * 1000 + f; + + if (val <= 0) return -EINVAL; mutex_lock(&indio_dev->mlock); @@ -281,7 +282,8 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, return sps; } - ret = adis16400_set_filter(indio_dev, sps, val); + ret = adis16400_set_filter(indio_dev, sps, + val * 1000 + val2 / 1000); mutex_unlock(&indio_dev->mlock); return ret; default: @@ -355,9 +357,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, return ret; } ret = st->variant->get_freq(st); - if (ret >= 0) - *val = ret / adis16400_3db_divisors[val16 & 0x07]; - *val2 = 0; + if (ret >= 0) { + ret /= adis16400_3db_divisors[val16 & 0x07]; + *val = ret / 1000; + *val2 = (ret % 1000) * 1000; + } mutex_unlock(&indio_dev->mlock); if (ret < 0) return ret; -- cgit v0.10.2 From 7ba8a04dcdfb5ebcb4985a92dfc4dc4f59510464 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: iio:adis16400: Add support for the 52.85 Hz base sampling rate The adis16400 and similar have two different base sampling rate available, from which the actual sampling rate is derived. 1638 Hz and 52.85 Hz, switching to the lower base sampling rate allows to support lower sampling rates. This patch adds support for switching to the lower base sampling rate if the requested sampling frequency is outside of the range which can be supported by the higher base sampling rate. The function which is used to read the current sampling rate already has support for the lower sampling rate, so no changes are required there. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index 8551fde..58699ac 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -92,18 +92,26 @@ static int adis16400_get_freq(struct adis16400_state *st) static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) { unsigned int t; + uint8_t val = 0; t = 1638404 / freq; - if (t > 0) + if (t >= 128) { + val |= ADIS16400_SMPL_PRD_TIME_BASE; + t = 52851 / freq; + if (t >= 128) + t = 127; + } else if (t != 0) { t--; - t &= ADIS16400_SMPL_PRD_DIV_MASK; + } + + val |= t; - if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) + if (t >= 0x0A || (val & ADIS16400_SMPL_PRD_TIME_BASE)) st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; else st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; - return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, t); + return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val); } static ssize_t adis16400_read_frequency(struct device *dev, -- cgit v0.10.2 From 1db18bb4c25823bfc11f370157f9d23a4d99ea1d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: iio:adis16400: Expose some debug information in debugfs Expose some information useful for debugging a device in debugfs. This includes for now the flash count, the product id and the serial number and raw register access. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h index a3b9e56..6270185 100644 --- a/drivers/iio/imu/adis16400.h +++ b/drivers/iio/imu/adis16400.h @@ -74,7 +74,10 @@ #define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ #define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ +#define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */ +#define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */ #define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ +#define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */ #define ADIS16400_ERROR_ACTIVE (1<<14) #define ADIS16400_NEW_DATA (1<<14) @@ -132,6 +135,7 @@ #define ADIS16400_HAS_PROD_ID BIT(0) #define ADIS16400_NO_BURST BIT(1) #define ADIS16400_HAS_SLOW_MODE BIT(2) +#define ADIS16400_HAS_SERIAL_NUMBER BIT(3) struct adis16400_state; diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index 58699ac..e8f84c9 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -32,6 +33,104 @@ #include "adis16400.h" +#ifdef CONFIG_DEBUG_FS + +static ssize_t adis16400_show_serial_number(struct file *file, + char __user *userbuf, size_t count, loff_t *ppos) +{ + struct adis16400_state *st = file->private_data; + u16 lot1, lot2, serial_number; + char buf[16]; + size_t len; + int ret; + + ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1); + if (ret < 0) + return ret; + + ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2); + if (ret < 0) + return ret; + + ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER, + &serial_number); + if (ret < 0) + return ret; + + len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2, + serial_number); + + return simple_read_from_buffer(userbuf, count, ppos, buf, len); +} + +static const struct file_operations adis16400_serial_number_fops = { + .open = simple_open, + .read = adis16400_show_serial_number, + .llseek = default_llseek, + .owner = THIS_MODULE, +}; + +static int adis16400_show_product_id(void *arg, u64 *val) +{ + struct adis16400_state *st = arg; + uint16_t prod_id; + int ret; + + ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id); + if (ret < 0) + return ret; + + *val = prod_id; + + return 0; +} +DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops, + adis16400_show_product_id, NULL, "%lld\n"); + +static int adis16400_show_flash_count(void *arg, u64 *val) +{ + struct adis16400_state *st = arg; + uint16_t flash_count; + int ret; + + ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count); + if (ret < 0) + return ret; + + *val = flash_count; + + return 0; +} +DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops, + adis16400_show_flash_count, NULL, "%lld\n"); + +static int adis16400_debugfs_init(struct iio_dev *indio_dev) +{ + struct adis16400_state *st = iio_priv(indio_dev); + + if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER) + debugfs_create_file("serial_number", 0400, + indio_dev->debugfs_dentry, st, + &adis16400_serial_number_fops); + if (st->variant->flags & ADIS16400_HAS_PROD_ID) + debugfs_create_file("product_id", 0400, + indio_dev->debugfs_dentry, st, + &adis16400_product_id_fops); + debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, + st, &adis16400_flash_count_fops); + + return 0; +} + +#else + +static int adis16400_debugfs_init(struct iio_dev *indio_dev) +{ + return 0; +} + +#endif + enum adis16400_chip_variant { ADIS16300, ADIS16334, @@ -600,7 +699,8 @@ static struct adis16400_chip_info adis16400_chips[] = { [ADIS16334] = { .channels = adis16334_channels, .num_channels = ARRAY_SIZE(adis16334_channels), - .flags = ADIS16400_HAS_PROD_ID, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_NO_BURST | + ADIS16400_HAS_SERIAL_NUMBER, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ .temp_scale_nano = 67850000, /* 0.06785 C */ @@ -622,7 +722,8 @@ static struct adis16400_chip_info adis16400_chips[] = { [ADIS16360] = { .channels = adis16350_channels, .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | + ADIS16400_HAS_SERIAL_NUMBER, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ @@ -633,7 +734,8 @@ static struct adis16400_chip_info adis16400_chips[] = { [ADIS16362] = { .channels = adis16350_channels, .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | + ADIS16400_HAS_SERIAL_NUMBER, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ @@ -644,7 +746,8 @@ static struct adis16400_chip_info adis16400_chips[] = { [ADIS16364] = { .channels = adis16350_channels, .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | + ADIS16400_HAS_SERIAL_NUMBER, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ @@ -671,6 +774,7 @@ static const struct iio_info adis16400_info = { .write_raw = &adis16400_write_raw, .attrs = &adis16400_attribute_group, .update_scan_mode = adis16400_update_scan_mode, + .debugfs_reg_access = adis_debugfs_reg_access, }; static const unsigned long adis16400_burst_scan_mask[] = { @@ -768,6 +872,7 @@ static int adis16400_probe(struct spi_device *spi) if (ret) goto error_cleanup_buffer; + adis16400_debugfs_init(indio_dev); return 0; error_cleanup_buffer: -- cgit v0.10.2 From 76ada52f7f5d4c83cbb6d61e556e3fbd0ac6d34f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 16 Jan 2013 12:48:00 +0000 Subject: iio:adis16400: Add support for the adis16448 The adis16448 is more or less from the same family of devices as supported by this driver. It features three acceleration channels, three angular velocity channels, three magnetometer channels, one temperature channels and one barometric pressure channel. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h index 6270185..2f8f9d6 100644 --- a/drivers/iio/imu/adis16400.h +++ b/drivers/iio/imu/adis16400.h @@ -44,6 +44,9 @@ #define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */ #define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */ +#define ADIS16448_BARO_OUT 0x16 /* Barometric pressure output */ +#define ADIS16448_TEMP_OUT 0x18 /* Temperature output */ + /* Calibration parameters */ #define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */ #define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */ @@ -179,6 +182,7 @@ enum { ADIS16400_SCAN_MAGN_X, ADIS16400_SCAN_MAGN_Y, ADIS16400_SCAN_MAGN_Z, + ADIS16400_SCAN_BARO, ADIS16350_SCAN_TEMP_X, ADIS16350_SCAN_TEMP_Y, ADIS16350_SCAN_TEMP_Z, diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index e8f84c9..b7f215e 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c @@ -139,6 +139,7 @@ enum adis16400_chip_variant { ADIS16362, ADIS16364, ADIS16400, + ADIS16448, }; static int adis16334_get_freq(struct adis16400_state *st) @@ -633,6 +634,28 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(12) }; +static const struct iio_chan_spec adis16448_channels[] = { + ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16), + ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16), + ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 16), + ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 16), + ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 16), + ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 16), + ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 16), + ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 16), + ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 16), + { + .type = IIO_PRESSURE, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SHARED_BIT, + .address = ADIS16448_BARO_OUT, + .scan_index = ADIS16400_SCAN_BARO, + .scan_type = IIO_ST('s', 16, 16, 0), + }, + ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12), + IIO_CHAN_SOFT_TIMESTAMP(11) +}; + static const struct iio_chan_spec adis16350_channels[] = { ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), @@ -765,6 +788,18 @@ static struct adis16400_chip_info adis16400_chips[] = { .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ .set_freq = adis16400_set_freq, .get_freq = adis16400_get_freq, + }, + [ADIS16448] = { + .channels = adis16448_channels, + .num_channels = ARRAY_SIZE(adis16448_channels), + .flags = ADIS16400_HAS_PROD_ID | + ADIS16400_HAS_SERIAL_NUMBER, + .gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */ + .accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */ + .temp_scale_nano = 73860000, /* 0.07386 C */ + .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */ + .set_freq = adis16334_set_freq, + .get_freq = adis16334_get_freq, } }; @@ -909,6 +944,7 @@ static const struct spi_device_id adis16400_id[] = { {"adis16365", ADIS16360}, {"adis16400", ADIS16400}, {"adis16405", ADIS16400}, + {"adis16448", ADIS16448}, {} }; MODULE_DEVICE_TABLE(spi, adis16400_id); -- cgit v0.10.2 From a819a0df8ab6e9425cb8d038424f4e7c5c9d77cd Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Fri, 30 Nov 2012 14:22:00 +0000 Subject: staging:iio:accel:lis3l02dq remove sw_ring support. The sw_ring buffer is being removed in favour of the kfifo version. This is one of only a couple of driver still supporting its use. This driver will hopefully also be removed in favour of supporting the part in the unified ST accelerometer driver. Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig index 2b54430..fa772a9 100644 --- a/drivers/staging/iio/accel/Kconfig +++ b/drivers/staging/iio/accel/Kconfig @@ -67,34 +67,13 @@ config LIS3L02DQ tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver" depends on SPI select IIO_TRIGGER if IIO_BUFFER - depends on !IIO_BUFFER || IIO_KFIFO_BUF || IIO_SW_RING + depends on !IIO_BUFFER || IIO_KFIFO_BUF depends on GENERIC_GPIO help Say yes here to build SPI support for the ST microelectronics accelerometer. The driver supplies direct access via sysfs files and an event interface via a character device. -choice - prompt "Buffer type" - depends on LIS3L02DQ && IIO_BUFFER - -config LIS3L02DQ_BUF_KFIFO - depends on IIO_KFIFO_BUF - bool "Simple FIFO" - help - Kfifo based FIFO. Does not provide any events so it is up - to userspace to ensure it reads often enough that data is not - lost. - -config LIS3L02DQ_BUF_RING_SW - depends on IIO_SW_RING - bool "IIO Software Ring" - help - Original IIO ring buffer implementation. Provides simple - buffer events, half full etc. - -endchoice - config SCA3000 depends on IIO_BUFFER depends on SPI diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h index 2bac722..0a8ea82 100644 --- a/drivers/staging/iio/accel/lis3l02dq.h +++ b/drivers/staging/iio/accel/lis3l02dq.h @@ -185,14 +185,6 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev); int lis3l02dq_configure_buffer(struct iio_dev *indio_dev); void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev); -#ifdef CONFIG_LIS3L02DQ_BUF_RING_SW -#define lis3l02dq_free_buf iio_sw_rb_free -#define lis3l02dq_alloc_buf iio_sw_rb_allocate -#endif -#ifdef CONFIG_LIS3L02DQ_BUF_KFIFO -#define lis3l02dq_free_buf iio_kfifo_free -#define lis3l02dq_alloc_buf iio_kfifo_allocate -#endif irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private); #define lis3l02dq_th lis3l02dq_data_rdy_trig_poll diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c index bc38651..6861877 100644 --- a/drivers/staging/iio/accel/lis3l02dq_ring.c +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c @@ -7,7 +7,6 @@ #include #include -#include "../ring_sw.h" #include #include #include @@ -318,7 +317,7 @@ void lis3l02dq_remove_trigger(struct iio_dev *indio_dev) void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev) { iio_dealloc_pollfunc(indio_dev->pollfunc); - lis3l02dq_free_buf(indio_dev->buffer); + iio_kfifo_free(indio_dev->buffer); } static int lis3l02dq_buffer_postenable(struct iio_dev *indio_dev) @@ -401,7 +400,7 @@ int lis3l02dq_configure_buffer(struct iio_dev *indio_dev) int ret; struct iio_buffer *buffer; - buffer = lis3l02dq_alloc_buf(indio_dev); + buffer = iio_kfifo_allocate(indio_dev); if (!buffer) return -ENOMEM; @@ -427,6 +426,6 @@ int lis3l02dq_configure_buffer(struct iio_dev *indio_dev) return 0; error_iio_sw_rb_free: - lis3l02dq_free_buf(indio_dev->buffer); + iio_kfifo_free(indio_dev->buffer); return ret; } -- cgit v0.10.2 From 032658a446145b9e6af7f90521179a9e0111b546 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Fri, 30 Nov 2012 14:22:00 +0000 Subject: staging:iio:impedance-analyzer switch from sw_ring to kfifo. sw_ring buffer implementation is going away so switch to the kfifo based alternative. Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig b/drivers/staging/iio/impedance-analyzer/Kconfig index ad0ff76..dd97b6b 100644 --- a/drivers/staging/iio/impedance-analyzer/Kconfig +++ b/drivers/staging/iio/impedance-analyzer/Kconfig @@ -7,7 +7,7 @@ config AD5933 tristate "Analog Devices AD5933, AD5934 driver" depends on I2C select IIO_BUFFER - select IIO_SW_RING + select IIO_KFIFO_BUF help Say yes here to build support for Analog Devices Impedance Converter, Network Analyzer, AD5933/4, provides direct access via sysfs. diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 779243d..440e226 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -22,7 +22,7 @@ #include #include #include -#include "../ring_sw.h" +#include #include "ad5933.h" @@ -630,7 +630,7 @@ static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = { static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev) { - indio_dev->buffer = iio_sw_rb_allocate(indio_dev); + indio_dev->buffer = iio_kfifo_allocate(indio_dev); if (!indio_dev->buffer) return -ENOMEM; @@ -774,7 +774,7 @@ static int ad5933_probe(struct i2c_client *client, error_uninitialize_ring: iio_buffer_unregister(indio_dev); error_unreg_ring: - iio_sw_rb_free(indio_dev->buffer); + iio_kfifo_free(indio_dev->buffer); error_disable_reg: if (!IS_ERR(st->reg)) regulator_disable(st->reg); @@ -794,7 +794,7 @@ static int ad5933_remove(struct i2c_client *client) iio_device_unregister(indio_dev); iio_buffer_unregister(indio_dev); - iio_sw_rb_free(indio_dev->buffer); + iio_kfifo_free(indio_dev->buffer); if (!IS_ERR(st->reg)) { regulator_disable(st->reg); regulator_put(st->reg); -- cgit v0.10.2 From 94f3c7cd829319317a95649cd43abb07c188c191 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Fri, 30 Nov 2012 14:22:00 +0000 Subject: staging:iio:meter:ade7758 switch from sw_ring to kfifo sw ring is going away so switch over to kfifo based buffer implementation. The only real change is that poll will return on some data there rather than buffer 50% full. Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/meter/Kconfig b/drivers/staging/iio/meter/Kconfig index d290d27..e53274b 100644 --- a/drivers/staging/iio/meter/Kconfig +++ b/drivers/staging/iio/meter/Kconfig @@ -21,7 +21,7 @@ config ADE7758 tristate "Analog Devices ADE7758 Poly Phase Multifunction Energy Metering IC Driver" depends on SPI select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_KFIFO_BUF if IIO_BUFFER help Say yes here to build support for Analog Devices ADE7758 Polyphase Multifunction Energy Metering IC with Per Phase Information Driver. diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c index 4552a4c..b29e2d5 100644 --- a/drivers/staging/iio/meter/ade7758_ring.c +++ b/drivers/staging/iio/meter/ade7758_ring.c @@ -13,7 +13,7 @@ #include #include -#include "../ring_sw.h" +#include #include #include "ade7758.h" @@ -119,7 +119,7 @@ static const struct iio_buffer_setup_ops ade7758_ring_setup_ops = { void ade7758_unconfigure_ring(struct iio_dev *indio_dev) { iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); + iio_kfifo_free(indio_dev->buffer); } int ade7758_configure_ring(struct iio_dev *indio_dev) @@ -127,7 +127,7 @@ int ade7758_configure_ring(struct iio_dev *indio_dev) struct ade7758_state *st = iio_priv(indio_dev); int ret = 0; - indio_dev->buffer = iio_sw_rb_allocate(indio_dev); + indio_dev->buffer = iio_kfifo_allocate(indio_dev); if (!indio_dev->buffer) { ret = -ENOMEM; return ret; @@ -143,7 +143,7 @@ int ade7758_configure_ring(struct iio_dev *indio_dev) indio_dev->id); if (indio_dev->pollfunc == NULL) { ret = -ENOMEM; - goto error_iio_sw_rb_free; + goto error_iio_kfifo_free; } indio_dev->modes |= INDIO_BUFFER_TRIGGERED; @@ -183,8 +183,8 @@ int ade7758_configure_ring(struct iio_dev *indio_dev) return 0; -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); +error_iio_kfifo_free: + iio_kfifo_free(indio_dev->buffer); return ret; } -- cgit v0.10.2 From df2e8f78e7fe749332f82dcba6438fc2b3016a96 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Fri, 30 Nov 2012 14:22:00 +0000 Subject: staging:iio: drop sw_ring buffer implementation. Whilst this is IIO's oldest buffer implementation it is messy, poorly implemented and whilst it works, no one is entirely sure it always will. New IIO drivers have not been using this for some time and now all remaining old users have been converted to use the kfifo based alternative. Clearly a fifo isn't the same as a ring buffer but in many use cases it really doesn't matter. We also loose the watershed based poll implementation. However having poll effectively report data only when the buffer was half full was at best an 'unusual' use of the interface. At somepoint in the future we may bring watersheds back on a different buffer implementation, but then we will think a lot more about how to do the interface first. Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig index 94d60d5..dc26717 100644 --- a/drivers/staging/iio/Kconfig +++ b/drivers/staging/iio/Kconfig @@ -12,19 +12,6 @@ config IIO_ST_HWMON map allows IIO devices to provide basic hwmon functionality for those channels specified in the map. -if IIO_BUFFER - -config IIO_SW_RING - select IIO_TRIGGER - tristate "Industrial I/O lock free software ring" - help - Example software ring buffer implementation. The design aim - of this particular realization was to minimize write locking - with the intention that some devices would be able to write - in interrupt context. - -endif # IIO_BUFFER - source "drivers/staging/iio/accel/Kconfig" source "drivers/staging/iio/adc/Kconfig" source "drivers/staging/iio/addac/Kconfig" diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile index 468b7f8..158e0a0 100644 --- a/drivers/staging/iio/Makefile +++ b/drivers/staging/iio/Makefile @@ -2,8 +2,6 @@ # Makefile for the industrial I/O core. # -obj-$(CONFIG_IIO_SW_RING) += ring_sw.o - obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o iio_dummy-y := iio_simple_dummy.o iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_EVENTS) += iio_simple_dummy_events.o diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c deleted file mode 100644 index 3a45f9a..0000000 --- a/drivers/staging/iio/ring_sw.c +++ /dev/null @@ -1,366 +0,0 @@ -/* The industrial I/O simple minimally locked ring buffer. - * - * Copyright (c) 2008 Jonathan Cameron - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "ring_sw.h" -#include - -/** - * struct iio_sw_ring_buffer - software ring buffer - * @buf: generic ring buffer elements - * @data: the ring buffer memory - * @read_p: read pointer (oldest available) - * @write_p: write pointer - * @half_p: half buffer length behind write_p (event generation) - * @update_needed: flag to indicate change in size requested - * - * Note that the first element of all ring buffers must be a - * struct iio_buffer. -**/ -struct iio_sw_ring_buffer { - struct iio_buffer buf; - unsigned char *data; - unsigned char *read_p; - unsigned char *write_p; - /* used to act as a point at which to signal an event */ - unsigned char *half_p; - int update_needed; -}; - -#define iio_to_sw_ring(r) container_of(r, struct iio_sw_ring_buffer, buf) - -static inline int __iio_allocate_sw_ring_buffer(struct iio_sw_ring_buffer *ring, - int bytes_per_datum, int length) -{ - if ((length == 0) || (bytes_per_datum == 0)) - return -EINVAL; - __iio_update_buffer(&ring->buf, bytes_per_datum, length); - ring->data = kmalloc(length*ring->buf.bytes_per_datum, GFP_ATOMIC); - ring->read_p = NULL; - ring->write_p = NULL; - ring->half_p = NULL; - return ring->data ? 0 : -ENOMEM; -} - -static inline void __iio_free_sw_ring_buffer(struct iio_sw_ring_buffer *ring) -{ - kfree(ring->data); -} - -/* Ring buffer related functionality */ -/* Store to ring is typically called in the bh of a data ready interrupt handler - * in the device driver */ -/* Lock always held if their is a chance this may be called */ -/* Only one of these per ring may run concurrently - enforced by drivers */ -static int iio_store_to_sw_ring(struct iio_sw_ring_buffer *ring, - unsigned char *data) -{ - int ret = 0; - unsigned char *temp_ptr, *change_test_ptr; - - /* initial store */ - if (unlikely(ring->write_p == NULL)) { - ring->write_p = ring->data; - /* Doesn't actually matter if this is out of the set - * as long as the read pointer is valid before this - * passes it - guaranteed as set later in this function. - */ - ring->half_p = ring->data - ring->buf.length*ring->buf.bytes_per_datum/2; - } - /* Copy data to where ever the current write pointer says */ - memcpy(ring->write_p, data, ring->buf.bytes_per_datum); - barrier(); - /* Update the pointer used to get most recent value. - * Always valid as either points to latest or second latest value. - * Before this runs it is null and read attempts fail with -EAGAIN. - */ - barrier(); - /* temp_ptr used to ensure we never have an invalid pointer - * it may be slightly lagging, but never invalid - */ - temp_ptr = ring->write_p + ring->buf.bytes_per_datum; - /* End of ring, back to the beginning */ - if (temp_ptr == ring->data + ring->buf.length*ring->buf.bytes_per_datum) - temp_ptr = ring->data; - /* Update the write pointer - * always valid as long as this is the only function able to write. - * Care needed with smp systems to ensure more than one ring fill - * is never scheduled. - */ - ring->write_p = temp_ptr; - - if (ring->read_p == NULL) - ring->read_p = ring->data; - /* Buffer full - move the read pointer and create / escalate - * ring event */ - /* Tricky case - if the read pointer moves before we adjust it. - * Handle by not pushing if it has moved - may result in occasional - * unnecessary buffer full events when it wasn't quite true. - */ - else if (ring->write_p == ring->read_p) { - change_test_ptr = ring->read_p; - temp_ptr = change_test_ptr + ring->buf.bytes_per_datum; - if (temp_ptr - == ring->data + ring->buf.length*ring->buf.bytes_per_datum) { - temp_ptr = ring->data; - } - /* We are moving pointer on one because the ring is full. Any - * change to the read pointer will be this or greater. - */ - if (change_test_ptr == ring->read_p) - ring->read_p = temp_ptr; - } - /* investigate if our event barrier has been passed */ - /* There are definite 'issues' with this and chances of - * simultaneous read */ - /* Also need to use loop count to ensure this only happens once */ - ring->half_p += ring->buf.bytes_per_datum; - if (ring->half_p == ring->data + ring->buf.length*ring->buf.bytes_per_datum) - ring->half_p = ring->data; - if (ring->half_p == ring->read_p) { - ring->buf.stufftoread = true; - wake_up_interruptible(&ring->buf.pollq); - } - return ret; -} - -static int iio_read_first_n_sw_rb(struct iio_buffer *r, - size_t n, char __user *buf) -{ - struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r); - - u8 *initial_read_p, *initial_write_p, *current_read_p, *end_read_p; - u8 *data; - int ret, max_copied, bytes_to_rip, dead_offset; - size_t data_available, buffer_size; - - /* A userspace program has probably made an error if it tries to - * read something that is not a whole number of bpds. - * Return an error. - */ - if (n % ring->buf.bytes_per_datum) { - ret = -EINVAL; - printk(KERN_INFO "Ring buffer read request not whole number of" - "samples: Request bytes %zd, Current bytes per datum %d\n", - n, ring->buf.bytes_per_datum); - goto error_ret; - } - - buffer_size = ring->buf.bytes_per_datum*ring->buf.length; - - /* Limit size to whole of ring buffer */ - bytes_to_rip = min_t(size_t, buffer_size, n); - - data = kmalloc(bytes_to_rip, GFP_KERNEL); - if (data == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - /* build local copy */ - initial_read_p = ring->read_p; - if (unlikely(initial_read_p == NULL)) { /* No data here as yet */ - ret = 0; - goto error_free_data_cpy; - } - - initial_write_p = ring->write_p; - - /* Need a consistent pair */ - while ((initial_read_p != ring->read_p) - || (initial_write_p != ring->write_p)) { - initial_read_p = ring->read_p; - initial_write_p = ring->write_p; - } - if (initial_write_p == initial_read_p) { - /* No new data available.*/ - ret = 0; - goto error_free_data_cpy; - } - - if (initial_write_p >= initial_read_p) - data_available = initial_write_p - initial_read_p; - else - data_available = buffer_size - (initial_read_p - initial_write_p); - - if (data_available < bytes_to_rip) - bytes_to_rip = data_available; - - if (initial_read_p + bytes_to_rip >= ring->data + buffer_size) { - max_copied = ring->data + buffer_size - initial_read_p; - memcpy(data, initial_read_p, max_copied); - memcpy(data + max_copied, ring->data, bytes_to_rip - max_copied); - end_read_p = ring->data + bytes_to_rip - max_copied; - } else { - memcpy(data, initial_read_p, bytes_to_rip); - end_read_p = initial_read_p + bytes_to_rip; - } - - /* Now to verify which section was cleanly copied - i.e. how far - * read pointer has been pushed */ - current_read_p = ring->read_p; - - if (initial_read_p <= current_read_p) - dead_offset = current_read_p - initial_read_p; - else - dead_offset = buffer_size - (initial_read_p - current_read_p); - - /* possible issue if the initial write has been lapped or indeed - * the point we were reading to has been passed */ - /* No valid data read. - * In this case the read pointer is already correct having been - * pushed further than we would look. */ - if (bytes_to_rip - dead_offset < 0) { - ret = 0; - goto error_free_data_cpy; - } - - /* setup the next read position */ - /* Beware, this may fail due to concurrency fun and games. - * Possible that sufficient fill commands have run to push the read - * pointer past where we would be after the rip. If this occurs, leave - * it be. - */ - /* Tricky - deal with loops */ - - while (ring->read_p != end_read_p) - ring->read_p = end_read_p; - - ret = bytes_to_rip - dead_offset; - - if (copy_to_user(buf, data + dead_offset, ret)) { - ret = -EFAULT; - goto error_free_data_cpy; - } - - if (bytes_to_rip >= ring->buf.length*ring->buf.bytes_per_datum/2) - ring->buf.stufftoread = 0; - -error_free_data_cpy: - kfree(data); -error_ret: - - return ret; -} - -static int iio_store_to_sw_rb(struct iio_buffer *r, - u8 *data) -{ - struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r); - return iio_store_to_sw_ring(ring, data); -} - -static int iio_request_update_sw_rb(struct iio_buffer *r) -{ - int ret = 0; - struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r); - - r->stufftoread = false; - if (!ring->update_needed) - goto error_ret; - __iio_free_sw_ring_buffer(ring); - ret = __iio_allocate_sw_ring_buffer(ring, ring->buf.bytes_per_datum, - ring->buf.length); -error_ret: - return ret; -} - -static int iio_get_bytes_per_datum_sw_rb(struct iio_buffer *r) -{ - struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r); - return ring->buf.bytes_per_datum; -} - -static int iio_mark_update_needed_sw_rb(struct iio_buffer *r) -{ - struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r); - ring->update_needed = true; - return 0; -} - -static int iio_set_bytes_per_datum_sw_rb(struct iio_buffer *r, size_t bpd) -{ - if (r->bytes_per_datum != bpd) { - r->bytes_per_datum = bpd; - iio_mark_update_needed_sw_rb(r); - } - return 0; -} - -static int iio_get_length_sw_rb(struct iio_buffer *r) -{ - return r->length; -} - -static int iio_set_length_sw_rb(struct iio_buffer *r, int length) -{ - if (r->length != length) { - r->length = length; - iio_mark_update_needed_sw_rb(r); - } - return 0; -} - -static IIO_BUFFER_ENABLE_ATTR; -static IIO_BUFFER_LENGTH_ATTR; - -/* Standard set of ring buffer attributes */ -static struct attribute *iio_ring_attributes[] = { - &dev_attr_length.attr, - &dev_attr_enable.attr, - NULL, -}; - -static struct attribute_group iio_ring_attribute_group = { - .attrs = iio_ring_attributes, - .name = "buffer", -}; - -static const struct iio_buffer_access_funcs ring_sw_access_funcs = { - .store_to = &iio_store_to_sw_rb, - .read_first_n = &iio_read_first_n_sw_rb, - .request_update = &iio_request_update_sw_rb, - .get_bytes_per_datum = &iio_get_bytes_per_datum_sw_rb, - .set_bytes_per_datum = &iio_set_bytes_per_datum_sw_rb, - .get_length = &iio_get_length_sw_rb, - .set_length = &iio_set_length_sw_rb, -}; - -struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev) -{ - struct iio_buffer *buf; - struct iio_sw_ring_buffer *ring; - - ring = kzalloc(sizeof *ring, GFP_KERNEL); - if (!ring) - return NULL; - ring->update_needed = true; - buf = &ring->buf; - iio_buffer_init(buf); - buf->attrs = &iio_ring_attribute_group; - buf->access = &ring_sw_access_funcs; - - return buf; -} -EXPORT_SYMBOL(iio_sw_rb_allocate); - -void iio_sw_rb_free(struct iio_buffer *r) -{ - kfree(iio_to_sw_ring(r)); -} -EXPORT_SYMBOL(iio_sw_rb_free); - -MODULE_DESCRIPTION("Industrial I/O software ring buffer"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.h deleted file mode 100644 index a5857aa..0000000 --- a/drivers/staging/iio/ring_sw.h +++ /dev/null @@ -1,30 +0,0 @@ -/* The industrial I/O simple minimally locked ring buffer. - * - * Copyright (c) 2008 Jonathan Cameron - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - * - * This code is deliberately kept separate from the main industrialio I/O core - * as it is intended that in the future a number of different software ring - * buffer implementations will exist with different characteristics to suit - * different applications. - * - * This particular one was designed for a data capture application where it was - * particularly important that no userspace reads would interrupt the capture - * process. To this end the ring is not locked during a read. - * - * Comments on this buffer design welcomed. It's far from efficient and some of - * my understanding of the effects of scheduling on this are somewhat limited. - * Frankly, to my mind, this is the current weak point in the industrial I/O - * patch set. - */ - -#ifndef _IIO_RING_SW_H_ -#define _IIO_RING_SW_H_ -#include - -struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev); -void iio_sw_rb_free(struct iio_buffer *ring); -#endif /* _IIO_RING_SW_H_ */ -- cgit v0.10.2 From b775dce99621af52d32c1d7335cf94eee4383e8a Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 17 Jan 2013 01:49:00 +0000 Subject: rtc: hid-sensor-time: Add missing spin_lock_init Signed-off-by: Axel Lin Acked-by: Alexander Holler Signed-off-by: Jonathan Cameron diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index 0438c9e..31c5728 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c @@ -225,6 +225,7 @@ static int hid_time_probe(struct platform_device *pdev) platform_set_drvdata(pdev, time_state); + spin_lock_init(&time_state->lock_last_time); init_completion(&time_state->comp_last_time); time_state->common_attributes.hsdev = hsdev; time_state->common_attributes.pdev = pdev; -- cgit v0.10.2 From d526e513c7dd1bb3f9696c7d38634e5ebf5f0919 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 6 Jan 2013 15:10:00 +0000 Subject: staging:iio:accel:kxsd9 Remove an unneeded initialization and trivial reorder to ensure the device is ready when the device is registered. Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/staging/iio/accel/kxsd9.c index 318331f..4a24c2e 100644 --- a/drivers/staging/iio/accel/kxsd9.c +++ b/drivers/staging/iio/accel/kxsd9.c @@ -226,7 +226,7 @@ static int kxsd9_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct kxsd9_state *st; - int ret = 0; + int ret; indio_dev = iio_device_alloc(sizeof(*st)); if (indio_dev == NULL) { @@ -245,14 +245,14 @@ static int kxsd9_probe(struct spi_device *spi) indio_dev->info = &kxsd9_info; indio_dev->modes = INDIO_DIRECT_MODE; - ret = iio_device_register(indio_dev); - if (ret) - goto error_free_dev; - spi->mode = SPI_MODE_0; spi_setup(spi); kxsd9_power_up(st); + ret = iio_device_register(indio_dev); + if (ret) + goto error_free_dev; + return 0; error_free_dev: -- cgit v0.10.2 From 81ca486fe54c799033fac1eb6d93baf64df37ba6 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 6 Jan 2013 15:10:00 +0000 Subject: iio:accel:kxsd9 move out of staging This is a very simple driver giving basic access to this part over an spi bus. Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 05e996f..d600353 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -14,4 +14,11 @@ config HID_SENSOR_ACCEL_3D Say yes here to build support for the HID SENSOR accelerometers 3D. +config KXSD9 + tristate "Kionix KXSD9 Accelerometer Driver" + depends on SPI + help + Say yes here to build support for the Kionix KXSD9 accelerometer. + Currently this only supports the device via an SPI interface. + endmenu diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 5bc6855..4e1c859 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -3,3 +3,4 @@ # obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o +obj-$(CONFIG_KXSD9) += kxsd9.o diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c new file mode 100644 index 0000000..4a24c2e --- /dev/null +++ b/drivers/iio/accel/kxsd9.c @@ -0,0 +1,291 @@ +/* + * kxsd9.c simple support for the Kionix KXSD9 3D + * accelerometer. + * + * Copyright (c) 2008-2009 Jonathan Cameron + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * The i2c interface is very similar, so shouldn't be a problem once + * I have a suitable wire made up. + * + * TODO: Support the motion detector + * Uses register address incrementing so could have a + * heavily optimized ring buffer access function. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define KXSD9_REG_X 0x00 +#define KXSD9_REG_Y 0x02 +#define KXSD9_REG_Z 0x04 +#define KXSD9_REG_AUX 0x06 +#define KXSD9_REG_RESET 0x0a +#define KXSD9_REG_CTRL_C 0x0c + +#define KXSD9_FS_MASK 0x03 + +#define KXSD9_REG_CTRL_B 0x0d +#define KXSD9_REG_CTRL_A 0x0e + +#define KXSD9_READ(a) (0x80 | (a)) +#define KXSD9_WRITE(a) (a) + +#define KXSD9_STATE_RX_SIZE 2 +#define KXSD9_STATE_TX_SIZE 2 +/** + * struct kxsd9_state - device related storage + * @buf_lock: protect the rx and tx buffers. + * @us: spi device + * @rx: single rx buffer storage + * @tx: single tx buffer storage + **/ +struct kxsd9_state { + struct mutex buf_lock; + struct spi_device *us; + u8 rx[KXSD9_STATE_RX_SIZE] ____cacheline_aligned; + u8 tx[KXSD9_STATE_TX_SIZE]; +}; + +#define KXSD9_SCALE_2G "0.011978" +#define KXSD9_SCALE_4G "0.023927" +#define KXSD9_SCALE_6G "0.035934" +#define KXSD9_SCALE_8G "0.047853" + +/* reverse order */ +static const int kxsd9_micro_scales[4] = { 47853, 35934, 23927, 11978 }; + +static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro) +{ + int ret, i; + struct kxsd9_state *st = iio_priv(indio_dev); + bool foundit = false; + + for (i = 0; i < 4; i++) + if (micro == kxsd9_micro_scales[i]) { + foundit = true; + break; + } + if (!foundit) + return -EINVAL; + + mutex_lock(&st->buf_lock); + ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C)); + if (ret) + goto error_ret; + st->tx[0] = KXSD9_WRITE(KXSD9_REG_CTRL_C); + st->tx[1] = (ret & ~KXSD9_FS_MASK) | i; + + ret = spi_write(st->us, st->tx, 2); +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +static int kxsd9_read(struct iio_dev *indio_dev, u8 address) +{ + struct spi_message msg; + int ret; + struct kxsd9_state *st = iio_priv(indio_dev); + struct spi_transfer xfers[] = { + { + .bits_per_word = 8, + .len = 1, + .delay_usecs = 200, + .tx_buf = st->tx, + }, { + .bits_per_word = 8, + .len = 2, + .rx_buf = st->rx, + }, + }; + + mutex_lock(&st->buf_lock); + st->tx[0] = KXSD9_READ(address); + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); + if (ret) + return ret; + return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0); +} + +static IIO_CONST_ATTR(accel_scale_available, + KXSD9_SCALE_2G " " + KXSD9_SCALE_4G " " + KXSD9_SCALE_6G " " + KXSD9_SCALE_8G); + +static struct attribute *kxsd9_attributes[] = { + &iio_const_attr_accel_scale_available.dev_attr.attr, + NULL, +}; + +static int kxsd9_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long mask) +{ + int ret = -EINVAL; + + if (mask == IIO_CHAN_INFO_SCALE) { + /* Check no integer component */ + if (val) + return -EINVAL; + ret = kxsd9_write_scale(indio_dev, val2); + } + + return ret; +} + +static int kxsd9_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + int ret = -EINVAL; + struct kxsd9_state *st = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = kxsd9_read(indio_dev, chan->address); + if (ret < 0) + goto error_ret; + *val = ret; + break; + case IIO_CHAN_INFO_SCALE: + ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C)); + if (ret) + goto error_ret; + *val2 = kxsd9_micro_scales[ret & KXSD9_FS_MASK]; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + } + +error_ret: + return ret; +}; +#define KXSD9_ACCEL_CHAN(axis) \ + { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT, \ + .address = KXSD9_REG_##axis, \ + } + +static const struct iio_chan_spec kxsd9_channels[] = { + KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z), + { + .type = IIO_VOLTAGE, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, + .indexed = 1, + .address = KXSD9_REG_AUX, + } +}; + +static const struct attribute_group kxsd9_attribute_group = { + .attrs = kxsd9_attributes, +}; + +static int kxsd9_power_up(struct kxsd9_state *st) +{ + int ret; + + st->tx[0] = 0x0d; + st->tx[1] = 0x40; + ret = spi_write(st->us, st->tx, 2); + if (ret) + return ret; + + st->tx[0] = 0x0c; + st->tx[1] = 0x9b; + return spi_write(st->us, st->tx, 2); +}; + +static const struct iio_info kxsd9_info = { + .read_raw = &kxsd9_read_raw, + .write_raw = &kxsd9_write_raw, + .attrs = &kxsd9_attribute_group, + .driver_module = THIS_MODULE, +}; + +static int kxsd9_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct kxsd9_state *st; + int ret; + + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) { + ret = -ENOMEM; + goto error_ret; + } + st = iio_priv(indio_dev); + spi_set_drvdata(spi, indio_dev); + + st->us = spi; + mutex_init(&st->buf_lock); + indio_dev->channels = kxsd9_channels; + indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels); + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->dev.parent = &spi->dev; + indio_dev->info = &kxsd9_info; + indio_dev->modes = INDIO_DIRECT_MODE; + + spi->mode = SPI_MODE_0; + spi_setup(spi); + kxsd9_power_up(st); + + ret = iio_device_register(indio_dev); + if (ret) + goto error_free_dev; + + return 0; + +error_free_dev: + iio_device_free(indio_dev); +error_ret: + return ret; +} + +static int kxsd9_remove(struct spi_device *spi) +{ + iio_device_unregister(spi_get_drvdata(spi)); + iio_device_free(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id kxsd9_id[] = { + {"kxsd9", 0}, + { }, +}; +MODULE_DEVICE_TABLE(spi, kxsd9_id); + +static struct spi_driver kxsd9_driver = { + .driver = { + .name = "kxsd9", + .owner = THIS_MODULE, + }, + .probe = kxsd9_probe, + .remove = kxsd9_remove, + .id_table = kxsd9_id, +}; +module_spi_driver(kxsd9_driver); + +MODULE_AUTHOR("Jonathan Cameron "); +MODULE_DESCRIPTION("Kionix KXSD9 SPI driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig index fa772a9..e2e786d 100644 --- a/drivers/staging/iio/accel/Kconfig +++ b/drivers/staging/iio/accel/Kconfig @@ -56,13 +56,6 @@ config ADIS16240 Say yes here to build support for Analog Devices adis16240 programmable impact Sensor and recorder. -config KXSD9 - tristate "Kionix KXSD9 Accelerometer Driver" - depends on SPI - help - Say yes here to build support for the Kionix KXSD9 accelerometer. - Currently this only supports the device via an SPI interface. - config LIS3L02DQ tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver" depends on SPI diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile index 8e7ee03..1ed137f 100644 --- a/drivers/staging/iio/accel/Makefile +++ b/drivers/staging/iio/accel/Makefile @@ -20,8 +20,6 @@ obj-$(CONFIG_ADIS16220) += adis16220.o adis16240-y := adis16240_core.o obj-$(CONFIG_ADIS16240) += adis16240.o -obj-$(CONFIG_KXSD9) += kxsd9.o - lis3l02dq-y := lis3l02dq_core.o lis3l02dq-$(CONFIG_IIO_BUFFER) += lis3l02dq_ring.o obj-$(CONFIG_LIS3L02DQ) += lis3l02dq.o diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/staging/iio/accel/kxsd9.c deleted file mode 100644 index 4a24c2e..0000000 --- a/drivers/staging/iio/accel/kxsd9.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * kxsd9.c simple support for the Kionix KXSD9 3D - * accelerometer. - * - * Copyright (c) 2008-2009 Jonathan Cameron - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * The i2c interface is very similar, so shouldn't be a problem once - * I have a suitable wire made up. - * - * TODO: Support the motion detector - * Uses register address incrementing so could have a - * heavily optimized ring buffer access function. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#define KXSD9_REG_X 0x00 -#define KXSD9_REG_Y 0x02 -#define KXSD9_REG_Z 0x04 -#define KXSD9_REG_AUX 0x06 -#define KXSD9_REG_RESET 0x0a -#define KXSD9_REG_CTRL_C 0x0c - -#define KXSD9_FS_MASK 0x03 - -#define KXSD9_REG_CTRL_B 0x0d -#define KXSD9_REG_CTRL_A 0x0e - -#define KXSD9_READ(a) (0x80 | (a)) -#define KXSD9_WRITE(a) (a) - -#define KXSD9_STATE_RX_SIZE 2 -#define KXSD9_STATE_TX_SIZE 2 -/** - * struct kxsd9_state - device related storage - * @buf_lock: protect the rx and tx buffers. - * @us: spi device - * @rx: single rx buffer storage - * @tx: single tx buffer storage - **/ -struct kxsd9_state { - struct mutex buf_lock; - struct spi_device *us; - u8 rx[KXSD9_STATE_RX_SIZE] ____cacheline_aligned; - u8 tx[KXSD9_STATE_TX_SIZE]; -}; - -#define KXSD9_SCALE_2G "0.011978" -#define KXSD9_SCALE_4G "0.023927" -#define KXSD9_SCALE_6G "0.035934" -#define KXSD9_SCALE_8G "0.047853" - -/* reverse order */ -static const int kxsd9_micro_scales[4] = { 47853, 35934, 23927, 11978 }; - -static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro) -{ - int ret, i; - struct kxsd9_state *st = iio_priv(indio_dev); - bool foundit = false; - - for (i = 0; i < 4; i++) - if (micro == kxsd9_micro_scales[i]) { - foundit = true; - break; - } - if (!foundit) - return -EINVAL; - - mutex_lock(&st->buf_lock); - ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C)); - if (ret) - goto error_ret; - st->tx[0] = KXSD9_WRITE(KXSD9_REG_CTRL_C); - st->tx[1] = (ret & ~KXSD9_FS_MASK) | i; - - ret = spi_write(st->us, st->tx, 2); -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static int kxsd9_read(struct iio_dev *indio_dev, u8 address) -{ - struct spi_message msg; - int ret; - struct kxsd9_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .bits_per_word = 8, - .len = 1, - .delay_usecs = 200, - .tx_buf = st->tx, - }, { - .bits_per_word = 8, - .len = 2, - .rx_buf = st->rx, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = KXSD9_READ(address); - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) - return ret; - return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0); -} - -static IIO_CONST_ATTR(accel_scale_available, - KXSD9_SCALE_2G " " - KXSD9_SCALE_4G " " - KXSD9_SCALE_6G " " - KXSD9_SCALE_8G); - -static struct attribute *kxsd9_attributes[] = { - &iio_const_attr_accel_scale_available.dev_attr.attr, - NULL, -}; - -static int kxsd9_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - int ret = -EINVAL; - - if (mask == IIO_CHAN_INFO_SCALE) { - /* Check no integer component */ - if (val) - return -EINVAL; - ret = kxsd9_write_scale(indio_dev, val2); - } - - return ret; -} - -static int kxsd9_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) -{ - int ret = -EINVAL; - struct kxsd9_state *st = iio_priv(indio_dev); - - switch (mask) { - case IIO_CHAN_INFO_RAW: - ret = kxsd9_read(indio_dev, chan->address); - if (ret < 0) - goto error_ret; - *val = ret; - break; - case IIO_CHAN_INFO_SCALE: - ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C)); - if (ret) - goto error_ret; - *val2 = kxsd9_micro_scales[ret & KXSD9_FS_MASK]; - ret = IIO_VAL_INT_PLUS_MICRO; - break; - } - -error_ret: - return ret; -}; -#define KXSD9_ACCEL_CHAN(axis) \ - { \ - .type = IIO_ACCEL, \ - .modified = 1, \ - .channel2 = IIO_MOD_##axis, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT, \ - .address = KXSD9_REG_##axis, \ - } - -static const struct iio_chan_spec kxsd9_channels[] = { - KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z), - { - .type = IIO_VOLTAGE, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, - .indexed = 1, - .address = KXSD9_REG_AUX, - } -}; - -static const struct attribute_group kxsd9_attribute_group = { - .attrs = kxsd9_attributes, -}; - -static int kxsd9_power_up(struct kxsd9_state *st) -{ - int ret; - - st->tx[0] = 0x0d; - st->tx[1] = 0x40; - ret = spi_write(st->us, st->tx, 2); - if (ret) - return ret; - - st->tx[0] = 0x0c; - st->tx[1] = 0x9b; - return spi_write(st->us, st->tx, 2); -}; - -static const struct iio_info kxsd9_info = { - .read_raw = &kxsd9_read_raw, - .write_raw = &kxsd9_write_raw, - .attrs = &kxsd9_attribute_group, - .driver_module = THIS_MODULE, -}; - -static int kxsd9_probe(struct spi_device *spi) -{ - struct iio_dev *indio_dev; - struct kxsd9_state *st; - int ret; - - indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } - st = iio_priv(indio_dev); - spi_set_drvdata(spi, indio_dev); - - st->us = spi; - mutex_init(&st->buf_lock); - indio_dev->channels = kxsd9_channels; - indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels); - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->dev.parent = &spi->dev; - indio_dev->info = &kxsd9_info; - indio_dev->modes = INDIO_DIRECT_MODE; - - spi->mode = SPI_MODE_0; - spi_setup(spi); - kxsd9_power_up(st); - - ret = iio_device_register(indio_dev); - if (ret) - goto error_free_dev; - - return 0; - -error_free_dev: - iio_device_free(indio_dev); -error_ret: - return ret; -} - -static int kxsd9_remove(struct spi_device *spi) -{ - iio_device_unregister(spi_get_drvdata(spi)); - iio_device_free(spi_get_drvdata(spi)); - - return 0; -} - -static const struct spi_device_id kxsd9_id[] = { - {"kxsd9", 0}, - { }, -}; -MODULE_DEVICE_TABLE(spi, kxsd9_id); - -static struct spi_driver kxsd9_driver = { - .driver = { - .name = "kxsd9", - .owner = THIS_MODULE, - }, - .probe = kxsd9_probe, - .remove = kxsd9_remove, - .id_table = kxsd9_id, -}; -module_spi_driver(kxsd9_driver); - -MODULE_AUTHOR("Jonathan Cameron "); -MODULE_DESCRIPTION("Kionix KXSD9 SPI driver"); -MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 232827fb8168d07844a589f0d4991afab16a23ea Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Mon, 21 Jan 2013 21:14:00 +0000 Subject: staging/iio: Use correct argument for sizeof found with coccicheck sizeof when applied to a pointer typed expression gives the size of the pointer The semantic patch that makes this output is available in scripts/coccinelle/misc/noderef.cocci. More information about semantic patching is available at http://coccinelle.lip6.fr/ Signed-off-by: Peter Huewe Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c index c7a5f97..97ad645 100644 --- a/drivers/staging/iio/iio_hwmon.c +++ b/drivers/staging/iio/iio_hwmon.c @@ -93,7 +93,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) while (st->channels[st->num_channels].indio_dev) st->num_channels++; - st->attrs = kzalloc(sizeof(st->attrs) * (st->num_channels + 1), + st->attrs = kzalloc(sizeof(*st->attrs) * (st->num_channels + 1), GFP_KERNEL); if (st->attrs == NULL) { ret = -ENOMEM; -- cgit v0.10.2 From 5e1f9aca0a8f8696a97cb1637b3f7eb89688e393 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 21 Jan 2013 20:05:00 +0000 Subject: iio: mxs: Add MX23 support into the IIO driver This patch adds support for i.MX23 into the LRADC driver. The LRADC block on MX23 is not much different from the one on MX28, thus this is only a few changes fixing the parts that are specific to MX23. Signed-off-by: Marek Vasut Cc: Fabio Estevam Cc: Jonathan Cameron Cc: Shawn Guo Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index fb8c239..7b2a01d 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -119,12 +119,12 @@ config LPC32XX_ADC via sysfs. config MXS_LRADC - tristate "Freescale i.MX28 LRADC" + tristate "Freescale i.MX23/i.MX28 LRADC" depends on ARCH_MXS select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for i.MX28 LRADC convertor + Say yes here to build support for i.MX23/i.MX28 LRADC convertor built into these chips. To compile this driver as a module, choose M here: the diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index e472871..b1b8c42 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -76,7 +76,24 @@ */ #define LRADC_TS_SAMPLE_AMOUNT 4 -static const char * const mxs_lradc_irq_name[] = { +enum mxs_lradc_id { + IMX23_LRADC, + IMX28_LRADC, +}; + +static const char * const mx23_lradc_irq_names[] = { + "mxs-lradc-touchscreen", + "mxs-lradc-channel0", + "mxs-lradc-channel1", + "mxs-lradc-channel2", + "mxs-lradc-channel3", + "mxs-lradc-channel4", + "mxs-lradc-channel5", + "mxs-lradc-channel6", + "mxs-lradc-channel7", +}; + +static const char * const mx28_lradc_irq_names[] = { "mxs-lradc-touchscreen", "mxs-lradc-thresh0", "mxs-lradc-thresh1", @@ -92,6 +109,22 @@ static const char * const mxs_lradc_irq_name[] = { "mxs-lradc-button1", }; +struct mxs_lradc_of_config { + const int irq_count; + const char * const *irq_name; +}; + +static const struct mxs_lradc_of_config const mxs_lradc_of_config[] = { + [IMX23_LRADC] = { + .irq_count = ARRAY_SIZE(mx23_lradc_irq_names), + .irq_name = mx23_lradc_irq_names, + }, + [IMX28_LRADC] = { + .irq_count = ARRAY_SIZE(mx28_lradc_irq_names), + .irq_name = mx28_lradc_irq_names, + }, +}; + enum mxs_lradc_ts { MXS_LRADC_TOUCHSCREEN_NONE = 0, MXS_LRADC_TOUCHSCREEN_4WIRE, @@ -857,8 +890,19 @@ static void mxs_lradc_hw_stop(struct mxs_lradc *lradc) writel(0, lradc->base + LRADC_DELAY(i)); } +static const struct of_device_id mxs_lradc_dt_ids[] = { + { .compatible = "fsl,imx23-lradc", .data = (void *)IMX23_LRADC, }, + { .compatible = "fsl,imx28-lradc", .data = (void *)IMX28_LRADC, }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids); + static int mxs_lradc_probe(struct platform_device *pdev) { + const struct of_device_id *of_id = + of_match_device(mxs_lradc_dt_ids, &pdev->dev); + const struct mxs_lradc_of_config *of_cfg = + &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data]; struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct mxs_lradc *lradc; @@ -902,7 +946,7 @@ static int mxs_lradc_probe(struct platform_device *pdev) ts_wires); /* Grab all IRQ sources */ - for (i = 0; i < 13; i++) { + for (i = 0; i < of_cfg->irq_count; i++) { lradc->irq[i] = platform_get_irq(pdev, i); if (lradc->irq[i] < 0) { ret = -EINVAL; @@ -911,7 +955,7 @@ static int mxs_lradc_probe(struct platform_device *pdev) ret = devm_request_irq(dev, lradc->irq[i], mxs_lradc_handle_irq, 0, - mxs_lradc_irq_name[i], iio); + of_cfg->irq_name[i], iio); if (ret) goto err_addr; } @@ -983,12 +1027,6 @@ static int mxs_lradc_remove(struct platform_device *pdev) return 0; } -static const struct of_device_id mxs_lradc_dt_ids[] = { - { .compatible = "fsl,imx28-lradc", }, - { /* sentinel */ } -}; -MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids); - static struct platform_driver mxs_lradc_driver = { .driver = { .name = DRIVER_NAME, -- cgit v0.10.2 From 1f45188c40432843825865582ace8d118f9ed407 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 21 Jan 2013 20:05:00 +0000 Subject: ARM: mxs: Add OF props for MX23 LRADC Add interrupt mapping and compatible string for MX23 LRADC. Signed-off-by: Marek Vasut Cc: Fabio Estevam Acked-by: Shawn Guo Signed-off-by: Jonathan Cameron diff --git a/arch/arm/boot/dts/imx23.dtsi b/arch/arm/boot/dts/imx23.dtsi index 65415c5..56afcf4 100644 --- a/arch/arm/boot/dts/imx23.dtsi +++ b/arch/arm/boot/dts/imx23.dtsi @@ -391,7 +391,9 @@ }; lradc@80050000 { + compatible = "fsl,imx23-lradc"; reg = <0x80050000 0x2000>; + interrupts = <36 37 38 39 40 41 42 43 44>; status = "disabled"; }; -- cgit v0.10.2 From c21ab7005140bdc5898907f73a5d73a86ea60a5d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 14:01:00 +0000 Subject: staging:iio:adis16080: Add device id table entry for the adis16100 The adis16100 is very similar to the adis16080. The driver description already states that the driver supports the adis16100 as-well. But so far the there is no device id table for the adis16100 and the drivers does not bind to a device named adis16100. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig index 87979a0..a439e05 100644 --- a/drivers/staging/iio/gyro/Kconfig +++ b/drivers/staging/iio/gyro/Kconfig @@ -14,8 +14,8 @@ config ADIS16080 tristate "Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver" depends on SPI help - Say yes here to build support for Analog Devices adis16080/100 Yaw Rate - Gyroscope with SPI. + Say yes here to build support for Analog Devices ADIS16080, ADIS16100 Yaw + Rate Gyroscope with SPI. config ADIS16130 tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver" diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index 41d7350..2eb559c 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -185,6 +185,13 @@ static int adis16080_remove(struct spi_device *spi) return 0; } +static const struct spi_device_id adis16080_ids[] = { + { "adis16080", 0 }, + { "adis16100", 0 }, + {}, +}; +MODULE_DEVICE_TABLE(spi, adis16080_ids); + static struct spi_driver adis16080_driver = { .driver = { .name = "adis16080", @@ -192,10 +199,10 @@ static struct spi_driver adis16080_driver = { }, .probe = adis16080_probe, .remove = adis16080_remove, + .id_table = adis16080_ids, }; module_spi_driver(adis16080_driver); MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); MODULE_DESCRIPTION("Analog Devices ADIS16080/100 Yaw Rate Gyroscope Driver"); MODULE_LICENSE("GPL v2"); -MODULE_ALIAS("spi:adis16080"); -- cgit v0.10.2 From 9ab82f071125e340a052570df90813b11574f8d4 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 14:01:00 +0000 Subject: staging:iio:adis16080: Cleanup SPI transfer During sampling the driver currently does a spi_read followed by a spi_write. This is not a problem per se, since CS needs to be deasserted between the two transfers. So even if another device claims the bus between the two transfers we should still get a result. But the code is actually spread out over multiple functions. E.g. the spi_read happens in one function the spi_write in another, this makes the code harder to follow. This patch re-factors the code to just use a single spi transaction to do both the read and the write transfer. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index 2eb559c..ddeae16 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -42,32 +42,32 @@ struct adis16080_state { u8 buf[2] ____cacheline_aligned; }; -static int adis16080_spi_write(struct iio_dev *indio_dev, - u16 val) +static int adis16080_read_sample(struct iio_dev *indio_dev, + u16 addr, int *val) { - int ret; struct adis16080_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->buf[0] = val >> 8; - st->buf[1] = val; - - ret = spi_write(st->us, st->buf, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -static int adis16080_spi_read(struct iio_dev *indio_dev, - u16 *val) -{ + struct spi_message m; int ret; - struct adis16080_state *st = iio_priv(indio_dev); + struct spi_transfer t[] = { + { + .tx_buf = &st->buf, + .len = 2, + .cs_change = 1, + }, { + .rx_buf = &st->buf, + .len = 2, + }, + }; mutex_lock(&st->buf_lock); + st->buf[0] = addr >> 8; + st->buf[1] = addr; - ret = spi_read(st->us, st->buf, 2); + spi_message_init(&m); + spi_message_add_tail(&t[0], &m); + spi_message_add_tail(&t[1], &m); + ret = spi_sync(st->us, &m); if (ret == 0) *val = sign_extend32(((st->buf[0] & 0xF) << 8) | st->buf[1], 11); mutex_unlock(&st->buf_lock); @@ -81,28 +81,17 @@ static int adis16080_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { - int ret = -EINVAL; - u16 ut = 0; - /* Take the iio_dev status lock */ + int ret; - mutex_lock(&indio_dev->mlock); switch (mask) { case IIO_CHAN_INFO_RAW: - ret = adis16080_spi_write(indio_dev, - chan->address | - ADIS16080_DIN_WRITE); - if (ret < 0) - break; - ret = adis16080_spi_read(indio_dev, &ut); - if (ret < 0) - break; - *val = ut; - ret = IIO_VAL_INT; - break; + mutex_lock(&indio_dev->mlock); + ret = adis16080_read_sample(indio_dev, chan->address, val); + mutex_unlock(&indio_dev->mlock); + return ret ? ret : IIO_VAL_INT; } - mutex_unlock(&indio_dev->mlock); - return ret; + return -EINVAL; } static const struct iio_chan_spec adis16080_channels[] = { -- cgit v0.10.2 From 3c80372dae17cb1a5a493c9ed02f7ca2a8d9ce53 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 14:01:00 +0000 Subject: staging:iio:adis16080: be16 cleanups The sample buffer contains big endian 16bit words. So use the be16 datatype for the buffer and use the proper helper functions for endianness conversion instead of openconding it. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index ddeae16..d033b6f 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -39,7 +39,7 @@ struct adis16080_state { struct spi_device *us; struct mutex buf_lock; - u8 buf[2] ____cacheline_aligned; + __be16 buf ____cacheline_aligned; }; static int adis16080_read_sample(struct iio_dev *indio_dev, @@ -60,8 +60,7 @@ static int adis16080_read_sample(struct iio_dev *indio_dev, }; mutex_lock(&st->buf_lock); - st->buf[0] = addr >> 8; - st->buf[1] = addr; + st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE); spi_message_init(&m); spi_message_add_tail(&t[0], &m); @@ -69,7 +68,7 @@ static int adis16080_read_sample(struct iio_dev *indio_dev, ret = spi_sync(st->us, &m); if (ret == 0) - *val = sign_extend32(((st->buf[0] & 0xF) << 8) | st->buf[1], 11); + *val = sign_extend32(be16_to_cpu(st->buf), 11); mutex_unlock(&st->buf_lock); return ret; -- cgit v0.10.2 From 61992d993beb5af8c64c617ec474439079aa726d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 14:01:00 +0000 Subject: staging:iio:adis16080: Remove unnecessary lock All sections in which the transfer buffer is accessed are already protected by the IIO device's mlock. So we do not need the extra mutex protecting the buffer. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index d033b6f..76764ba 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -33,11 +33,9 @@ * struct adis16080_state - device instance specific data * @us: actual spi_device to write data * @buf: transmit or receive buffer - * @buf_lock: mutex to protect tx and rx **/ struct adis16080_state { struct spi_device *us; - struct mutex buf_lock; __be16 buf ____cacheline_aligned; }; @@ -59,7 +57,6 @@ static int adis16080_read_sample(struct iio_dev *indio_dev, }, }; - mutex_lock(&st->buf_lock); st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE); spi_message_init(&m); @@ -69,7 +66,6 @@ static int adis16080_read_sample(struct iio_dev *indio_dev, ret = spi_sync(st->us, &m); if (ret == 0) *val = sign_extend32(be16_to_cpu(st->buf), 11); - mutex_unlock(&st->buf_lock); return ret; } @@ -144,7 +140,6 @@ static int adis16080_probe(struct spi_device *spi) /* Allocate the comms buffers */ st->us = spi; - mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; indio_dev->channels = adis16080_channels; -- cgit v0.10.2 From 668cce24965a454f110c5835e0a2198a9aea55af Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 14:01:00 +0000 Subject: staging:iio:adis16080: Add scale and offset attributes Report scale and offset for the velocity, voltage and temperature channels. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index 76764ba..098a0a1 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -29,13 +29,20 @@ #define ADIS16080_DIN_WRITE (1 << 15) +struct adis16080_chip_info { + int scale_val; + int scale_val2; +}; + /** * struct adis16080_state - device instance specific data * @us: actual spi_device to write data + * @info: chip specific parameters * @buf: transmit or receive buffer **/ struct adis16080_state { struct spi_device *us; + const struct adis16080_chip_info *info; __be16 buf ____cacheline_aligned; }; @@ -76,6 +83,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { + struct adis16080_state *st = iio_priv(indio_dev); int ret; switch (mask) { @@ -84,6 +92,40 @@ static int adis16080_read_raw(struct iio_dev *indio_dev, ret = adis16080_read_sample(indio_dev, chan->address, val); mutex_unlock(&indio_dev->mlock); return ret ? ret : IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = st->info->scale_val; + *val2 = st->info->scale_val2; + return IIO_VAL_FRACTIONAL; + case IIO_VOLTAGE: + /* VREF = 5V, 12 bits */ + *val = 5000; + *val2 = 12; + return IIO_VAL_FRACTIONAL_LOG2; + case IIO_TEMP: + /* 85 C = 585, 25 C = 0 */ + *val = 85000 - 25000; + *val2 = 585; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_VOLTAGE: + /* 2.5 V = 0 */ + *val = 2048; + return IIO_VAL_INT; + case IIO_TEMP: + /* 85 C = 585, 25 C = 0 */ + *val = DIV_ROUND_CLOSEST(25 * 585, 85 - 25); + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + break; } return -EINVAL; @@ -94,25 +136,32 @@ static const struct iio_chan_spec adis16080_channels[] = { .type = IIO_ANGL_VEL, .modified = 1, .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, .address = ADIS16080_DIN_GYRO, }, { .type = IIO_VOLTAGE, .indexed = 1, .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, .address = ADIS16080_DIN_AIN1, }, { .type = IIO_VOLTAGE, .indexed = 1, .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, .address = ADIS16080_DIN_AIN2, }, { .type = IIO_TEMP, .indexed = 1, .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, .address = ADIS16080_DIN_TEMP, } }; @@ -122,8 +171,27 @@ static const struct iio_info adis16080_info = { .driver_module = THIS_MODULE, }; +enum { + ID_ADIS16080, + ID_ADIS16100, +}; + +static const struct adis16080_chip_info adis16080_chip_info[] = { + [ID_ADIS16080] = { + /* 80 degree = 819, 819 rad = 46925 degree */ + .scale_val = 80, + .scale_val2 = 46925, + }, + [ID_ADIS16100] = { + /* 300 degree = 1230, 1230 rad = 70474 degree */ + .scale_val = 300, + .scale_val2 = 70474, + }, +}; + static int adis16080_probe(struct spi_device *spi) { + const struct spi_device_id *id = spi_get_device_id(spi); int ret; struct adis16080_state *st; struct iio_dev *indio_dev; @@ -140,6 +208,7 @@ static int adis16080_probe(struct spi_device *spi) /* Allocate the comms buffers */ st->us = spi; + st->info = &adis16080_chip_info[id->driver_data]; indio_dev->name = spi->dev.driver->name; indio_dev->channels = adis16080_channels; @@ -169,8 +238,8 @@ static int adis16080_remove(struct spi_device *spi) } static const struct spi_device_id adis16080_ids[] = { - { "adis16080", 0 }, - { "adis16100", 0 }, + { "adis16080", ID_ADIS16080 }, + { "adis16100", ID_ADIS16100 }, {}, }; MODULE_DEVICE_TABLE(spi, adis16080_ids); -- cgit v0.10.2 From a9fbbee8a2e90f88ff605ec72b388ec20b808ee4 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 14:01:00 +0000 Subject: staging:iio:adis16080: Move out of staging The driver is rather simple and in a good shape. It follows the IIO ABI and the standard codechecker tools do not report any issues, so move it out of staging. While moving it also remove one outdated 'fixme' comment. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 96b68f6..752ac8a 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -3,6 +3,13 @@ # menu "Digital gyroscope sensors" +config ADIS16080 + tristate "Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADIS16080, ADIS16100 Yaw + Rate Gyroscope with SPI. + config ADIS16136 tristate "Analog devices ADIS16136 and similar gyroscopes driver" depends on SPI_MASTER diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index 702a058..9b090ee 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -2,5 +2,6 @@ # Makefile for industrial I/O gyroscope sensor drivers # +obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16136) += adis16136.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o diff --git a/drivers/iio/gyro/adis16080.c b/drivers/iio/gyro/adis16080.c new file mode 100644 index 0000000..1861287 --- /dev/null +++ b/drivers/iio/gyro/adis16080.c @@ -0,0 +1,259 @@ +/* + * ADIS16080/100 Yaw Rate Gyroscope with SPI driver + * + * Copyright 2010 Analog Devices Inc. + * + * Licensed under the GPL-2 or later. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */ +#define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */ +#define ADIS16080_DIN_AIN1 (2 << 10) +#define ADIS16080_DIN_AIN2 (3 << 10) + +/* + * 1: Write contents on DIN to control register. + * 0: No changes to control register. + */ + +#define ADIS16080_DIN_WRITE (1 << 15) + +struct adis16080_chip_info { + int scale_val; + int scale_val2; +}; + +/** + * struct adis16080_state - device instance specific data + * @us: actual spi_device to write data + * @info: chip specific parameters + * @buf: transmit or receive buffer + **/ +struct adis16080_state { + struct spi_device *us; + const struct adis16080_chip_info *info; + + __be16 buf ____cacheline_aligned; +}; + +static int adis16080_read_sample(struct iio_dev *indio_dev, + u16 addr, int *val) +{ + struct adis16080_state *st = iio_priv(indio_dev); + struct spi_message m; + int ret; + struct spi_transfer t[] = { + { + .tx_buf = &st->buf, + .len = 2, + .cs_change = 1, + }, { + .rx_buf = &st->buf, + .len = 2, + }, + }; + + st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE); + + spi_message_init(&m); + spi_message_add_tail(&t[0], &m); + spi_message_add_tail(&t[1], &m); + + ret = spi_sync(st->us, &m); + if (ret == 0) + *val = sign_extend32(be16_to_cpu(st->buf), 11); + + return ret; +} + +static int adis16080_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) +{ + struct adis16080_state *st = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + mutex_lock(&indio_dev->mlock); + ret = adis16080_read_sample(indio_dev, chan->address, val); + mutex_unlock(&indio_dev->mlock); + return ret ? ret : IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = st->info->scale_val; + *val2 = st->info->scale_val2; + return IIO_VAL_FRACTIONAL; + case IIO_VOLTAGE: + /* VREF = 5V, 12 bits */ + *val = 5000; + *val2 = 12; + return IIO_VAL_FRACTIONAL_LOG2; + case IIO_TEMP: + /* 85 C = 585, 25 C = 0 */ + *val = 85000 - 25000; + *val2 = 585; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_VOLTAGE: + /* 2.5 V = 0 */ + *val = 2048; + return IIO_VAL_INT; + case IIO_TEMP: + /* 85 C = 585, 25 C = 0 */ + *val = DIV_ROUND_CLOSEST(25 * 585, 85 - 25); + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + break; + } + + return -EINVAL; +} + +static const struct iio_chan_spec adis16080_channels[] = { + { + .type = IIO_ANGL_VEL, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + .address = ADIS16080_DIN_GYRO, + }, { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, + .address = ADIS16080_DIN_AIN1, + }, { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, + .address = ADIS16080_DIN_AIN2, + }, { + .type = IIO_TEMP, + .indexed = 1, + .channel = 0, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, + .address = ADIS16080_DIN_TEMP, + } +}; + +static const struct iio_info adis16080_info = { + .read_raw = &adis16080_read_raw, + .driver_module = THIS_MODULE, +}; + +enum { + ID_ADIS16080, + ID_ADIS16100, +}; + +static const struct adis16080_chip_info adis16080_chip_info[] = { + [ID_ADIS16080] = { + /* 80 degree = 819, 819 rad = 46925 degree */ + .scale_val = 80, + .scale_val2 = 46925, + }, + [ID_ADIS16100] = { + /* 300 degree = 1230, 1230 rad = 70474 degree */ + .scale_val = 300, + .scale_val2 = 70474, + }, +}; + +static int adis16080_probe(struct spi_device *spi) +{ + const struct spi_device_id *id = spi_get_device_id(spi); + int ret; + struct adis16080_state *st; + struct iio_dev *indio_dev; + + /* setup the industrialio driver allocated elements */ + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) { + ret = -ENOMEM; + goto error_ret; + } + st = iio_priv(indio_dev); + /* this is only used for removal purposes */ + spi_set_drvdata(spi, indio_dev); + + /* Allocate the comms buffers */ + st->us = spi; + st->info = &adis16080_chip_info[id->driver_data]; + + indio_dev->name = spi->dev.driver->name; + indio_dev->channels = adis16080_channels; + indio_dev->num_channels = ARRAY_SIZE(adis16080_channels); + indio_dev->dev.parent = &spi->dev; + indio_dev->info = &adis16080_info; + indio_dev->modes = INDIO_DIRECT_MODE; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_free_dev; + return 0; + +error_free_dev: + iio_device_free(indio_dev); +error_ret: + return ret; +} + +static int adis16080_remove(struct spi_device *spi) +{ + iio_device_unregister(spi_get_drvdata(spi)); + iio_device_free(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id adis16080_ids[] = { + { "adis16080", ID_ADIS16080 }, + { "adis16100", ID_ADIS16100 }, + {}, +}; +MODULE_DEVICE_TABLE(spi, adis16080_ids); + +static struct spi_driver adis16080_driver = { + .driver = { + .name = "adis16080", + .owner = THIS_MODULE, + }, + .probe = adis16080_probe, + .remove = adis16080_remove, + .id_table = adis16080_ids, +}; +module_spi_driver(adis16080_driver); + +MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); +MODULE_DESCRIPTION("Analog Devices ADIS16080/100 Yaw Rate Gyroscope Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig index a439e05..658b367 100644 --- a/drivers/staging/iio/gyro/Kconfig +++ b/drivers/staging/iio/gyro/Kconfig @@ -10,13 +10,6 @@ config ADIS16060 Say yes here to build support for Analog Devices adis16060 wide bandwidth yaw rate gyroscope with SPI. -config ADIS16080 - tristate "Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver" - depends on SPI - help - Say yes here to build support for Analog Devices ADIS16080, ADIS16100 Yaw - Rate Gyroscope with SPI. - config ADIS16130 tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver" depends on SPI diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile index 79bef4e..ef33161 100644 --- a/drivers/staging/iio/gyro/Makefile +++ b/drivers/staging/iio/gyro/Makefile @@ -5,9 +5,6 @@ adis16060-y := adis16060_core.o obj-$(CONFIG_ADIS16060) += adis16060.o -adis16080-y := adis16080_core.o -obj-$(CONFIG_ADIS16080) += adis16080.o - adis16130-y := adis16130_core.o obj-$(CONFIG_ADIS16130) += adis16130.o diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c deleted file mode 100644 index 098a0a1..0000000 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * ADIS16080/100 Yaw Rate Gyroscope with SPI driver - * - * Copyright 2010 Analog Devices Inc. - * - * Licensed under the GPL-2 or later. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */ -#define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */ -#define ADIS16080_DIN_AIN1 (2 << 10) -#define ADIS16080_DIN_AIN2 (3 << 10) - -/* - * 1: Write contents on DIN to control register. - * 0: No changes to control register. - */ - -#define ADIS16080_DIN_WRITE (1 << 15) - -struct adis16080_chip_info { - int scale_val; - int scale_val2; -}; - -/** - * struct adis16080_state - device instance specific data - * @us: actual spi_device to write data - * @info: chip specific parameters - * @buf: transmit or receive buffer - **/ -struct adis16080_state { - struct spi_device *us; - const struct adis16080_chip_info *info; - - __be16 buf ____cacheline_aligned; -}; - -static int adis16080_read_sample(struct iio_dev *indio_dev, - u16 addr, int *val) -{ - struct adis16080_state *st = iio_priv(indio_dev); - struct spi_message m; - int ret; - struct spi_transfer t[] = { - { - .tx_buf = &st->buf, - .len = 2, - .cs_change = 1, - }, { - .rx_buf = &st->buf, - .len = 2, - }, - }; - - st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE); - - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - - ret = spi_sync(st->us, &m); - if (ret == 0) - *val = sign_extend32(be16_to_cpu(st->buf), 11); - - return ret; -} - -static int adis16080_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long mask) -{ - struct adis16080_state *st = iio_priv(indio_dev); - int ret; - - switch (mask) { - case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - ret = adis16080_read_sample(indio_dev, chan->address, val); - mutex_unlock(&indio_dev->mlock); - return ret ? ret : IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_ANGL_VEL: - *val = st->info->scale_val; - *val2 = st->info->scale_val2; - return IIO_VAL_FRACTIONAL; - case IIO_VOLTAGE: - /* VREF = 5V, 12 bits */ - *val = 5000; - *val2 = 12; - return IIO_VAL_FRACTIONAL_LOG2; - case IIO_TEMP: - /* 85 C = 585, 25 C = 0 */ - *val = 85000 - 25000; - *val2 = 585; - return IIO_VAL_FRACTIONAL; - default: - return -EINVAL; - } - case IIO_CHAN_INFO_OFFSET: - switch (chan->type) { - case IIO_VOLTAGE: - /* 2.5 V = 0 */ - *val = 2048; - return IIO_VAL_INT; - case IIO_TEMP: - /* 85 C = 585, 25 C = 0 */ - *val = DIV_ROUND_CLOSEST(25 * 585, 85 - 25); - return IIO_VAL_INT; - default: - return -EINVAL; - } - default: - break; - } - - return -EINVAL; -} - -static const struct iio_chan_spec adis16080_channels[] = { - { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = ADIS16080_DIN_GYRO, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = ADIS16080_DIN_AIN1, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = ADIS16080_DIN_AIN2, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = ADIS16080_DIN_TEMP, - } -}; - -static const struct iio_info adis16080_info = { - .read_raw = &adis16080_read_raw, - .driver_module = THIS_MODULE, -}; - -enum { - ID_ADIS16080, - ID_ADIS16100, -}; - -static const struct adis16080_chip_info adis16080_chip_info[] = { - [ID_ADIS16080] = { - /* 80 degree = 819, 819 rad = 46925 degree */ - .scale_val = 80, - .scale_val2 = 46925, - }, - [ID_ADIS16100] = { - /* 300 degree = 1230, 1230 rad = 70474 degree */ - .scale_val = 300, - .scale_val2 = 70474, - }, -}; - -static int adis16080_probe(struct spi_device *spi) -{ - const struct spi_device_id *id = spi_get_device_id(spi); - int ret; - struct adis16080_state *st; - struct iio_dev *indio_dev; - - /* setup the industrialio driver allocated elements */ - indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } - st = iio_priv(indio_dev); - /* this is only used for removal purposes */ - spi_set_drvdata(spi, indio_dev); - - /* Allocate the comms buffers */ - st->us = spi; - st->info = &adis16080_chip_info[id->driver_data]; - - indio_dev->name = spi->dev.driver->name; - indio_dev->channels = adis16080_channels; - indio_dev->num_channels = ARRAY_SIZE(adis16080_channels); - indio_dev->dev.parent = &spi->dev; - indio_dev->info = &adis16080_info; - indio_dev->modes = INDIO_DIRECT_MODE; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_free_dev; - return 0; - -error_free_dev: - iio_device_free(indio_dev); -error_ret: - return ret; -} - -/* fixme, confirm ordering in this function */ -static int adis16080_remove(struct spi_device *spi) -{ - iio_device_unregister(spi_get_drvdata(spi)); - iio_device_free(spi_get_drvdata(spi)); - - return 0; -} - -static const struct spi_device_id adis16080_ids[] = { - { "adis16080", ID_ADIS16080 }, - { "adis16100", ID_ADIS16100 }, - {}, -}; -MODULE_DEVICE_TABLE(spi, adis16080_ids); - -static struct spi_driver adis16080_driver = { - .driver = { - .name = "adis16080", - .owner = THIS_MODULE, - }, - .probe = adis16080_probe, - .remove = adis16080_remove, - .id_table = adis16080_ids, -}; -module_spi_driver(adis16080_driver); - -MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); -MODULE_DESCRIPTION("Analog Devices ADIS16080/100 Yaw Rate Gyroscope Driver"); -MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 5ade7633ac324098b31ae859f83cee73129d74d3 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 12 Jan 2013 10:35:00 +0000 Subject: staging:iio:light:tsl2563 drop unnecessary brackets around constants. Not sure why these were ever there. Signed-off-by: Jonathan Cameron Acked-by: Peter Meerwald diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c index 1a9adc0..1ee0a6f 100644 --- a/drivers/staging/iio/light/tsl2563.c +++ b/drivers/staging/iio/light/tsl2563.c @@ -41,49 +41,49 @@ #include "tsl2563.h" /* Use this many bits for fraction part. */ -#define ADC_FRAC_BITS (14) +#define ADC_FRAC_BITS 14 /* Given number of 1/10000's in ADC_FRAC_BITS precision. */ #define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000)) /* Bits used for fraction in calibration coefficients.*/ -#define CALIB_FRAC_BITS (10) +#define CALIB_FRAC_BITS 10 /* 0.5 in CALIB_FRAC_BITS precision */ #define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1)) /* Make a fraction from a number n that was multiplied with b. */ #define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b)) /* Decimal 10^(digits in sysfs presentation) */ -#define CALIB_BASE_SYSFS (1000) - -#define TSL2563_CMD (0x80) -#define TSL2563_CLEARINT (0x40) - -#define TSL2563_REG_CTRL (0x00) -#define TSL2563_REG_TIMING (0x01) -#define TSL2563_REG_LOWLOW (0x02) /* data0 low threshold, 2 bytes */ -#define TSL2563_REG_LOWHIGH (0x03) -#define TSL2563_REG_HIGHLOW (0x04) /* data0 high threshold, 2 bytes */ -#define TSL2563_REG_HIGHHIGH (0x05) -#define TSL2563_REG_INT (0x06) -#define TSL2563_REG_ID (0x0a) -#define TSL2563_REG_DATA0LOW (0x0c) /* broadband sensor value, 2 bytes */ -#define TSL2563_REG_DATA0HIGH (0x0d) -#define TSL2563_REG_DATA1LOW (0x0e) /* infrared sensor value, 2 bytes */ -#define TSL2563_REG_DATA1HIGH (0x0f) - -#define TSL2563_CMD_POWER_ON (0x03) -#define TSL2563_CMD_POWER_OFF (0x00) -#define TSL2563_CTRL_POWER_MASK (0x03) - -#define TSL2563_TIMING_13MS (0x00) -#define TSL2563_TIMING_100MS (0x01) -#define TSL2563_TIMING_400MS (0x02) -#define TSL2563_TIMING_MASK (0x03) -#define TSL2563_TIMING_GAIN16 (0x10) -#define TSL2563_TIMING_GAIN1 (0x00) - -#define TSL2563_INT_DISBLED (0x00) -#define TSL2563_INT_LEVEL (0x10) +#define CALIB_BASE_SYSFS 1000 + +#define TSL2563_CMD 0x80 +#define TSL2563_CLEARINT 0x40 + +#define TSL2563_REG_CTRL 0x00 +#define TSL2563_REG_TIMING 0x01 +#define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */ +#define TSL2563_REG_LOWHIGH 0x03 +#define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */ +#define TSL2563_REG_HIGHHIGH 0x05 +#define TSL2563_REG_INT 0x06 +#define TSL2563_REG_ID 0x0a +#define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */ +#define TSL2563_REG_DATA0HIGH 0x0d +#define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */ +#define TSL2563_REG_DATA1HIGH 0x0f + +#define TSL2563_CMD_POWER_ON 0x03 +#define TSL2563_CMD_POWER_OFF 0x00 +#define TSL2563_CTRL_POWER_MASK 0x03 + +#define TSL2563_TIMING_13MS 0x00 +#define TSL2563_TIMING_100MS 0x01 +#define TSL2563_TIMING_400MS 0x02 +#define TSL2563_TIMING_MASK 0x03 +#define TSL2563_TIMING_GAIN16 0x10 +#define TSL2563_TIMING_GAIN1 0x00 + +#define TSL2563_INT_DISBLED 0x00 +#define TSL2563_INT_LEVEL 0x10 #define TSL2563_INT_PERSIST(n) ((n) & 0x0F) struct tsl2563_gainlevel_coeff { -- cgit v0.10.2 From a9e244f65df170ae6efba03bdb0a203626ae1cd3 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 12 Jan 2013 10:35:00 +0000 Subject: staging:iio:light:tsl2563 clean comments up. Fix formatting of some comments and drop a few generic information free ones. Signed-off-by: Jonathan Cameron Acked-by: Peter Meerwald diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c index 1ee0a6f..547203c 100644 --- a/drivers/staging/iio/light/tsl2563.c +++ b/drivers/staging/iio/light/tsl2563.c @@ -190,8 +190,10 @@ static int tsl2563_configure(struct tsl2563_chip *chip) ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_LOWHIGH, (chip->low_thres >> 8) & 0xFF); -/* Interrupt register is automatically written anyway if it is relevant - so is not here */ +/* + * Interrupt register is automatically written anyway if it is relevant + * so is not here. + */ error_ret: return ret; } @@ -423,9 +425,7 @@ static const struct tsl2563_lux_coeff lux_table[] = { }, }; -/* - * Convert normalized, scaled ADC values to lux. - */ +/* Convert normalized, scaled ADC values to lux. */ static unsigned int adc_to_lux(u32 adc0, u32 adc1) { const struct tsl2563_lux_coeff *lp = lux_table; @@ -441,11 +441,6 @@ static unsigned int adc_to_lux(u32 adc0, u32 adc1) return (unsigned int) (lux >> ADC_FRAC_BITS); } -/*--------------------------------------------------------------*/ -/* Sysfs interface */ -/*--------------------------------------------------------------*/ - - /* Apply calibration coefficient to ADC count. */ static u32 calib_adc(u32 adc, u32 calib) { @@ -684,9 +679,6 @@ error_ret: return ret; } -/*--------------------------------------------------------------*/ -/* Probe, Attach, Remove */ -/*--------------------------------------------------------------*/ static struct i2c_driver tsl2563_i2c_driver; static const struct iio_info tsl2563_info_no_irq = { -- cgit v0.10.2 From a722dcca4da47a480a6042c0c0275695a597b77f Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 12 Jan 2013 10:35:00 +0000 Subject: staging:iio:tsl2563 Simplify exit path on error in read_interrupt_config. A rather over complicated exit path given there is only one exit route and nothing much is done after it. Signed-off-by: Jonathan Cameron Acked-by: Peter Meerwald diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c index 547203c..1a3092a 100644 --- a/drivers/staging/iio/light/tsl2563.c +++ b/drivers/staging/iio/light/tsl2563.c @@ -672,11 +672,9 @@ static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev, TSL2563_CMD | TSL2563_REG_INT); mutex_unlock(&chip->lock); if (ret < 0) - goto error_ret; - ret = !!(ret & 0x30); -error_ret: + return ret; - return ret; + return !!(ret & 0x30); } static struct i2c_driver tsl2563_i2c_driver; -- cgit v0.10.2 From af0b8ee32c831e6e8fbfe0b311b9ac017d14b78d Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 12 Jan 2013 10:35:00 +0000 Subject: staging:iio:tsl2563 drop pointless forward declaration Signed-off-by: Jonathan Cameron Acked-by: Peter Meerwald diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c index 1a3092a..b91d9bb 100644 --- a/drivers/staging/iio/light/tsl2563.c +++ b/drivers/staging/iio/light/tsl2563.c @@ -677,8 +677,6 @@ static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev, return !!(ret & 0x30); } -static struct i2c_driver tsl2563_i2c_driver; - static const struct iio_info tsl2563_info_no_irq = { .driver_module = THIS_MODULE, .read_raw = &tsl2563_read_raw, -- cgit v0.10.2 From 9c2251dd4b7feba14d35835c6835024840b1f76b Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 12 Jan 2013 10:35:00 +0000 Subject: iio:light:tsl2563 move out of staging This driver is simple, uses the latest interfaces and contains few if any controversial elements. All of its interfaces have been in place for a long time now. Hence let's move it out of staging. Signed-off-by: Jonathan Cameron Acked-by: Peter Meerwald diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c index cf07e28..f3d075b 100644 --- a/arch/arm/mach-omap2/board-rx51-peripherals.c +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c @@ -42,7 +42,7 @@ #include #include -#include <../drivers/staging/iio/light/tsl2563.h> +#include #include #if defined(CONFIG_IR_RX51) || defined(CONFIG_IR_RX51_MODULE) diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index dbf80ab..5ef1a39 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -32,6 +32,16 @@ config SENSORS_LM3533 changes. The ALS-control output values can be set per zone for the three current output channels. +config SENSORS_TSL2563 + tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors" + depends on I2C + help + If you say yes here you get support for the Taos TSL2560, + TSL2561, TSL2562 and TSL2563 ambient light sensors. + + This driver can also be built as a module. If so, the module + will be called tsl2563. + config VCNL4000 tristate "VCNL4000 combined ALS and proximity sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 21a8f0d..040d9c7 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -4,5 +4,6 @@ obj-$(CONFIG_ADJD_S311) += adjd_s311.o obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o +obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o obj-$(CONFIG_VCNL4000) += vcnl4000.o obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c new file mode 100644 index 0000000..fd8be69 --- /dev/null +++ b/drivers/iio/light/tsl2563.c @@ -0,0 +1,887 @@ +/* + * drivers/iio/light/tsl2563.c + * + * Copyright (C) 2008 Nokia Corporation + * + * Written by Timo O. Karjalainen + * Contact: Amit Kucheria + * + * Converted to IIO driver + * Amit Kucheria + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* Use this many bits for fraction part. */ +#define ADC_FRAC_BITS 14 + +/* Given number of 1/10000's in ADC_FRAC_BITS precision. */ +#define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000)) + +/* Bits used for fraction in calibration coefficients.*/ +#define CALIB_FRAC_BITS 10 +/* 0.5 in CALIB_FRAC_BITS precision */ +#define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1)) +/* Make a fraction from a number n that was multiplied with b. */ +#define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b)) +/* Decimal 10^(digits in sysfs presentation) */ +#define CALIB_BASE_SYSFS 1000 + +#define TSL2563_CMD 0x80 +#define TSL2563_CLEARINT 0x40 + +#define TSL2563_REG_CTRL 0x00 +#define TSL2563_REG_TIMING 0x01 +#define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */ +#define TSL2563_REG_LOWHIGH 0x03 +#define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */ +#define TSL2563_REG_HIGHHIGH 0x05 +#define TSL2563_REG_INT 0x06 +#define TSL2563_REG_ID 0x0a +#define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */ +#define TSL2563_REG_DATA0HIGH 0x0d +#define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */ +#define TSL2563_REG_DATA1HIGH 0x0f + +#define TSL2563_CMD_POWER_ON 0x03 +#define TSL2563_CMD_POWER_OFF 0x00 +#define TSL2563_CTRL_POWER_MASK 0x03 + +#define TSL2563_TIMING_13MS 0x00 +#define TSL2563_TIMING_100MS 0x01 +#define TSL2563_TIMING_400MS 0x02 +#define TSL2563_TIMING_MASK 0x03 +#define TSL2563_TIMING_GAIN16 0x10 +#define TSL2563_TIMING_GAIN1 0x00 + +#define TSL2563_INT_DISBLED 0x00 +#define TSL2563_INT_LEVEL 0x10 +#define TSL2563_INT_PERSIST(n) ((n) & 0x0F) + +struct tsl2563_gainlevel_coeff { + u8 gaintime; + u16 min; + u16 max; +}; + +static const struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = { + { + .gaintime = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN16, + .min = 0, + .max = 65534, + }, { + .gaintime = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN1, + .min = 2048, + .max = 65534, + }, { + .gaintime = TSL2563_TIMING_100MS | TSL2563_TIMING_GAIN1, + .min = 4095, + .max = 37177, + }, { + .gaintime = TSL2563_TIMING_13MS | TSL2563_TIMING_GAIN1, + .min = 3000, + .max = 65535, + }, +}; + +struct tsl2563_chip { + struct mutex lock; + struct i2c_client *client; + struct delayed_work poweroff_work; + + /* Remember state for suspend and resume functions */ + bool suspended; + + struct tsl2563_gainlevel_coeff const *gainlevel; + + u16 low_thres; + u16 high_thres; + u8 intr; + bool int_enabled; + + /* Calibration coefficients */ + u32 calib0; + u32 calib1; + int cover_comp_gain; + + /* Cache current values, to be returned while suspended */ + u32 data0; + u32 data1; +}; + +static int tsl2563_set_power(struct tsl2563_chip *chip, int on) +{ + struct i2c_client *client = chip->client; + u8 cmd; + + cmd = on ? TSL2563_CMD_POWER_ON : TSL2563_CMD_POWER_OFF; + return i2c_smbus_write_byte_data(client, + TSL2563_CMD | TSL2563_REG_CTRL, cmd); +} + +/* + * Return value is 0 for off, 1 for on, or a negative error + * code if reading failed. + */ +static int tsl2563_get_power(struct tsl2563_chip *chip) +{ + struct i2c_client *client = chip->client; + int ret; + + ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_CTRL); + if (ret < 0) + return ret; + + return (ret & TSL2563_CTRL_POWER_MASK) == TSL2563_CMD_POWER_ON; +} + +static int tsl2563_configure(struct tsl2563_chip *chip) +{ + int ret; + + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_TIMING, + chip->gainlevel->gaintime); + if (ret) + goto error_ret; + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_HIGHLOW, + chip->high_thres & 0xFF); + if (ret) + goto error_ret; + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_HIGHHIGH, + (chip->high_thres >> 8) & 0xFF); + if (ret) + goto error_ret; + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_LOWLOW, + chip->low_thres & 0xFF); + if (ret) + goto error_ret; + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_LOWHIGH, + (chip->low_thres >> 8) & 0xFF); +/* + * Interrupt register is automatically written anyway if it is relevant + * so is not here. + */ +error_ret: + return ret; +} + +static void tsl2563_poweroff_work(struct work_struct *work) +{ + struct tsl2563_chip *chip = + container_of(work, struct tsl2563_chip, poweroff_work.work); + tsl2563_set_power(chip, 0); +} + +static int tsl2563_detect(struct tsl2563_chip *chip) +{ + int ret; + + ret = tsl2563_set_power(chip, 1); + if (ret) + return ret; + + ret = tsl2563_get_power(chip); + if (ret < 0) + return ret; + + return ret ? 0 : -ENODEV; +} + +static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) +{ + struct i2c_client *client = chip->client; + int ret; + + ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_ID); + if (ret < 0) + return ret; + + *id = ret; + + return 0; +} + +/* + * "Normalized" ADC value is one obtained with 400ms of integration time and + * 16x gain. This function returns the number of bits of shift needed to + * convert between normalized values and HW values obtained using given + * timing and gain settings. + */ +static int adc_shiftbits(u8 timing) +{ + int shift = 0; + + switch (timing & TSL2563_TIMING_MASK) { + case TSL2563_TIMING_13MS: + shift += 5; + break; + case TSL2563_TIMING_100MS: + shift += 2; + break; + case TSL2563_TIMING_400MS: + /* no-op */ + break; + } + + if (!(timing & TSL2563_TIMING_GAIN16)) + shift += 4; + + return shift; +} + +/* Convert a HW ADC value to normalized scale. */ +static u32 normalize_adc(u16 adc, u8 timing) +{ + return adc << adc_shiftbits(timing); +} + +static void tsl2563_wait_adc(struct tsl2563_chip *chip) +{ + unsigned int delay; + + switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) { + case TSL2563_TIMING_13MS: + delay = 14; + break; + case TSL2563_TIMING_100MS: + delay = 101; + break; + default: + delay = 402; + } + /* + * TODO: Make sure that we wait at least required delay but why we + * have to extend it one tick more? + */ + schedule_timeout_interruptible(msecs_to_jiffies(delay) + 2); +} + +static int tsl2563_adjust_gainlevel(struct tsl2563_chip *chip, u16 adc) +{ + struct i2c_client *client = chip->client; + + if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) { + + (adc > chip->gainlevel->max) ? + chip->gainlevel++ : chip->gainlevel--; + + i2c_smbus_write_byte_data(client, + TSL2563_CMD | TSL2563_REG_TIMING, + chip->gainlevel->gaintime); + + tsl2563_wait_adc(chip); + tsl2563_wait_adc(chip); + + return 1; + } else + return 0; +} + +static int tsl2563_get_adc(struct tsl2563_chip *chip) +{ + struct i2c_client *client = chip->client; + u16 adc0, adc1; + int retry = 1; + int ret = 0; + + if (chip->suspended) + goto out; + + if (!chip->int_enabled) { + cancel_delayed_work(&chip->poweroff_work); + + if (!tsl2563_get_power(chip)) { + ret = tsl2563_set_power(chip, 1); + if (ret) + goto out; + ret = tsl2563_configure(chip); + if (ret) + goto out; + tsl2563_wait_adc(chip); + } + } + + while (retry) { + ret = i2c_smbus_read_word_data(client, + TSL2563_CMD | TSL2563_REG_DATA0LOW); + if (ret < 0) + goto out; + adc0 = ret; + + ret = i2c_smbus_read_word_data(client, + TSL2563_CMD | TSL2563_REG_DATA1LOW); + if (ret < 0) + goto out; + adc1 = ret; + + retry = tsl2563_adjust_gainlevel(chip, adc0); + } + + chip->data0 = normalize_adc(adc0, chip->gainlevel->gaintime); + chip->data1 = normalize_adc(adc1, chip->gainlevel->gaintime); + + if (!chip->int_enabled) + schedule_delayed_work(&chip->poweroff_work, 5 * HZ); + + ret = 0; +out: + return ret; +} + +static inline int calib_to_sysfs(u32 calib) +{ + return (int) (((calib * CALIB_BASE_SYSFS) + + CALIB_FRAC_HALF) >> CALIB_FRAC_BITS); +} + +static inline u32 calib_from_sysfs(int value) +{ + return (((u32) value) << CALIB_FRAC_BITS) / CALIB_BASE_SYSFS; +} + +/* + * Conversions between lux and ADC values. + * + * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are + * appropriate constants. Different constants are needed for different + * kinds of light, determined by the ratio adc1/adc0 (basically the ratio + * of the intensities in infrared and visible wavelengths). lux_table below + * lists the upper threshold of the adc1/adc0 ratio and the corresponding + * constants. + */ + +struct tsl2563_lux_coeff { + unsigned long ch_ratio; + unsigned long ch0_coeff; + unsigned long ch1_coeff; +}; + +static const struct tsl2563_lux_coeff lux_table[] = { + { + .ch_ratio = FRAC10K(1300), + .ch0_coeff = FRAC10K(315), + .ch1_coeff = FRAC10K(262), + }, { + .ch_ratio = FRAC10K(2600), + .ch0_coeff = FRAC10K(337), + .ch1_coeff = FRAC10K(430), + }, { + .ch_ratio = FRAC10K(3900), + .ch0_coeff = FRAC10K(363), + .ch1_coeff = FRAC10K(529), + }, { + .ch_ratio = FRAC10K(5200), + .ch0_coeff = FRAC10K(392), + .ch1_coeff = FRAC10K(605), + }, { + .ch_ratio = FRAC10K(6500), + .ch0_coeff = FRAC10K(229), + .ch1_coeff = FRAC10K(291), + }, { + .ch_ratio = FRAC10K(8000), + .ch0_coeff = FRAC10K(157), + .ch1_coeff = FRAC10K(180), + }, { + .ch_ratio = FRAC10K(13000), + .ch0_coeff = FRAC10K(34), + .ch1_coeff = FRAC10K(26), + }, { + .ch_ratio = ULONG_MAX, + .ch0_coeff = 0, + .ch1_coeff = 0, + }, +}; + +/* Convert normalized, scaled ADC values to lux. */ +static unsigned int adc_to_lux(u32 adc0, u32 adc1) +{ + const struct tsl2563_lux_coeff *lp = lux_table; + unsigned long ratio, lux, ch0 = adc0, ch1 = adc1; + + ratio = ch0 ? ((ch1 << ADC_FRAC_BITS) / ch0) : ULONG_MAX; + + while (lp->ch_ratio < ratio) + lp++; + + lux = ch0 * lp->ch0_coeff - ch1 * lp->ch1_coeff; + + return (unsigned int) (lux >> ADC_FRAC_BITS); +} + +/* Apply calibration coefficient to ADC count. */ +static u32 calib_adc(u32 adc, u32 calib) +{ + unsigned long scaled = adc; + + scaled *= calib; + scaled >>= CALIB_FRAC_BITS; + + return (u32) scaled; +} + +static int tsl2563_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long mask) +{ + struct tsl2563_chip *chip = iio_priv(indio_dev); + + if (chan->channel == IIO_MOD_LIGHT_BOTH) + chip->calib0 = calib_from_sysfs(val); + else + chip->calib1 = calib_from_sysfs(val); + + return 0; +} + +static int tsl2563_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long m) +{ + int ret = -EINVAL; + u32 calib0, calib1; + struct tsl2563_chip *chip = iio_priv(indio_dev); + + mutex_lock(&chip->lock); + switch (m) { + case IIO_CHAN_INFO_RAW: + case IIO_CHAN_INFO_PROCESSED: + switch (chan->type) { + case IIO_LIGHT: + ret = tsl2563_get_adc(chip); + if (ret) + goto error_ret; + calib0 = calib_adc(chip->data0, chip->calib0) * + chip->cover_comp_gain; + calib1 = calib_adc(chip->data1, chip->calib1) * + chip->cover_comp_gain; + *val = adc_to_lux(calib0, calib1); + ret = IIO_VAL_INT; + break; + case IIO_INTENSITY: + ret = tsl2563_get_adc(chip); + if (ret) + goto error_ret; + if (chan->channel == 0) + *val = chip->data0; + else + *val = chip->data1; + ret = IIO_VAL_INT; + break; + default: + break; + } + break; + + case IIO_CHAN_INFO_CALIBSCALE: + if (chan->channel == 0) + *val = calib_to_sysfs(chip->calib0); + else + *val = calib_to_sysfs(chip->calib1); + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + goto error_ret; + } + +error_ret: + mutex_unlock(&chip->lock); + return ret; +} + +static const struct iio_chan_spec tsl2563_channels[] = { + { + .type = IIO_LIGHT, + .indexed = 1, + .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT, + .channel = 0, + }, { + .type = IIO_INTENSITY, + .modified = 1, + .channel2 = IIO_MOD_LIGHT_BOTH, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, + .event_mask = (IIO_EV_BIT(IIO_EV_TYPE_THRESH, + IIO_EV_DIR_RISING) | + IIO_EV_BIT(IIO_EV_TYPE_THRESH, + IIO_EV_DIR_FALLING)), + }, { + .type = IIO_INTENSITY, + .modified = 1, + .channel2 = IIO_MOD_LIGHT_IR, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, + } +}; + +static int tsl2563_read_thresh(struct iio_dev *indio_dev, + u64 event_code, + int *val) +{ + struct tsl2563_chip *chip = iio_priv(indio_dev); + + switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { + case IIO_EV_DIR_RISING: + *val = chip->high_thres; + break; + case IIO_EV_DIR_FALLING: + *val = chip->low_thres; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int tsl2563_write_thresh(struct iio_dev *indio_dev, + u64 event_code, + int val) +{ + struct tsl2563_chip *chip = iio_priv(indio_dev); + int ret; + u8 address; + + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING) + address = TSL2563_REG_HIGHLOW; + else + address = TSL2563_REG_LOWLOW; + mutex_lock(&chip->lock); + ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | address, + val & 0xFF); + if (ret) + goto error_ret; + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | (address + 1), + (val >> 8) & 0xFF); + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING) + chip->high_thres = val; + else + chip->low_thres = val; + +error_ret: + mutex_unlock(&chip->lock); + + return ret; +} + +static irqreturn_t tsl2563_event_handler(int irq, void *private) +{ + struct iio_dev *dev_info = private; + struct tsl2563_chip *chip = iio_priv(dev_info); + + iio_push_event(dev_info, + IIO_UNMOD_EVENT_CODE(IIO_LIGHT, + 0, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_EITHER), + iio_get_time_ns()); + + /* clear the interrupt and push the event */ + i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT); + return IRQ_HANDLED; +} + +static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev, + u64 event_code, + int state) +{ + struct tsl2563_chip *chip = iio_priv(indio_dev); + int ret = 0; + + mutex_lock(&chip->lock); + if (state && !(chip->intr & 0x30)) { + chip->intr &= ~0x30; + chip->intr |= 0x10; + /* ensure the chip is actually on */ + cancel_delayed_work(&chip->poweroff_work); + if (!tsl2563_get_power(chip)) { + ret = tsl2563_set_power(chip, 1); + if (ret) + goto out; + ret = tsl2563_configure(chip); + if (ret) + goto out; + } + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_INT, + chip->intr); + chip->int_enabled = true; + } + + if (!state && (chip->intr & 0x30)) { + chip->intr &= ~0x30; + ret = i2c_smbus_write_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_INT, + chip->intr); + chip->int_enabled = false; + /* now the interrupt is not enabled, we can go to sleep */ + schedule_delayed_work(&chip->poweroff_work, 5 * HZ); + } +out: + mutex_unlock(&chip->lock); + + return ret; +} + +static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev, + u64 event_code) +{ + struct tsl2563_chip *chip = iio_priv(indio_dev); + int ret; + + mutex_lock(&chip->lock); + ret = i2c_smbus_read_byte_data(chip->client, + TSL2563_CMD | TSL2563_REG_INT); + mutex_unlock(&chip->lock); + if (ret < 0) + return ret; + + return !!(ret & 0x30); +} + +static const struct iio_info tsl2563_info_no_irq = { + .driver_module = THIS_MODULE, + .read_raw = &tsl2563_read_raw, + .write_raw = &tsl2563_write_raw, +}; + +static const struct iio_info tsl2563_info = { + .driver_module = THIS_MODULE, + .read_raw = &tsl2563_read_raw, + .write_raw = &tsl2563_write_raw, + .read_event_value = &tsl2563_read_thresh, + .write_event_value = &tsl2563_write_thresh, + .read_event_config = &tsl2563_read_interrupt_config, + .write_event_config = &tsl2563_write_interrupt_config, +}; + +static int tsl2563_probe(struct i2c_client *client, + const struct i2c_device_id *device_id) +{ + struct iio_dev *indio_dev; + struct tsl2563_chip *chip; + struct tsl2563_platform_data *pdata = client->dev.platform_data; + int err = 0; + u8 id = 0; + + indio_dev = iio_device_alloc(sizeof(*chip)); + if (!indio_dev) + return -ENOMEM; + + chip = iio_priv(indio_dev); + + i2c_set_clientdata(client, chip); + chip->client = client; + + err = tsl2563_detect(chip); + if (err) { + dev_err(&client->dev, "detect error %d\n", -err); + goto fail1; + } + + err = tsl2563_read_id(chip, &id); + if (err) { + dev_err(&client->dev, "read id error %d\n", -err); + goto fail1; + } + + mutex_init(&chip->lock); + + /* Default values used until userspace says otherwise */ + chip->low_thres = 0x0; + chip->high_thres = 0xffff; + chip->gainlevel = tsl2563_gainlevel_table; + chip->intr = TSL2563_INT_PERSIST(4); + chip->calib0 = calib_from_sysfs(CALIB_BASE_SYSFS); + chip->calib1 = calib_from_sysfs(CALIB_BASE_SYSFS); + + if (pdata) + chip->cover_comp_gain = pdata->cover_comp_gain; + else + chip->cover_comp_gain = 1; + + dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f); + indio_dev->name = client->name; + indio_dev->channels = tsl2563_channels; + indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels); + indio_dev->dev.parent = &client->dev; + indio_dev->modes = INDIO_DIRECT_MODE; + + if (client->irq) + indio_dev->info = &tsl2563_info; + else + indio_dev->info = &tsl2563_info_no_irq; + + if (client->irq) { + err = request_threaded_irq(client->irq, + NULL, + &tsl2563_event_handler, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + "tsl2563_event", + indio_dev); + if (err) { + dev_err(&client->dev, "irq request error %d\n", -err); + goto fail1; + } + } + + err = tsl2563_configure(chip); + if (err) { + dev_err(&client->dev, "configure error %d\n", -err); + goto fail2; + } + + INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); + + /* The interrupt cannot yet be enabled so this is fine without lock */ + schedule_delayed_work(&chip->poweroff_work, 5 * HZ); + + err = iio_device_register(indio_dev); + if (err) { + dev_err(&client->dev, "iio registration error %d\n", -err); + goto fail3; + } + + return 0; + +fail3: + cancel_delayed_work(&chip->poweroff_work); + flush_scheduled_work(); +fail2: + if (client->irq) + free_irq(client->irq, indio_dev); +fail1: + iio_device_free(indio_dev); + return err; +} + +static int tsl2563_remove(struct i2c_client *client) +{ + struct tsl2563_chip *chip = i2c_get_clientdata(client); + struct iio_dev *indio_dev = iio_priv_to_dev(chip); + + iio_device_unregister(indio_dev); + if (!chip->int_enabled) + cancel_delayed_work(&chip->poweroff_work); + /* Ensure that interrupts are disabled - then flush any bottom halves */ + chip->intr &= ~0x30; + i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, + chip->intr); + flush_scheduled_work(); + tsl2563_set_power(chip, 0); + if (client->irq) + free_irq(client->irq, indio_dev); + + iio_device_free(indio_dev); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int tsl2563_suspend(struct device *dev) +{ + struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); + int ret; + + mutex_lock(&chip->lock); + + ret = tsl2563_set_power(chip, 0); + if (ret) + goto out; + + chip->suspended = true; + +out: + mutex_unlock(&chip->lock); + return ret; +} + +static int tsl2563_resume(struct device *dev) +{ + struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); + int ret; + + mutex_lock(&chip->lock); + + ret = tsl2563_set_power(chip, 1); + if (ret) + goto out; + + ret = tsl2563_configure(chip); + if (ret) + goto out; + + chip->suspended = false; + +out: + mutex_unlock(&chip->lock); + return ret; +} + +static SIMPLE_DEV_PM_OPS(tsl2563_pm_ops, tsl2563_suspend, tsl2563_resume); +#define TSL2563_PM_OPS (&tsl2563_pm_ops) +#else +#define TSL2563_PM_OPS NULL +#endif + +static const struct i2c_device_id tsl2563_id[] = { + { "tsl2560", 0 }, + { "tsl2561", 1 }, + { "tsl2562", 2 }, + { "tsl2563", 3 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, tsl2563_id); + +static struct i2c_driver tsl2563_i2c_driver = { + .driver = { + .name = "tsl2563", + .pm = TSL2563_PM_OPS, + }, + .probe = tsl2563_probe, + .remove = tsl2563_remove, + .id_table = tsl2563_id, +}; +module_i2c_driver(tsl2563_i2c_driver); + +MODULE_AUTHOR("Nokia Corporation"); +MODULE_DESCRIPTION("tsl2563 light sensor driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig index 4bed30e..ca8d6e6 100644 --- a/drivers/staging/iio/light/Kconfig +++ b/drivers/staging/iio/light/Kconfig @@ -25,16 +25,6 @@ config SENSORS_ISL29028 Proximity value via iio. The ISL29028 provides the concurrent sensing of ambient light and proximity. -config SENSORS_TSL2563 - tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors" - depends on I2C - help - If you say yes here you get support for the Taos TSL2560, - TSL2561, TSL2562 and TSL2563 ambient light sensors. - - This driver can also be built as a module. If so, the module - will be called tsl2563. - config TSL2583 tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters" depends on I2C diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile index 141af1e..9960fdf 100644 --- a/drivers/staging/iio/light/Makefile +++ b/drivers/staging/iio/light/Makefile @@ -2,7 +2,6 @@ # Makefile for industrial I/O Light sensors # -obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o obj-$(CONFIG_TSL2583) += tsl2583.o diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c deleted file mode 100644 index b91d9bb..0000000 --- a/drivers/staging/iio/light/tsl2563.c +++ /dev/null @@ -1,887 +0,0 @@ -/* - * drivers/i2c/chips/tsl2563.c - * - * Copyright (C) 2008 Nokia Corporation - * - * Written by Timo O. Karjalainen - * Contact: Amit Kucheria - * - * Converted to IIO driver - * Amit Kucheria - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include "tsl2563.h" - -/* Use this many bits for fraction part. */ -#define ADC_FRAC_BITS 14 - -/* Given number of 1/10000's in ADC_FRAC_BITS precision. */ -#define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000)) - -/* Bits used for fraction in calibration coefficients.*/ -#define CALIB_FRAC_BITS 10 -/* 0.5 in CALIB_FRAC_BITS precision */ -#define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1)) -/* Make a fraction from a number n that was multiplied with b. */ -#define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b)) -/* Decimal 10^(digits in sysfs presentation) */ -#define CALIB_BASE_SYSFS 1000 - -#define TSL2563_CMD 0x80 -#define TSL2563_CLEARINT 0x40 - -#define TSL2563_REG_CTRL 0x00 -#define TSL2563_REG_TIMING 0x01 -#define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */ -#define TSL2563_REG_LOWHIGH 0x03 -#define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */ -#define TSL2563_REG_HIGHHIGH 0x05 -#define TSL2563_REG_INT 0x06 -#define TSL2563_REG_ID 0x0a -#define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */ -#define TSL2563_REG_DATA0HIGH 0x0d -#define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */ -#define TSL2563_REG_DATA1HIGH 0x0f - -#define TSL2563_CMD_POWER_ON 0x03 -#define TSL2563_CMD_POWER_OFF 0x00 -#define TSL2563_CTRL_POWER_MASK 0x03 - -#define TSL2563_TIMING_13MS 0x00 -#define TSL2563_TIMING_100MS 0x01 -#define TSL2563_TIMING_400MS 0x02 -#define TSL2563_TIMING_MASK 0x03 -#define TSL2563_TIMING_GAIN16 0x10 -#define TSL2563_TIMING_GAIN1 0x00 - -#define TSL2563_INT_DISBLED 0x00 -#define TSL2563_INT_LEVEL 0x10 -#define TSL2563_INT_PERSIST(n) ((n) & 0x0F) - -struct tsl2563_gainlevel_coeff { - u8 gaintime; - u16 min; - u16 max; -}; - -static const struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = { - { - .gaintime = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN16, - .min = 0, - .max = 65534, - }, { - .gaintime = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN1, - .min = 2048, - .max = 65534, - }, { - .gaintime = TSL2563_TIMING_100MS | TSL2563_TIMING_GAIN1, - .min = 4095, - .max = 37177, - }, { - .gaintime = TSL2563_TIMING_13MS | TSL2563_TIMING_GAIN1, - .min = 3000, - .max = 65535, - }, -}; - -struct tsl2563_chip { - struct mutex lock; - struct i2c_client *client; - struct delayed_work poweroff_work; - - /* Remember state for suspend and resume functions */ - bool suspended; - - struct tsl2563_gainlevel_coeff const *gainlevel; - - u16 low_thres; - u16 high_thres; - u8 intr; - bool int_enabled; - - /* Calibration coefficients */ - u32 calib0; - u32 calib1; - int cover_comp_gain; - - /* Cache current values, to be returned while suspended */ - u32 data0; - u32 data1; -}; - -static int tsl2563_set_power(struct tsl2563_chip *chip, int on) -{ - struct i2c_client *client = chip->client; - u8 cmd; - - cmd = on ? TSL2563_CMD_POWER_ON : TSL2563_CMD_POWER_OFF; - return i2c_smbus_write_byte_data(client, - TSL2563_CMD | TSL2563_REG_CTRL, cmd); -} - -/* - * Return value is 0 for off, 1 for on, or a negative error - * code if reading failed. - */ -static int tsl2563_get_power(struct tsl2563_chip *chip) -{ - struct i2c_client *client = chip->client; - int ret; - - ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_CTRL); - if (ret < 0) - return ret; - - return (ret & TSL2563_CTRL_POWER_MASK) == TSL2563_CMD_POWER_ON; -} - -static int tsl2563_configure(struct tsl2563_chip *chip) -{ - int ret; - - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_TIMING, - chip->gainlevel->gaintime); - if (ret) - goto error_ret; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_HIGHLOW, - chip->high_thres & 0xFF); - if (ret) - goto error_ret; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_HIGHHIGH, - (chip->high_thres >> 8) & 0xFF); - if (ret) - goto error_ret; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_LOWLOW, - chip->low_thres & 0xFF); - if (ret) - goto error_ret; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_LOWHIGH, - (chip->low_thres >> 8) & 0xFF); -/* - * Interrupt register is automatically written anyway if it is relevant - * so is not here. - */ -error_ret: - return ret; -} - -static void tsl2563_poweroff_work(struct work_struct *work) -{ - struct tsl2563_chip *chip = - container_of(work, struct tsl2563_chip, poweroff_work.work); - tsl2563_set_power(chip, 0); -} - -static int tsl2563_detect(struct tsl2563_chip *chip) -{ - int ret; - - ret = tsl2563_set_power(chip, 1); - if (ret) - return ret; - - ret = tsl2563_get_power(chip); - if (ret < 0) - return ret; - - return ret ? 0 : -ENODEV; -} - -static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) -{ - struct i2c_client *client = chip->client; - int ret; - - ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_ID); - if (ret < 0) - return ret; - - *id = ret; - - return 0; -} - -/* - * "Normalized" ADC value is one obtained with 400ms of integration time and - * 16x gain. This function returns the number of bits of shift needed to - * convert between normalized values and HW values obtained using given - * timing and gain settings. - */ -static int adc_shiftbits(u8 timing) -{ - int shift = 0; - - switch (timing & TSL2563_TIMING_MASK) { - case TSL2563_TIMING_13MS: - shift += 5; - break; - case TSL2563_TIMING_100MS: - shift += 2; - break; - case TSL2563_TIMING_400MS: - /* no-op */ - break; - } - - if (!(timing & TSL2563_TIMING_GAIN16)) - shift += 4; - - return shift; -} - -/* Convert a HW ADC value to normalized scale. */ -static u32 normalize_adc(u16 adc, u8 timing) -{ - return adc << adc_shiftbits(timing); -} - -static void tsl2563_wait_adc(struct tsl2563_chip *chip) -{ - unsigned int delay; - - switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) { - case TSL2563_TIMING_13MS: - delay = 14; - break; - case TSL2563_TIMING_100MS: - delay = 101; - break; - default: - delay = 402; - } - /* - * TODO: Make sure that we wait at least required delay but why we - * have to extend it one tick more? - */ - schedule_timeout_interruptible(msecs_to_jiffies(delay) + 2); -} - -static int tsl2563_adjust_gainlevel(struct tsl2563_chip *chip, u16 adc) -{ - struct i2c_client *client = chip->client; - - if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) { - - (adc > chip->gainlevel->max) ? - chip->gainlevel++ : chip->gainlevel--; - - i2c_smbus_write_byte_data(client, - TSL2563_CMD | TSL2563_REG_TIMING, - chip->gainlevel->gaintime); - - tsl2563_wait_adc(chip); - tsl2563_wait_adc(chip); - - return 1; - } else - return 0; -} - -static int tsl2563_get_adc(struct tsl2563_chip *chip) -{ - struct i2c_client *client = chip->client; - u16 adc0, adc1; - int retry = 1; - int ret = 0; - - if (chip->suspended) - goto out; - - if (!chip->int_enabled) { - cancel_delayed_work(&chip->poweroff_work); - - if (!tsl2563_get_power(chip)) { - ret = tsl2563_set_power(chip, 1); - if (ret) - goto out; - ret = tsl2563_configure(chip); - if (ret) - goto out; - tsl2563_wait_adc(chip); - } - } - - while (retry) { - ret = i2c_smbus_read_word_data(client, - TSL2563_CMD | TSL2563_REG_DATA0LOW); - if (ret < 0) - goto out; - adc0 = ret; - - ret = i2c_smbus_read_word_data(client, - TSL2563_CMD | TSL2563_REG_DATA1LOW); - if (ret < 0) - goto out; - adc1 = ret; - - retry = tsl2563_adjust_gainlevel(chip, adc0); - } - - chip->data0 = normalize_adc(adc0, chip->gainlevel->gaintime); - chip->data1 = normalize_adc(adc1, chip->gainlevel->gaintime); - - if (!chip->int_enabled) - schedule_delayed_work(&chip->poweroff_work, 5 * HZ); - - ret = 0; -out: - return ret; -} - -static inline int calib_to_sysfs(u32 calib) -{ - return (int) (((calib * CALIB_BASE_SYSFS) + - CALIB_FRAC_HALF) >> CALIB_FRAC_BITS); -} - -static inline u32 calib_from_sysfs(int value) -{ - return (((u32) value) << CALIB_FRAC_BITS) / CALIB_BASE_SYSFS; -} - -/* - * Conversions between lux and ADC values. - * - * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are - * appropriate constants. Different constants are needed for different - * kinds of light, determined by the ratio adc1/adc0 (basically the ratio - * of the intensities in infrared and visible wavelengths). lux_table below - * lists the upper threshold of the adc1/adc0 ratio and the corresponding - * constants. - */ - -struct tsl2563_lux_coeff { - unsigned long ch_ratio; - unsigned long ch0_coeff; - unsigned long ch1_coeff; -}; - -static const struct tsl2563_lux_coeff lux_table[] = { - { - .ch_ratio = FRAC10K(1300), - .ch0_coeff = FRAC10K(315), - .ch1_coeff = FRAC10K(262), - }, { - .ch_ratio = FRAC10K(2600), - .ch0_coeff = FRAC10K(337), - .ch1_coeff = FRAC10K(430), - }, { - .ch_ratio = FRAC10K(3900), - .ch0_coeff = FRAC10K(363), - .ch1_coeff = FRAC10K(529), - }, { - .ch_ratio = FRAC10K(5200), - .ch0_coeff = FRAC10K(392), - .ch1_coeff = FRAC10K(605), - }, { - .ch_ratio = FRAC10K(6500), - .ch0_coeff = FRAC10K(229), - .ch1_coeff = FRAC10K(291), - }, { - .ch_ratio = FRAC10K(8000), - .ch0_coeff = FRAC10K(157), - .ch1_coeff = FRAC10K(180), - }, { - .ch_ratio = FRAC10K(13000), - .ch0_coeff = FRAC10K(34), - .ch1_coeff = FRAC10K(26), - }, { - .ch_ratio = ULONG_MAX, - .ch0_coeff = 0, - .ch1_coeff = 0, - }, -}; - -/* Convert normalized, scaled ADC values to lux. */ -static unsigned int adc_to_lux(u32 adc0, u32 adc1) -{ - const struct tsl2563_lux_coeff *lp = lux_table; - unsigned long ratio, lux, ch0 = adc0, ch1 = adc1; - - ratio = ch0 ? ((ch1 << ADC_FRAC_BITS) / ch0) : ULONG_MAX; - - while (lp->ch_ratio < ratio) - lp++; - - lux = ch0 * lp->ch0_coeff - ch1 * lp->ch1_coeff; - - return (unsigned int) (lux >> ADC_FRAC_BITS); -} - -/* Apply calibration coefficient to ADC count. */ -static u32 calib_adc(u32 adc, u32 calib) -{ - unsigned long scaled = adc; - - scaled *= calib; - scaled >>= CALIB_FRAC_BITS; - - return (u32) scaled; -} - -static int tsl2563_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - struct tsl2563_chip *chip = iio_priv(indio_dev); - - if (chan->channel == IIO_MOD_LIGHT_BOTH) - chip->calib0 = calib_from_sysfs(val); - else - chip->calib1 = calib_from_sysfs(val); - - return 0; -} - -static int tsl2563_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - int ret = -EINVAL; - u32 calib0, calib1; - struct tsl2563_chip *chip = iio_priv(indio_dev); - - mutex_lock(&chip->lock); - switch (m) { - case IIO_CHAN_INFO_RAW: - case IIO_CHAN_INFO_PROCESSED: - switch (chan->type) { - case IIO_LIGHT: - ret = tsl2563_get_adc(chip); - if (ret) - goto error_ret; - calib0 = calib_adc(chip->data0, chip->calib0) * - chip->cover_comp_gain; - calib1 = calib_adc(chip->data1, chip->calib1) * - chip->cover_comp_gain; - *val = adc_to_lux(calib0, calib1); - ret = IIO_VAL_INT; - break; - case IIO_INTENSITY: - ret = tsl2563_get_adc(chip); - if (ret) - goto error_ret; - if (chan->channel == 0) - *val = chip->data0; - else - *val = chip->data1; - ret = IIO_VAL_INT; - break; - default: - break; - } - break; - - case IIO_CHAN_INFO_CALIBSCALE: - if (chan->channel == 0) - *val = calib_to_sysfs(chip->calib0); - else - *val = calib_to_sysfs(chip->calib1); - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - goto error_ret; - } - -error_ret: - mutex_unlock(&chip->lock); - return ret; -} - -static const struct iio_chan_spec tsl2563_channels[] = { - { - .type = IIO_LIGHT, - .indexed = 1, - .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT, - .channel = 0, - }, { - .type = IIO_INTENSITY, - .modified = 1, - .channel2 = IIO_MOD_LIGHT_BOTH, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, - .event_mask = (IIO_EV_BIT(IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING) | - IIO_EV_BIT(IIO_EV_TYPE_THRESH, - IIO_EV_DIR_FALLING)), - }, { - .type = IIO_INTENSITY, - .modified = 1, - .channel2 = IIO_MOD_LIGHT_IR, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, - } -}; - -static int tsl2563_read_thresh(struct iio_dev *indio_dev, - u64 event_code, - int *val) -{ - struct tsl2563_chip *chip = iio_priv(indio_dev); - - switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { - case IIO_EV_DIR_RISING: - *val = chip->high_thres; - break; - case IIO_EV_DIR_FALLING: - *val = chip->low_thres; - break; - default: - return -EINVAL; - } - - return 0; -} - -static int tsl2563_write_thresh(struct iio_dev *indio_dev, - u64 event_code, - int val) -{ - struct tsl2563_chip *chip = iio_priv(indio_dev); - int ret; - u8 address; - - if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING) - address = TSL2563_REG_HIGHLOW; - else - address = TSL2563_REG_LOWLOW; - mutex_lock(&chip->lock); - ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | address, - val & 0xFF); - if (ret) - goto error_ret; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | (address + 1), - (val >> 8) & 0xFF); - if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING) - chip->high_thres = val; - else - chip->low_thres = val; - -error_ret: - mutex_unlock(&chip->lock); - - return ret; -} - -static irqreturn_t tsl2563_event_handler(int irq, void *private) -{ - struct iio_dev *dev_info = private; - struct tsl2563_chip *chip = iio_priv(dev_info); - - iio_push_event(dev_info, - IIO_UNMOD_EVENT_CODE(IIO_LIGHT, - 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_EITHER), - iio_get_time_ns()); - - /* clear the interrupt and push the event */ - i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT); - return IRQ_HANDLED; -} - -static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev, - u64 event_code, - int state) -{ - struct tsl2563_chip *chip = iio_priv(indio_dev); - int ret = 0; - - mutex_lock(&chip->lock); - if (state && !(chip->intr & 0x30)) { - chip->intr &= ~0x30; - chip->intr |= 0x10; - /* ensure the chip is actually on */ - cancel_delayed_work(&chip->poweroff_work); - if (!tsl2563_get_power(chip)) { - ret = tsl2563_set_power(chip, 1); - if (ret) - goto out; - ret = tsl2563_configure(chip); - if (ret) - goto out; - } - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_INT, - chip->intr); - chip->int_enabled = true; - } - - if (!state && (chip->intr & 0x30)) { - chip->intr &= ~0x30; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_INT, - chip->intr); - chip->int_enabled = false; - /* now the interrupt is not enabled, we can go to sleep */ - schedule_delayed_work(&chip->poweroff_work, 5 * HZ); - } -out: - mutex_unlock(&chip->lock); - - return ret; -} - -static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev, - u64 event_code) -{ - struct tsl2563_chip *chip = iio_priv(indio_dev); - int ret; - - mutex_lock(&chip->lock); - ret = i2c_smbus_read_byte_data(chip->client, - TSL2563_CMD | TSL2563_REG_INT); - mutex_unlock(&chip->lock); - if (ret < 0) - return ret; - - return !!(ret & 0x30); -} - -static const struct iio_info tsl2563_info_no_irq = { - .driver_module = THIS_MODULE, - .read_raw = &tsl2563_read_raw, - .write_raw = &tsl2563_write_raw, -}; - -static const struct iio_info tsl2563_info = { - .driver_module = THIS_MODULE, - .read_raw = &tsl2563_read_raw, - .write_raw = &tsl2563_write_raw, - .read_event_value = &tsl2563_read_thresh, - .write_event_value = &tsl2563_write_thresh, - .read_event_config = &tsl2563_read_interrupt_config, - .write_event_config = &tsl2563_write_interrupt_config, -}; - -static int tsl2563_probe(struct i2c_client *client, - const struct i2c_device_id *device_id) -{ - struct iio_dev *indio_dev; - struct tsl2563_chip *chip; - struct tsl2563_platform_data *pdata = client->dev.platform_data; - int err = 0; - u8 id = 0; - - indio_dev = iio_device_alloc(sizeof(*chip)); - if (!indio_dev) - return -ENOMEM; - - chip = iio_priv(indio_dev); - - i2c_set_clientdata(client, chip); - chip->client = client; - - err = tsl2563_detect(chip); - if (err) { - dev_err(&client->dev, "detect error %d\n", -err); - goto fail1; - } - - err = tsl2563_read_id(chip, &id); - if (err) { - dev_err(&client->dev, "read id error %d\n", -err); - goto fail1; - } - - mutex_init(&chip->lock); - - /* Default values used until userspace says otherwise */ - chip->low_thres = 0x0; - chip->high_thres = 0xffff; - chip->gainlevel = tsl2563_gainlevel_table; - chip->intr = TSL2563_INT_PERSIST(4); - chip->calib0 = calib_from_sysfs(CALIB_BASE_SYSFS); - chip->calib1 = calib_from_sysfs(CALIB_BASE_SYSFS); - - if (pdata) - chip->cover_comp_gain = pdata->cover_comp_gain; - else - chip->cover_comp_gain = 1; - - dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f); - indio_dev->name = client->name; - indio_dev->channels = tsl2563_channels; - indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels); - indio_dev->dev.parent = &client->dev; - indio_dev->modes = INDIO_DIRECT_MODE; - - if (client->irq) - indio_dev->info = &tsl2563_info; - else - indio_dev->info = &tsl2563_info_no_irq; - - if (client->irq) { - err = request_threaded_irq(client->irq, - NULL, - &tsl2563_event_handler, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - "tsl2563_event", - indio_dev); - if (err) { - dev_err(&client->dev, "irq request error %d\n", -err); - goto fail1; - } - } - - err = tsl2563_configure(chip); - if (err) { - dev_err(&client->dev, "configure error %d\n", -err); - goto fail2; - } - - INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); - - /* The interrupt cannot yet be enabled so this is fine without lock */ - schedule_delayed_work(&chip->poweroff_work, 5 * HZ); - - err = iio_device_register(indio_dev); - if (err) { - dev_err(&client->dev, "iio registration error %d\n", -err); - goto fail3; - } - - return 0; - -fail3: - cancel_delayed_work(&chip->poweroff_work); - flush_scheduled_work(); -fail2: - if (client->irq) - free_irq(client->irq, indio_dev); -fail1: - iio_device_free(indio_dev); - return err; -} - -static int tsl2563_remove(struct i2c_client *client) -{ - struct tsl2563_chip *chip = i2c_get_clientdata(client); - struct iio_dev *indio_dev = iio_priv_to_dev(chip); - - iio_device_unregister(indio_dev); - if (!chip->int_enabled) - cancel_delayed_work(&chip->poweroff_work); - /* Ensure that interrupts are disabled - then flush any bottom halves */ - chip->intr &= ~0x30; - i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, - chip->intr); - flush_scheduled_work(); - tsl2563_set_power(chip, 0); - if (client->irq) - free_irq(client->irq, indio_dev); - - iio_device_free(indio_dev); - - return 0; -} - -#ifdef CONFIG_PM_SLEEP -static int tsl2563_suspend(struct device *dev) -{ - struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); - int ret; - - mutex_lock(&chip->lock); - - ret = tsl2563_set_power(chip, 0); - if (ret) - goto out; - - chip->suspended = true; - -out: - mutex_unlock(&chip->lock); - return ret; -} - -static int tsl2563_resume(struct device *dev) -{ - struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); - int ret; - - mutex_lock(&chip->lock); - - ret = tsl2563_set_power(chip, 1); - if (ret) - goto out; - - ret = tsl2563_configure(chip); - if (ret) - goto out; - - chip->suspended = false; - -out: - mutex_unlock(&chip->lock); - return ret; -} - -static SIMPLE_DEV_PM_OPS(tsl2563_pm_ops, tsl2563_suspend, tsl2563_resume); -#define TSL2563_PM_OPS (&tsl2563_pm_ops) -#else -#define TSL2563_PM_OPS NULL -#endif - -static const struct i2c_device_id tsl2563_id[] = { - { "tsl2560", 0 }, - { "tsl2561", 1 }, - { "tsl2562", 2 }, - { "tsl2563", 3 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, tsl2563_id); - -static struct i2c_driver tsl2563_i2c_driver = { - .driver = { - .name = "tsl2563", - .pm = TSL2563_PM_OPS, - }, - .probe = tsl2563_probe, - .remove = tsl2563_remove, - .id_table = tsl2563_id, -}; -module_i2c_driver(tsl2563_i2c_driver); - -MODULE_AUTHOR("Nokia Corporation"); -MODULE_DESCRIPTION("tsl2563 light sensor driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/iio/light/tsl2563.h b/drivers/staging/iio/light/tsl2563.h deleted file mode 100644 index b97368b..0000000 --- a/drivers/staging/iio/light/tsl2563.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __LINUX_TSL2563_H -#define __LINUX_TSL2563_H - -struct tsl2563_platform_data { - int cover_comp_gain; -}; - -#endif /* __LINUX_TSL2563_H */ - diff --git a/include/linux/platform_data/tsl2563.h b/include/linux/platform_data/tsl2563.h new file mode 100644 index 0000000..c90d7a0 --- /dev/null +++ b/include/linux/platform_data/tsl2563.h @@ -0,0 +1,8 @@ +#ifndef __LINUX_TSL2563_H +#define __LINUX_TSL2563_H + +struct tsl2563_platform_data { + int cover_comp_gain; +}; + +#endif /* __LINUX_TSL2563_H */ -- cgit v0.10.2 From 04c5904155839920afaffb083742f8bd603b88cb Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 14:58:36 -0700 Subject: staging: comedi: quatech_daqp_cs: move MODULE_* info to end of file For aesthetic reasons, move all the MODULE_* information to the end of the file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 55d8cc6..ca087ea 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -1042,11 +1042,7 @@ static const struct pcmcia_device_id daqp_cs_id_table[] = { PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0027), PCMCIA_DEVICE_NULL }; - MODULE_DEVICE_TABLE(pcmcia, daqp_cs_id_table); -MODULE_AUTHOR("Brent Baccala "); -MODULE_DESCRIPTION("Comedi driver for Quatech DAQP PCMCIA data capture cards"); -MODULE_LICENSE("GPL"); static struct pcmcia_driver daqp_cs_driver = { .probe = daqp_cs_attach, @@ -1057,5 +1053,8 @@ static struct pcmcia_driver daqp_cs_driver = { .owner = THIS_MODULE, .name = "quatech_daqp_cs", }; - module_comedi_pcmcia_driver(driver_daqp, daqp_cs_driver); + +MODULE_DESCRIPTION("Comedi driver for Quatech DAQP PCMCIA data capture cards"); +MODULE_AUTHOR("Brent Baccala "); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 433a0e22132d132844875764bda2911db28b36ad Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 14:58:58 -0700 Subject: staging: comedi: quatech_daqp_cs: cleanup pcmcia_driver For aesthetic reasons, reorder the pcmcia_driver variables and add some whitespace. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index ca087ea..c4a03eb 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -1045,13 +1045,13 @@ static const struct pcmcia_device_id daqp_cs_id_table[] = { MODULE_DEVICE_TABLE(pcmcia, daqp_cs_id_table); static struct pcmcia_driver daqp_cs_driver = { - .probe = daqp_cs_attach, - .remove = daqp_cs_detach, - .suspend = daqp_cs_suspend, - .resume = daqp_cs_resume, - .id_table = daqp_cs_id_table, - .owner = THIS_MODULE, - .name = "quatech_daqp_cs", + .name = "quatech_daqp_cs", + .owner = THIS_MODULE, + .id_table = daqp_cs_id_table, + .probe = daqp_cs_attach, + .remove = daqp_cs_detach, + .suspend = daqp_cs_suspend, + .resume = daqp_cs_resume, }; module_comedi_pcmcia_driver(driver_daqp, daqp_cs_driver); -- cgit v0.10.2 From d1db2a4134bb486b28f943baac175e3edcc51053 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 14:59:17 -0700 Subject: staging: comedi: quatech_daqp_cs: remove forward declarations Move some of the functions to remove the need for the forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index c4a03eb..748aa6a 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -180,19 +180,6 @@ static const struct comedi_lrange range_daqp_ai = { 4, { static const struct comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)} }; -/*====================================================================*/ - -/* comedi interface code */ - -static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it); -static void daqp_detach(struct comedi_device *dev); -static struct comedi_driver driver_daqp = { - .driver_name = "quatech_daqp_cs", - .module = THIS_MODULE, - .attach = daqp_attach, - .detach = daqp_detach, -}; - #ifdef DAQP_DEBUG static void daqp_dump(struct comedi_device *dev) @@ -889,6 +876,13 @@ static void daqp_detach(struct comedi_device *dev) /* Nothing to cleanup */ } +static struct comedi_driver driver_daqp = { + .driver_name = "quatech_daqp_cs", + .module = THIS_MODULE, + .attach = daqp_attach, + .detach = daqp_detach, +}; + /*==================================================================== PCMCIA interface code @@ -924,55 +918,29 @@ static void daqp_detach(struct comedi_device *dev) ======================================================================*/ -static void daqp_cs_config(struct pcmcia_device *link); -static void daqp_cs_release(struct pcmcia_device *link); -static int daqp_cs_suspend(struct pcmcia_device *p_dev); -static int daqp_cs_resume(struct pcmcia_device *p_dev); - -static int daqp_cs_attach(struct pcmcia_device *); -static void daqp_cs_detach(struct pcmcia_device *); - -static int daqp_cs_attach(struct pcmcia_device *link) +static int daqp_cs_suspend(struct pcmcia_device *link) { - struct local_info_t *local; - int i; - - dev_dbg(&link->dev, "daqp_cs_attach()\n"); - - for (i = 0; i < MAX_DEV; i++) - if (dev_table[i] == NULL) - break; - if (i == MAX_DEV) { - dev_notice(&link->dev, "no devices available\n"); - return -ENODEV; - } + struct local_info_t *local = link->priv; - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); - if (!local) - return -ENOMEM; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + return 0; +} - local->table_index = i; - dev_table[i] = local; - local->link = link; - link->priv = local; +static int daqp_cs_resume(struct pcmcia_device *link) +{ + struct local_info_t *local = link->priv; - daqp_cs_config(link); + local->stop = 0; return 0; -} /* daqp_cs_attach */ +} -static void daqp_cs_detach(struct pcmcia_device *link) +static void daqp_cs_release(struct pcmcia_device *link) { - struct local_info_t *dev = link->priv; - - dev->stop = 1; - daqp_cs_release(link); - - /* Unlink device structure, and free it */ - dev_table[dev->table_index] = NULL; - kfree(dev); + dev_dbg(&link->dev, "daqp_cs_release\n"); + pcmcia_disable_device(link); } static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) @@ -1009,32 +977,48 @@ static void daqp_cs_config(struct pcmcia_device *link) failed: daqp_cs_release(link); +} -} /* daqp_cs_config */ - -static void daqp_cs_release(struct pcmcia_device *link) +static int daqp_cs_attach(struct pcmcia_device *link) { - dev_dbg(&link->dev, "daqp_cs_release\n"); + struct local_info_t *local; + int i; - pcmcia_disable_device(link); -} /* daqp_cs_release */ + dev_dbg(&link->dev, "daqp_cs_attach()\n"); -static int daqp_cs_suspend(struct pcmcia_device *link) -{ - struct local_info_t *local = link->priv; + for (i = 0; i < MAX_DEV; i++) + if (dev_table[i] == NULL) + break; + if (i == MAX_DEV) { + dev_notice(&link->dev, "no devices available\n"); + return -ENODEV; + } + + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; + + local->table_index = i; + dev_table[i] = local; + local->link = link; + link->priv = local; + + daqp_cs_config(link); - /* Mark the device as stopped, to block IO until later */ - local->stop = 1; return 0; } -static int daqp_cs_resume(struct pcmcia_device *link) +static void daqp_cs_detach(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; + struct local_info_t *dev = link->priv; - local->stop = 0; + dev->stop = 1; + daqp_cs_release(link); - return 0; + /* Unlink device structure, and free it */ + dev_table[dev->table_index] = NULL; + kfree(dev); } /*====================================================================*/ -- cgit v0.10.2 From 86be5680f5804690654519751ed77aaa54b01826 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 14:59:36 -0700 Subject: staging: comedi: quatech_daqp_cs: remove daqp_cs_release() This function justs emits a dev_dbg() message then calls pcmcia_disable_device(). The dev_dbg() is just added noise. Remove the function and just call pcmcia_disable_device(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 748aa6a..b2b755f 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -936,13 +936,6 @@ static int daqp_cs_resume(struct pcmcia_device *link) return 0; } -static void daqp_cs_release(struct pcmcia_device *link) -{ - dev_dbg(&link->dev, "daqp_cs_release\n"); - - pcmcia_disable_device(link); -} - static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { if (p_dev->config_index == 0) @@ -976,7 +969,7 @@ static void daqp_cs_config(struct pcmcia_device *link) return; failed: - daqp_cs_release(link); + pcmcia_disable_device(link); } static int daqp_cs_attach(struct pcmcia_device *link) @@ -1014,7 +1007,7 @@ static void daqp_cs_detach(struct pcmcia_device *link) struct local_info_t *dev = link->priv; dev->stop = 1; - daqp_cs_release(link); + pcmcia_disable_device(link); /* Unlink device structure, and free it */ dev_table[dev->table_index] = NULL; -- cgit v0.10.2 From cdcc02291bea28b85b81230cb9bd328ab7a3cb35 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 14:59:56 -0700 Subject: staging: comedi: quatech_daqp_cs: cleanup daqp_cs_attach() Absorb the code from daqp_cs_config() into this function and properly return the error if the configuration fails. Remove the dev_dbg() function trace messages. Fix the kzalloc(). The preferred form for passing a size of a struct is: p = kzalloc(sizeof(*p), ...); Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index b2b755f..8eea8a9 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -944,41 +944,12 @@ static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) return pcmcia_request_io(p_dev); } -static void daqp_cs_config(struct pcmcia_device *link) -{ - int ret; - - dev_dbg(&link->dev, "daqp_cs_config\n"); - - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL); - if (ret) { - dev_warn(&link->dev, "no configuration found\n"); - goto failed; - } - - ret = pcmcia_request_irq(link, daqp_interrupt); - if (ret) - goto failed; - - ret = pcmcia_enable_device(link); - if (ret) - goto failed; - - return; - -failed: - pcmcia_disable_device(link); -} - static int daqp_cs_attach(struct pcmcia_device *link) { struct local_info_t *local; + int ret; int i; - dev_dbg(&link->dev, "daqp_cs_attach()\n"); - for (i = 0; i < MAX_DEV; i++) if (dev_table[i] == NULL) break; @@ -988,7 +959,7 @@ static int daqp_cs_attach(struct pcmcia_device *link) } /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); + local = kzalloc(sizeof(*local), GFP_KERNEL); if (!local) return -ENOMEM; @@ -997,9 +968,27 @@ static int daqp_cs_attach(struct pcmcia_device *link) local->link = link; link->priv = local; - daqp_cs_config(link); + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; + + ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL); + if (ret) { + dev_warn(&link->dev, "no configuration found\n"); + goto failed; + } + + ret = pcmcia_request_irq(link, daqp_interrupt); + if (ret) + goto failed; + + ret = pcmcia_enable_device(link); + if (ret) + goto failed; return 0; + +failed: + pcmcia_disable_device(link); + return ret; } static void daqp_cs_detach(struct pcmcia_device *link) -- cgit v0.10.2 From b8319710de2d3f14e11c2d951d238797e2aa489d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:00:22 -0700 Subject: staging: comedi: quatech_daqp_cs: remove casts of void * Casting a void * is not necessary. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 8eea8a9..39af156 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -210,7 +210,7 @@ static void hex_dump(char *str, void *ptr, int len) static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { - struct local_info_t *local = (struct local_info_t *)s->private; + struct local_info_t *local = s->private; if (local->stop) return -EIO; @@ -237,7 +237,7 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) */ static enum irqreturn daqp_interrupt(int irq, void *dev_id) { - struct local_info_t *local = (struct local_info_t *)dev_id; + struct local_info_t *local = dev_id; struct comedi_device *dev; struct comedi_subdevice *s; int loop_limit = 10000; @@ -265,7 +265,7 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) return IRQ_NONE; } - if ((struct local_info_t *)s->private != local) { + if (s->private != local) { pr_warn("invalid comedi_subdevice.\n"); return IRQ_NONE; } @@ -335,7 +335,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = (struct local_info_t *)s->private; + struct local_info_t *local = s->private; int i; int v; int counter = 10000; @@ -528,7 +528,7 @@ static int daqp_ai_cmdtest(struct comedi_device *dev, static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { - struct local_info_t *local = (struct local_info_t *)s->private; + struct local_info_t *local = s->private; struct comedi_cmd *cmd = &s->async->cmd; int counter; int scanlist_start_on_every_entry; @@ -730,7 +730,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = (struct local_info_t *)s->private; + struct local_info_t *local = s->private; int d; unsigned int chan; @@ -757,7 +757,7 @@ static int daqp_di_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = (struct local_info_t *)s->private; + struct local_info_t *local = s->private; if (local->stop) return -EIO; @@ -773,7 +773,7 @@ static int daqp_do_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = (struct local_info_t *)s->private; + struct local_info_t *local = s->private; if (local->stop) return -EIO; -- cgit v0.10.2 From 90967d66269f20f24e8465121dadb99e51ad1f64 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:00:48 -0700 Subject: staging: comedi: quatech_daqp_cs: simplify IRQ_NONE checks in daqp_interrupt() Remove all the pr_warn() noise in the sanity checks that make sure the interrupt is for this device. Simplify the sanity checks into one if() condition. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 39af156..fe36450 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -238,37 +238,13 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) static enum irqreturn daqp_interrupt(int irq, void *dev_id) { struct local_info_t *local = dev_id; - struct comedi_device *dev; - struct comedi_subdevice *s; + struct comedi_device *dev = local ? local->dev : NULL; + struct comedi_subdevice *s = local ? local->s : NULL; int loop_limit = 10000; int status; - if (local == NULL) { - pr_warn("irq %d for unknown device.\n", irq); - return IRQ_NONE; - } - - dev = local->dev; - if (dev == NULL) { - pr_warn("NULL comedi_device.\n"); - return IRQ_NONE; - } - - if (!dev->attached) { - pr_warn("struct comedi_device not yet attached.\n"); + if (!dev || !dev->attached || !s || s->private != local) return IRQ_NONE; - } - - s = local->s; - if (s == NULL) { - pr_warn("NULL comedi_subdevice.\n"); - return IRQ_NONE; - } - - if (s->private != local) { - pr_warn("invalid comedi_subdevice.\n"); - return IRQ_NONE; - } switch (local->interrupt_mode) { -- cgit v0.10.2 From 79a53df7fa7913d4589d5785130f6781430c64ce Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:01:06 -0700 Subject: staging: comedi: quatech_daqp_cs: remove debug functions The functions daqp_dump() and hex_dump() are not used in this driver. Just remove them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index fe36450..c6a7943 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -180,32 +180,6 @@ static const struct comedi_lrange range_daqp_ai = { 4, { static const struct comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)} }; -#ifdef DAQP_DEBUG - -static void daqp_dump(struct comedi_device *dev) -{ - dev_info(dev->class_dev, "status %02x; aux status %02x\n", - inb(dev->iobase + DAQP_STATUS), inb(dev->iobase + DAQP_AUX)); -} - -static void hex_dump(char *str, void *ptr, int len) -{ - unsigned char *cptr = ptr; - int i; - - printk(str); - - for (i = 0; i < len; i++) { - if (i % 16 == 0) - printk("\n%p:", cptr); - - printk(" %02x", *(cptr++)); - } - printk("\n"); -} - -#endif - /* Cancel a running acquisition */ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) -- cgit v0.10.2 From 7b947d6116d6408afe7ffaa176e634c715cef9b9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:01:25 -0700 Subject: staging: comedi: quatech_daqp_cs: remove #define pr_fmt There are not pr_[level] uses in this file. Remove the pr_fmt define. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index c6a7943..a74581f 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -47,8 +47,6 @@ Status: works Devices: [Quatech] DAQP-208 (daqp), DAQP-308 */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include "../comedidev.h" #include -- cgit v0.10.2 From e23fe9a1bf80eee77d4cc97504bcec0c40ed973d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:01:46 -0700 Subject: staging: comedi: quatech_daqp_cs: cleanup the comedi_lrange tables For aesthetic reasons, cleanup the whitespace of the range_daqp_ai table. Remove the range_daqp_ao table and use the comedi core provided range table for bipolar 5V (range_bipolar5). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index a74581f..185632e 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -163,21 +163,15 @@ static struct local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ }; #define DAQP_AUX_FIFO_NEARFULL 0x02 #define DAQP_AUX_FIFO_EMPTY 0x01 -/* These range structures tell COMEDI how the sample values map to - * voltages. The A/D converter has four .ranges = +/- 10V through - * +/- 1.25V, and the D/A converter has only .one = +/- 5V. - */ - -static const struct comedi_lrange range_daqp_ai = { 4, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25) - } +static const struct comedi_lrange range_daqp_ai = { + 4, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25) + } }; -static const struct comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)} }; - /* Cancel a running acquisition */ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) @@ -797,7 +791,7 @@ static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it) s->n_chan = 2; s->len_chanlist = 1; s->maxdata = 0x0fff; - s->range_table = &range_daqp_ao; + s->range_table = &range_bipolar5; s->insn_write = daqp_ao_insn_write; s = &dev->subdevices[2]; -- cgit v0.10.2 From c65c64d0f0b269b1239fdce253fd4717281cc98d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:02:06 -0700 Subject: staging: comedi: quatech_daqp_cs: fix possible memory dereference issue In daqp_attach(), the first options value passed in the comedi_devconfig is used as an index to the private dev_table[] in this driver. This table is used to pass the pcmcia_device to the comedi_driver. Fix the code so that the index is checked before the table is accessed so that we don't get a possible memory dereference BUG. Change the error returned to the comedi core from -EIO to -ENODEV. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 185632e..2a5f9ab 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -733,15 +733,16 @@ static int daqp_do_insn_write(struct comedi_device *dev, static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it) { - int ret; - struct local_info_t *local = dev_table[it->options[0]]; + struct local_info_t *local; struct comedi_subdevice *s; + int ret; - if (it->options[0] < 0 || it->options[0] >= MAX_DEV || !local) { - dev_err(dev->class_dev, "No such daqp device %d\n", - it->options[0]); - return -EIO; - } + if (it->options[0] < 0 || it->options[0] >= MAX_DEV) + return -ENODEV; + + local = dev_table[it->options[0]]; + if (!local) + return -ENODEV; /* Typically brittle code that I don't completely understand, * but "it works on my card". The intent is to pull the model -- cgit v0.10.2 From b7c0afa4b68c7b1cacaa4511721347682f7e1558 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 15:02:28 -0700 Subject: staging: comedi: quatech_daqp_cs: cleanup subdevice init Remove the dev_info() board attach noise. For aesthetic reasons, add some whitespace to the subdevice init. Remove the init of the s->len_chanlist for the subdevices that do not support commands. It's not used by them and the comedi core will handle initializing it properly in the postconfig. Change the return after a successful attach to "0". The comedi core expects a < 0 value to indicate an error and "0" is the typical value returned to indicate success. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 2a5f9ab..2c35d75 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -767,51 +767,46 @@ static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (ret) return ret; - dev_info(dev->class_dev, "attaching daqp%d (io 0x%04lx)\n", - it->options[0], dev->iobase); - s = &dev->subdevices[0]; dev->read_subdev = s; - s->private = local; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; - s->n_chan = 8; - s->len_chanlist = 2048; - s->maxdata = 0xffff; - s->range_table = &range_daqp_ai; - s->insn_read = daqp_ai_insn_read; - s->do_cmdtest = daqp_ai_cmdtest; - s->do_cmd = daqp_ai_cmd; - s->cancel = daqp_ai_cancel; + s->private = local; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; + s->n_chan = 8; + s->len_chanlist = 2048; + s->maxdata = 0xffff; + s->range_table = &range_daqp_ai; + s->insn_read = daqp_ai_insn_read; + s->do_cmdtest = daqp_ai_cmdtest; + s->do_cmd = daqp_ai_cmd; + s->cancel = daqp_ai_cancel; s = &dev->subdevices[1]; dev->write_subdev = s; - s->private = local; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 2; - s->len_chanlist = 1; - s->maxdata = 0x0fff; - s->range_table = &range_bipolar5; - s->insn_write = daqp_ao_insn_write; + s->private = local; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 2; + s->maxdata = 0x0fff; + s->range_table = &range_bipolar5; + s->insn_write = daqp_ao_insn_write; s = &dev->subdevices[2]; - s->private = local; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 1; - s->len_chanlist = 1; - s->insn_read = daqp_di_insn_read; + s->private = local; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 1; + s->insn_read = daqp_di_insn_read; s = &dev->subdevices[3]; - s->private = local; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 1; - s->len_chanlist = 1; - s->insn_write = daqp_do_insn_write; + s->private = local; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 1; + s->len_chanlist = 1; + s->insn_write = daqp_do_insn_write; - return 1; + return 0; } static void daqp_detach(struct comedi_device *dev) -- cgit v0.10.2 From 27629c600d6090af0f9d5af9a09bf9dd2aff5adf Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:32:42 -0700 Subject: staging: comedi: ni_mio_cs: move MODULE_* info to end of file For aesthetic reasons, move all the MODULE_* information to the end of the file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index b5c5d58..2feeff2 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -416,11 +416,7 @@ static const struct pcmcia_device_id ni_mio_cs_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */ PCMCIA_DEVICE_NULL }; - MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids); -MODULE_AUTHOR("David A. Schleef "); -MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series"); -MODULE_LICENSE("GPL"); static struct pcmcia_driver ni_mio_cs_driver = { .probe = &cs_attach, @@ -431,5 +427,8 @@ static struct pcmcia_driver ni_mio_cs_driver = { .owner = THIS_MODULE, .name = "ni_mio_cs", }; - module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver); + +MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series"); +MODULE_AUTHOR("David A. Schleef "); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From a7538b8271b2abe6fa4cc8b8ce684d2970de1bfb Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:33:00 -0700 Subject: staging: comedi: ni_mio_cs: cleanup pcmcia_driver For aesthetic reasons, reorder the pcmcia_driver variables and add some whitespace. Also, remove the unnecessary '&' before the function names. They are already addresses. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 2feeff2..47ce237 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -419,13 +419,13 @@ static const struct pcmcia_device_id ni_mio_cs_ids[] = { MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids); static struct pcmcia_driver ni_mio_cs_driver = { - .probe = &cs_attach, - .remove = &cs_detach, - .suspend = &mio_cs_suspend, - .resume = &mio_cs_resume, - .id_table = ni_mio_cs_ids, - .owner = THIS_MODULE, - .name = "ni_mio_cs", + .name = "ni_mio_cs", + .owner = THIS_MODULE, + .id_table = ni_mio_cs_ids, + .probe = cs_attach, + .remove = cs_detach, + .suspend = mio_cs_suspend, + .resume = mio_cs_resume, }; module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver); -- cgit v0.10.2 From b8f4c930e0ff5340e3fea6b1142ccf7100df6d76 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:33:17 -0700 Subject: staging: comedi: ni_mio_cs: remove setting dev->driver The comedi core sets the dev->driver pointer before calling the comedi_driver attach function. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 47ce237..c4ab3b6 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -335,7 +335,6 @@ static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (!link) return -EIO; - dev->driver = &driver_ni_mio_cs; dev->iobase = link->resource[0]->start; irq = link->irq; -- cgit v0.10.2 From 63e563af82e643cc0aaf3409fea2328809f2cf36 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:33:37 -0700 Subject: staging: comedi: ni_mio_cs: remove pcmcia_driver suspend/resume The pcmcia_driver suspend and resume functions in this driver don't do anything. Since they are optional just remove them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index c4ab3b6..1099b8b 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -272,20 +272,6 @@ static void cs_detach(struct pcmcia_device *link) cs_release(link); } -static int mio_cs_suspend(struct pcmcia_device *link) -{ - DPRINTK("pm suspend\n"); - - return 0; -} - -static int mio_cs_resume(struct pcmcia_device *link) -{ - DPRINTK("pm resume\n"); - return 0; -} - - static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { int base, ret; @@ -423,8 +409,6 @@ static struct pcmcia_driver ni_mio_cs_driver = { .id_table = ni_mio_cs_ids, .probe = cs_attach, .remove = cs_detach, - .suspend = mio_cs_suspend, - .resume = mio_cs_resume, }; module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver); -- cgit v0.10.2 From bea5b9035dae264e5da4a8a6aacc8bace0647c35 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:33:54 -0700 Subject: staging: comedi: ni_mio_cs: move pcmcia_driver functions For aesthetic reasons, move all the pcmcia_driver functions so they are near the pcmcia_driver declaration. This also removes the need for a couple forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 1099b8b..4043d02 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -247,67 +247,8 @@ static void mio_cs_detach(struct comedi_device *dev) free_irq(dev->irq, dev); } -static void mio_cs_config(struct pcmcia_device *link); -static void cs_release(struct pcmcia_device *link); -static void cs_detach(struct pcmcia_device *); - static struct pcmcia_device *cur_dev; -static int cs_attach(struct pcmcia_device *link) -{ - cur_dev = link; - - mio_cs_config(link); - - return 0; -} - -static void cs_release(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); -} - -static void cs_detach(struct pcmcia_device *link) -{ - cs_release(link); -} - -static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) -{ - int base, ret; - - p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; - p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; - - for (base = 0x000; base < 0x400; base += 0x20) { - p_dev->resource[0]->start = base; - ret = pcmcia_request_io(p_dev); - if (!ret) - return 0; - } - return -ENODEV; -} - - -static void mio_cs_config(struct pcmcia_device *link) -{ - int ret; - - DPRINTK("mio_cs_config(link=%p)\n", link); - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); - if (ret) { - dev_warn(&link->dev, "no configuration found\n"); - return; - } - - if (!link->irq) - dev_info(&link->dev, "no IRQ available\n"); - - ret = pcmcia_enable_device(link); -} - static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) { struct ni_private *devpriv; @@ -393,6 +334,60 @@ static int ni_getboardtype(struct comedi_device *dev, return 0; } +static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) +{ + int base, ret; + + p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; + p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; + + for (base = 0x000; base < 0x400; base += 0x20) { + p_dev->resource[0]->start = base; + ret = pcmcia_request_io(p_dev); + if (!ret) + return 0; + } + return -ENODEV; +} + +static void mio_cs_config(struct pcmcia_device *link) +{ + int ret; + + DPRINTK("mio_cs_config(link=%p)\n", link); + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; + + ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); + if (ret) { + dev_warn(&link->dev, "no configuration found\n"); + return; + } + + if (!link->irq) + dev_info(&link->dev, "no IRQ available\n"); + + ret = pcmcia_enable_device(link); +} + +static int cs_attach(struct pcmcia_device *link) +{ + cur_dev = link; + + mio_cs_config(link); + + return 0; +} + +static void cs_release(struct pcmcia_device *link) +{ + pcmcia_disable_device(link); +} + +static void cs_detach(struct pcmcia_device *link) +{ + cs_release(link); +} + static const struct pcmcia_device_id ni_mio_cs_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */ -- cgit v0.10.2 From 1b69a7577a2a67841c0a6fb742392457a7aa989c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:34:10 -0700 Subject: staging: comedi: ni_mio_cs: remove cs_release() This function simply calls pcmcia_disable_device(). Remove it and just call pcmcia_disable_device() where needed. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 4043d02..e0adf23 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -378,14 +378,9 @@ static int cs_attach(struct pcmcia_device *link) return 0; } -static void cs_release(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); -} - static void cs_detach(struct pcmcia_device *link) { - cs_release(link); + pcmcia_disable_device(link); } static const struct pcmcia_device_id ni_mio_cs_ids[] = { -- cgit v0.10.2 From e5e7ff89e660e8e1a0861062197f3fd4d7576c41 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:34:27 -0700 Subject: staging: comedi: ni_mio_cs: cleanup cs_attach() Absorb the code from mio_cs_config() into this function and properly return the error if the configuration fails. Remove the DPRINTK() function trace message. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index e0adf23..84f4378 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -350,32 +350,24 @@ static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) return -ENODEV; } -static void mio_cs_config(struct pcmcia_device *link) +static int cs_attach(struct pcmcia_device *link) { int ret; - DPRINTK("mio_cs_config(link=%p)\n", link); + cur_dev = link; + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); if (ret) { dev_warn(&link->dev, "no configuration found\n"); - return; + return ret; } if (!link->irq) dev_info(&link->dev, "no IRQ available\n"); - ret = pcmcia_enable_device(link); -} - -static int cs_attach(struct pcmcia_device *link) -{ - cur_dev = link; - - mio_cs_config(link); - - return 0; + return pcmcia_enable_device(link); } static void cs_detach(struct pcmcia_device *link) -- cgit v0.10.2 From aaefe848e056474a583b43c13c4891fbda50caa4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:34:45 -0700 Subject: staging: comedi: ni_mio_cs: move comedi_driver declaration Move the comedi_driver declaration down in the file. This gets rid of the need for a couple forward declarations. For aesthetic reasons, add some whitespace to the declaration. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 84f4378..253f735 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -225,16 +225,6 @@ static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr) return ret; } -static int mio_cs_attach(struct comedi_device *dev, - struct comedi_devconfig *it); -static void mio_cs_detach(struct comedi_device *dev); -static struct comedi_driver driver_ni_mio_cs = { - .driver_name = "ni_mio_cs", - .module = THIS_MODULE, - .attach = mio_cs_attach, - .detach = mio_cs_detach, -}; - #include "ni_mio_common.c" static int ni_getboardtype(struct comedi_device *dev, @@ -334,6 +324,13 @@ static int ni_getboardtype(struct comedi_device *dev, return 0; } +static struct comedi_driver driver_ni_mio_cs = { + .driver_name = "ni_mio_cs", + .module = THIS_MODULE, + .attach = mio_cs_attach, + .detach = mio_cs_detach, +}; + static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { int base, ret; -- cgit v0.10.2 From abbe0796baa03610f3147c786c7c3f20b0050c1d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:35:02 -0700 Subject: staging: comedi: ni_mio_cs: move mio_cs_detach() For aesthetic reasons, move this function down so it's by the comedi_driver declaration. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 253f735..2d28a71 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -230,13 +230,6 @@ static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr) static int ni_getboardtype(struct comedi_device *dev, struct pcmcia_device *link); -static void mio_cs_detach(struct comedi_device *dev) -{ - mio_common_detach(dev); - if (dev->irq) - free_irq(dev->irq, dev); -} - static struct pcmcia_device *cur_dev; static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) @@ -324,6 +317,13 @@ static int ni_getboardtype(struct comedi_device *dev, return 0; } +static void mio_cs_detach(struct comedi_device *dev) +{ + mio_common_detach(dev); + if (dev->irq) + free_irq(dev->irq, dev); +} + static struct comedi_driver driver_ni_mio_cs = { .driver_name = "ni_mio_cs", .module = THIS_MODULE, -- cgit v0.10.2 From 616b7a479e190e099f75073231c027fa393da5b2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:35:19 -0700 Subject: staging: comedi: ni_mio_cs: remove last forward declaration Move the ni_getboardtype() function to remove the last forward declaration in this file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 2d28a71..a9cd552 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -227,10 +227,23 @@ static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr) #include "ni_mio_common.c" +static struct pcmcia_device *cur_dev; + static int ni_getboardtype(struct comedi_device *dev, - struct pcmcia_device *link); + struct pcmcia_device *link) +{ + int i; -static struct pcmcia_device *cur_dev; + for (i = 0; i < n_ni_boards; i++) { + if (ni_boards[i].device_id == link->card_id) + return i; + } + + dev_err(dev->class_dev, + "unknown board 0x%04x -- pretend it is a ", link->card_id); + + return 0; +} static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) { @@ -301,22 +314,6 @@ static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) return 0; } -static int ni_getboardtype(struct comedi_device *dev, - struct pcmcia_device *link) -{ - int i; - - for (i = 0; i < n_ni_boards; i++) { - if (ni_boards[i].device_id == link->card_id) - return i; - } - - dev_err(dev->class_dev, - "unknown board 0x%04x -- pretend it is a ", link->card_id); - - return 0; -} - static void mio_cs_detach(struct comedi_device *dev) { mio_common_detach(dev); -- cgit v0.10.2 From 678a6ff3e98ddbb049f3a012520c36da3065af4d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:35:37 -0700 Subject: staging: comedi: ni_mio_cs: cleanup mio_cs_attach() Remove the DPRINTK() function trace message as well as the #if 0'ed out debug code that dumps the board "fingerprint". Remove the need for the local variable that holds the link->irq passed to request_irq(). Also, return the error code from that function instead of assuming -EINVAL. Use the dev->board_name for the resource string passed to request_irq() instead of the open coded string "ni_mio_cs". For aesthetic reasons, add some whitespace to the initializatio of the devpriv values. Just return the result of ni_E_init() instead of checking it for an error, returning the error, or returning "0". Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index a9cd552..4e03c46 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -245,73 +245,38 @@ static int ni_getboardtype(struct comedi_device *dev, return 0; } -static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int mio_cs_attach(struct comedi_device *dev, + struct comedi_devconfig *it) { struct ni_private *devpriv; struct pcmcia_device *link; - unsigned int irq; int ret; - DPRINTK("mio_cs_attach(dev=%p,it=%p)\n", dev, it); - link = cur_dev; /* XXX hack */ if (!link) return -EIO; - dev->iobase = link->resource[0]->start; - - irq = link->irq; - dev->board_ptr = ni_boards + ni_getboardtype(dev, link); - -#if 0 - { - int i; - - printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ", - dev->minor, dev->driver->driver_name, dev->iobase, irq); - - printk(" board fingerprint:"); - for (i = 0; i < 32; i += 2) { - printk(" %04x %02x", inw(dev->iobase + i), - inb(dev->iobase + i + 1)); - } - printk("\n"); - printk(" board fingerprint (windowed):"); - for (i = 0; i < 10; i++) - printk(" 0x%04x", win_in(i)); - printk("\n"); - - printk("boardtype.name: %s\n", boardtype.name); - } -#endif - dev->board_name = boardtype.name; + dev->iobase = link->resource[0]->start; - ret = request_irq(irq, ni_E_interrupt, NI_E_IRQ_FLAGS, - "ni_mio_cs", dev); - if (ret < 0) { - dev_err(dev->class_dev, "irq not available\n"); - return -EINVAL; - } - dev->irq = irq; + ret = request_irq(link->irq, ni_E_interrupt, NI_E_IRQ_FLAGS, + dev->board_name, dev); + if (ret < 0) + return ret; + dev->irq = link->irq; ret = ni_alloc_private(dev); if (ret) return ret; - devpriv = dev->private; - - devpriv->stc_writew = &mio_cs_win_out; - devpriv->stc_readw = &mio_cs_win_in; - devpriv->stc_writel = &win_out2; - devpriv->stc_readl = &win_in2; - ret = ni_E_init(dev); - - if (ret < 0) - return ret; + devpriv = dev->private; + devpriv->stc_writew = mio_cs_win_out; + devpriv->stc_readw = mio_cs_win_in; + devpriv->stc_writel = win_out2; + devpriv->stc_readl = win_in2; - return 0; + return ni_E_init(dev); } static void mio_cs_detach(struct comedi_device *dev) -- cgit v0.10.2 From 885d8bce7f6e834c190ee3c60561c1c6c0e6174b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 17:35:55 -0700 Subject: staging: comedi: ni_mio_cs: cleanup the boardinfo declaration For aesthetic reasons, reformat the boardinfo declaration and add some whitespace. Remove all the information that is set to '0' as this is the default. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 4e03c46..07e4bd8 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -65,104 +65,84 @@ See the notes in the ni_atmio.o driver. #define MAX_N_CALDACS 32 static const struct ni_board_struct ni_boards[] = { - {.device_id = 0x010d, - .name = "DAQCard-ai-16xe-50", - .n_adchan = 16, - .adbits = 16, - .ai_fifo_depth = 1024, - .alwaysdither = 0, - .gainlkup = ai_gain_8, - .ai_speed = 5000, - .n_aochan = 0, - .aobits = 0, - .ao_fifo_depth = 0, - .ao_unipolar = 0, - .num_p0_dio_channels = 8, - .has_8255 = 0, - .caldac = {dac8800, dac8043}, - }, - {.device_id = 0x010c, - .name = "DAQCard-ai-16e-4", - .n_adchan = 16, - .adbits = 12, - .ai_fifo_depth = 1024, - .alwaysdither = 0, - .gainlkup = ai_gain_16, - .ai_speed = 4000, - .n_aochan = 0, - .aobits = 0, - .ao_fifo_depth = 0, - .ao_unipolar = 0, - .num_p0_dio_channels = 8, - .has_8255 = 0, - .caldac = {mb88341}, /* verified */ - }, - {.device_id = 0x02c4, - .name = "DAQCard-6062E", - .n_adchan = 16, - .adbits = 12, - .ai_fifo_depth = 8192, - .alwaysdither = 0, - .gainlkup = ai_gain_16, - .ai_speed = 2000, - .n_aochan = 2, - .aobits = 12, - .ao_fifo_depth = 2048, - .ao_range_table = &range_bipolar10, - .ao_unipolar = 0, - .ao_speed = 1176, - .num_p0_dio_channels = 8, - .has_8255 = 0, - .caldac = {ad8804_debug}, /* verified */ - }, - {.device_id = 0x075e, - .name = "DAQCard-6024E", /* specs incorrect! */ - .n_adchan = 16, - .adbits = 12, - .ai_fifo_depth = 1024, - .alwaysdither = 0, - .gainlkup = ai_gain_4, - .ai_speed = 5000, - .n_aochan = 2, - .aobits = 12, - .ao_fifo_depth = 0, - .ao_range_table = &range_bipolar10, - .ao_unipolar = 0, - .ao_speed = 1000000, - .num_p0_dio_channels = 8, - .has_8255 = 0, - .caldac = {ad8804_debug}, - }, - {.device_id = 0x0245, - .name = "DAQCard-6036E", /* specs incorrect! */ - .n_adchan = 16, - .adbits = 16, - .ai_fifo_depth = 1024, - .alwaysdither = 1, - .gainlkup = ai_gain_4, - .ai_speed = 5000, - .n_aochan = 2, - .aobits = 16, - .ao_fifo_depth = 0, - .ao_range_table = &range_bipolar10, - .ao_unipolar = 0, - .ao_speed = 1000000, - .num_p0_dio_channels = 8, - .has_8255 = 0, - .caldac = {ad8804_debug}, + { + .device_id = 0x010d, + .name = "DAQCard-ai-16xe-50", + .n_adchan = 16, + .adbits = 16, + .ai_fifo_depth = 1024, + .gainlkup = ai_gain_8, + .ai_speed = 5000, + .num_p0_dio_channels = 8, + .caldac = { dac8800, dac8043 }, + }, { + .device_id = 0x010c, + .name = "DAQCard-ai-16e-4", + .n_adchan = 16, + .adbits = 12, + .ai_fifo_depth = 1024, + .gainlkup = ai_gain_16, + .ai_speed = 4000, + .num_p0_dio_channels = 8, + .caldac = { mb88341 }, /* verified */ + }, { + .device_id = 0x02c4, + .name = "DAQCard-6062E", + .n_adchan = 16, + .adbits = 12, + .ai_fifo_depth = 8192, + .gainlkup = ai_gain_16, + .ai_speed = 2000, + .n_aochan = 2, + .aobits = 12, + .ao_fifo_depth = 2048, + .ao_range_table = &range_bipolar10, + .ao_speed = 1176, + .num_p0_dio_channels = 8, + .caldac = { ad8804_debug }, /* verified */ + }, { + /* specs incorrect! */ + .device_id = 0x075e, + .name = "DAQCard-6024E", + .n_adchan = 16, + .adbits = 12, + .ai_fifo_depth = 1024, + .gainlkup = ai_gain_4, + .ai_speed = 5000, + .n_aochan = 2, + .aobits = 12, + .ao_range_table = &range_bipolar10, + .ao_speed = 1000000, + .num_p0_dio_channels = 8, + .caldac = { ad8804_debug }, + }, { + /* specs incorrect! */ + .device_id = 0x0245, + .name = "DAQCard-6036E", + .n_adchan = 16, + .adbits = 16, + .ai_fifo_depth = 1024, + .alwaysdither = 1, + .gainlkup = ai_gain_4, + .ai_speed = 5000, + .n_aochan = 2, + .aobits = 16, + .ao_range_table = &range_bipolar10, + .ao_speed = 1000000, + .num_p0_dio_channels = 8, + .caldac = { ad8804_debug }, }, #if 0 - {.device_id = 0x0000, /* unknown */ - .name = "DAQCard-6715", - .n_adchan = 0, - .n_aochan = 8, - .aobits = 12, - .ao_671x = 8192, - .num_p0_dio_channels = 8, - .caldac = {mb88341, mb88341}, - }, + { + .device_id = 0x0000, /* unknown */ + .name = "DAQCard-6715", + .n_aochan = 8, + .aobits = 12, + .ao_671x = 8192, + .num_p0_dio_channels = 8, + .caldac = { mb88341, mb88341 }, + }, #endif - /* N.B. Update ni_mio_cs_ids[] when entries added above. */ }; #define interrupt_pin(a) 0 -- cgit v0.10.2 From 3e6c183306009b62c8de6e0d439ae61e7af22bc0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:35:06 -0700 Subject: staging: comedi: ni_labpc_cs: move MODULE_* info to end of file For aesthetic reasons, move all the MODULE_* information to the end of the file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index b26496d..7d9fce9 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -268,9 +268,6 @@ static const struct pcmcia_device_id labpc_cs_ids[] = { }; MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids); -MODULE_AUTHOR("Frank Mori Hess "); -MODULE_DESCRIPTION("Comedi driver for National Instruments Lab-PC"); -MODULE_LICENSE("GPL"); static struct pcmcia_driver labpc_cs_driver = { .probe = labpc_cs_attach, @@ -281,5 +278,8 @@ static struct pcmcia_driver labpc_cs_driver = { .owner = THIS_MODULE, .name = "daqcard-1200", }; - module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver); + +MODULE_DESCRIPTION("Comedi driver for National Instruments Lab-PC"); +MODULE_AUTHOR("Frank Mori Hess "); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 098303caaf3a24e43a67d9a6e7d2f7d3033a601f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:35:22 -0700 Subject: staging: comedi: ni_labpc_cs: cleanup pcmcia_driver For aesthetic reasons, reorder the pcmcia_driver variables and add some whitespace. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 7d9fce9..f2c7ab6 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -266,17 +266,16 @@ static const struct pcmcia_device_id labpc_cs_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ PCMCIA_DEVICE_NULL }; - MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids); static struct pcmcia_driver labpc_cs_driver = { - .probe = labpc_cs_attach, - .remove = labpc_cs_detach, - .suspend = labpc_cs_suspend, - .resume = labpc_cs_resume, - .id_table = labpc_cs_ids, - .owner = THIS_MODULE, - .name = "daqcard-1200", + .name = "daqcard-1200", + .owner = THIS_MODULE, + .id_table = labpc_cs_ids, + .probe = labpc_cs_attach, + .remove = labpc_cs_detach, + .suspend = labpc_cs_suspend, + .resume = labpc_cs_resume, }; module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver); -- cgit v0.10.2 From 88dd3eb4d8cb335166df779bcaabab9d1c5fa513 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:35:39 -0700 Subject: staging: comedi: ni_labpc_cs: remove labpc_release() The function simply calls pcmcia_disable_device(). Remove it and just call pcmcia_disable_device() where needed. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index f2c7ab6..64fe4b2 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -155,7 +155,6 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) } static void labpc_config(struct pcmcia_device *link); -static void labpc_release(struct pcmcia_device *link); static int labpc_cs_suspend(struct pcmcia_device *p_dev); static int labpc_cs_resume(struct pcmcia_device *p_dev); @@ -191,7 +190,7 @@ static int labpc_cs_attach(struct pcmcia_device *link) static void labpc_cs_detach(struct pcmcia_device *link) { ((struct local_info_t *)link->priv)->stop = 1; - labpc_release(link); + pcmcia_disable_device(link); /* This points to the parent local_info_t struct (may be null) */ kfree(link->priv); @@ -233,16 +232,8 @@ static void labpc_config(struct pcmcia_device *link) return; failed: - labpc_release(link); - -} /* labpc_config */ - -static void labpc_release(struct pcmcia_device *link) -{ - dev_dbg(&link->dev, "labpc_release\n"); - pcmcia_disable_device(link); -} /* labpc_release */ +} static int labpc_cs_suspend(struct pcmcia_device *link) { -- cgit v0.10.2 From deead9d973f4e225447f77bc4f128864fefd9a88 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:35:55 -0700 Subject: staging: comedi: ni_labpc_cs: remove 'stop' from private pcmcia data The pcmcia_driver suspend and remove functions set the 'stop' variable and the resume function clears it. Nothing in the comedi_driver code uses the 'stop' variable. Just remove it so we can get rid of the suspend/resume. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 64fe4b2..ef3c0ef 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -163,7 +163,6 @@ static void labpc_cs_detach(struct pcmcia_device *); struct local_info_t { struct pcmcia_device *link; - int stop; struct bus_operations *bus; }; @@ -189,7 +188,6 @@ static int labpc_cs_attach(struct pcmcia_device *link) static void labpc_cs_detach(struct pcmcia_device *link) { - ((struct local_info_t *)link->priv)->stop = 1; pcmcia_disable_device(link); /* This points to the parent local_info_t struct (may be null) */ @@ -237,18 +235,11 @@ failed: static int labpc_cs_suspend(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; - - /* Mark the device as stopped, to block IO until later */ - local->stop = 1; return 0; } /* labpc_cs_suspend */ static int labpc_cs_resume(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; - - local->stop = 0; return 0; } /* labpc_cs_resume */ -- cgit v0.10.2 From 4fc76ea03f5f847e7c70cd81849b2c825119ef78 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:36:16 -0700 Subject: staging: comedi: ni_labpc_cs: remove pcmcia_driver suspend/resume The pcmcia_driver suspend and resume functions in this driver don't do anything. Since they are optional just remove them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index ef3c0ef..30b2ddd 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -155,8 +155,6 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) } static void labpc_config(struct pcmcia_device *link); -static int labpc_cs_suspend(struct pcmcia_device *p_dev); -static int labpc_cs_resume(struct pcmcia_device *p_dev); static int labpc_cs_attach(struct pcmcia_device *); static void labpc_cs_detach(struct pcmcia_device *); @@ -233,16 +231,6 @@ failed: pcmcia_disable_device(link); } -static int labpc_cs_suspend(struct pcmcia_device *link) -{ - return 0; -} /* labpc_cs_suspend */ - -static int labpc_cs_resume(struct pcmcia_device *link) -{ - return 0; -} /* labpc_cs_resume */ - static const struct pcmcia_device_id labpc_cs_ids[] = { /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ @@ -256,8 +244,6 @@ static struct pcmcia_driver labpc_cs_driver = { .id_table = labpc_cs_ids, .probe = labpc_cs_attach, .remove = labpc_cs_detach, - .suspend = labpc_cs_suspend, - .resume = labpc_cs_resume, }; module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver); -- cgit v0.10.2 From 00cefaa56219ac78fa6ece610b0854628a9724aa Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:36:33 -0700 Subject: staging: comedi: ni_labpc_cs: move pcmcia_driver functions For aesthetic reasons, move all the pcmcia_driver functions so they are near the pcmcia_driver declaration. This also removes the need for some of the forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 30b2ddd..61ad5ce 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -154,45 +154,11 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) return labpc_common_attach(dev, iobase, irq, 0); } -static void labpc_config(struct pcmcia_device *link); - -static int labpc_cs_attach(struct pcmcia_device *); -static void labpc_cs_detach(struct pcmcia_device *); - struct local_info_t { struct pcmcia_device *link; struct bus_operations *bus; }; -static int labpc_cs_attach(struct pcmcia_device *link) -{ - struct local_info_t *local; - - dev_dbg(&link->dev, "labpc_cs_attach()\n"); - - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); - if (!local) - return -ENOMEM; - local->link = link; - link->priv = local; - - pcmcia_cur_dev = link; - - labpc_config(link); - - return 0; -} /* labpc_cs_attach */ - -static void labpc_cs_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); - - /* This points to the parent local_info_t struct (may be null) */ - kfree(link->priv); - -} - static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { @@ -202,7 +168,6 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, return pcmcia_request_io(p_dev); } - static void labpc_config(struct pcmcia_device *link) { int ret; @@ -231,6 +196,34 @@ failed: pcmcia_disable_device(link); } +static int labpc_cs_attach(struct pcmcia_device *link) +{ + struct local_info_t *local; + + dev_dbg(&link->dev, "labpc_cs_attach()\n"); + + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; + + pcmcia_cur_dev = link; + + labpc_config(link); + + return 0; +} + +static void labpc_cs_detach(struct pcmcia_device *link) +{ + pcmcia_disable_device(link); + + /* This points to the parent local_info_t struct (may be null) */ + kfree(link->priv); +} + static const struct pcmcia_device_id labpc_cs_ids[] = { /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ -- cgit v0.10.2 From fdcb5fdee2c7ec6327d08f4529da7e1130d0fa63 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:36:50 -0700 Subject: staging: comedi: ni_labpc_cs: cleanup labpc_cs_attach() Absorb the code from labpc_config() into this function and properly return the error if the configuration fails. Also, remove the dev_dbg() function trace message. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 61ad5ce..e3ea13d 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -168,11 +168,18 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, return pcmcia_request_io(p_dev); } -static void labpc_config(struct pcmcia_device *link) +static int labpc_cs_attach(struct pcmcia_device *link) { + struct local_info_t *local; int ret; - dev_dbg(&link->dev, "labpc_config\n"); + local = kzalloc(sizeof(*local), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; + + pcmcia_cur_dev = link; link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ | CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; @@ -190,30 +197,11 @@ static void labpc_config(struct pcmcia_device *link) if (ret) goto failed; - return; + return 0; failed: pcmcia_disable_device(link); -} - -static int labpc_cs_attach(struct pcmcia_device *link) -{ - struct local_info_t *local; - - dev_dbg(&link->dev, "labpc_cs_attach()\n"); - - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); - if (!local) - return -ENOMEM; - local->link = link; - link->priv = local; - - pcmcia_cur_dev = link; - - labpc_config(link); - - return 0; + return ret; } static void labpc_cs_detach(struct pcmcia_device *link) -- cgit v0.10.2 From b2e1be03ac1747cbb758fa146fe5cf364f306420 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:37:06 -0700 Subject: staging: comedi: ni_labpc_cs: remove pcmcia_device private data The private data, struct local_info_t, is not being used in the driver. Remove it as well as the kzalloc/kfree. Also, don't set the 'pcmcia_cur_dev' variable unless the pcmcia configuration is successful. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index e3ea13d..831411d 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -154,11 +154,6 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) return labpc_common_attach(dev, iobase, irq, 0); } -struct local_info_t { - struct pcmcia_device *link; - struct bus_operations *bus; -}; - static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { @@ -170,17 +165,8 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, static int labpc_cs_attach(struct pcmcia_device *link) { - struct local_info_t *local; int ret; - local = kzalloc(sizeof(*local), GFP_KERNEL); - if (!local) - return -ENOMEM; - local->link = link; - link->priv = local; - - pcmcia_cur_dev = link; - link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ | CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; @@ -197,6 +183,8 @@ static int labpc_cs_attach(struct pcmcia_device *link) if (ret) goto failed; + pcmcia_cur_dev = link; + return 0; failed: @@ -207,9 +195,6 @@ failed: static void labpc_cs_detach(struct pcmcia_device *link) { pcmcia_disable_device(link); - - /* This points to the parent local_info_t struct (may be null) */ - kfree(link->priv); } static const struct pcmcia_device_id labpc_cs_ids[] = { -- cgit v0.10.2 From 6749ffa84028b5283889eb68b9bbec2e27049722 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:37:27 -0700 Subject: staging: comedi: ni_labpc_cs: move comedi_driver declaration Move the comedi_driver declaration down in the file. This removes the need for the forward declaration. For aesthetic reasons, add some whitespace to the declaration and remove the unnecessary '&' before the function names. They are already addresses. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 831411d..669894c 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -77,8 +77,6 @@ NI manuals: static struct pcmcia_device *pcmcia_cur_dev; -static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it); - static const struct labpc_board_struct labpc_cs_boards[] = { { .name = "daqcard-1200", @@ -115,16 +113,6 @@ static const struct labpc_board_struct labpc_cs_boards[] = { */ #define thisboard ((const struct labpc_board_struct *)dev->board_ptr) -static struct comedi_driver driver_labpc_cs = { - .driver_name = "ni_labpc_cs", - .module = THIS_MODULE, - .attach = &labpc_attach, - .detach = &labpc_common_detach, - .num_names = ARRAY_SIZE(labpc_cs_boards), - .board_name = &labpc_cs_boards[0].name, - .offset = sizeof(struct labpc_board_struct), -}; - static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) { struct labpc_private *devpriv; @@ -154,6 +142,16 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) return labpc_common_attach(dev, iobase, irq, 0); } +static struct comedi_driver driver_labpc_cs = { + .driver_name = "ni_labpc_cs", + .module = THIS_MODULE, + .attach = labpc_attach, + .detach = labpc_common_detach, + .num_names = ARRAY_SIZE(labpc_cs_boards), + .board_name = &labpc_cs_boards[0].name, + .offset = sizeof(struct labpc_board_struct), +}; + static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { -- cgit v0.10.2 From 6e4733c34fd344fe17c7f6f8bd340d116f5377ec Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:37:41 -0700 Subject: staging: comedi: ni_labpc_cs: remove thisboard macro The 'thisboard' macro relies on a local variable having a specific name and yields a pointer derived from that local variable. Replace the macro with a local variable and use the comedi_board() helper to get the pointer. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 669894c..6c6ca40 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -108,13 +108,9 @@ static const struct labpc_board_struct labpc_cs_boards[] = { }, }; -/* - * Useful for shorthand access to the particular board structure - */ -#define thisboard ((const struct labpc_board_struct *)dev->board_ptr) - static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) { + const struct labpc_board_struct *thisboard = comedi_board(dev); struct labpc_private *devpriv; unsigned long iobase = 0; unsigned int irq = 0; -- cgit v0.10.2 From 40faa60bd448a8d487563a5753fba100c17940f2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:38:04 -0700 Subject: staging: comedi: ni_labpc_cs: cleanup the boardinfo declaration For aesthetic reasons, reformat the boardinfo declaration and add some whitespace. Remove all the information that is set to '0' as this is the default. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 6c6ca40..334fa78 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -79,33 +79,27 @@ static struct pcmcia_device *pcmcia_cur_dev; static const struct labpc_board_struct labpc_cs_boards[] = { { - .name = "daqcard-1200", - .device_id = 0x103, /* 0x10b is manufacturer id, - 0x103 is device id */ - .ai_speed = 10000, - .bustype = pcmcia_bustype, - .register_layout = labpc_1200_layout, - .has_ao = 1, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, - .ai_scan_up = 0, - .memory_mapped_io = 0, - }, - /* duplicate entry, to support using alternate name */ - { - .name = "ni_labpc_cs", - .device_id = 0x103, - .ai_speed = 10000, - .bustype = pcmcia_bustype, - .register_layout = labpc_1200_layout, - .has_ao = 1, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, - .ai_scan_up = 0, - .memory_mapped_io = 0, - }, + .name = "daqcard-1200", + .device_id = 0x103, + .ai_speed = 10000, + .bustype = pcmcia_bustype, + .register_layout = labpc_1200_layout, + .has_ao = 1, + .ai_range_table = &range_labpc_1200_ai, + .ai_range_code = labpc_1200_ai_gain_bits, + .ai_range_is_unipolar = labpc_1200_is_unipolar, + }, { + /* duplicate entry, to support using alternate name */ + .name = "ni_labpc_cs", + .device_id = 0x103, + .ai_speed = 10000, + .bustype = pcmcia_bustype, + .register_layout = labpc_1200_layout, + .has_ao = 1, + .ai_range_table = &range_labpc_1200_ai, + .ai_range_code = labpc_1200_ai_gain_bits, + .ai_range_is_unipolar = labpc_1200_is_unipolar, + }, }; static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) -- cgit v0.10.2 From 12e9a5f1df9bf274fb49fb8453196e9fe51c8d77 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 18:38:23 -0700 Subject: staging: comedi: ni_labpc_cs: remove '#undef LABPC_DEBUG' The LABPC_DEBUG define is not used in any of the code. Just remove the #undef. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 334fa78..c459881 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -59,8 +59,6 @@ NI manuals: */ -#undef LABPC_DEBUG /* debugging messages */ - #include "../comedidev.h" #include -- cgit v0.10.2 From 104640606be0df6bcdb5ec7960a9c3c1278117ae Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 29 Jan 2013 14:05:58 +0000 Subject: staging: comedi: don't override read/write subdevice if not supported For comedi devices that support asynchronous commands on some of their subdevices, the comedi core creates extra device files for each of those subdevices of the form "/dev/comedi%i_subd%i". These use the same comedi device as the corresponding "/dev/comedi%i" but override the default "read" and "write" subdevice for the device. Currently it overrides both the read and write subdevice, but it only makes sense to override the "read" subdevice if the subdevice supports "read" commands, and to override the "write" subdevice if the subdevice supports "write" commands. In `comedi_alloc_subdevice_minor()`, only set `info->read_subdevice` non-NULL if the subdevice has the `SDF_CMD_READ` flag set, and only set `info->write_subdevice` non-NULL if the subdevice has the `SDF_CMD_WRITE` flag set. (`comedi_read_subdevice(info)` will use the device's default read subdevice if `info->read_subdevice` is NULL. `comedi_write_subdevice(info)` will use the device's default write subdevice if `info->write_subdevice` is NULL. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index b798e42..fa534fe 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2358,8 +2358,10 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, if (!info) return -ENOMEM; info->device = dev; - info->read_subdevice = s; - info->write_subdevice = s; + if (s->subdev_flags & SDF_CMD_READ) + info->read_subdevice = s; + if (s->subdev_flags & SDF_CMD_WRITE) + info->write_subdevice = s; spin_lock(&comedi_file_info_table_lock); for (i = COMEDI_FIRST_SUBDEVICE_MINOR; i < COMEDI_NUM_MINORS; ++i) { if (comedi_file_info_table[i] == NULL) { -- cgit v0.10.2 From bc3954b8147402e4495378d982cc8e708703a0f1 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 29 Jan 2013 16:20:17 +0000 Subject: staging: comedi: simplify comedi_set_hw_dev() Since `get_device()` and `put_device()` can take a NULL device parameter, `comedi_set_hw_dev()` can be simplified to always call `get_device()` for the new, possibly NULL hardware device, and `put_device()` for the old, possibly NULL hardware device. As long as we do it in that order, there shouldn't be any problem with `kref_release()` getting called unexpectedly when the new hardware device is the old hardware device. Simplify `comedi_set_hw_dev()` and update the comment because the function is used for additional purposes since the old comment was written. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index e2b7d60..503dd8c 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -429,20 +429,19 @@ static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) return sizeof(short); } -/* must be used in attach to set dev->hw_dev if you wish to dma directly -into comedi's buffer */ +/* + * Must set dev->hw_dev if you wish to dma directly into comedi's buffer. + * Also useful for retrieving a previously configured hardware device of + * known bus type. Set automatically for auto-configured devices. + * Automatically set to NULL when detaching hardware device. + */ static inline void comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev) { - if (dev->hw_dev == hw_dev) - return; - if (dev->hw_dev) - put_device(dev->hw_dev); - dev->hw_dev = hw_dev; - if (dev->hw_dev) { - dev->hw_dev = get_device(dev->hw_dev); - BUG_ON(dev->hw_dev == NULL); - } + struct device *old_hw_dev = dev->hw_dev; + + dev->hw_dev = get_device(hw_dev); + put_device(old_hw_dev); } static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) -- cgit v0.10.2 From e21545449b2b96775065f237063a224fff21ed9d Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 29 Jan 2013 00:36:39 +0100 Subject: staging/comedi/adl_pci8164: Don't assign string Assigning a string is really bad, and since we only have 1 char strings here we can simply use a char to store the value and change the format specifier. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index bfa71e0..ece84dd 100644 --- a/drivers/staging/comedi/drivers/adl_pci8164.c +++ b/drivers/staging/comedi/drivers/adl_pci8164.c @@ -62,35 +62,35 @@ static void adl_pci8164_insn_read(struct comedi_device *dev, char *action, unsigned short offset) { int axis, axis_reg; - char *axisname; + char axisname; axis = CR_CHAN(insn->chanspec); switch (axis) { case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + axisname = 'X'; break; case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; + axisname = 'Y'; break; case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; + axisname = 'Z'; break; case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; + axisname = 'U'; break; default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + axisname = 'X'; } data[0] = inw(dev->iobase + axis_reg + offset); dev_dbg(dev->class_dev, - "pci8164 %s read -> %04X:%04X on axis %s\n", + "pci8164 %s read -> %04X:%04X on axis %c\n", action, data[0], data[1], axisname); } @@ -142,36 +142,36 @@ static void adl_pci8164_insn_out(struct comedi_device *dev, { unsigned int axis, axis_reg; - char *axisname; + char axisname; axis = CR_CHAN(insn->chanspec); switch (axis) { case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + axisname = 'X'; break; case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; + axisname = 'Y'; break; case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; + axisname = 'Z'; break; case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; + axisname = 'U'; break; default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + axisname = 'X'; } outw(data[0], dev->iobase + axis_reg + offset); dev_dbg(dev->class_dev, - "pci8164 %s write -> %04X:%04X on axis %s\n", + "pci8164 %s write -> %04X:%04X on axis %c\n", action, data[0], data[1], axisname); } -- cgit v0.10.2 From d662b8eba94e9f6d4c036719dbf629ef0c9309cf Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Fri, 25 Jan 2013 11:46:18 -0600 Subject: staging: zsmalloc: make CLASS_DELTA relative to PAGE_SIZE Right now ZS_SIZE_CLASS_DELTA is hardcoded to be 16. This creates 254 classes for systems with 4k pages. However, on PPC64 with 64k pages, it creates 4095 classes which is far too many. This patch makes ZS_SIZE_CLASS_DELTA relative to PAGE_SIZE so that regardless of the page size, there will be the same number of classes. Acked-by: Nitin Gupta Acked-by: Minchan Kim Signed-off-by: Seth Jennings Acked-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c index eb00772..93eb03e 100644 --- a/drivers/staging/zsmalloc/zsmalloc-main.c +++ b/drivers/staging/zsmalloc/zsmalloc-main.c @@ -141,7 +141,7 @@ * ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN * (reason above) */ -#define ZS_SIZE_CLASS_DELTA 16 +#define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8) #define ZS_SIZE_CLASSES ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / \ ZS_SIZE_CLASS_DELTA + 1) -- cgit v0.10.2 From 2643c47fa4accb49abf46a1486909e20e4bb5df9 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sat, 26 Jan 2013 00:19:19 +0100 Subject: staging/csr: Use kmemdup rather than duplicating its implementation Found with coccicheck. The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/csr/drv.c b/drivers/staging/csr/drv.c index 4780c32..3bd52fd 100644 --- a/drivers/staging/csr/drv.c +++ b/drivers/staging/csr/drv.c @@ -819,15 +819,15 @@ unifi_write(struct file *filp, const char *p, size_t len, loff_t *poff) unifi_trace(priv, UDBG2, "unifi_write: signal 0x%.4X len:%d\n", sig_id, signal_size); - /* Allocate a buffer for the signal */ - signal_buf = kmalloc(signal_size, GFP_KERNEL); + /* Allocate a buffer for the signal */ + signal_buf = kmemdup(bulkdata.d[0].os_data_ptr, signal_size, + GFP_KERNEL); if (!signal_buf) { unifi_net_data_free(priv, &bulkdata.d[0]); return -ENOMEM; } /* Get the signal from the os_data_ptr */ - memcpy(signal_buf, bulkdata.d[0].os_data_ptr, signal_size); signal_buf[5] = (pcli->sender_id >> 8) & 0xff; if (signal_size < len) { -- cgit v0.10.2 From 05014d73d68a0f5203fc78eb58e6d7e512581695 Mon Sep 17 00:00:00 2001 From: Ryo Munakata Date: Sat, 26 Jan 2013 19:50:53 +0900 Subject: Staging: zcache: remove unnecessary braces in zcache-main.c This fixes a checkpatch.pl issue of 'braces {} are not necessary for single statement blocks' Signed-off-by: Ryo Munakata Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 6ab13e1..c1ac905 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -1017,11 +1017,10 @@ static int zcache_frontswap_unuse(void) unuse_ret = frontswap_unuse(type, offset, newpage2 != NULL ? newpage2 : evictpage2, ZCACHE_GFP_MASK); - if (unuse_ret != 0) { + if (unuse_ret != 0) goto free_and_out; - } else if (evictpage2 != NULL) { + else if (evictpage2 != NULL) zcache_unacct_page(); - } } ret = 0; goto out; -- cgit v0.10.2 From e6200964713e381cb19017ccf567a0fb886b9c6c Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sat, 26 Jan 2013 00:40:13 +0100 Subject: staging/omapdrm: Use kmemdup rather than duplicating its implementation Found with coccicheck. The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Peter Huewe Signed-off-by: Rob Clark Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c index 08f1e292..f9297eb 100644 --- a/drivers/staging/omapdrm/omap_gem.c +++ b/drivers/staging/omapdrm/omap_gem.c @@ -1267,12 +1267,12 @@ int omap_gem_set_sync_object(struct drm_gem_object *obj, void *syncobj) if ((omap_obj->flags & OMAP_BO_EXT_SYNC) && !syncobj) { /* clearing a previously set syncobj */ - syncobj = kzalloc(sizeof(*omap_obj->sync), GFP_ATOMIC); + syncobj = kmemdup(omap_obj->sync, sizeof(*omap_obj->sync), + GFP_ATOMIC); if (!syncobj) { ret = -ENOMEM; goto unlock; } - memcpy(syncobj, omap_obj->sync, sizeof(*omap_obj->sync)); omap_obj->flags &= ~OMAP_BO_EXT_SYNC; omap_obj->sync = syncobj; } else if (syncobj && !(omap_obj->flags & OMAP_BO_EXT_SYNC)) { -- cgit v0.10.2 From 9915518887e83764269d5b617d01782893877ed3 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Mon, 28 Jan 2013 10:00:08 +0900 Subject: staging: zsmalloc: Fix TLB coherency and build problem Recently, Matt Sealey reported he fail to build zsmalloc caused by using of local_flush_tlb_kernel_range which are architecture dependent function so !CONFIG_SMP in ARM couldn't implement it so it ends up build error following as. MODPOST 216 modules LZMA arch/arm/boot/compressed/piggy.lzma AS arch/arm/boot/compressed/lib1funcs.o ERROR: "v7wbi_flush_kern_tlb_range" [drivers/staging/zsmalloc/zsmalloc.ko] undefined! make[1]: *** [__modpost] Error 1 make: *** [modules] Error 2 make: *** Waiting for unfinished jobs.... The reason we used that function is copy method by [1] was really slow in ARM but at that time. More severe problem is ARM can prefetch speculatively on other CPUs so under us, other TLBs can have an entry only if we do flush local CPU. Russell King pointed that. Thanks! We don't have many choices except using flush_tlb_kernel_range. My experiment in ARMv7 processor 4 core didn't make any difference with zsmapbench[2] between local_flush_tlb_kernel_range and flush_tlb_kernel_range but still page-table based is much better than copy-based. * bigger is better. 1. local_flush_tlb_kernel_range: 3918795 mappings 2. flush_tlb_kernel_range : 3989538 mappings 3. copy-based: 635158 mappings This patch replace local_flush_tlb_kernel_range with flush_tlb_kernel_range which are avaialbe in all architectures because we already have used it in vmalloc allocator which are generic one so build problem should go away and performane loss shoud be void. [1] f553646, zsmalloc: add page table mapping method [2] https://github.com/spartacus06/zsmapbench Cc: stable@vger.kernel.org Cc: Dan Magenheimer Cc: Russell King Cc: Konrad Rzeszutek Wilk Cc: Nitin Gupta Cc: Seth Jennings Reported-by: Matt Sealey Signed-off-by: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c index 93eb03e..4666609 100644 --- a/drivers/staging/zsmalloc/zsmalloc-main.c +++ b/drivers/staging/zsmalloc/zsmalloc-main.c @@ -222,11 +222,9 @@ struct zs_pool { /* * By default, zsmalloc uses a copy-based object mapping method to access * allocations that span two pages. However, if a particular architecture - * 1) Implements local_flush_tlb_kernel_range() and 2) Performs VM mapping - * faster than copying, then it should be added here so that - * USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use page table - * mapping rather than copying - * for object mapping. + * performs VM mapping faster than copying, then it should be added here + * so that USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use + * page table mapping rather than copying for object mapping. */ #if defined(CONFIG_ARM) #define USE_PGTABLE_MAPPING @@ -663,7 +661,7 @@ static inline void __zs_unmap_object(struct mapping_area *area, flush_cache_vunmap(addr, end); unmap_kernel_range_noflush(addr, PAGE_SIZE * 2); - local_flush_tlb_kernel_range(addr, end); + flush_tlb_kernel_range(addr, end); } #else /* USE_PGTABLE_MAPPING */ -- cgit v0.10.2 From 518945fbfbe9e2bc39057115aa23e25b084a03e0 Mon Sep 17 00:00:00 2001 From: Marc Dietrich Date: Sun, 27 Jan 2013 17:43:41 +0100 Subject: staging: nvec: move toggle global event reporting to its own function Cleanup toggle of global event reporting by moving it to its own function. This simplifies the following cleanup. Signed-off-by: Marc Dietrich Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 2830946..6fab02f 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -72,8 +72,10 @@ enum nvec_msg_category { NVEC_MSG_TX, }; -static const unsigned char EC_DISABLE_EVENT_REPORTING[3] = "\x04\x00\x00"; -static const unsigned char EC_ENABLE_EVENT_REPORTING[3] = "\x04\x00\x01"; +enum nvec_sleep_subcmds { + GLOBAL_EVENTS, +}; + static const unsigned char EC_GET_FIRMWARE_VERSION[2] = "\x07\x15"; static struct nvec_chip *nvec_power_handle; @@ -318,6 +320,20 @@ struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec, EXPORT_SYMBOL(nvec_write_sync); /** + * nvec_toggle_global_events - enables or disables global event reporting + * @nvec: nvec handle + * @state: true for enable, false for disable + * + * This switches on/off global event reports by the embedded controller. + */ +static void nvec_toggle_global_events(struct nvec_chip *nvec, bool state) +{ + unsigned char global_events[] = { NVEC_SLEEP, GLOBAL_EVENTS, state }; + + nvec_write_async(nvec, global_events, 3); +} + +/** * nvec_request_master - Process outgoing messages * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip) * @@ -711,7 +727,7 @@ static void nvec_disable_i2c_slave(struct nvec_chip *nvec) static void nvec_power_off(void) { - nvec_write_async(nvec_power_handle, EC_DISABLE_EVENT_REPORTING, 3); + nvec_toggle_global_events(nvec_power_handle, false); nvec_write_async(nvec_power_handle, "\x04\x01", 2); } @@ -815,8 +831,7 @@ static int tegra_nvec_probe(struct platform_device *pdev) /* enable event reporting */ - nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING, - sizeof(EC_ENABLE_EVENT_REPORTING)); + nvec_toggle_global_events(nvec, true); nvec->nvec_status_notifier.notifier_call = nvec_status_notifier; nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0); @@ -856,7 +871,7 @@ static int tegra_nvec_remove(struct platform_device *pdev) { struct nvec_chip *nvec = platform_get_drvdata(pdev); - nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3); + nvec_toggle_global_events(nvec, false); mfd_remove_devices(nvec->dev); cancel_work_sync(&nvec->rx_work); cancel_work_sync(&nvec->tx_work); @@ -891,7 +906,7 @@ static int nvec_resume(struct device *dev) dev_dbg(nvec->dev, "resuming\n"); tegra_init_i2c_slave(nvec); - nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING, 3); + nvec_toggle_global_events(nvec, true); return 0; } diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h index ba6ed8f..bfcd9a9 100644 --- a/drivers/staging/nvec/nvec.h +++ b/drivers/staging/nvec/nvec.h @@ -71,7 +71,9 @@ enum nvec_event_size { enum nvec_msg_type { NVEC_SYS = 1, NVEC_BAT, - NVEC_KBD = 5, + NVEC_GPIO, + NVEC_SLEEP, + NVEC_KBD, NVEC_PS2, NVEC_CNTL, NVEC_KB_EVT = 0x80, -- cgit v0.10.2 From 85a90528b2b4f2d38a56df5b3f137223983aad4b Mon Sep 17 00:00:00 2001 From: Marc Dietrich Date: Sun, 27 Jan 2013 17:43:42 +0100 Subject: staging: nvec: fix mouse suspend/resume calls The EC command for enable/disable is not an EC command. Instead it needs to be send to the mouse. Signed-off-by: Marc Dietrich Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c index 88dd288..b1a5a96 100644 --- a/drivers/staging/nvec/nvec_ps2.c +++ b/drivers/staging/nvec/nvec_ps2.c @@ -25,6 +25,9 @@ #define STOP_STREAMING {'\x06', '\x04'} #define SEND_COMMAND {'\x06', '\x01', '\xf4', '\x01'} +#define ENABLE_MOUSE 0xf4 +#define DISABLE_MOUSE 0xf5 + #ifdef NVEC_PS2_DEBUG #define NVEC_PHD(str, buf, len) \ print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \ @@ -133,27 +136,22 @@ static int nvec_mouse_remove(struct platform_device *pdev) #ifdef CONFIG_PM_SLEEP static int nvec_mouse_suspend(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); - /* disable mouse */ - nvec_write_async(nvec, "\x06\xf4", 2); + ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE); /* send cancel autoreceive */ - nvec_write_async(nvec, "\x06\x04", 2); + ps2_stopstreaming(ps2_dev.ser_dev); return 0; } static int nvec_mouse_resume(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); - + /* start streaming */ ps2_startstreaming(ps2_dev.ser_dev); /* enable mouse */ - nvec_write_async(nvec, "\x06\xf5", 2); + ps2_sendcommand(ps2_dev.ser_dev, ENABLE_MOUSE); return 0; } -- cgit v0.10.2 From 93eff83ff1640bef8062568687b5e0e41a0d4c42 Mon Sep 17 00:00:00 2001 From: Marc Dietrich Date: Sun, 27 Jan 2013 17:43:43 +0100 Subject: staging: nvec: cleanup the string mess Replace the various command strings by named constants. Signed-off-by: Marc Dietrich Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 6fab02f..7555850 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -74,9 +74,14 @@ enum nvec_msg_category { enum nvec_sleep_subcmds { GLOBAL_EVENTS, + AP_PWR_DOWN, + AP_SUSPEND, }; -static const unsigned char EC_GET_FIRMWARE_VERSION[2] = "\x07\x15"; +#define CNF_EVENT_REPORTING 0x01 +#define GET_FIRMWARE_VERSION 0x15 +#define LID_SWITCH BIT(1) +#define PWR_BUTTON BIT(15) static struct nvec_chip *nvec_power_handle; @@ -334,6 +339,27 @@ static void nvec_toggle_global_events(struct nvec_chip *nvec, bool state) } /** + * nvec_event_mask - fill the command string with event bitfield + * ev: points to event command string + * mask: bit to insert into the event mask + * + * Configure event command expects a 32 bit bitfield which describes + * which events to enable. The bitfield has the following structure + * (from highest byte to lowest): + * system state bits 7-0 + * system state bits 15-8 + * oem system state bits 7-0 + * oem system state bits 15-8 + */ +static void nvec_event_mask(char *ev, u32 mask) +{ + ev[3] = mask >> 16 && 0xff; + ev[4] = mask >> 24 && 0xff; + ev[5] = mask >> 0 && 0xff; + ev[6] = mask >> 8 && 0xff; +} + +/** * nvec_request_master - Process outgoing messages * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip) * @@ -727,8 +753,10 @@ static void nvec_disable_i2c_slave(struct nvec_chip *nvec) static void nvec_power_off(void) { + char ap_pwr_down[] = { NVEC_SLEEP, AP_PWR_DOWN }; + nvec_toggle_global_events(nvec_power_handle, false); - nvec_write_async(nvec_power_handle, "\x04\x01", 2); + nvec_write_async(nvec_power_handle, ap_pwr_down, 2); } static int tegra_nvec_probe(struct platform_device *pdev) @@ -740,6 +768,9 @@ static int tegra_nvec_probe(struct platform_device *pdev) struct nvec_msg *msg; struct resource *res; void __iomem *base; + char get_firmware_version[] = { NVEC_CNTL, GET_FIRMWARE_VERSION }, + unmute_speakers[] = { NVEC_OEM0, 0x10, 0x59, 0x95 }, + enable_event[7] = { NVEC_SYS, CNF_EVENT_REPORTING, true }; nvec = devm_kzalloc(&pdev->dev, sizeof(struct nvec_chip), GFP_KERNEL); if (nvec == NULL) { @@ -840,8 +871,7 @@ static int tegra_nvec_probe(struct platform_device *pdev) pm_power_off = nvec_power_off; /* Get Firmware Version */ - msg = nvec_write_sync(nvec, EC_GET_FIRMWARE_VERSION, - sizeof(EC_GET_FIRMWARE_VERSION)); + msg = nvec_write_sync(nvec, get_firmware_version, 2); if (msg) { dev_warn(nvec->dev, "ec firmware version %02x.%02x.%02x / %02x\n", @@ -856,13 +886,15 @@ static int tegra_nvec_probe(struct platform_device *pdev) dev_err(nvec->dev, "error adding subdevices\n"); /* unmute speakers? */ - nvec_write_async(nvec, "\x0d\x10\x59\x95", 4); + nvec_write_async(nvec, unmute_speakers, 4); /* enable lid switch event */ - nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x02\x00", 7); + nvec_event_mask(enable_event, LID_SWITCH); + nvec_write_async(nvec, enable_event, 7); /* enable power button event */ - nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7); + nvec_event_mask(enable_event, PWR_BUTTON); + nvec_write_async(nvec, enable_event, 7); return 0; } @@ -885,13 +917,14 @@ static int nvec_suspend(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct nvec_chip *nvec = platform_get_drvdata(pdev); struct nvec_msg *msg; + char ap_suspend[] = { NVEC_SLEEP, AP_SUSPEND }; dev_dbg(nvec->dev, "suspending\n"); /* keep these sync or you'll break suspend */ - msg = nvec_write_sync(nvec, EC_DISABLE_EVENT_REPORTING, 3); - nvec_msg_free(nvec, msg); - msg = nvec_write_sync(nvec, "\x04\x02", 2); + nvec_toggle_global_events(nvec, false); + + msg = nvec_write_sync(nvec, ap_suspend, sizeof(ap_suspend)); nvec_msg_free(nvec, msg); nvec_disable_i2c_slave(nvec); diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h index bfcd9a9..b7a14bc 100644 --- a/drivers/staging/nvec/nvec.h +++ b/drivers/staging/nvec/nvec.h @@ -76,6 +76,7 @@ enum nvec_msg_type { NVEC_KBD, NVEC_PS2, NVEC_CNTL, + NVEC_OEM0 = 0x0d, NVEC_KB_EVT = 0x80, NVEC_PS2_EVT, }; diff --git a/drivers/staging/nvec/nvec_kbd.c b/drivers/staging/nvec/nvec_kbd.c index 7cb149b..7445ce6 100644 --- a/drivers/staging/nvec/nvec_kbd.c +++ b/drivers/staging/nvec/nvec_kbd.c @@ -21,10 +21,14 @@ #include "nvec-keytable.h" #include "nvec.h" -#define ACK_KBD_EVENT {'\x05', '\xed', '\x01'} +enum kbd_subcmds { + CNFG_WAKE = 3, + CNFG_WAKE_KEY_REPORTING, + SET_LEDS = 0xed, + ENABLE_KBD = 0xf4, + DISABLE_KBD, +}; -static const char led_on[3] = "\x05\xed\x07"; -static const char led_off[3] = "\x05\xed\x00"; static unsigned char keycodes[ARRAY_SIZE(code_tab_102us) + ARRAY_SIZE(extcode_tab_us102)]; @@ -39,12 +43,15 @@ static struct nvec_keys keys_dev; static void nvec_kbd_toggle_led(void) { + char buf[] = { NVEC_KBD, SET_LEDS, 0 }; + keys_dev.caps_lock = !keys_dev.caps_lock; if (keys_dev.caps_lock) - nvec_write_async(keys_dev.nvec, led_on, sizeof(led_on)); - else - nvec_write_async(keys_dev.nvec, led_off, sizeof(led_off)); + /* should be BIT(0) only, firmware bug? */ + buf[2] = BIT(0) | BIT(1) | BIT(2); + + nvec_write_async(keys_dev.nvec, buf, sizeof(buf)); } static int nvec_keys_notifier(struct notifier_block *nb, @@ -82,8 +89,8 @@ static int nvec_keys_notifier(struct notifier_block *nb, static int nvec_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { - unsigned char buf[] = ACK_KBD_EVENT; struct nvec_chip *nvec = keys_dev.nvec; + char buf[] = { NVEC_KBD, SET_LEDS, 0 }; if (type == EV_REP) return 0; @@ -105,6 +112,11 @@ static int nvec_kbd_probe(struct platform_device *pdev) struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); int i, j, err; struct input_dev *idev; + char clear_leds[] = { NVEC_KBD, SET_LEDS, 0 }, + enable_kbd[] = { NVEC_KBD, ENABLE_KBD }, + cnfg_wake[] = { NVEC_KBD, CNFG_WAKE, true, true }, + cnfg_wake_key_reporting[] = { NVEC_KBD, CNFG_WAKE_KEY_REPORTING, + true }; j = 0; @@ -138,19 +150,15 @@ static int nvec_kbd_probe(struct platform_device *pdev) nvec_register_notifier(nvec, &keys_dev.notifier, 0); /* Enable keyboard */ - nvec_write_async(nvec, "\x05\xf4", 2); + nvec_write_async(nvec, enable_kbd, 2); - /* keyboard reset? */ - nvec_write_async(nvec, "\x05\x03\x01\x01", 4); - nvec_write_async(nvec, "\x05\x04\x01", 3); - nvec_write_async(nvec, "\x06\x01\xff\x03", 4); -/* FIXME - wait until keyboard reset is finished - or until we have a sync write */ - mdelay(1000); + /* configures wake on special keys */ + nvec_write_async(nvec, cnfg_wake, 4); + /* enable wake key reporting */ + nvec_write_async(nvec, cnfg_wake_key_reporting, 3); /* Disable caps lock LED */ - nvec_write_async(nvec, led_off, sizeof(led_off)); + nvec_write_async(nvec, clear_leds, sizeof(clear_leds)); return 0; diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c index b7b6d54..296f7b9 100644 --- a/drivers/staging/nvec/nvec_power.c +++ b/drivers/staging/nvec/nvec_power.c @@ -22,6 +22,8 @@ #include "nvec.h" +#define GET_SYSTEM_STATUS 0x00 + struct nvec_power { struct notifier_block notifier; struct delayed_work poller; @@ -111,7 +113,7 @@ static const int bat_init[] = { static void get_bat_mfg_data(struct nvec_power *power) { int i; - char buf[] = { '\x02', '\x00' }; + char buf[] = { NVEC_BAT, SLOT_STATUS }; for (i = 0; i < ARRAY_SIZE(bat_init); i++) { buf[1] = bat_init[i]; @@ -348,7 +350,7 @@ static int const bat_iter[] = { static void nvec_power_poll(struct work_struct *work) { - char buf[] = { '\x01', '\x00' }; + char buf[] = { NVEC_SYS, GET_SYSTEM_STATUS }; struct nvec_power *power = container_of(work, struct nvec_power, poller.work); @@ -361,7 +363,7 @@ static void nvec_power_poll(struct work_struct *work) /* select a battery request function via round robin doing it all at once seems to overload the power supply */ - buf[0] = '\x02'; /* battery */ + buf[0] = NVEC_BAT; buf[1] = bat_iter[counter++]; nvec_write_async(power->nvec, buf, 2); diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c index b1a5a96..aff6b9b 100644 --- a/drivers/staging/nvec/nvec_ps2.c +++ b/drivers/staging/nvec/nvec_ps2.c @@ -21,12 +21,11 @@ #include "nvec.h" -#define START_STREAMING {'\x06', '\x03', '\x06'} -#define STOP_STREAMING {'\x06', '\x04'} -#define SEND_COMMAND {'\x06', '\x01', '\xf4', '\x01'} +#define PACKET_SIZE 6 -#define ENABLE_MOUSE 0xf4 -#define DISABLE_MOUSE 0xf5 +#define ENABLE_MOUSE 0xf4 +#define DISABLE_MOUSE 0xf5 +#define PSMOUSE_RST 0xff #ifdef NVEC_PS2_DEBUG #define NVEC_PHD(str, buf, len) \ @@ -36,7 +35,12 @@ #define NVEC_PHD(str, buf, len) #endif -static const unsigned char MOUSE_RESET[] = {'\x06', '\x01', '\xff', '\x03'}; +enum ps2_subcmds { + SEND_COMMAND = 1, + RECEIVE_N, + AUTO_RECEIVE_N, + CANCEL_AUTO_RECEIVE, +}; struct nvec_ps2 { struct serio *ser_dev; @@ -48,19 +52,19 @@ static struct nvec_ps2 ps2_dev; static int ps2_startstreaming(struct serio *ser_dev) { - unsigned char buf[] = START_STREAMING; + unsigned char buf[] = { NVEC_PS2, AUTO_RECEIVE_N, PACKET_SIZE }; return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf)); } static void ps2_stopstreaming(struct serio *ser_dev) { - unsigned char buf[] = STOP_STREAMING; + unsigned char buf[] = { NVEC_PS2, CANCEL_AUTO_RECEIVE }; nvec_write_async(ps2_dev.nvec, buf, sizeof(buf)); } static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd) { - unsigned char buf[] = SEND_COMMAND; + unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 }; buf[2] = cmd & 0xff; @@ -100,6 +104,7 @@ static int nvec_mouse_probe(struct platform_device *pdev) { struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); struct serio *ser_dev; + char mouse_reset[] = { NVEC_PS2, SEND_COMMAND, PSMOUSE_RST, 3 }; ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL); if (ser_dev == NULL) @@ -121,7 +126,7 @@ static int nvec_mouse_probe(struct platform_device *pdev) serio_register_port(ser_dev); /* mouse reset */ - nvec_write_async(nvec, MOUSE_RESET, 4); + nvec_write_async(nvec, mouse_reset, sizeof(mouse_reset)); return 0; } -- cgit v0.10.2 From b360cb9726ce04480840e279150a907c21837334 Mon Sep 17 00:00:00 2001 From: Rupesh Gujare Date: Tue, 29 Jan 2013 17:00:55 +0000 Subject: staging:ozwpan: Fix following warning. The patch ae926051d7eb: "staging: ozwpan: Added USB HCD implementation" from Feb 20, 2012, leads to the following warning: drivers/staging/ozwpan/ozhcd.c:1094 oz_hcd_heartbeat() warn: what is this condition about? 'ep->buffered_units * 50' Reported-by: Dan Carpenter Signed-off-by: Rupesh Gujare Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index b2d77df..9154f33 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -1091,7 +1091,7 @@ int oz_hcd_heartbeat(void *hport) list_for_each(e, &port->isoc_in_ep) { struct oz_endpoint *ep = ep_from_link(e); if (ep->flags & OZ_F_EP_BUFFERING) { - if (ep->buffered_units * OZ_IN_BUFFERING_UNITS) { + if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) { ep->flags &= ~OZ_F_EP_BUFFERING; ep->credit = 0; oz_event_log(OZ_EVT_EP_CREDIT, -- cgit v0.10.2 From 06b8f14dc2649ee12ff5194fc562d74353c8b4ba Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 20:57:44 -0500 Subject: staging/fwserial: Remove bandwidth limit logic Self-limiting asynchronous bandwidth (via reducing the payload) is not necessary and does not work, because 1) asynchronous traffic will absorb all available bandwidth (less that being used for isochronous traffic) 2) isochronous arbitration always wins. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index d03a7f5..0125738 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -40,12 +40,10 @@ static int num_ttys = 4; /* # of std ttys to create per fw_card */ /* - doubles as loopback port index */ static bool auto_connect = true; /* try to VIRT_CABLE to every peer */ static bool create_loop_dev = true; /* create a loopback device for each card */ -bool limit_bw; /* limit async bandwidth to 20% of max */ module_param_named(ttys, num_ttys, int, S_IRUGO | S_IWUSR); module_param_named(auto, auto_connect, bool, S_IRUGO | S_IWUSR); module_param_named(loop, create_loop_dev, bool, S_IRUGO | S_IWUSR); -module_param(limit_bw, bool, S_IRUGO | S_IWUSR); /* * Threshold below which the tty is woken for writing @@ -2940,4 +2938,3 @@ MODULE_DEVICE_TABLE(ieee1394, fwserial_id_table); MODULE_PARM_DESC(ttys, "Number of ttys to create for each local firewire node"); MODULE_PARM_DESC(auto, "Auto-connect a tty to each firewire node discovered"); MODULE_PARM_DESC(loop, "Create a loopback device, fwloop, with ttys"); -MODULE_PARM_DESC(limit_bw, "Limit bandwidth utilization to 20%."); diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index caa1c1e..e157318 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -351,7 +351,6 @@ struct fw_serial { #define TTY_DEV_NAME "fwtty" /* ttyFW was taken */ static const char tty_dev_name[] = TTY_DEV_NAME; static const char loop_dev_name[] = "fwloop"; -extern bool limit_bw; struct tty_driver *fwtty_driver; @@ -370,18 +369,16 @@ static inline void fwtty_bind_console(struct fwtty_port *port, /* * Returns the max send async payload size in bytes based on the unit device - * link speed - if set to limit bandwidth to max 20%, use lookup table + * link speed. Self-limiting asynchronous bandwidth (via reducing the payload) + * is not necessary and does not work, because + * 1) asynchronous traffic will absorb all available bandwidth (less that + * being used for isochronous traffic) + * 2) isochronous arbitration always wins. */ static inline int link_speed_to_max_payload(unsigned speed) { - static const int max_async[] = { 307, 614, 1229, 2458, }; - BUILD_BUG_ON(ARRAY_SIZE(max_async) - 1 != SCODE_800); - speed = clamp(speed, (unsigned) SCODE_100, (unsigned) SCODE_800); - if (limit_bw) - return max_async[speed]; - else - return 1 << (speed + 9); + return 1 << (speed + 9); } #endif /* _FIREWIRE_FWSERIAL_H */ -- cgit v0.10.2 From 5d110d92961317c1f289396473be3c26d01f171c Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 20:57:45 -0500 Subject: staging/fwserial: Refer to fw_device as "node" Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 0125738..5f54743 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -174,7 +174,7 @@ static void dump_profile(struct seq_file *m, struct stats *stats) #define dump_profile(m, stats) #endif -/* Returns the max receive packet size for the given card */ +/* Returns the max receive packet size for the given node */ static inline int device_max_receive(struct fw_device *fw_device) { return 1 << (clamp_t(int, fw_device->max_rec, 8U, 11U) + 1); -- cgit v0.10.2 From d83561894db22ee9c40fdd85d49eb5ee573125cc Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 20:57:46 -0500 Subject: staging/fwserial: Simplify max payload calculation Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index e157318..953ece6 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -377,8 +377,8 @@ static inline void fwtty_bind_console(struct fwtty_port *port, */ static inline int link_speed_to_max_payload(unsigned speed) { - speed = clamp(speed, (unsigned) SCODE_100, (unsigned) SCODE_800); - return 1 << (speed + 9); + /* Max async payload is 4096 - see IEEE 1394-2008 tables 6-4, 16-18 */ + return min(512 << speed, 4096); } #endif /* _FIREWIRE_FWSERIAL_H */ -- cgit v0.10.2 From 3b1f315415d3e9b2648bec82c0c1cd9eff2d8743 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 20:57:47 -0500 Subject: staging/fwserial: Fold constant MAX_ASYNC_PAYLOAD Since peer->max_payload is now limited to 1394-2008 spec maximum of 4096, the port->max_payload limit can now be simplified. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 5f54743..815c011 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -1683,8 +1683,7 @@ static void fwserial_virt_plug_complete(struct fwtty_peer *peer, /* reconfigure tx_fifo optimally for this peer */ spin_lock_bh(&port->lock); - port->max_payload = min3(peer->max_payload, peer->fifo_len, - MAX_ASYNC_PAYLOAD); + port->max_payload = min(peer->max_payload, peer->fifo_len); dma_fifo_change_tx_limit(&port->tx_fifo, port->max_payload); spin_unlock_bh(&peer->port->lock); -- cgit v0.10.2 From 9883a7396b9cc36e27185f2da9f81f23f2ab67ae Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 20:57:48 -0500 Subject: staging/fwserial: Assume firmware is OHCI-complaint Devices which are OHCI v1.0/ v1.1/ v1.2-draft compliant or RFC 2734 compliant are required by specification to support max_rec of 8 (512 bytes) or more. Accept reported value. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 815c011..59e90e6 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -174,10 +174,15 @@ static void dump_profile(struct seq_file *m, struct stats *stats) #define dump_profile(m, stats) #endif -/* Returns the max receive packet size for the given node */ +/* + * Returns the max receive packet size for the given node + * Devices which are OHCI v1.0/ v1.1/ v1.2-draft or RFC 2734 compliant + * are required by specification to support max_rec of 8 (512 bytes) or more. + */ static inline int device_max_receive(struct fw_device *fw_device) { - return 1 << (clamp_t(int, fw_device->max_rec, 8U, 11U) + 1); + /* see IEEE 1394-2008 table 8-8 */ + return min(2 << fw_device->max_rec, 4096); } static void fwtty_log_tx_error(struct fwtty_port *port, int rcode) -- cgit v0.10.2 From 2b86216ba1d059b2609532ded9400f905013b376 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 20:57:49 -0500 Subject: staging/fwserial: Drop suggestion for helper fn integration The firewire core does not require or want the suggested helper fns; drop suggestion from TODO file. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/TODO b/drivers/staging/fwserial/TODO index 8dae8fb..dc61d97 100644 --- a/drivers/staging/fwserial/TODO +++ b/drivers/staging/fwserial/TODO @@ -12,8 +12,6 @@ TODOs prior to this driver moving out of staging 1. This driver uses the same unregistered vendor id that the firewire core does (0xd00d1e). Perhaps this could be exposed as a define in firewire.h? -3. Maybe device_max_receive() and link_speed_to_max_payload() should be - taken up by the firewire core? -- Issues with TTY core -- 1. Hack for alternate device name scheme -- cgit v0.10.2 From de321a14da65a534da89a80dde949d0c6ff6316f Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:35 -0500 Subject: staging/fwserial: Only reset port status for attached peers When a port has been reserved in an attempt to connect to a peer but that attempt does not succeed, releasing the port should not reset the port line status. Although resetting is functionally harmless, it can appear as if a remote peer dropped carrier to a port it was not attached to (which can be confusing). Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 59e90e6..8db4b41 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -1783,10 +1783,11 @@ static struct fwtty_port *fwserial_find_port(struct fwtty_peer *peer) return NULL; } -static void fwserial_release_port(struct fwtty_port *port) +static void fwserial_release_port(struct fwtty_port *port, bool reset) { /* drop carrier (and all other line status) */ - fwtty_update_port_status(port, 0); + if (reset) + fwtty_update_port_status(port, 0); spin_lock_bh(&port->lock); @@ -1816,7 +1817,7 @@ static void fwserial_plug_timeout(unsigned long data) spin_unlock_bh(&peer->lock); if (port) - fwserial_release_port(port); + fwserial_release_port(port, false); } /** @@ -1879,7 +1880,7 @@ cancel_timer: peer_revert_state(peer); release_port: spin_unlock_bh(&peer->lock); - fwserial_release_port(port); + fwserial_release_port(port, false); free_pkt: kfree(pkt); return err; @@ -2157,7 +2158,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer) spin_unlock_bh(&peer->lock); if (port) - fwserial_release_port(port); + fwserial_release_port(port, true); synchronize_rcu(); kfree(peer); @@ -2617,7 +2618,7 @@ static void fwserial_handle_plug_req(struct work_struct *work) spin_unlock_bh(&peer->lock); if (port) - fwserial_release_port(port); + fwserial_release_port(port, false); rcode = fwserial_send_mgmt_sync(peer, pkt); @@ -2639,7 +2640,7 @@ static void fwserial_handle_plug_req(struct work_struct *work) cleanup: spin_unlock_bh(&peer->lock); if (port) - fwserial_release_port(port); + fwserial_release_port(port, false); kfree(pkt); return; } @@ -2691,7 +2692,7 @@ static void fwserial_handle_unplug_req(struct work_struct *work) cleanup: spin_unlock_bh(&peer->lock); if (port) - fwserial_release_port(port); + fwserial_release_port(port, true); kfree(pkt); return; } @@ -2702,6 +2703,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, size_t len) { struct fwtty_port *port = NULL; + bool reset = false; int rcode; if (addr != fwserial_mgmt_addr_handler.offset || len < sizeof(pkt->hdr)) @@ -2777,6 +2779,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK) fwtty_notice(&peer->unit, "NACK unplug?"); port = peer_revert_state(peer); + reset = true; } break; @@ -2788,7 +2791,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, spin_unlock_bh(&peer->lock); if (port) - fwserial_release_port(port); + fwserial_release_port(port, reset); return rcode; } -- cgit v0.10.2 From c88d40b25ffc8099aa7a28f62dce85bee66b1892 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:36 -0500 Subject: staging/fwserial: Release port regardless of unplug response code After sending the unplug response, release the port even if an error occurred. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 8db4b41..e40b480 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -2684,10 +2684,9 @@ static void fwserial_handle_unplug_req(struct work_struct *work) spin_lock_bh(&peer->lock); if (peer->state == FWPS_UNPLUG_RESPONDING) { - if (rcode == RCODE_COMPLETE) - port = peer_revert_state(peer); - else + if (rcode != RCODE_COMPLETE) fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)", rcode); + port = peer_revert_state(peer); } cleanup: spin_unlock_bh(&peer->lock); -- cgit v0.10.2 From a3d9ad474ef391166a48128bea753f455e9a7d69 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:37 -0500 Subject: staging/fwserial: Fix sparse build warnings Reported-by: Stefan Richter Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index e40b480..a9e814e 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -78,6 +78,8 @@ static int num_ports; /* slab used as pool for struct fwtty_transactions */ static struct kmem_cache *fwtty_txn_cache; +struct tty_driver *fwtty_driver; + struct fwtty_transaction; typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode, void *data, size_t length, @@ -2552,7 +2554,7 @@ static struct fw_descriptor fwserial_unit_directory = { * The management address is in the unit space region but above other known * address users (to keep wild writes from causing havoc) */ -const struct fw_address_region fwserial_mgmt_addr_region = { +static const struct fw_address_region fwserial_mgmt_addr_region = { .start = CSR_REGISTER_BASE + 0x1e0000ULL, .end = 0x1000000000000ULL, }; diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index 953ece6..3602809 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -352,7 +352,7 @@ struct fw_serial { static const char tty_dev_name[] = TTY_DEV_NAME; static const char loop_dev_name[] = "fwloop"; -struct tty_driver *fwtty_driver; +extern struct tty_driver *fwtty_driver; #define driver_err(s, v...) pr_err(KBUILD_MODNAME ": " s, ##v) -- cgit v0.10.2 From fa1da242c3d24801ae946f4664406f679865388f Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:38 -0500 Subject: staging/fwserial: Create loop device the 'tty' way Register a second tty driver to create loopback devices for each firewire node. Note that the loopback devices are numbered from 0; the tty->index is transformed when used to index the port table. Remove the hack that previously enabled this. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/TODO b/drivers/staging/fwserial/TODO index dc61d97..382a795 100644 --- a/drivers/staging/fwserial/TODO +++ b/drivers/staging/fwserial/TODO @@ -12,16 +12,3 @@ TODOs prior to this driver moving out of staging 1. This driver uses the same unregistered vendor id that the firewire core does (0xd00d1e). Perhaps this could be exposed as a define in firewire.h? - --- Issues with TTY core -- - 1. Hack for alternate device name scheme - - because udev no longer allows device renaming, devices should have - their proper names on creation. This is an issue for creating the - fwloop device with the fwtty devices because although duplicating - roughly the same operations as tty_port_register_device() isn't difficult, - access to the tty_class & tty_fops is restricted in scope. - - This is currently being worked around in create_loop_device() by - extracting the tty_class ptr and tty_fops ptr from the previously created - tty devices. Perhaps an add'l api can be added -- eg., - tty_{port_}register_named_device(). diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index a9e814e..3f2d26e 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -72,6 +72,9 @@ static DEFINE_MUTEX(port_table_lock); static bool port_table_corrupt; #define FWTTY_INVALID_INDEX MAX_TOTAL_PORTS +#define loop_idx(port) (((port)->index) / num_ports) +#define table_idx(loop) ((loop) * num_ports + num_ttys) + /* total # of tty ports created per fw_card */ static int num_ports; @@ -79,6 +82,7 @@ static int num_ports; static struct kmem_cache *fwtty_txn_cache; struct tty_driver *fwtty_driver; +static struct tty_driver *fwloop_driver; struct fwtty_transaction; typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode, @@ -1165,6 +1169,19 @@ static int fwtty_install(struct tty_driver *driver, struct tty_struct *tty) return err; } +static int fwloop_install(struct tty_driver *driver, struct tty_struct *tty) +{ + struct fwtty_port *port = fwtty_port_get(table_idx(tty->index)); + int err; + + err = tty_standard_install(driver, tty); + if (!err) + tty->driver_data = port; + else + fwtty_port_put(port); + return err; +} + static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c) { struct fwtty_port *port = tty->driver_data; @@ -1601,6 +1618,26 @@ static const struct tty_operations fwtty_ops = { .proc_fops = &fwtty_proc_fops, }; +static const struct tty_operations fwloop_ops = { + .open = fwtty_open, + .close = fwtty_close, + .hangup = fwtty_hangup, + .cleanup = fwtty_cleanup, + .install = fwloop_install, + .write = fwtty_write, + .write_room = fwtty_write_room, + .chars_in_buffer = fwtty_chars_in_buffer, + .send_xchar = fwtty_send_xchar, + .throttle = fwtty_throttle, + .unthrottle = fwtty_unthrottle, + .ioctl = fwtty_ioctl, + .set_termios = fwtty_set_termios, + .break_ctl = fwtty_break_ctl, + .tiocmget = fwtty_tiocmget, + .tiocmset = fwtty_tiocmset, + .get_icount = fwtty_get_icount, +}; + static inline int mgmt_pkt_expected_len(__be16 code) { static const struct fwserial_mgmt_pkt pkt; @@ -1897,7 +1934,8 @@ free_pkt: * The port reference is put by fwtty_cleanup (if a reference was * ever taken). */ -static void fwserial_close_port(struct fwtty_port *port) +static void fwserial_close_port(struct tty_driver *driver, + struct fwtty_port *port) { struct tty_struct *tty; @@ -1909,7 +1947,10 @@ static void fwserial_close_port(struct fwtty_port *port) } mutex_unlock(&port->port.mutex); - tty_unregister_device(fwtty_driver, port->index); + if (driver == fwloop_driver) + tty_unregister_device(driver, loop_idx(port)); + else + tty_unregister_device(driver, port->index); } /** @@ -2167,78 +2208,6 @@ static void fwserial_remove_peer(struct fwtty_peer *peer) } /** - * create_loop_device - create a loopback tty device - * @tty_driver: tty_driver to own loopback device - * @prototype: ptr to already-assigned 'prototype' tty port - * @index: index to associate this device with the tty port - * @parent: device to child to - * - * HACK - this is basically tty_port_register_device() with an - * alternate naming scheme. Suggest tty_port_register_named_device() - * helper api. - * - * Creates a loopback tty device named 'fwloop' which is attached to - * the local unit in fwserial_add_peer(). Note that in the device - * name advances in increments of port allocation blocks, ie., for port - * indices 0..3, the device name will be 'fwloop0'; for 4..7, 'fwloop1', - * and so on. - * - * Only one loopback device should be created per fw_card. - */ -static void release_loop_device(struct device *dev) -{ - kfree(dev); -} - -static struct device *create_loop_device(struct tty_driver *driver, - struct fwtty_port *prototype, - struct fwtty_port *port, - struct device *parent) -{ - char name[64]; - int index = port->index; - dev_t devt = MKDEV(driver->major, driver->minor_start) + index; - struct device *dev = NULL; - int err; - - if (index >= fwtty_driver->num) - return ERR_PTR(-EINVAL); - - snprintf(name, 64, "%s%d", loop_dev_name, index / num_ports); - - tty_port_link_device(&port->port, driver, index); - - cdev_init(&driver->cdevs[index], driver->cdevs[prototype->index].ops); - driver->cdevs[index].owner = driver->owner; - err = cdev_add(&driver->cdevs[index], devt, 1); - if (err) - return ERR_PTR(err); - - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) { - cdev_del(&driver->cdevs[index]); - return ERR_PTR(-ENOMEM); - } - - dev->devt = devt; - dev->class = prototype->device->class; - dev->parent = parent; - dev->release = release_loop_device; - dev_set_name(dev, "%s", name); - dev->groups = NULL; - dev_set_drvdata(dev, NULL); - - err = device_register(dev); - if (err) { - put_device(dev); - cdev_del(&driver->cdevs[index]); - return ERR_PTR(err); - } - - return dev; -} - -/** * fwserial_create - init everything to create TTYs for a specific fw_card * @unit: fw_unit for first 'serial' unit device probed for this fw_card * @@ -2336,17 +2305,17 @@ static int fwserial_create(struct fw_unit *unit) if (create_loop_dev) { struct device *loop_dev; - loop_dev = create_loop_device(fwtty_driver, - serial->ports[0], - serial->ports[num_ttys], - card->device); + loop_dev = tty_port_register_device(&serial->ports[j]->port, + fwloop_driver, + loop_idx(serial->ports[j]), + card->device); if (IS_ERR(loop_dev)) { err = PTR_ERR(loop_dev); fwtty_err(&unit, "create loop device failed (%d)", err); goto unregister_ttys; } - serial->ports[num_ttys]->device = loop_dev; - serial->ports[num_ttys]->loopback = true; + serial->ports[j]->device = loop_dev; + serial->ports[j]->loopback = true; } list_add_rcu(&serial->list, &fwserial_list); @@ -2362,6 +2331,8 @@ static int fwserial_create(struct fw_unit *unit) /* fall-through to error processing */ list_del_rcu(&serial->list); + if (create_loop_dev) + tty_unregister_device(fwloop_driver, loop_idx(serial->ports[j])); unregister_ttys: for (--j; j >= 0; --j) tty_unregister_device(fwtty_driver, serial->ports[j]->index); @@ -2450,8 +2421,10 @@ static int fwserial_remove(struct device *dev) /* unlink from the fwserial_list here */ list_del_rcu(&serial->list); - for (i = 0; i < num_ports; ++i) - fwserial_close_port(serial->ports[i]); + for (i = 0; i < num_ttys; ++i) + fwserial_close_port(fwtty_driver, serial->ports[i]); + if (create_loop_dev) + fwserial_close_port(fwloop_driver, serial->ports[i]); kref_put(&serial->kref, fwserial_destroy); } mutex_unlock(&fwserial_list_mutex); @@ -2872,12 +2845,39 @@ static int __init fwserial_init(void) goto put_tty; } + if (create_loop_dev) { + fwloop_driver = alloc_tty_driver(MAX_TOTAL_PORTS / num_ports); + if (!fwloop_driver) { + err = -ENOMEM; + goto unregister_driver; + } + + fwloop_driver->driver_name = KBUILD_MODNAME "_loop"; + fwloop_driver->name = loop_dev_name; + fwloop_driver->major = 0; + fwloop_driver->minor_start = 0; + fwloop_driver->type = TTY_DRIVER_TYPE_SERIAL; + fwloop_driver->subtype = SERIAL_TYPE_NORMAL; + fwloop_driver->flags = TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV; + + fwloop_driver->init_termios = tty_std_termios; + fwloop_driver->init_termios.c_cflag |= CLOCAL; + tty_set_operations(fwloop_driver, &fwloop_ops); + + err = tty_register_driver(fwloop_driver); + if (err) { + driver_err("register loop driver failed (%d)", err); + goto put_loop; + } + } + fwtty_txn_cache = kmem_cache_create("fwtty_txn_cache", sizeof(struct fwtty_transaction), 0, 0, fwtty_txn_constructor); if (!fwtty_txn_cache) { err = -ENOMEM; - goto unregister_driver; + goto unregister_loop; } /* @@ -2919,6 +2919,12 @@ remove_handler: fw_core_remove_address_handler(&fwserial_mgmt_addr_handler); destroy_cache: kmem_cache_destroy(fwtty_txn_cache); +unregister_loop: + if (create_loop_dev) + tty_unregister_driver(fwloop_driver); +put_loop: + if (create_loop_dev) + put_tty_driver(fwloop_driver); unregister_driver: tty_unregister_driver(fwtty_driver); put_tty: @@ -2932,6 +2938,10 @@ static void __exit fwserial_exit(void) fw_core_remove_descriptor(&fwserial_unit_directory); fw_core_remove_address_handler(&fwserial_mgmt_addr_handler); kmem_cache_destroy(fwtty_txn_cache); + if (create_loop_dev) { + tty_unregister_driver(fwloop_driver); + put_tty_driver(fwloop_driver); + } tty_unregister_driver(fwtty_driver); put_tty_driver(fwtty_driver); } -- cgit v0.10.2 From e16d1ded85b9ceddbf8092d239646ee520353e47 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:39 -0500 Subject: staging/fwserial: Cleanup /proc/tty/driver/ file Factor out extra stats, data profiles, debugging info and peer info from procfs file in preparation for using debugfs instead. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 3f2d26e..fb00a8a 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -1509,17 +1509,26 @@ static void fwtty_proc_show_port(struct seq_file *m, struct fwtty_port *port) if (port->port.console) (*port->fwcon_ops->stats)(&stats, port->con_data); - seq_printf(m, " tx:%d rx:%d", port->icount.tx + stats.xchars, - port->icount.rx); + seq_printf(m, " addr:%012llx tx:%d rx:%d", port->rx_handler.offset, + port->icount.tx + stats.xchars, port->icount.rx); seq_printf(m, " cts:%d dsr:%d rng:%d dcd:%d", port->icount.cts, port->icount.dsr, port->icount.rng, port->icount.dcd); seq_printf(m, " fe:%d oe:%d pe:%d brk:%d", port->icount.frame, port->icount.overrun, port->icount.parity, port->icount.brk); +} + +static void fwtty_debugfs_show_port(struct seq_file *m, struct fwtty_port *port) +{ + struct stats stats; + + memcpy(&stats, &port->stats, sizeof(stats)); + if (port->port.console) + (*port->fwcon_ops->stats)(&stats, port->con_data); + seq_printf(m, " dr:%d st:%d err:%d lost:%d", stats.dropped, stats.tx_stall, stats.fifo_errs, stats.lost); seq_printf(m, " pkts:%d thr:%d wtrmk:%d", stats.sent, stats.throttled, stats.watermark); - seq_printf(m, " addr:%012llx", port->rx_handler.offset); if (port->port.console) { seq_printf(m, "\n "); @@ -1529,7 +1538,7 @@ static void fwtty_proc_show_port(struct seq_file *m, struct fwtty_port *port) dump_profile(m, &port->stats); } -static void fwtty_proc_show_peer(struct seq_file *m, struct fwtty_peer *peer) +static void fwtty_debugfs_show_peer(struct seq_file *m, struct fwtty_peer *peer) { int generation = peer->generation; @@ -1538,21 +1547,14 @@ static void fwtty_proc_show_peer(struct seq_file *m, struct fwtty_peer *peer) seq_printf(m, " node:%04x gen:%d", peer->node_id, generation); seq_printf(m, " sp:%d max:%d guid:%016llx", peer->speed, peer->max_payload, (unsigned long long) peer->guid); - - if (capable(CAP_SYS_ADMIN)) { - seq_printf(m, " mgmt:%012llx", - (unsigned long long) peer->mgmt_addr); - seq_printf(m, " addr:%012llx", - (unsigned long long) peer->status_addr); - } + seq_printf(m, " mgmt:%012llx", (unsigned long long) peer->mgmt_addr); + seq_printf(m, " addr:%012llx", (unsigned long long) peer->status_addr); seq_putc(m, '\n'); } static int fwtty_proc_show(struct seq_file *m, void *v) { struct fwtty_port *port; - struct fw_serial *serial; - struct fwtty_peer *peer; int i; seq_puts(m, "fwserinfo: 1.0 driver: 1.0\n"); @@ -1563,17 +1565,6 @@ static int fwtty_proc_show(struct seq_file *m, void *v) fwtty_port_put(port); seq_printf(m, "\n"); } - seq_putc(m, '\n'); - - rcu_read_lock(); - list_for_each_entry_rcu(serial, &fwserial_list, list) { - seq_printf(m, "card: %s guid: %016llx\n", - dev_name(serial->card->device), - (unsigned long long) serial->card->guid); - list_for_each_entry_rcu(peer, &serial->peer_list, list) - fwtty_proc_show_peer(m, peer); - } - rcu_read_unlock(); return 0; } -- cgit v0.10.2 From 4df5bb0464769a07ce6d6a265174477786512f2e Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:40 -0500 Subject: staging/fwserial: Factor unstable stats/debug/status info to debugfs Add the following file hierarchy to debugfs: -+ +- firewire_serial -+- -+- peers | +- stats | +- -+- peers +- stats The 'peers' file (read-only) contains status and configuration info for attached peers for the given fwserial unit. The 'stats' file (read-only) contains statistics and data profiling information for each tty port for the given fwserial unit. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index fb00a8a..37b082b 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -84,6 +84,8 @@ static struct kmem_cache *fwtty_txn_cache; struct tty_driver *fwtty_driver; static struct tty_driver *fwloop_driver; +static struct dentry *fwserial_debugfs; + struct fwtty_transaction; typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode, void *data, size_t length, @@ -1568,11 +1570,71 @@ static int fwtty_proc_show(struct seq_file *m, void *v) return 0; } +static int fwtty_debugfs_stats_show(struct seq_file *m, void *v) +{ + struct fw_serial *serial = m->private; + struct fwtty_port *port; + int i; + + for (i = 0; i < num_ports; ++i) { + port = fwtty_port_get(serial->ports[i]->index); + if (port) { + seq_printf(m, "%2d:", port->index); + fwtty_proc_show_port(m, port); + fwtty_debugfs_show_port(m, port); + fwtty_port_put(port); + seq_printf(m, "\n"); + } + } + return 0; +} + +static int fwtty_debugfs_peers_show(struct seq_file *m, void *v) +{ + struct fw_serial *serial = m->private; + struct fwtty_peer *peer; + + rcu_read_lock(); + seq_printf(m, "card: %s guid: %016llx\n", + dev_name(serial->card->device), + (unsigned long long) serial->card->guid); + list_for_each_entry_rcu(peer, &serial->peer_list, list) + fwtty_debugfs_show_peer(m, peer); + rcu_read_unlock(); + return 0; +} + static int fwtty_proc_open(struct inode *inode, struct file *fp) { return single_open(fp, fwtty_proc_show, NULL); } +static int fwtty_stats_open(struct inode *inode, struct file *fp) +{ + return single_open(fp, fwtty_debugfs_stats_show, inode->i_private); +} + +static int fwtty_peers_open(struct inode *inode, struct file *fp) +{ + return single_open(fp, fwtty_debugfs_peers_show, inode->i_private); +} + +static const struct file_operations fwtty_stats_fops = { + .owner = THIS_MODULE, + .open = fwtty_stats_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static const struct file_operations fwtty_peers_fops = { + .owner = THIS_MODULE, + .open = fwtty_peers_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static const struct file_operations fwtty_proc_fops = { .owner = THIS_MODULE, .open = fwtty_proc_open, @@ -2309,6 +2371,17 @@ static int fwserial_create(struct fw_unit *unit) serial->ports[j]->loopback = true; } + if (!IS_ERR_OR_NULL(fwserial_debugfs)) { + serial->debugfs = debugfs_create_dir(dev_name(&unit->device), + fwserial_debugfs); + if (!IS_ERR_OR_NULL(serial->debugfs)) { + debugfs_create_file("peers", 0444, serial->debugfs, + serial, &fwtty_peers_fops); + debugfs_create_file("stats", 0444, serial->debugfs, + serial, &fwtty_stats_fops); + } + } + list_add_rcu(&serial->list, &fwserial_list); fwtty_notice(&unit, "TTY over FireWire on device %s (guid %016llx)", @@ -2321,6 +2394,8 @@ static int fwserial_create(struct fw_unit *unit) fwtty_err(&unit, "unable to add peer unit device (%d)", err); /* fall-through to error processing */ + debugfs_remove_recursive(serial->debugfs); + list_del_rcu(&serial->list); if (create_loop_dev) tty_unregister_device(fwloop_driver, loop_idx(serial->ports[j])); @@ -2412,6 +2487,8 @@ static int fwserial_remove(struct device *dev) /* unlink from the fwserial_list here */ list_del_rcu(&serial->list); + debugfs_remove_recursive(serial->debugfs); + for (i = 0; i < num_ttys; ++i) fwserial_close_port(fwtty_driver, serial->ports[i]); if (create_loop_dev) @@ -2806,6 +2883,9 @@ static int __init fwserial_init(void) { int err, num_loops = !!(create_loop_dev); + /* XXX: placeholder for a "firewire" debugfs node */ + fwserial_debugfs = debugfs_create_dir(KBUILD_MODNAME, NULL); + /* num_ttys/num_ports must not be set above the static alloc avail */ if (num_ttys + num_loops > MAX_CARD_PORTS) num_ttys = MAX_CARD_PORTS - num_loops; @@ -2920,6 +3000,7 @@ unregister_driver: tty_unregister_driver(fwtty_driver); put_tty: put_tty_driver(fwtty_driver); + debugfs_remove_recursive(fwserial_debugfs); return err; } @@ -2935,6 +3016,7 @@ static void __exit fwserial_exit(void) } tty_unregister_driver(fwtty_driver); put_tty_driver(fwtty_driver); + debugfs_remove_recursive(fwserial_debugfs); } module_init(fwserial_init); diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index 3602809..c768aad 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "dma_fifo.h" @@ -338,6 +339,7 @@ struct fw_serial { struct fw_card *card; struct kref kref; + struct dentry *debugfs; struct fwtty_peer *self; struct list_head list; -- cgit v0.10.2 From 84472c3b584db1fcd4cb8a434468696bbf8640d8 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:41 -0500 Subject: staging/fwserial: Don't use deprecated alloc_tty_driver() Use tty_alloc_driver() instead. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 37b082b..258ac35 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -2891,9 +2891,10 @@ static int __init fwserial_init(void) num_ttys = MAX_CARD_PORTS - num_loops; num_ports = num_ttys + num_loops; - fwtty_driver = alloc_tty_driver(MAX_TOTAL_PORTS); - if (!fwtty_driver) { - err = -ENOMEM; + fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW + | TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(fwtty_driver)) { + err = PTR_ERR(fwtty_driver); return err; } @@ -2903,9 +2904,6 @@ static int __init fwserial_init(void) fwtty_driver->minor_start = 0; fwtty_driver->type = TTY_DRIVER_TYPE_SERIAL; fwtty_driver->subtype = SERIAL_TYPE_NORMAL; - fwtty_driver->flags = TTY_DRIVER_REAL_RAW | - TTY_DRIVER_DYNAMIC_DEV; - fwtty_driver->init_termios = tty_std_termios; fwtty_driver->init_termios.c_cflag |= CLOCAL; tty_set_operations(fwtty_driver, &fwtty_ops); @@ -2917,9 +2915,11 @@ static int __init fwserial_init(void) } if (create_loop_dev) { - fwloop_driver = alloc_tty_driver(MAX_TOTAL_PORTS / num_ports); - if (!fwloop_driver) { - err = -ENOMEM; + fwloop_driver = tty_alloc_driver(MAX_TOTAL_PORTS / num_ports, + TTY_DRIVER_REAL_RAW + | TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(fwloop_driver)) { + err = PTR_ERR(fwloop_driver); goto unregister_driver; } @@ -2929,9 +2929,6 @@ static int __init fwserial_init(void) fwloop_driver->minor_start = 0; fwloop_driver->type = TTY_DRIVER_TYPE_SERIAL; fwloop_driver->subtype = SERIAL_TYPE_NORMAL; - fwloop_driver->flags = TTY_DRIVER_REAL_RAW | - TTY_DRIVER_DYNAMIC_DEV; - fwloop_driver->init_termios = tty_std_termios; fwloop_driver->init_termios.c_cflag |= CLOCAL; tty_set_operations(fwloop_driver, &fwloop_ops); -- cgit v0.10.2 From 2257d1224fa93875d472c21195b7817b0d7bcc50 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:42 -0500 Subject: staging/fwserial: Remove reference to removed constant FWSERIAL_TTY_START_MINOR was removed. The minor_start is allocated by tty_alloc_driver(). Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index c768aad..33a3a53 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -194,7 +194,7 @@ struct buffered_rx { * @port: underlying tty_port * @device: tty device * @index: index into port_table for this particular port - * note: minor = index + FWSERIAL_TTY_START_MINOR + * note: minor = index + minor_start assigned by tty_alloc_driver() * @serial: back pointer to the containing fw_serial * @rx_handler: bus address handler for unique addr region used by remotes * to communicate with this port. Every port uses -- cgit v0.10.2 From ef34dd184d58824f1cde7402afa8ba2a957029d9 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 28 Jan 2013 22:34:43 -0500 Subject: staging/fwserial: add diagnostic for buffer overflow Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index 258ac35..fe9a688 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -577,8 +577,11 @@ static int fwtty_buffer_rx(struct fwtty_port *port, unsigned char *d, size_t n) struct buffered_rx *buf; size_t size = (n + sizeof(struct buffered_rx) + 0xFF) & ~0xFF; - if (port->buffered + n > HIGH_WATERMARK) + if (port->buffered + n > HIGH_WATERMARK) { + fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %ld wtrmk: %d", + port->buffered, n, HIGH_WATERMARK); return 0; + } buf = kmalloc(size, GFP_ATOMIC); if (!buf) return 0; -- cgit v0.10.2 From 612588a886965706e9593626c277e561c1932249 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Tue, 29 Jan 2013 09:10:30 -0500 Subject: staging/fwserial: Fix endian issue in unit directory Reported-by: YOSHIFUJI Hideaki Acked-by: YOSHIFUJI Hideaki Signed-off-by: Peter Hurley Acked-by: Stefan Richter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index fe9a688..cad9e98 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -2559,26 +2559,25 @@ static struct fw_driver fwserial_driver = { /* XXX: config ROM definitons could be improved with semi-automated offset * and length calculation */ +#define FW_ROM_LEN(quads) ((quads) << 16) #define FW_ROM_DESCRIPTOR(ofs) (((CSR_LEAF | CSR_DESCRIPTOR) << 24) | (ofs)) struct fwserial_unit_directory_data { - u16 crc; - u16 len; + u32 len_crc; u32 unit_specifier; u32 unit_sw_version; u32 unit_addr_offset; u32 desc1_ofs; - u16 desc1_crc; - u16 desc1_len; + u32 desc1_len_crc; u32 desc1_data[5]; } __packed; static struct fwserial_unit_directory_data fwserial_unit_directory_data = { - .len = 4, + .len_crc = FW_ROM_LEN(4), .unit_specifier = FW_UNIT_SPECIFIER(LINUX_VENDOR_ID), .unit_sw_version = FW_UNIT_VERSION(FWSERIAL_VERSION), .desc1_ofs = FW_ROM_DESCRIPTOR(1), - .desc1_len = 5, + .desc1_len_crc = FW_ROM_LEN(5), .desc1_data = { 0x00000000, /* type = text */ 0x00000000, /* enc = ASCII, lang EN */ -- cgit v0.10.2 From 754ab5c0e55dd118273ca2c217c4d95e9fbc8259 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 28 Jan 2013 16:14:31 +0000 Subject: staging: comedi: disallow COMEDI_DEVCONFIG on non-board minors Comedi has two sorts of minor devices: (a) normal board minor devices in the range 0 to COMEDI_NUM_BOARD_MINORS-1 inclusive; and (b) special subdevice minor devices in the range COMEDI_NUM_BOARD_MINORS upwards that are used to open the same underlying comedi device as the normal board minor devices, but with non-default read and write subdevices for asynchronous commands. The special subdevice minor devices get created when a board supporting asynchronous commands is attached to a normal board minor device, and destroyed when the board is detached from the normal board minor device. One way to attach or detach a board is by using the COMEDI_DEVCONFIG ioctl. This should only be used on normal board minors as the special subdevice minors are too ephemeral. In particular, the change introduced in commit 7d3135af399e92cf4c9bbc5f86b6c140aab3b88c ("staging: comedi: prevent auto-unconfig of manually configured devices") breaks horribly for special subdevice minor devices. Since there's no legitimate use for the COMEDI_DEVCONFIG ioctl on a special subdevice minor device node, disallow it and return -ENOTTY. Signed-off-by: Ian Abbott Cc: stable Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index fa534fe..38e4fcb 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1633,6 +1633,11 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, /* Device config is special, because it must work on * an unconfigured device. */ if (cmd == COMEDI_DEVCONFIG) { + if (minor >= COMEDI_NUM_BOARD_MINORS) { + /* Device config not appropriate on non-board minors. */ + rc = -ENOTTY; + goto done; + } rc = do_devconfig_ioctl(dev, (struct comedi_devconfig __user *)arg); if (rc == 0) -- cgit v0.10.2 From 682b911938f8c0e88c8204bb1178c2c7728d5661 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 28 Jan 2013 17:07:39 +0000 Subject: staging: comedi: cleanup all board minors on module exit The comedi core module optionally allocates some legacy board minor devices on module load and cleans these up on module exit. These are used for manual configuration of comedi boards (for those low-level comedi drivers that support manual configuration - mainly for ISA boards). Other board minor devices are created and destroyed dynamically in response to bus device probe and remove requests. The ioctl used for manual configuration (attachment) and removal (detachment) of devices is COMEDI_DEVCONFIG, but that works for any board minor device, including those that were originally created dynamically. If the COMEDI_DEVCONFIG ioctl is used to manually detach an automatically created and attached device, commit 7d3135af399e92cf4c9bbc5f86b6c140aab3b88c ("staging: comedi: prevent auto-unconfig of manually configured devices") ensures that the board minor will no longer be automatically detached and destroyed by a bus device remove request. From that point on the board minor behaves more like one of the comedi "legacy" board minors. (There would be some justification for destroying the board minor instead, but I'd rather leave that decision until removal of board minors has been made safer than it currently is.) Although the board minor behaves more like a legacy board minor, it is not currently cleaned up on module exit. In fact, the module exit code will bug out because this board minor has not been cleaned up. Change comedi_cleanup_legacy_minors() (called from the module exit code, and from the module init code on error) to clean up all board minors. Rename the function to comedi_cleanup_board_minors() to reflect the change in functionality. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 38e4fcb..c7377d0 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2415,11 +2415,11 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s) kfree(info); } -static void comedi_cleanup_legacy_minors(void) +static void comedi_cleanup_board_minors(void) { unsigned i; - for (i = 0; i < comedi_num_legacy_minors; i++) + for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) comedi_free_board_minor(i); } @@ -2479,7 +2479,7 @@ static int __init comedi_init(void) int minor; minor = comedi_alloc_board_minor(NULL); if (minor < 0) { - comedi_cleanup_legacy_minors(); + comedi_cleanup_board_minors(); cdev_del(&comedi_cdev); unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); @@ -2495,7 +2495,7 @@ static void __exit comedi_cleanup(void) { int i; - comedi_cleanup_legacy_minors(); + comedi_cleanup_board_minors(); for (i = 0; i < COMEDI_NUM_MINORS; ++i) BUG_ON(comedi_file_info_table[i]); -- cgit v0.10.2 From 5ccac0fd59877c5b9583e7167edef9ddcf21b443 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 30 Jan 2013 13:00:09 +0100 Subject: staging: comedi: ISA DMA drivers should depend on ISA_DMA_API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m68k allmodconfig: CC [M] drivers/staging/comedi/drivers/pcl812.o drivers/staging/comedi/drivers/pcl812.c: In function ‘pcl812_ai_cmd’: drivers/staging/comedi/drivers/pcl812.c:736: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/pcl812.c:736: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/pcl812.c:736: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/pcl812.c:736: error: for each function it appears in.) drivers/staging/comedi/drivers/pcl812.c:737: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/pcl812.c:738: error: implicit declaration of function ‘clear_dma_ff’ drivers/staging/comedi/drivers/pcl812.c:739: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/pcl812.c:740: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/pcl812.c:741: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/pcl812.c:742: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/pcl812.c: In function ‘interrupt_pcl812_ai_dma’: drivers/staging/comedi/drivers/pcl812.c:883: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/pcl812.c:884: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/pcl812.c: In function ‘pcl812_ai_poll’: drivers/staging/comedi/drivers/pcl812.c:947: error: implicit declaration of function ‘get_dma_residue’ make[2]: *** [drivers/staging/comedi/drivers/pcl812.o] Error 1 CC [M] drivers/staging/comedi/drivers/pcl816.o drivers/staging/comedi/drivers/pcl816.c: In function ‘interrupt_pcl816_ai_mode13_dma’: drivers/staging/comedi/drivers/pcl816.c:359: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/pcl816.c:366: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/pcl816.c:366: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/pcl816.c:366: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/pcl816.c:366: error: for each function it appears in.) drivers/staging/comedi/drivers/pcl816.c:367: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/pcl816.c:369: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/pcl816.c:372: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/pcl816.c:378: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/pcl816.c:379: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/pcl816.c: In function ‘pcl816_ai_cmd’: drivers/staging/comedi/drivers/pcl816.c:629: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/pcl816.c:631: error: implicit declaration of function ‘clear_dma_ff’ drivers/staging/comedi/drivers/pcl816.c: In function ‘pcl816_ai_poll’: drivers/staging/comedi/drivers/pcl816.c:679: error: implicit declaration of function ‘get_dma_residue’ make[2]: *** [drivers/staging/comedi/drivers/pcl816.o] Error 1 CC [M] drivers/staging/comedi/drivers/pcl818.o drivers/staging/comedi/drivers/pcl818.c: In function ‘interrupt_pcl818_ai_mode13_dma’: drivers/staging/comedi/drivers/pcl818.c:547: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/pcl818.c:550: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/pcl818.c:550: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/pcl818.c:550: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/pcl818.c:550: error: for each function it appears in.) drivers/staging/comedi/drivers/pcl818.c:551: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/pcl818.c:552: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/pcl818.c:555: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/pcl818.c:561: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/pcl818.c:562: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/pcl818.c: In function ‘pcl818_ai_mode13dma_int’: drivers/staging/comedi/drivers/pcl818.c:886: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/pcl818.c:888: error: implicit declaration of function ‘clear_dma_ff’ make[2]: *** [drivers/staging/comedi/drivers/pcl818.o] Error 1 CC [M] drivers/staging/comedi/drivers/das16.o drivers/staging/comedi/drivers/das16.c: In function ‘das16_cmd_exec’: drivers/staging/comedi/drivers/das16.c:644: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/das16.c:645: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/das16.c:648: error: implicit declaration of function ‘clear_dma_ff’ drivers/staging/comedi/drivers/das16.c:650: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/das16.c:654: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/das16.c:655: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/das16.c:656: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/das16.c: In function ‘disable_dma_on_even’: drivers/staging/comedi/drivers/das16.c:845: error: implicit declaration of function ‘get_dma_residue’ drivers/staging/comedi/drivers/das16.c: In function ‘das16_attach’: drivers/staging/comedi/drivers/das16.c:1197: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/das16.c:1197: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/das16.c:1197: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/das16.c:1197: error: for each function it appears in.) make[2]: *** [drivers/staging/comedi/drivers/das16.o] Error 1 CC [M] drivers/staging/comedi/drivers/das1800.o drivers/staging/comedi/drivers/das1800.c: In function ‘das1800_flush_dma_channel’: drivers/staging/comedi/drivers/das1800.c:555: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/das1800.c:559: error: implicit declaration of function ‘clear_dma_ff’ drivers/staging/comedi/drivers/das1800.c:562: error: implicit declaration of function ‘get_dma_residue’ drivers/staging/comedi/drivers/das1800.c: In function ‘das1800_flush_dma’: drivers/staging/comedi/drivers/das1800.c:586: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/das1800.c:603: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/das1800.c: In function ‘das1800_handle_dma’: drivers/staging/comedi/drivers/das1800.c:622: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/das1800.c:624: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/das1800.c:625: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/das1800.c: In function ‘das1800_init_dma’: drivers/staging/comedi/drivers/das1800.c:1424: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/das1800.c:1424: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/das1800.c:1424: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/das1800.c:1424: error: for each function it appears in.) make[2]: *** [drivers/staging/comedi/drivers/das1800.o] Error 1 CC [M] drivers/staging/comedi/drivers/dt282x.o drivers/staging/comedi/drivers/dt282x.c: In function ‘dt282x_ao_dma_interrupt’: drivers/staging/comedi/drivers/dt282x.c:328: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/dt282x.c: In function ‘prep_ai_dma’: drivers/staging/comedi/drivers/dt282x.c:416: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/dt282x.c:416: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/dt282x.c:416: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/dt282x.c:416: error: for each function it appears in.) drivers/staging/comedi/drivers/dt282x.c:417: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/dt282x.c:418: error: implicit declaration of function ‘clear_dma_ff’ drivers/staging/comedi/drivers/dt282x.c:419: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/dt282x.c:420: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/dt282x.c:421: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/dt282x.c:423: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/dt282x.c: In function ‘prep_ao_dma’: drivers/staging/comedi/drivers/dt282x.c:439: error: ‘DMA_MODE_WRITE’ undeclared (first use in this function) drivers/staging/comedi/drivers/dt282x.c: In function ‘dt282x_interrupt’: drivers/staging/comedi/drivers/dt282x.c:471: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/dt282x.c: In function ‘dt282x_ai_cmd’: drivers/staging/comedi/drivers/dt282x.c:690: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/dt282x.c: In function ‘dt282x_ao_cmd’: drivers/staging/comedi/drivers/dt282x.c:938: error: ‘DMA_MODE_WRITE’ undeclared (first use in this function) make[2]: *** [drivers/staging/comedi/drivers/dt282x.o] Error 1 CC [M] drivers/staging/comedi/drivers/ni_at_a2150.o drivers/staging/comedi/drivers/ni_at_a2150.c: In function ‘a2150_interrupt’: drivers/staging/comedi/drivers/ni_at_a2150.c:237: error: implicit declaration of function ‘claim_dma_lock’ drivers/staging/comedi/drivers/ni_at_a2150.c:238: error: implicit declaration of function ‘disable_dma’ drivers/staging/comedi/drivers/ni_at_a2150.c:241: error: implicit declaration of function ‘clear_dma_ff’ drivers/staging/comedi/drivers/ni_at_a2150.c:249: error: implicit declaration of function ‘get_dma_residue’ drivers/staging/comedi/drivers/ni_at_a2150.c:286: error: implicit declaration of function ‘set_dma_addr’ drivers/staging/comedi/drivers/ni_at_a2150.c:287: error: implicit declaration of function ‘set_dma_count’ drivers/staging/comedi/drivers/ni_at_a2150.c:288: error: implicit declaration of function ‘enable_dma’ drivers/staging/comedi/drivers/ni_at_a2150.c:290: error: implicit declaration of function ‘release_dma_lock’ drivers/staging/comedi/drivers/ni_at_a2150.c: In function ‘a2150_attach’: drivers/staging/comedi/drivers/ni_at_a2150.c:794: error: implicit declaration of function ‘set_dma_mode’ drivers/staging/comedi/drivers/ni_at_a2150.c:794: error: ‘DMA_MODE_READ’ undeclared (first use in this function) drivers/staging/comedi/drivers/ni_at_a2150.c:794: error: (Each undeclared identifier is reported only once drivers/staging/comedi/drivers/ni_at_a2150.c:794: error: for each function it appears in.) make[2]: *** [drivers/staging/comedi/drivers/ni_at_a2150.o] Error 1 Make PCL816, PCL818, DAS16, DAS1800, DT282X, and NI_AT_A2150 depend on ISA_DMA_API to fix this. Signed-off-by: Geert Uytterhoeven Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 4c80ac9..bb9acc9 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -164,7 +164,7 @@ config COMEDI_PCL730 config COMEDI_PCL812 tristate "Advantech PCL-812/813 and ADlink ACL-8112/8113/8113/8216" - depends on VIRT_TO_BUS + depends on VIRT_TO_BUS && ISA_DMA_API ---help--- Enable support for Advantech PCL-812/PG, PCL-813/B, ADLink ACL-8112DG/HG/PG, ACL-8113, ACL-8216, ICP DAS A-821PGH/PGL/PGL-NDA, @@ -175,7 +175,7 @@ config COMEDI_PCL812 config COMEDI_PCL816 tristate "Advantech PCL-814 and PCL-816 ISA card support" - depends on VIRT_TO_BUS + depends on VIRT_TO_BUS && ISA_DMA_API ---help--- Enable support for Advantech PCL-814 and PCL-816 ISA cards @@ -184,7 +184,7 @@ config COMEDI_PCL816 config COMEDI_PCL818 tristate "Advantech PCL-718 and PCL-818 ISA card support" - depends on VIRT_TO_BUS + depends on VIRT_TO_BUS && ISA_DMA_API ---help--- Enable support for Advantech PCL-818 ISA cards PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718 @@ -278,6 +278,7 @@ config COMEDI_DAS08_ISA config COMEDI_DAS16 tristate "DAS-16 compatible ISA and PC/104 card support" + depends on ISA_DMA_API select COMEDI_8255 select COMEDI_FC ---help--- @@ -307,7 +308,7 @@ config COMEDI_DAS800 config COMEDI_DAS1800 tristate "DAS1800 and compatible ISA card support" - depends on VIRT_TO_BUS + depends on VIRT_TO_BUS && ISA_DMA_API select COMEDI_FC ---help--- Enable support for DAS1800 and compatible ISA cards @@ -372,7 +373,7 @@ config COMEDI_DT2817 config COMEDI_DT282X tristate "Data Translation DT2821 series and DT-EZ ISA card support" select COMEDI_FC - depends on VIRT_TO_BUS + depends on VIRT_TO_BUS && ISA_DMA_API ---help--- Enable support for Data Translation DT2821 series including DT-EZ DT2821, DT2821-F-16SE, DT2821-F-8DI, DT2821-G-16SE, DT2821-G-8DI, @@ -444,7 +445,7 @@ config COMEDI_ADQ12B config COMEDI_NI_AT_A2150 tristate "NI AT-A2150 ISA card support" select COMEDI_FC - depends on VIRT_TO_BUS + depends on VIRT_TO_BUS && ISA_DMA_API ---help--- Enable support for National Instruments AT-A2150 cards -- cgit v0.10.2 From 0d145a501778042d0411c843ed5b468b41f8a171 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Wed, 30 Jan 2013 09:36:52 -0600 Subject: staging: zsmalloc: remove unused pool name zs_create_pool() currently takes a name argument which is never used in any useful way. This patch removes it. Signed-off-by: Seth Jennings Acked-by: Nitin Gupta Acked-by: Rik van Riel Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 77a3f0d..941b7c6 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -575,7 +575,7 @@ int zram_init_device(struct zram *zram) /* zram devices sort of resembles non-rotational disks */ queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); - zram->mem_pool = zs_create_pool("zram", GFP_NOIO | __GFP_HIGHMEM); + zram->mem_pool = zs_create_pool(GFP_NOIO | __GFP_HIGHMEM); if (!zram->mem_pool) { pr_err("Error creating memory pool\n"); ret = -ENOMEM; diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c index 4666609..06f73a9 100644 --- a/drivers/staging/zsmalloc/zsmalloc-main.c +++ b/drivers/staging/zsmalloc/zsmalloc-main.c @@ -207,7 +207,6 @@ struct zs_pool { struct size_class size_class[ZS_SIZE_CLASSES]; gfp_t flags; /* allocation flags used when growing pool */ - const char *name; }; /* @@ -798,8 +797,7 @@ fail: /** * zs_create_pool - Creates an allocation pool to work from. - * @name: name of the pool to be created - * @flags: allocation flags used when growing pool + * @flags: allocation flags used to allocate pool metadata * * This function must be called before anything when using * the zsmalloc allocator. @@ -807,14 +805,11 @@ fail: * On success, a pointer to the newly created pool is returned, * otherwise NULL. */ -struct zs_pool *zs_create_pool(const char *name, gfp_t flags) +struct zs_pool *zs_create_pool(gfp_t flags) { int i, ovhd_size; struct zs_pool *pool; - if (!name) - return NULL; - ovhd_size = roundup(sizeof(*pool), PAGE_SIZE); pool = kzalloc(ovhd_size, GFP_KERNEL); if (!pool) @@ -837,7 +832,6 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags) } pool->flags = flags; - pool->name = name; return pool; } diff --git a/drivers/staging/zsmalloc/zsmalloc.h b/drivers/staging/zsmalloc/zsmalloc.h index de2e8bf..46dbd05 100644 --- a/drivers/staging/zsmalloc/zsmalloc.h +++ b/drivers/staging/zsmalloc/zsmalloc.h @@ -28,7 +28,7 @@ enum zs_mapmode { struct zs_pool; -struct zs_pool *zs_create_pool(const char *name, gfp_t flags); +struct zs_pool *zs_create_pool(gfp_t flags); void zs_destroy_pool(struct zs_pool *pool); unsigned long zs_malloc(struct zs_pool *pool, size_t size); -- cgit v0.10.2 From 1aedfa8f25c13a2f5428cb1b0f806e04121cbef5 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 30 Jan 2013 17:44:16 -0500 Subject: staging/fwserial: Annotate rcu pointers with __rcu Fixes these sparse warnings: drivers/staging/fwserial/fwserial.c:430:16: sparse: incompatible types in comparison expression (different address spaces) drivers/staging/fwserial/fwserial.c:699:30: sparse: incompatible types in comparison expression (different address spaces) drivers/staging/fwserial/fwserial.c:802:16: sparse: incompatible types in comparison expression (different address spaces) drivers/staging/fwserial/fwserial.c:898:16: sparse: incompatible types in comparison expression (different address spaces) drivers/staging/fwserial/fwserial.c:1842:14: sparse: incompatible types in comparison expression (different address spaces) Reported-by: kbuild test robot Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index 33a3a53..514f571 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -280,7 +280,7 @@ struct fwtty_port { loopback:1; unsigned long flags; - struct fwtty_peer *peer; + struct fwtty_peer __rcu *peer; struct async_icount icount; struct stats stats; -- cgit v0.10.2 From d13b0b6d51e78b0107c76d79cf0ef06d9e07650b Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 30 Jan 2013 16:18:50 -0500 Subject: staging/fwserial: Fix compiler warning Fix: drivers/staging/fwserial/fwserial.c:581:3: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'size_t' Reported-by: kbuild test robot Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index cad9e98..8859c75 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -578,7 +578,7 @@ static int fwtty_buffer_rx(struct fwtty_port *port, unsigned char *d, size_t n) size_t size = (n + sizeof(struct buffered_rx) + 0xFF) & ~0xFF; if (port->buffered + n > HIGH_WATERMARK) { - fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %ld wtrmk: %d", + fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %zu wtrmk: %d", port->buffered, n, HIGH_WATERMARK); return 0; } -- cgit v0.10.2 From ae5943de8c8c4438cbac5cda599ff0b88c224468 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Wed, 30 Jan 2013 20:07:29 +0000 Subject: staging: vt6656: Fix URB submitted while active warning. This error happens because PIPEnsControlOut and PIPEnsControlIn unlock the spin lock for delay, letting in another thread. The patch moves the current MP_SET_FLAG to before filling of sUsbCtlRequest for pControlURB and clears it in event of failing. Any thread calling either function while fMP_CONTROL_READS or fMP_CONTROL_WRITES flags set will return STATUS_FAILURE. Signed-off-by: Malcolm Priestley Cc: stable@vger.kernel.org # 3.8 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c index 2a02067..22a3dde 100644 --- a/drivers/staging/vt6656/usbpipe.c +++ b/drivers/staging/vt6656/usbpipe.c @@ -126,6 +126,11 @@ int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue, if (pDevice->Flags & fMP_CONTROL_WRITES) return STATUS_FAILURE; + if (pDevice->Flags & fMP_CONTROL_READS) + return STATUS_FAILURE; + + MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES); + pDevice->sUsbCtlRequest.bRequestType = 0x40; pDevice->sUsbCtlRequest.bRequest = byRequest; pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue); @@ -140,12 +145,13 @@ int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue, ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC); if (ntStatus != 0) { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control send request submission failed: %d\n", ntStatus); + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "control send request submission failed: %d\n", + ntStatus); + MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES); return STATUS_FAILURE; } - else { - MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES); - } + spin_unlock_irq(&pDevice->lock); for (ii = 0; ii <= USB_CTL_WAIT; ii ++) { @@ -179,6 +185,11 @@ int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue, if (pDevice->Flags & fMP_CONTROL_READS) return STATUS_FAILURE; + if (pDevice->Flags & fMP_CONTROL_WRITES) + return STATUS_FAILURE; + + MP_SET_FLAG(pDevice, fMP_CONTROL_READS); + pDevice->sUsbCtlRequest.bRequestType = 0xC0; pDevice->sUsbCtlRequest.bRequest = byRequest; pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue); @@ -192,10 +203,11 @@ int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue, ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC); if (ntStatus != 0) { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control request submission failed: %d\n", ntStatus); - }else { - MP_SET_FLAG(pDevice, fMP_CONTROL_READS); - } + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO + "control request submission failed: %d\n", ntStatus); + MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); + return STATUS_FAILURE; + } spin_unlock_irq(&pDevice->lock); for (ii = 0; ii <= USB_CTL_WAIT; ii ++) { -- cgit v0.10.2 From abac8b54a353b9a1ac7d09ff790812655f618896 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:21:49 -0700 Subject: staging: comedi: conditionally build in USB driver support Separate the comedi_usb_* functions out of drivers.c into a new source file, comedi_usb.c. This allows conditionally building support for comedi USB drivers into the comedi core without the need for the #if'defery. Fix the Kconfig and Makefile appropriately. For aesthetic reasons, add some whitespace to the Makefile to keep everything lined up. Group all the comedi_usb_* prototypes into one place in comedidev.h. Protect these prototypes with an #ifdef so that building a comedi usb driver without USB support will cause a build error. This will normally not happen as long as the comedi USB driver is placed in the proper group in the Kconfig. Remove the #include from comedidev.h and drivers.c. This include is only needed by the comedi USB driver support code and the USB drivers. The include should occur in those files. Removing the include of usb.h exposed a couple drivers that need and . Add the missing includes. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index bb9acc9..e0aa246 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1175,11 +1175,7 @@ menuconfig COMEDI_USB_DRIVERS bool "Comedi USB drivers" depends on USB ---help--- - Enable comedi USB drivers to be built - - Note that the answer to this question won't directly affect the - kernel: saying N will just cause the configurator to skip all - the questions about USB comedi drivers. + Enable support for comedi USB drivers. if COMEDI_USB_DRIVERS diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index 51816c3..872a87b 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,9 +1,10 @@ -comedi-y := comedi_fops.o range.o drivers.o \ - comedi_buf.o -comedi-$(CONFIG_PROC_FS) += proc.o -comedi-$(CONFIG_COMPAT) += comedi_compat32.o +comedi-y := comedi_fops.o range.o drivers.o \ + comedi_buf.o +comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o +comedi-$(CONFIG_PROC_FS) += proc.o +comedi-$(CONFIG_COMPAT) += comedi_compat32.o -obj-$(CONFIG_COMEDI) += comedi.o +obj-$(CONFIG_COMEDI) += comedi.o -obj-$(CONFIG_COMEDI) += kcomedilib/ -obj-$(CONFIG_COMEDI) += drivers/ +obj-$(CONFIG_COMEDI) += kcomedilib/ +obj-$(CONFIG_COMEDI) += drivers/ diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c new file mode 100644 index 0000000..cd6abba --- /dev/null +++ b/drivers/staging/comedi/comedi_usb.c @@ -0,0 +1,106 @@ +/* + * comedi_usb.c + * Comedi USB driver specific functions. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include "comedidev.h" + +/** + * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer. + * @dev: comedi_device struct + */ +struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev) +{ + return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; +} +EXPORT_SYMBOL_GPL(comedi_to_usb_interface); + +/** + * comedi_usb_auto_config() - Configure/probe a comedi USB driver. + * @intf: usb_interface struct + * @driver: comedi_driver struct + * + * Typically called from the usb_driver (*probe) function. + */ +int comedi_usb_auto_config(struct usb_interface *intf, + struct comedi_driver *driver) +{ + return comedi_auto_config(&intf->dev, driver, 0); +} +EXPORT_SYMBOL_GPL(comedi_usb_auto_config); + +/** + * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver. + * @intf: usb_interface struct + * + * Typically called from the usb_driver (*disconnect) function. + */ +void comedi_usb_auto_unconfig(struct usb_interface *intf) +{ + comedi_auto_unconfig(&intf->dev); +} +EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig); + +/** + * comedi_usb_driver_register() - Register a comedi USB driver. + * @comedi_driver: comedi_driver struct + * @usb_driver: usb_driver struct + * + * This function is used for the module_init() of comedi USB drivers. + * Do not call it directly, use the module_comedi_usb_driver() helper + * macro instead. + */ +int comedi_usb_driver_register(struct comedi_driver *comedi_driver, + struct usb_driver *usb_driver) +{ + int ret; + + ret = comedi_driver_register(comedi_driver); + if (ret < 0) + return ret; + + ret = usb_register(usb_driver); + if (ret < 0) { + comedi_driver_unregister(comedi_driver); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(comedi_usb_driver_register); + +/** + * comedi_usb_driver_unregister() - Unregister a comedi USB driver. + * @comedi_driver: comedi_driver struct + * @usb_driver: usb_driver struct + * + * This function is used for the module_exit() of comedi USB drivers. + * Do not call it directly, use the module_comedi_usb_driver() helper + * macro instead. + */ +void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver, + struct usb_driver *usb_driver) +{ + usb_deregister(usb_driver); + comedi_driver_unregister(comedi_driver); +} +EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 503dd8c..4fe29d5 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -41,7 +41,6 @@ #include #include #include -#include #include "comedi.h" @@ -337,25 +336,6 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *, module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) -struct usb_driver; - -int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); -void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); - -/** - * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver - * @__comedi_driver: comedi_driver struct - * @__usb_driver: usb_driver struct - * - * Helper macro for comedi USB drivers which do not do anything special - * in module init/exit. This eliminates a lot of boilerplate. Each - * module may only use this macro once, and calling it replaces - * module_init() and module_exit() - */ -#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \ - module_driver(__comedi_driver, comedi_usb_driver_register, \ - comedi_usb_driver_unregister, &(__usb_driver)) - void init_polling(void); void cleanup_polling(void); void start_polling(struct comedi_device *); @@ -449,12 +429,6 @@ static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL; } -static inline struct usb_interface * -comedi_to_usb_interface(struct comedi_device *dev) -{ - return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; -} - unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); @@ -485,15 +459,35 @@ static inline int comedi_pci_auto_config(struct pci_dev *pcidev, void comedi_pci_auto_unconfig(struct pci_dev *pcidev); -static inline int comedi_usb_auto_config(struct usb_interface *intf, - struct comedi_driver *driver) -{ - return comedi_auto_config(&intf->dev, driver, 0); -} +#ifdef CONFIG_COMEDI_USB_DRIVERS -static inline void comedi_usb_auto_unconfig(struct usb_interface *intf) -{ - comedi_auto_unconfig(&intf->dev); -} +/* comedi_usb.c - comedi USB driver specific functions */ + +struct usb_driver; +struct usb_interface; + +struct usb_interface *comedi_to_usb_interface(struct comedi_device *); + +int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *); +void comedi_usb_auto_unconfig(struct usb_interface *); + +int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); +void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); + +/** + * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver + * @__comedi_driver: comedi_driver struct + * @__usb_driver: usb_driver struct + * + * Helper macro for comedi USB drivers which do not do anything special + * in module init/exit. This eliminates a lot of boilerplate. Each + * module may only use this macro once, and calling it replaces + * module_init() and module_exit() + */ +#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \ + module_driver(__comedi_driver, comedi_usb_driver_register, \ + comedi_usb_driver_unregister, &(__usb_driver)) + +#endif /* CONFIG_COMEDI_USB_DRIVERS */ #endif /* _COMEDIDEV_H */ diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 87eeee5..86fcd36 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -593,34 +592,3 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); #endif - -#if IS_ENABLED(CONFIG_USB) - -int comedi_usb_driver_register(struct comedi_driver *comedi_driver, - struct usb_driver *usb_driver) -{ - int ret; - - ret = comedi_driver_register(comedi_driver); - if (ret < 0) - return ret; - - ret = usb_register(usb_driver); - if (ret < 0) { - comedi_driver_unregister(comedi_driver); - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(comedi_usb_driver_register); - -void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver, - struct usb_driver *usb_driver) -{ - usb_deregister(usb_driver); - comedi_driver_unregister(comedi_driver); -} -EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister); - -#endif diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index d2abfc2..d6c7ba6 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -29,6 +29,8 @@ * source code. */ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 5ad9db9..15b080e 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -29,6 +29,8 @@ * this source code. */ +#include + #include "../comedidev.h" #include "addi_watchdog.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 8920b96..5512731 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -29,6 +29,9 @@ * this source code. */ +#include +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" -- cgit v0.10.2 From 33782dd5edf8db3cdb7c81a3523bf743dd0209b7 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:22:21 -0700 Subject: staging: comedi: conditionally build in PCI driver support Separate the comedi_pci_* functions out of drivers.c into a new source file, comedi_pci.c. This allows conditionally building support for comedi PCI drivers into the comedi core. Fix the Kconfig and Makefile appropriately. Group all the comedi_pci_* prototypes and related defines into one place in comedidev.h. Protect these prototypes with an #ifdef and provide some dummy functions so that the mixed ISA/PCI comedi drivers will still build correctly. Remove the #include from comedidev.h and drivers.c. This include is only needed by the comedi PCI driver support code and the PCI drivers. The include should occur in those files. Also, remove the #include from a couple non-PCI drivers since it's not needed. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index e0aa246..9cc16b5 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -542,11 +542,7 @@ menuconfig COMEDI_PCI_DRIVERS bool "Comedi PCI drivers" depends on PCI ---help--- - Enable comedi PCI drivers to be built - - Note that the answer to this question won't directly affect the - kernel: saying N will just cause the configurator to skip all - the questions about PCI comedi drivers. + Enable support for comedi PCI drivers. if COMEDI_PCI_DRIVERS diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index 872a87b..5372cb1 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,5 +1,6 @@ comedi-y := comedi_fops.o range.o drivers.o \ comedi_buf.o +comedi-$(CONFIG_COMEDI_PCI_DRIVERS) += comedi_pci.o comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o comedi-$(CONFIG_PROC_FS) += proc.o comedi-$(CONFIG_COMPAT) += comedi_compat32.o diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c new file mode 100644 index 0000000..37d2e46 --- /dev/null +++ b/drivers/staging/comedi/comedi_pci.c @@ -0,0 +1,140 @@ +/* + * comedi_pci.c + * Comedi PCI driver specific functions. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include "comedidev.h" + +/** + * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer. + * @dev: comedi_device struct + */ +struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) +{ + return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL; +} +EXPORT_SYMBOL_GPL(comedi_to_pci_dev); + +/** + * comedi_pci_enable() - Enable the PCI device and request the regions. + * @pcidev: pci_dev struct + * @res_name: name for the requested reqource + */ +int comedi_pci_enable(struct pci_dev *pcidev, const char *res_name) +{ + int rc; + + rc = pci_enable_device(pcidev); + if (rc < 0) + return rc; + + rc = pci_request_regions(pcidev, res_name); + if (rc < 0) + pci_disable_device(pcidev); + + return rc; +} +EXPORT_SYMBOL_GPL(comedi_pci_enable); + +/** + * comedi_pci_disable() - Release the regions and disable the PCI device. + * @pcidev: pci_dev struct + * + * This must be matched with a previous successful call to comedi_pci_enable(). + */ +void comedi_pci_disable(struct pci_dev *pcidev) +{ + pci_release_regions(pcidev); + pci_disable_device(pcidev); +} +EXPORT_SYMBOL_GPL(comedi_pci_disable); + +/** + * comedi_pci_auto_config() - Configure/probe a comedi PCI driver. + * @pcidev: pci_dev struct + * @driver: comedi_driver struct + * + * Typically called from the pci_driver (*probe) function. + */ +int comedi_pci_auto_config(struct pci_dev *pcidev, + struct comedi_driver *driver) +{ + return comedi_auto_config(&pcidev->dev, driver, 0); +} +EXPORT_SYMBOL_GPL(comedi_pci_auto_config); + +/** + * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver. + * @pcidev: pci_dev struct + * + * Typically called from the pci_driver (*remove) function. + */ +void comedi_pci_auto_unconfig(struct pci_dev *pcidev) +{ + comedi_auto_unconfig(&pcidev->dev); +} +EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig); + +/** + * comedi_pci_driver_register() - Register a comedi PCI driver. + * @comedi_driver: comedi_driver struct + * @pci_driver: pci_driver struct + * + * This function is used for the module_init() of comedi PCI drivers. + * Do not call it directly, use the module_comedi_pci_driver() helper + * macro instead. + */ +int comedi_pci_driver_register(struct comedi_driver *comedi_driver, + struct pci_driver *pci_driver) +{ + int ret; + + ret = comedi_driver_register(comedi_driver); + if (ret < 0) + return ret; + + ret = pci_register_driver(pci_driver); + if (ret < 0) { + comedi_driver_unregister(comedi_driver); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(comedi_pci_driver_register); + +/** + * comedi_pci_driver_unregister() - Unregister a comedi PCI driver. + * @comedi_driver: comedi_driver struct + * @pci_driver: pci_driver struct + * + * This function is used for the module_exit() of comedi PCI drivers. + * Do not call it directly, use the module_comedi_pci_driver() helper + * macro instead. + */ +void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver, + struct pci_driver *pci_driver) +{ + pci_unregister_driver(pci_driver); + comedi_driver_unregister(comedi_driver); +} +EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 4fe29d5..666cade 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -40,7 +40,6 @@ #include #include #include -#include #include "comedi.h" @@ -54,22 +53,6 @@ COMEDI_MINORVERSION, COMEDI_MICROVERSION) #define COMEDI_RELEASE VERSION -/* - * PCI Vendor IDs not in - */ -#define PCI_VENDOR_ID_KOLTER 0x1001 -#define PCI_VENDOR_ID_ICP 0x104c -#define PCI_VENDOR_ID_AMCC 0x10e8 -#define PCI_VENDOR_ID_DT 0x1116 -#define PCI_VENDOR_ID_IOTECH 0x1616 -#define PCI_VENDOR_ID_CONTEC 0x1221 -#define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */ -#define PCI_VENDOR_ID_ADVANTECH 0x13fe -#define PCI_VENDOR_ID_MEILHAUS 0x1402 -#define PCI_VENDOR_ID_RTD 0x1435 -#define PCI_VENDOR_ID_ADLINK 0x144a -#define PCI_VENDOR_ID_AMPLICON 0x14dc - #define COMEDI_NUM_MINORS 0x100 #define COMEDI_NUM_BOARD_MINORS 0x30 #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS @@ -295,26 +278,6 @@ int comedi_driver_unregister(struct comedi_driver *); module_driver(__comedi_driver, comedi_driver_register, \ comedi_driver_unregister) -int comedi_pci_enable(struct pci_dev *, const char *); -void comedi_pci_disable(struct pci_dev *); - -int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *); -void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *); - -/** - * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver - * @__comedi_driver: comedi_driver struct - * @__pci_driver: pci_driver struct - * - * Helper macro for comedi PCI drivers which do not do anything special - * in module init/exit. This eliminates a lot of boilerplate. Each - * module may only use this macro once, and calling it replaces - * module_init() and module_exit() - */ -#define module_comedi_pci_driver(__comedi_driver, __pci_driver) \ - module_driver(__comedi_driver, comedi_pci_driver_register, \ - comedi_pci_driver_unregister, &(__pci_driver)) - struct pcmcia_driver; int comedi_pcmcia_driver_register(struct comedi_driver *, @@ -424,11 +387,6 @@ static inline void comedi_set_hw_dev(struct comedi_device *dev, put_device(old_hw_dev); } -static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) -{ - return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL; -} - unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); @@ -451,13 +409,77 @@ int comedi_auto_config(struct device *hardware_device, struct comedi_driver *driver, unsigned long context); void comedi_auto_unconfig(struct device *hardware_device); -static inline int comedi_pci_auto_config(struct pci_dev *pcidev, - struct comedi_driver *driver) +#ifdef CONFIG_COMEDI_PCI_DRIVERS + +/* comedi_pci.c - comedi PCI driver specific functions */ + +/* + * PCI Vendor IDs not in + */ +#define PCI_VENDOR_ID_KOLTER 0x1001 +#define PCI_VENDOR_ID_ICP 0x104c +#define PCI_VENDOR_ID_AMCC 0x10e8 +#define PCI_VENDOR_ID_DT 0x1116 +#define PCI_VENDOR_ID_IOTECH 0x1616 +#define PCI_VENDOR_ID_CONTEC 0x1221 +#define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */ +#define PCI_VENDOR_ID_ADVANTECH 0x13fe +#define PCI_VENDOR_ID_MEILHAUS 0x1402 +#define PCI_VENDOR_ID_RTD 0x1435 +#define PCI_VENDOR_ID_ADLINK 0x144a +#define PCI_VENDOR_ID_AMPLICON 0x14dc + +struct pci_dev; +struct pci_driver; + +struct pci_dev *comedi_to_pci_dev(struct comedi_device *); + +int comedi_pci_enable(struct pci_dev *, const char *); +void comedi_pci_disable(struct pci_dev *); + +int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *); +void comedi_pci_auto_unconfig(struct pci_dev *); + +int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *); +void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *); + +/** + * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver + * @__comedi_driver: comedi_driver struct + * @__pci_driver: pci_driver struct + * + * Helper macro for comedi PCI drivers which do not do anything special + * in module init/exit. This eliminates a lot of boilerplate. Each + * module may only use this macro once, and calling it replaces + * module_init() and module_exit() + */ +#define module_comedi_pci_driver(__comedi_driver, __pci_driver) \ + module_driver(__comedi_driver, comedi_pci_driver_register, \ + comedi_pci_driver_unregister, &(__pci_driver)) + +#else + +/* + * Some of the comedi mixed ISA/PCI drivers call the PCI specific + * functions. Provide some dummy functions if CONFIG_COMEDI_PCI_DRIVERS + * is not enabled. + */ + +static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) +{ + return NULL; +} + +static inline int comedi_pci_enable(struct pci_dev *dev, const char *name) +{ + return -ENOSYS; +} + +static inline void comedi_pci_disable(struct pci_dev *dev) { - return comedi_auto_config(&pcidev->dev, driver, 0); } -void comedi_pci_auto_unconfig(struct pci_dev *pcidev); +#endif /* CONFIG_COMEDI_PCI_DRIVERS */ #ifdef CONFIG_COMEDI_USB_DRIVERS diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 86fcd36..4e6e8a1 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -496,73 +495,6 @@ void comedi_auto_unconfig(struct device *hardware_device) } EXPORT_SYMBOL_GPL(comedi_auto_unconfig); -/** - * comedi_pci_enable() - Enable the PCI device and request the regions. - * @pdev: pci_dev struct - * @res_name: name for the requested reqource - */ -int comedi_pci_enable(struct pci_dev *pdev, const char *res_name) -{ - int rc; - - rc = pci_enable_device(pdev); - if (rc < 0) - return rc; - - rc = pci_request_regions(pdev, res_name); - if (rc < 0) - pci_disable_device(pdev); - - return rc; -} -EXPORT_SYMBOL_GPL(comedi_pci_enable); - -/** - * comedi_pci_disable() - Release the regions and disable the PCI device. - * @pdev: pci_dev struct - * - * This must be matched with a previous successful call to comedi_pci_enable(). - */ -void comedi_pci_disable(struct pci_dev *pdev) -{ - pci_release_regions(pdev); - pci_disable_device(pdev); -} -EXPORT_SYMBOL_GPL(comedi_pci_disable); - -int comedi_pci_driver_register(struct comedi_driver *comedi_driver, - struct pci_driver *pci_driver) -{ - int ret; - - ret = comedi_driver_register(comedi_driver); - if (ret < 0) - return ret; - - ret = pci_register_driver(pci_driver); - if (ret < 0) { - comedi_driver_unregister(comedi_driver); - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(comedi_pci_driver_register); - -void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver, - struct pci_driver *pci_driver) -{ - pci_unregister_driver(pci_driver); - comedi_driver_unregister(comedi_driver); -} -EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister); - -void comedi_pci_auto_unconfig(struct pci_dev *pcidev) -{ - comedi_auto_unconfig(&pcidev->dev); -} -EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig); - #if IS_ENABLED(CONFIG_PCMCIA) int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, struct pcmcia_driver *pcmcia_driver) diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index 87fe96d..0ae356a 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -54,6 +54,8 @@ Interrupt support for these boards is also not currently supported. Configuration Options: not applicable, uses PCI auto config */ +#include + #include "../comedidev.h" #include "8255.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_035.c b/drivers/staging/comedi/drivers/addi_apci_035.c index d69d6ec..5a53e58 100644 --- a/drivers/staging/comedi/drivers/addi_apci_035.c +++ b/drivers/staging/comedi/drivers/addi_apci_035.c @@ -1,3 +1,5 @@ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index d6c7ba6..c0d0429 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -29,6 +29,7 @@ * source code. */ +#include #include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_1500.c b/drivers/staging/comedi/drivers/addi_apci_1500.c index 1ac4062..9c2f8ee 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1500.c +++ b/drivers/staging/comedi/drivers/addi_apci_1500.c @@ -1,3 +1,5 @@ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c index 1721ba7..69e3996 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1516.c +++ b/drivers/staging/comedi/drivers/addi_apci_1516.c @@ -29,6 +29,8 @@ * this source code. */ +#include + #include "../comedidev.h" #include "addi_watchdog.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c index 3556c61..ddea64d 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1564.c +++ b/drivers/staging/comedi/drivers/addi_apci_1564.c @@ -1,3 +1,5 @@ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 8b88503..e51f800 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -29,6 +29,8 @@ * this source code. */ +#include + #include "../comedidev.h" /* diff --git a/drivers/staging/comedi/drivers/addi_apci_1710.c b/drivers/staging/comedi/drivers/addi_apci_1710.c index 7eb03b1..e83e829 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1710.c +++ b/drivers/staging/comedi/drivers/addi_apci_1710.c @@ -1,3 +1,5 @@ +#include + #include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 15b080e..9ce1d26 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -29,6 +29,7 @@ * this source code. */ +#include #include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index a9891b4..b1c4226 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -29,6 +29,8 @@ * this source code. */ +#include + #include "../comedidev.h" #include "addi_watchdog.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c index 8cad18f..917234d 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3120.c +++ b/drivers/staging/comedi/drivers/addi_apci_3120.c @@ -1,3 +1,5 @@ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_3200.c b/drivers/staging/comedi/drivers/addi_apci_3200.c index c11bf4b..90ee4f8 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3200.c +++ b/drivers/staging/comedi/drivers/addi_apci_3200.c @@ -1,3 +1,5 @@ +#include + #include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 5512731..786fcaf 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -29,6 +29,7 @@ * this source code. */ +#include #include #include diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index 69f5bf4..09d4b21 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -1,3 +1,5 @@ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c index 41df010..7b3e3316 100644 --- a/drivers/staging/comedi/drivers/adl_pci6208.c +++ b/drivers/staging/comedi/drivers/adl_pci6208.c @@ -42,6 +42,8 @@ References: - adl_pci9118.c */ +#include + #include "../comedidev.h" /* diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c index 2a8bc98..539b1d8 100644 --- a/drivers/staging/comedi/drivers/adl_pci7x3x.c +++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c @@ -54,6 +54,8 @@ driver. Configuration Options: not applicable */ +#include + #include "../comedidev.h" /* diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index ece84dd..d06b83f 100644 --- a/drivers/staging/comedi/drivers/adl_pci8164.c +++ b/drivers/staging/comedi/drivers/adl_pci8164.c @@ -30,9 +30,11 @@ Updated: Mon, 14 Apr 2008 15:10:32 +0100 Configuration Options: not applicable, uses PCI auto config */ -#include "../comedidev.h" #include +#include #include + +#include "../comedidev.h" #include "comedi_fc.h" #include "8253.h" diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c index 1a31e91..eeb10ec 100644 --- a/drivers/staging/comedi/drivers/adl_pci9111.c +++ b/drivers/staging/comedi/drivers/adl_pci9111.c @@ -68,11 +68,12 @@ TODO: */ -#include "../comedidev.h" - +#include #include #include +#include "../comedidev.h" + #include "8253.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index d21dfe6..ef4dbe5 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -76,13 +76,15 @@ Configuration options: * attachment if necessary, and possibly to set other options supported by * manual attachment. */ -#include "../comedidev.h" +#include #include #include #include #include +#include "../comedidev.h" + #include "amcc_s5933.h" #include "8253.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c index d232d0c..3d788c7 100644 --- a/drivers/staging/comedi/drivers/adv_pci1710.c +++ b/drivers/staging/comedi/drivers/adv_pci1710.c @@ -41,6 +41,7 @@ Configuration options: device will be used. */ +#include #include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c index 1be8902..02ce55a 100644 --- a/drivers/staging/comedi/drivers/adv_pci1723.c +++ b/drivers/staging/comedi/drivers/adv_pci1723.c @@ -48,6 +48,8 @@ TODO: 3. Implement calibration. */ +#include + #include "../comedidev.h" /* all the registers for the pci1723 board */ diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index 35887e4..338c43e 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -29,10 +29,11 @@ Configuration options: */ -#include "../comedidev.h" - +#include #include +#include "../comedidev.h" + #include "8255.h" #include "8253.h" diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c index 1fadf5d..b30d1a0 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.c +++ b/drivers/staging/comedi/drivers/amplc_dio200.c @@ -258,6 +258,7 @@ * order they appear in the channel list. */ +#include #include #include diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c index 5011016..479e10f 100644 --- a/drivers/staging/comedi/drivers/amplc_pc236.c +++ b/drivers/staging/comedi/drivers/amplc_pc236.c @@ -52,6 +52,7 @@ the IRQ jumper. If no interrupt is connected, then subdevice 1 is unused. */ +#include #include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c index c34bb00..11c1f47 100644 --- a/drivers/staging/comedi/drivers/amplc_pc263.c +++ b/drivers/staging/comedi/drivers/amplc_pc263.c @@ -44,6 +44,8 @@ connected to a reed-relay. Relay contacts are closed when output is 1. The state of the outputs can be read. */ +#include + #include "../comedidev.h" #define PC263_DRIVER_NAME "amplc_pc263" diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c index 24794f4..c9da4cd 100644 --- a/drivers/staging/comedi/drivers/amplc_pci224.c +++ b/drivers/staging/comedi/drivers/amplc_pci224.c @@ -103,6 +103,7 @@ Caveats: correctly. */ +#include #include #include diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 2440596..e2244c6 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -188,11 +188,12 @@ Support for PCI230+/260+, more triggered scan functionality, and workarounds for (or detection of) various hardware problems added by Ian Abbott. */ -#include "../comedidev.h" - +#include #include #include +#include "../comedidev.h" + #include "comedi_fc.h" #include "8253.h" #include "8255.h" diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index 0fd6fcf..79c7211 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -67,10 +67,12 @@ TODO: analog triggering on 1602 series */ -#include "../comedidev.h" +#include #include #include +#include "../comedidev.h" + #include "8253.h" #include "8255.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c index e7d2977..d33fc32 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas64.c +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c @@ -87,10 +87,12 @@ TODO: #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include "../comedidev.h" +#include #include #include +#include "../comedidev.h" + #include "8253.h" #include "8255.h" #include "plx9080.h" diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index 04be8c6..e2cadc7 100644 --- a/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/drivers/staging/comedi/drivers/cb_pcidda.c @@ -41,6 +41,8 @@ * Only simple analog output writing is supported. */ +#include + #include "../comedidev.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c index 709c5c6..aae063c 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdas.c +++ b/drivers/staging/comedi/drivers/cb_pcimdas.c @@ -40,11 +40,12 @@ No interrupts, multi channel or FIFO AI, although the card looks like it could s See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details. */ -#include "../comedidev.h" - +#include #include #include +#include "../comedidev.h" + #include "plx9052.h" #include "8255.h" diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index 74aa4e0..63cfbaf 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c @@ -79,6 +79,8 @@ Configuration Options: not applicable, uses PCI auto config -Calin Culianu */ +#include + #include "../comedidev.h" #include "8255.h" diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c index e0273c4..182dea6 100644 --- a/drivers/staging/comedi/drivers/contec_pci_dio.c +++ b/drivers/staging/comedi/drivers/contec_pci_dio.c @@ -30,6 +30,8 @@ Status: works Configuration Options: not applicable, uses comedi PCI auto config */ +#include + #include "../comedidev.h" #define PCI_DEVICE_ID_PIO1616L 0x8172 diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index d1fc190..50b450f 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -107,12 +107,13 @@ Configuration options: not applicable, uses PCI auto config */ -#include "../comedidev.h" - +#include #include #include #include +#include "../comedidev.h" + #include "8255.h" #define DAQBOARD2000_FIRMWARE "daqboard2000_firmware.bin" diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c index 37f03c2..45a937e 100644 --- a/drivers/staging/comedi/drivers/das08.c +++ b/drivers/staging/comedi/drivers/das08.c @@ -51,10 +51,11 @@ * driver. */ -#include "../comedidev.h" - +#include #include +#include "../comedidev.h" + #include "8255.h" #include "8253.h" #include "das08.h" diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index 73a2418..ff67348 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -46,12 +46,11 @@ Options (for pcm-das08): Command support does not exist, but could be added for this board. */ -#include "../comedidev.h" - #include -#include #include +#include "../comedidev.h" + #include "das08.h" /* pcmcia includes */ diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c index b159f44..f238a1f 100644 --- a/drivers/staging/comedi/drivers/das16.c +++ b/drivers/staging/comedi/drivers/das16.c @@ -82,7 +82,9 @@ www.measurementcomputing.com #include #include #include + #include + #include "../comedidev.h" #include "8253.h" diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index 1fabe88..3ce499f 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -55,9 +55,11 @@ AO commands are not supported. #define DEBUG 1 +#include +#include #include + #include "../comedidev.h" -#include #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c index 5aa695e..decc17f 100644 --- a/drivers/staging/comedi/drivers/dyna_pci10xx.c +++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c @@ -37,9 +37,11 @@ their cards in their manuals. */ -#include "../comedidev.h" +#include #include +#include "../comedidev.h" + #define READ_TIMEOUT 50 static const struct comedi_lrange range_pci1050_ai = { 3, { diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c index 6d88b72..b60c975 100644 --- a/drivers/staging/comedi/drivers/gsc_hpdi.c +++ b/drivers/staging/comedi/drivers/gsc_hpdi.c @@ -47,9 +47,11 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include +#include #include + #include "../comedidev.h" -#include #include "plx9080.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c index 0174295..1e08f91 100644 --- a/drivers/staging/comedi/drivers/icp_multi.c +++ b/drivers/staging/comedi/drivers/icp_multi.c @@ -47,11 +47,11 @@ There are 4 x 12-bit Analogue Outputs. Ranges : 5V, 10V, +/-5V, +/-10V Configuration options: not applicable, uses PCI auto config */ +#include +#include #include -#include "../comedidev.h" -#include -#include +#include "../comedidev.h" #define PCI_DEVICE_ID_ICP_MULTI 0x8000 diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c index 8d79c76..17ba75e 100644 --- a/drivers/staging/comedi/drivers/jr3_pci.c +++ b/drivers/staging/comedi/drivers/jr3_pci.c @@ -42,15 +42,17 @@ * comedi_nonfree_firmware tarball. The file is called "jr3pci.idm". */ -#include "../comedidev.h" - +#include +#include #include #include #include #include #include #include -#include + +#include "../comedidev.h" + #include "jr3_pci.h" #define PCI_VENDOR_ID_JR3 0x1762 diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index 535800a..8c09c02 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c @@ -34,6 +34,8 @@ This driver is a simple driver to read the counter values from Kolter Electronic PCI Counter Card. */ +#include + #include "../comedidev.h" #define CNT_CARD_DEVICE_ID 0x0014 diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 4312b37..b766bb9 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -45,13 +45,14 @@ broken. */ -#include -#include "../comedidev.h" - +#include #include +#include #include #include +#include "../comedidev.h" + #include "comedi_fc.h" #include "8253.h" diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index ee8bafc..06490eb 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -34,9 +34,11 @@ * Analog Input, Analog Output, Digital I/O */ +#include #include #include #include + #include "../comedidev.h" #define ME2600_FIRMWARE "me2600_firmware.bin" diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c index e27850f..be2c15f 100644 --- a/drivers/staging/comedi/drivers/mite.c +++ b/drivers/staging/comedi/drivers/mite.c @@ -51,11 +51,12 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include "mite.h" +#include -#include "comedi_fc.h" #include "../comedidev.h" +#include "comedi_fc.h" +#include "mite.h" #define PCI_MITE_SIZE 4096 #define PCI_DAQ_SIZE 4096 diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c index 67aa6f4..bcd4df2 100644 --- a/drivers/staging/comedi/drivers/ni_6527.c +++ b/drivers/staging/comedi/drivers/ni_6527.c @@ -41,7 +41,9 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800 #define DEBUG 1 #define DEBUG_FLAGS +#include #include + #include "../comedidev.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index fb7e8b8..bfa790e 100644 --- a/drivers/staging/comedi/drivers/ni_65xx.c +++ b/drivers/staging/comedi/drivers/ni_65xx.c @@ -50,8 +50,11 @@ except maybe the 6514. #define DEBUG 1 #define DEBUG_FLAGS + +#include #include #include + #include "../comedidev.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c index bdef2e4..e46dd7a 100644 --- a/drivers/staging/comedi/drivers/ni_660x.c +++ b/drivers/staging/comedi/drivers/ni_660x.c @@ -40,8 +40,11 @@ DAQ 6601/6602 User Manual (NI 322137B-01) */ +#include #include + #include "../comedidev.h" + #include "mite.h" #include "ni_tio.h" diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c index 6f3c090..2faf86c 100644 --- a/drivers/staging/comedi/drivers/ni_670x.c +++ b/drivers/staging/comedi/drivers/ni_670x.c @@ -41,8 +41,10 @@ Commands are not supported. */ +#include #include #include + #include "../comedidev.h" #include "mite.h" diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index dedb2ab..9e4d2da 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -73,12 +73,14 @@ NI manuals: */ +#include #include #include #include +#include + #include "../comedidev.h" -#include #include #include "8253.h" diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c index ba8c2f2..0a00260 100644 --- a/drivers/staging/comedi/drivers/ni_pcidio.c +++ b/drivers/staging/comedi/drivers/ni_pcidio.c @@ -55,9 +55,11 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org /* #define DEBUG 1 */ /* #define DEBUG_FLAGS */ +#include #include #include #include + #include "../comedidev.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c index 26a870c..98b43f2 100644 --- a/drivers/staging/comedi/drivers/ni_pcimio.c +++ b/drivers/staging/comedi/drivers/ni_pcimio.c @@ -110,10 +110,12 @@ Bugs: */ +#include +#include + #include "../comedidev.h" #include -#include #include "ni_stc.h" #include "mite.h" diff --git a/drivers/staging/comedi/drivers/pcmda12.c b/drivers/staging/comedi/drivers/pcmda12.c index 48b049b..13f79f4 100644 --- a/drivers/staging/comedi/drivers/pcmda12.c +++ b/drivers/staging/comedi/drivers/pcmda12.c @@ -53,8 +53,6 @@ Configuration Options: #include "../comedidev.h" -#include /* for PCI devices */ - #define CHANS 8 #define IOSIZE 16 #define LSB(x) ((unsigned char)((x) & 0xff)) diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c index d6d3d95..5fa1fe0 100644 --- a/drivers/staging/comedi/drivers/pcmmio.c +++ b/drivers/staging/comedi/drivers/pcmmio.c @@ -78,9 +78,9 @@ Configuration Options: #include #include -#include #include "../comedidev.h" + #include "comedi_fc.h" /* This stuff is all from pcmuio.c -- it refers to the DIO subdevices only */ diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index b74431f..71ef3f9 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c @@ -77,9 +77,9 @@ Configuration Options: #include #include -#include #include "../comedidev.h" + #include "comedi_fc.h" #define CHANS_PER_PORT 8 diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c index 5581452..6a5c914 100644 --- a/drivers/staging/comedi/drivers/rtd520.c +++ b/drivers/staging/comedi/drivers/rtd520.c @@ -101,8 +101,9 @@ Configuration options: */ -#include +#include #include +#include #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 0c7221c..81a1fe6 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -64,6 +64,7 @@ INSN_CONFIG instructions: comedi_do_insn(cf,&insn); //executing configuration */ +#include #include #include #include diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c index 0aad815..cb83f6a 100644 --- a/drivers/staging/comedi/drivers/skel.c +++ b/drivers/staging/comedi/drivers/skel.c @@ -72,9 +72,9 @@ Configuration Options: * options that are used with comedi_config. */ -#include "../comedidev.h" +#include -#include /* for PCI devices */ +#include "../comedidev.h" #include "comedi_fc.h" -- cgit v0.10.2 From 309231d7a610554b02084ff7b465e43ef383a3bc Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:22:44 -0700 Subject: staging: comedi: conditionally build in PCMCIA driver support Separate the comedi_pcmcia_* functions out of drivers.c into a new source file, comedi_pcmcia.c. This allows conditionally building support for comedi pcmcia drivers into the comedi core without the need for the #if'defery. Fix the Kconfig and Makefile appropriately. Group all the comedi_pcmcia_* prototypes into one place in comedidev.h. Protect these prototypes with an #ifdef so that building a comedi pcmcia driver without PCMCIA support will cause a build error. This will normally not happen as long as the comedi pcmcia driver is placed in the proper group in the Kconfig. Remove the #include from drivers.c. These includes are only needed by the comedi pcmcia driver support code and the pcmcia drivers. The include should occur in those files. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 9cc16b5..2da9290 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1090,11 +1090,7 @@ menuconfig COMEDI_PCMCIA_DRIVERS bool "Comedi PCMCIA drivers" depends on PCMCIA ---help--- - Enable comedi PCMCIA and PCCARD drivers to be built - - Note that the answer to this question won't directly affect the - kernel: saying N will just cause the configurator to skip all - the questions about PCMCIA comedi drivers. + Enable support for comedi PCMCIA drivers. if COMEDI_PCMCIA_DRIVERS diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index 5372cb1..e6dfc98 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,6 +1,7 @@ comedi-y := comedi_fops.o range.o drivers.o \ comedi_buf.o comedi-$(CONFIG_COMEDI_PCI_DRIVERS) += comedi_pci.o +comedi-$(CONFIG_COMEDI_PCMCIA_DRIVERS) += comedi_pcmcia.o comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o comedi-$(CONFIG_PROC_FS) += proc.o comedi-$(CONFIG_COMPAT) += comedi_compat32.o diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c new file mode 100644 index 0000000..8522945 --- /dev/null +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -0,0 +1,73 @@ +/* + * comedi_pcmcia.c + * Comedi PCMCIA driver specific functions. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include + +#include "comedidev.h" + +/** + * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver. + * @comedi_driver: comedi_driver struct + * @pcmcia_driver: pcmcia_driver struct + * + * This function is used for the module_init() of comedi USB drivers. + * Do not call it directly, use the module_comedi_pcmcia_driver() helper + * macro instead. + */ +int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, + struct pcmcia_driver *pcmcia_driver) +{ + int ret; + + ret = comedi_driver_register(comedi_driver); + if (ret < 0) + return ret; + + ret = pcmcia_register_driver(pcmcia_driver); + if (ret < 0) { + comedi_driver_unregister(comedi_driver); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register); + +/** + * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver. + * @comedi_driver: comedi_driver struct + * @pcmcia_driver: pcmcia_driver struct + * + * This function is used for the module_exit() of comedi PCMCIA drivers. + * Do not call it directly, use the module_comedi_pcmcia_driver() helper + * macro instead. + */ +void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, + struct pcmcia_driver *pcmcia_driver) +{ + pcmcia_unregister_driver(pcmcia_driver); + comedi_driver_unregister(comedi_driver); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 666cade..329b1d7 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -278,27 +278,6 @@ int comedi_driver_unregister(struct comedi_driver *); module_driver(__comedi_driver, comedi_driver_register, \ comedi_driver_unregister) -struct pcmcia_driver; - -int comedi_pcmcia_driver_register(struct comedi_driver *, - struct pcmcia_driver *); -void comedi_pcmcia_driver_unregister(struct comedi_driver *, - struct pcmcia_driver *); - -/** - * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver - * @__comedi_driver: comedi_driver struct - * @__pcmcia_driver: pcmcia_driver struct - * - * Helper macro for comedi PCMCIA drivers which do not do anything special - * in module init/exit. This eliminates a lot of boilerplate. Each - * module may only use this macro once, and calling it replaces - * module_init() and module_exit() - */ -#define module_comedi_pcmcia_driver(__comedi_driver, __pcmcia_driver) \ - module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ - comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) - void init_polling(void); void cleanup_polling(void); void start_polling(struct comedi_device *); @@ -481,6 +460,33 @@ static inline void comedi_pci_disable(struct pci_dev *dev) #endif /* CONFIG_COMEDI_PCI_DRIVERS */ +#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS + +/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */ + +struct pcmcia_driver; + +int comedi_pcmcia_driver_register(struct comedi_driver *, + struct pcmcia_driver *); +void comedi_pcmcia_driver_unregister(struct comedi_driver *, + struct pcmcia_driver *); + +/** + * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver + * @__comedi_driver: comedi_driver struct + * @__pcmcia_driver: pcmcia_driver struct + * + * Helper macro for comedi PCMCIA drivers which do not do anything special + * in module init/exit. This eliminates a lot of boilerplate. Each + * module may only use this macro once, and calling it replaces + * module_init() and module_exit() + */ +#define module_comedi_pcmcia_driver(__comedi_driver, __pcmcia_driver) \ + module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ + comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) + +#endif /* CONFIG_COMEDI_PCMCIA_DRIVERS */ + #ifdef CONFIG_COMEDI_USB_DRIVERS /* comedi_usb.c - comedi USB driver specific functions */ diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 4e6e8a1..151e084 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -23,8 +23,6 @@ #include #include -#include -#include #include #include #include @@ -494,33 +492,3 @@ void comedi_auto_unconfig(struct device *hardware_device) comedi_free_board_minor(minor); } EXPORT_SYMBOL_GPL(comedi_auto_unconfig); - -#if IS_ENABLED(CONFIG_PCMCIA) -int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, - struct pcmcia_driver *pcmcia_driver) -{ - int ret; - - ret = comedi_driver_register(comedi_driver); - if (ret < 0) - return ret; - - ret = pcmcia_register_driver(pcmcia_driver); - if (ret < 0) { - comedi_driver_unregister(comedi_driver); - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register); - -void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, - struct pcmcia_driver *pcmcia_driver) -{ - pcmcia_unregister_driver(pcmcia_driver); - comedi_driver_unregister(comedi_driver); -} -EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); - -#endif -- cgit v0.10.2 From 1f021e1f3b187586e457b4584d0e5f0f5ca5fa15 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:23:06 -0700 Subject: staging: comedi: allow pcmcia drivers to auto attach Introduce some helper functions to allow converting the comedi pcmcia drivers to the comedi auto_attach mechanism. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c index 8522945..f10bcc5 100644 --- a/drivers/staging/comedi/comedi_pcmcia.c +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -28,6 +28,42 @@ #include "comedidev.h" /** + * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer. + * @dev: comedi_device struct + */ +struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev) +{ + return dev->hw_dev ? to_pcmcia_dev(dev->hw_dev) : NULL; +} +EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev); + +/** + * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver. + * @link: pcmcia_device struct + * @driver: comedi_driver struct + * + * Typically called from the pcmcia_driver (*probe) function. + */ +int comedi_pcmcia_auto_config(struct pcmcia_device *link, + struct comedi_driver *driver) +{ + return comedi_auto_config(&link->dev, driver, 0); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config); + +/** + * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver. + * @link: pcmcia_device struct + * + * Typically called from the pcmcia_driver (*remove) function. + */ +void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link) +{ + comedi_auto_unconfig(&link->dev); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig); + +/** * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver. * @comedi_driver: comedi_driver struct * @pcmcia_driver: pcmcia_driver struct diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 329b1d7..ea585eb 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -465,6 +465,12 @@ static inline void comedi_pci_disable(struct pci_dev *dev) /* comedi_pcmcia.c - comedi PCMCIA driver specific functions */ struct pcmcia_driver; +struct pcmcia_device; + +struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *); + +int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *); +void comedi_pcmcia_auto_unconfig(struct pcmcia_device *); int comedi_pcmcia_driver_register(struct comedi_driver *, struct pcmcia_driver *); -- cgit v0.10.2 From 2bdaef1afc15ae675a1d26e19d2b77bde215ef4a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:23:27 -0700 Subject: staging: comedi: cb_das16_cs: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index e253fc0..efff059 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -40,9 +40,10 @@ Status: experimental #include #include -#include "../comedidev.h" #include +#include "../comedidev.h" + #include #include @@ -89,8 +90,6 @@ struct das16cs_private { unsigned short status2; }; -static struct pcmcia_device *cur_dev; - static const struct comedi_lrange das16cs_ai_range = { 4, { BIP_RANGE(10), @@ -383,45 +382,62 @@ static int das16cs_dio_insn_config(struct comedi_device *dev, return insn->n; } -static const struct das16cs_board *das16cs_probe(struct comedi_device *dev, - struct pcmcia_device *link) +static const void *das16cs_find_boardinfo(struct comedi_device *dev, + struct pcmcia_device *link) { + const struct das16cs_board *board; int i; for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) { - if (das16cs_boards[i].device_id == link->card_id) - return das16cs_boards + i; + board = &das16cs_boards[i]; + if (board->device_id == link->card_id) + return board; } - dev_dbg(dev->class_dev, "unknown board!\n"); - return NULL; } -static int das16cs_attach(struct comedi_device *dev, - struct comedi_devconfig *it) +static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev, + void *priv_data) +{ + if (p_dev->config_index == 0) + return -EINVAL; + + return pcmcia_request_io(p_dev); +} + +static int das16cs_auto_attach(struct comedi_device *dev, + unsigned long context) { - const struct das16cs_board *thisboard; + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + const struct das16cs_board *board; struct das16cs_private *devpriv; - struct pcmcia_device *link; struct comedi_subdevice *s; int ret; - link = cur_dev; /* XXX hack */ - if (!link) - return -EIO; + board = das16cs_find_boardinfo(dev, link); + if (!board) + return -ENODEV; + dev->board_ptr = board; + dev->board_name = board->name; - dev->board_ptr = das16cs_probe(dev, link); - if (!dev->board_ptr) - return -EIO; - thisboard = comedi_board(dev); + /* Do we need to allocate an interrupt? */ + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - dev->board_name = thisboard->name; + ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL); + if (ret) + return ret; + + if (!link->irq) + return -EINVAL; + ret = pcmcia_enable_device(link); + if (ret) + return ret; dev->iobase = link->resource[0]->start; - ret = request_irq(link->irq, das16cs_interrupt, - IRQF_SHARED, "cb_das16_cs", dev); + ret = request_irq(link->irq, das16cs_interrupt, IRQF_SHARED, + dev->board_name, dev); if (ret < 0) return ret; dev->irq = link->irq; @@ -450,10 +466,10 @@ static int das16cs_attach(struct comedi_device *dev, s = &dev->subdevices[1]; /* analog output subdevice */ - if (thisboard->n_ao_chans) { + if (board->n_ao_chans) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITABLE; - s->n_chan = thisboard->n_ao_chans; + s->n_chan = board->n_ao_chans; s->maxdata = 0xffff; s->range_table = &range_bipolar10; s->insn_write = &das16cs_ao_winsn; @@ -481,56 +497,24 @@ static int das16cs_attach(struct comedi_device *dev, static void das16cs_detach(struct comedi_device *dev) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + if (dev->irq) free_irq(dev->irq, dev); + if (dev->iobase) + pcmcia_disable_device(link); } static struct comedi_driver driver_das16cs = { .driver_name = "cb_das16_cs", .module = THIS_MODULE, - .attach = das16cs_attach, + .auto_attach = das16cs_auto_attach, .detach = das16cs_detach, }; -static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int das16cs_pcmcia_attach(struct pcmcia_device *link) { - int ret; - - /* Do we need to allocate an interrupt? */ - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL); - if (ret) - goto failed; - - if (!link->irq) - goto failed; - - ret = pcmcia_enable_device(link); - if (ret) - goto failed; - - cur_dev = link; - return 0; - -failed: - pcmcia_disable_device(link); - return ret; -} - -static void das16cs_pcmcia_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); - cur_dev = NULL; + return comedi_pcmcia_auto_config(link, &driver_das16cs); } static const struct pcmcia_device_id das16cs_id_table[] = { @@ -543,11 +527,10 @@ MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table); static struct pcmcia_driver das16cs_driver = { .name = "cb_das16_cs", .owner = THIS_MODULE, - .probe = das16cs_pcmcia_attach, - .remove = das16cs_pcmcia_detach, .id_table = das16cs_id_table, + .probe = das16cs_pcmcia_attach, + .remove = comedi_pcmcia_auto_unconfig, }; - module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver); MODULE_AUTHOR("David A. Schleef "); -- cgit v0.10.2 From 8cd98c826352b74281b8995a592b02e1c71b7204 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:23:50 -0700 Subject: staging: comedi: das08_cs: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. We still need the boardinfo because the das08 driver uses it. But we can get rid of the duplicate that allowed attaching with the driver name. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index ff67348..23fdb11 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -51,81 +51,25 @@ Command support does not exist, but could be added for this board. #include "../comedidev.h" -#include "das08.h" - -/* pcmcia includes */ #include #include +#include "das08.h" + static const struct das08_board_struct das08_cs_boards[] = { { - .name = "pcm-das08", - .id = 0x0, /* XXX */ - .bustype = pcmcia, - .ai_nbits = 12, - .ai_pg = das08_bipolar5, - .ai_encoding = das08_pcm_encode12, - .di_nchan = 3, - .do_nchan = 3, - .iosize = 16, - }, - /* duplicate so driver name can be used also */ - { - .name = "das08_cs", - .id = 0x0, /* XXX */ - .bustype = pcmcia, - .ai_nbits = 12, - .ai_pg = das08_bipolar5, - .ai_encoding = das08_pcm_encode12, - .di_nchan = 3, - .do_nchan = 3, - .iosize = 16, + .name = "pcm-das08", + .id = 0x0, /* XXX */ + .bustype = pcmcia, + .ai_nbits = 12, + .ai_pg = das08_bipolar5, + .ai_encoding = das08_pcm_encode12, + .di_nchan = 3, + .do_nchan = 3, + .iosize = 16, }, }; -static struct pcmcia_device *cur_dev; - -static int das08_cs_attach(struct comedi_device *dev, - struct comedi_devconfig *it) -{ - const struct das08_board_struct *thisboard = comedi_board(dev); - struct das08_private_struct *devpriv; - unsigned long iobase; - struct pcmcia_device *link = cur_dev; /* XXX hack */ - - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - - dev_info(dev->class_dev, "das08_cs: attach\n"); - /* deal with a pci board */ - - if (thisboard->bustype == pcmcia) { - if (link == NULL) { - dev_err(dev->class_dev, "no pcmcia cards found\n"); - return -EIO; - } - iobase = link->resource[0]->start; - } else { - dev_err(dev->class_dev, - "bug! board does not have PCMCIA bustype\n"); - return -EINVAL; - } - - return das08_common_attach(dev, iobase); -} - -static struct comedi_driver driver_das08_cs = { - .driver_name = "das08_cs", - .module = THIS_MODULE, - .attach = das08_cs_attach, - .detach = das08_common_detach, - .board_name = &das08_cs_boards[0].name, - .num_names = ARRAY_SIZE(das08_cs_boards), - .offset = sizeof(struct das08_board_struct), -}; - static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { @@ -135,35 +79,58 @@ static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, return pcmcia_request_io(p_dev); } -static int das08_pcmcia_attach(struct pcmcia_device *link) +static int das08_cs_auto_attach(struct comedi_device *dev, + unsigned long context) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + struct das08_private_struct *devpriv; + unsigned long iobase; int ret; + /* The das08 driver needs the board_ptr */ + dev->board_ptr = &das08_cs_boards[0]; + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); if (ret) - goto failed; + return ret; if (!link->irq) - goto failed; + return -EINVAL; ret = pcmcia_enable_device(link); if (ret) - goto failed; + return ret; + iobase = link->resource[0]->start; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + return das08_common_attach(dev, iobase); +} - cur_dev = link; - return 0; +static void das08_cs_detach(struct comedi_device *dev) +{ + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); -failed: - pcmcia_disable_device(link); - return ret; + das08_common_detach(dev); + if (dev->iobase) + pcmcia_disable_device(link); } -static void das08_pcmcia_detach(struct pcmcia_device *link) +static struct comedi_driver driver_das08_cs = { + .driver_name = "das08_cs", + .module = THIS_MODULE, + .auto_attach = das08_cs_auto_attach, + .detach = das08_cs_detach, +}; + +static int das08_pcmcia_attach(struct pcmcia_device *link) { - pcmcia_disable_device(link); - cur_dev = NULL; + return comedi_pcmcia_auto_config(link, &driver_das08_cs); } static const struct pcmcia_device_id das08_cs_id_table[] = { @@ -175,11 +142,10 @@ MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table); static struct pcmcia_driver das08_cs_driver = { .name = "pcm-das08", .owner = THIS_MODULE, - .probe = das08_pcmcia_attach, - .remove = das08_pcmcia_detach, .id_table = das08_cs_id_table, + .probe = das08_pcmcia_attach, + .remove = comedi_pcmcia_auto_unconfig, }; - module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver); MODULE_AUTHOR("David A. Schleef , " -- cgit v0.10.2 From 52c9bf4cf51d992b1b88edeaa63e018d178cbc83 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:24:13 -0700 Subject: staging: comedi: ni_daq_700: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. We can also get rid of the boardinfo since it was only used to provide the "name" that was used with the manual attach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index ff0e199..e537b8f 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -50,22 +50,15 @@ Manuals: Register level: http://www.ni.com/pdf/manuals/340698.pdf User Manual: http://www.ni.com/pdf/manuals/320676d.pdf */ +#include #include #include -#include "../comedidev.h" -#include +#include "../comedidev.h" #include -#include #include -static struct pcmcia_device *pcmcia_cur_dev; - -struct daq700_board { - const char *name; -}; - /* daqcard700 registers */ #define DIO_W 0x04 /* WO 8bit */ #define DIO_R 0x05 /* RO 8bit */ @@ -202,24 +195,35 @@ static void daq700_ai_config(struct comedi_device *dev, inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */ } -static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev, + void *priv_data) +{ + if (p_dev->config_index == 0) + return -EINVAL; + + return pcmcia_request_io(p_dev); +} + +static int daq700_auto_attach(struct comedi_device *dev, + unsigned long context) { - const struct daq700_board *thisboard = comedi_board(dev); + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); struct comedi_subdevice *s; - struct pcmcia_device *link; int ret; - link = pcmcia_cur_dev; /* XXX hack */ - if (!link) - return -EIO; + dev->board_name = dev->driver->driver_name; - dev->iobase = link->resource[0]->start; - if (!dev->iobase) { - dev_err(dev->class_dev, "io base address is zero!\n"); - return -EINVAL; - } + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | + CONF_AUTO_SET_IO; + + ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL); + if (ret) + return ret; - dev->board_name = thisboard->name; + ret = pcmcia_enable_device(link); + if (ret) + return ret; + dev->iobase = link->resource[0]->start; ret = comedi_alloc_subdevices(dev, 2); if (ret) @@ -258,66 +262,22 @@ static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) static void daq700_detach(struct comedi_device *dev) { - /* nothing to cleanup */ -} + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); -static const struct daq700_board daq700_boards[] = { - { - .name = "daqcard-700", - }, { - .name = "ni_daq_700", - }, -}; + if (dev->iobase) + pcmcia_disable_device(link); +} static struct comedi_driver daq700_driver = { .driver_name = "ni_daq_700", .module = THIS_MODULE, - .attach = daq700_attach, + .auto_attach = daq700_auto_attach, .detach = daq700_detach, - .board_name = &daq700_boards[0].name, - .num_names = ARRAY_SIZE(daq700_boards), - .offset = sizeof(struct daq700_board), }; -static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int daq700_cs_attach(struct pcmcia_device *link) { - int ret; - - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | - CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL); - if (ret) - goto failed; - - if (!link->irq) - goto failed; - - ret = pcmcia_enable_device(link); - if (ret) - goto failed; - - pcmcia_cur_dev = link; - return 0; - -failed: - pcmcia_disable_device(link); - return ret; -} - -static void daq700_cs_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); - pcmcia_cur_dev = NULL; + return comedi_pcmcia_auto_config(link, &daq700_driver); } static const struct pcmcia_device_id daq700_cs_ids[] = { @@ -329,11 +289,10 @@ MODULE_DEVICE_TABLE(pcmcia, daq700_cs_ids); static struct pcmcia_driver daq700_cs_driver = { .name = "ni_daq_700", .owner = THIS_MODULE, - .probe = daq700_cs_attach, - .remove = daq700_cs_detach, .id_table = daq700_cs_ids, + .probe = daq700_cs_attach, + .remove = comedi_pcmcia_auto_unconfig, }; - module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver); MODULE_AUTHOR("Fred Brooks "); -- cgit v0.10.2 From 1ae6b20b88737f1828649b6cbe349c83b9f97bf0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:24:38 -0700 Subject: staging: comedi: tidy up the general purpose driver functions Group all the general comedi driver register/config/attach prototypes into one place in comedidev.h. Reorder the functions in drivers.c a bit so they are in a more logical usage order (bottom to top). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index ea585eb..0f29dd5 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -258,26 +258,6 @@ static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; struct comedi_device *comedi_dev_from_minor(unsigned minor); -int comedi_alloc_subdevices(struct comedi_device *, int); - -void comedi_device_detach(struct comedi_device *dev); -int comedi_device_attach(struct comedi_device *dev, - struct comedi_devconfig *it); -int comedi_driver_register(struct comedi_driver *); -int comedi_driver_unregister(struct comedi_driver *); - -/** - * module_comedi_driver() - Helper macro for registering a comedi driver - * @__comedi_driver: comedi_driver struct - * - * Helper macro for comedi drivers which do not do anything special in module - * init/exit. This eliminates a lot of boilerplate. Each module may only use - * this macro once, and calling it replaces module_init() and module_exit(). - */ -#define module_comedi_driver(__comedi_driver) \ - module_driver(__comedi_driver, comedi_driver_register, \ - comedi_driver_unregister) - void init_polling(void); void cleanup_polling(void); void start_polling(struct comedi_device *); @@ -384,9 +364,32 @@ void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct comedi_subdevice *s); void comedi_free_subdevice_minor(struct comedi_subdevice *s); -int comedi_auto_config(struct device *hardware_device, - struct comedi_driver *driver, unsigned long context); -void comedi_auto_unconfig(struct device *hardware_device); + +/* drivers.c - general comedi driver functions */ + +int comedi_alloc_subdevices(struct comedi_device *, int); + +void comedi_device_detach(struct comedi_device *); +int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *); + +int comedi_auto_config(struct device *, struct comedi_driver *, + unsigned long context); +void comedi_auto_unconfig(struct device *); + +int comedi_driver_register(struct comedi_driver *); +int comedi_driver_unregister(struct comedi_driver *); + +/** + * module_comedi_driver() - Helper macro for registering a comedi driver + * @__comedi_driver: comedi_driver struct + * + * Helper macro for comedi drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate. Each module may only use + * this macro once, and calling it replaces module_init() and module_exit(). + */ +#define module_comedi_driver(__comedi_driver) \ + module_driver(__comedi_driver, comedi_driver_register, \ + comedi_driver_unregister) #ifdef CONFIG_COMEDI_PCI_DRIVERS diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 151e084..fe91e75 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -386,53 +386,6 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) return comedi_device_postconfig(dev); } -int comedi_driver_register(struct comedi_driver *driver) -{ - driver->next = comedi_drivers; - comedi_drivers = driver; - - return 0; -} -EXPORT_SYMBOL(comedi_driver_register); - -int comedi_driver_unregister(struct comedi_driver *driver) -{ - struct comedi_driver *prev; - int i; - - /* check for devices using this driver */ - for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { - struct comedi_device *dev = comedi_dev_from_minor(i); - - if (!dev) - continue; - - mutex_lock(&dev->mutex); - if (dev->attached && dev->driver == driver) { - if (dev->use_count) - dev_warn(dev->class_dev, - "BUG! detaching device with use_count=%d\n", - dev->use_count); - comedi_device_detach(dev); - } - mutex_unlock(&dev->mutex); - } - - if (comedi_drivers == driver) { - comedi_drivers = driver->next; - return 0; - } - - for (prev = comedi_drivers; prev->next; prev = prev->next) { - if (prev->next == driver) { - prev->next = driver->next; - return 0; - } - } - return -EINVAL; -} -EXPORT_SYMBOL(comedi_driver_unregister); - int comedi_auto_config(struct device *hardware_device, struct comedi_driver *driver, unsigned long context) { @@ -492,3 +445,50 @@ void comedi_auto_unconfig(struct device *hardware_device) comedi_free_board_minor(minor); } EXPORT_SYMBOL_GPL(comedi_auto_unconfig); + +int comedi_driver_register(struct comedi_driver *driver) +{ + driver->next = comedi_drivers; + comedi_drivers = driver; + + return 0; +} +EXPORT_SYMBOL(comedi_driver_register); + +int comedi_driver_unregister(struct comedi_driver *driver) +{ + struct comedi_driver *prev; + int i; + + /* check for devices using this driver */ + for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { + struct comedi_device *dev = comedi_dev_from_minor(i); + + if (!dev) + continue; + + mutex_lock(&dev->mutex); + if (dev->attached && dev->driver == driver) { + if (dev->use_count) + dev_warn(dev->class_dev, + "BUG! detaching device with use_count=%d\n", + dev->use_count); + comedi_device_detach(dev); + } + mutex_unlock(&dev->mutex); + } + + if (comedi_drivers == driver) { + comedi_drivers = driver->next; + return 0; + } + + for (prev = comedi_drivers; prev->next; prev = prev->next) { + if (prev->next == driver) { + prev->next = driver->next; + return 0; + } + } + return -EINVAL; +} +EXPORT_SYMBOL(comedi_driver_unregister); -- cgit v0.10.2 From 39bd5e59b1ebdaa58d9458923ab96f61bda1296c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:25:06 -0700 Subject: staging: comedi: don't expose comedi_device_{attach,detach} These functions are only used by the comedi core. Move the prototypes to comedi_internal.h so they are not exposed to the comedi drivers. Tidy up comedi_internal.h a bit so that all the internal stuff in drivers.c is grouped. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index 5e6f05b..81b6f78 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -8,8 +8,6 @@ */ int do_rangeinfo_ioctl(struct comedi_device *dev, struct comedi_rangeinfo __user *arg); -int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); int comedi_alloc_board_minor(struct device *hardware_device); void comedi_free_board_minor(unsigned minor); int comedi_find_board_minor(struct device *hardware_device); @@ -22,6 +20,15 @@ unsigned int comedi_buf_write_n_allocated(struct comedi_async *async); extern unsigned int comedi_default_buf_size_kb; extern unsigned int comedi_default_buf_maxsize_kb; extern bool comedi_autoconfig; + +/* drivers.c */ + extern struct comedi_driver *comedi_drivers; +int insn_inval(struct comedi_device *, struct comedi_subdevice *, + struct comedi_insn *, unsigned int *); + +void comedi_device_detach(struct comedi_device *); +int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *); + #endif /* _COMEDI_INTERNAL_H */ diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 0f29dd5..afaf2ae 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -369,9 +369,6 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s); int comedi_alloc_subdevices(struct comedi_device *, int); -void comedi_device_detach(struct comedi_device *); -int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *); - int comedi_auto_config(struct device *, struct comedi_driver *, unsigned long context); void comedi_auto_unconfig(struct device *); -- cgit v0.10.2 From 085494ac2039433a5df9fdd6fb653579e18b8c71 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:25:31 -0700 Subject: staging: comedi: don't expose comedi_proc_{init,cleanup} These functions are only used by the comedi core. Move the prototypes to comedi_internal.h so they are not exposed to the comedi drivers. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index 81b6f78..b36bb95 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -31,4 +31,19 @@ int insn_inval(struct comedi_device *, struct comedi_subdevice *, void comedi_device_detach(struct comedi_device *); int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *); +#ifdef CONFIG_PROC_FS + +/* proc.c */ + +void comedi_proc_init(void); +void comedi_proc_cleanup(void); +#else +static inline void comedi_proc_init(void) +{ +} +static inline void comedi_proc_cleanup(void) +{ +} +#endif + #endif /* _COMEDI_INTERNAL_H */ diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index afaf2ae..f4541ae 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -263,19 +263,6 @@ void cleanup_polling(void); void start_polling(struct comedi_device *); void stop_polling(struct comedi_device *); -#ifdef CONFIG_PROC_FS -void comedi_proc_init(void); -void comedi_proc_cleanup(void); -#else -static inline void comedi_proc_init(void) -{ -} - -static inline void comedi_proc_cleanup(void) -{ -} -#endif - /* subdevice runflags */ enum subdevice_runflags { SRF_USER = 0x00000001, -- cgit v0.10.2 From 23491b513bcd3dfe4ddb94547d73d9deb94eda44 Mon Sep 17 00:00:00 2001 From: Denis Ciocca Date: Fri, 25 Jan 2013 23:44:00 +0000 Subject: iio:common: Add STMicroelectronics common library This patch add a generic library for STMicroelectronics 3-axis sensors. Signed-off-by: Denis Ciocca Reviewed-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig index ed45ee5..0b6e97d 100644 --- a/drivers/iio/common/Kconfig +++ b/drivers/iio/common/Kconfig @@ -3,3 +3,4 @@ # source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/st_sensors/Kconfig" diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile index 8158400..c2352be 100644 --- a/drivers/iio/common/Makefile +++ b/drivers/iio/common/Makefile @@ -7,3 +7,4 @@ # obj-y += hid-sensors/ +obj-y += st_sensors/ diff --git a/drivers/iio/common/st_sensors/Kconfig b/drivers/iio/common/st_sensors/Kconfig new file mode 100644 index 0000000..865f1ca --- /dev/null +++ b/drivers/iio/common/st_sensors/Kconfig @@ -0,0 +1,14 @@ +# +# STMicroelectronics sensors common library +# + +config IIO_ST_SENSORS_I2C + tristate + +config IIO_ST_SENSORS_SPI + tristate + +config IIO_ST_SENSORS_CORE + tristate + select IIO_ST_SENSORS_I2C if I2C + select IIO_ST_SENSORS_SPI if SPI_MASTER diff --git a/drivers/iio/common/st_sensors/Makefile b/drivers/iio/common/st_sensors/Makefile new file mode 100644 index 0000000..9f3e24f --- /dev/null +++ b/drivers/iio/common/st_sensors/Makefile @@ -0,0 +1,10 @@ +# +# Makefile for the STMicroelectronics sensor common modules. +# + +obj-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o +obj-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o +obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o +st_sensors-y := st_sensors_core.o +st_sensors-$(CONFIG_IIO_BUFFER) += st_sensors_buffer.o +st_sensors-$(CONFIG_IIO_TRIGGER) += st_sensors_trigger.o diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c new file mode 100644 index 0000000..09b236d --- /dev/null +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c @@ -0,0 +1,116 @@ +/* + * STMicroelectronics sensors buffer library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) +{ + int i, n = 0, len; + u8 addr[ST_SENSORS_NUMBER_DATA_CHANNELS]; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + for (i = 0; i < ST_SENSORS_NUMBER_DATA_CHANNELS; i++) { + if (test_bit(i, indio_dev->active_scan_mask)) { + addr[n] = indio_dev->channels[i].address; + n++; + } + } + switch (n) { + case 1: + len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, + addr[0], ST_SENSORS_BYTE_FOR_CHANNEL, buf, + sdata->multiread_bit); + break; + case 2: + if ((addr[1] - addr[0]) == ST_SENSORS_BYTE_FOR_CHANNEL) { + len = sdata->tf->read_multiple_byte(&sdata->tb, + sdata->dev, addr[0], + ST_SENSORS_BYTE_FOR_CHANNEL*n, + buf, sdata->multiread_bit); + } else { + u8 rx_array[ST_SENSORS_BYTE_FOR_CHANNEL* + ST_SENSORS_NUMBER_DATA_CHANNELS]; + len = sdata->tf->read_multiple_byte(&sdata->tb, + sdata->dev, addr[0], + ST_SENSORS_BYTE_FOR_CHANNEL* + ST_SENSORS_NUMBER_DATA_CHANNELS, + rx_array, sdata->multiread_bit); + if (len < 0) + goto read_data_channels_error; + + for (i = 0; i < n * ST_SENSORS_NUMBER_DATA_CHANNELS; + i++) { + if (i < n) + buf[i] = rx_array[i]; + else + buf[i] = rx_array[n + i]; + } + len = ST_SENSORS_BYTE_FOR_CHANNEL*n; + } + break; + case 3: + len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, + addr[0], ST_SENSORS_BYTE_FOR_CHANNEL* + ST_SENSORS_NUMBER_DATA_CHANNELS, + buf, sdata->multiread_bit); + break; + default: + len = -EINVAL; + goto read_data_channels_error; + } + if (len != ST_SENSORS_BYTE_FOR_CHANNEL*n) { + len = -EIO; + goto read_data_channels_error; + } + +read_data_channels_error: + return len; +} +EXPORT_SYMBOL(st_sensors_get_buffer_element); + +irqreturn_t st_sensors_trigger_handler(int irq, void *p) +{ + int len; + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data); + if (len < 0) + goto st_sensors_get_buffer_element_error; + + if (indio_dev->scan_timestamp) + *(s64 *)((u8 *)sdata->buffer_data + + ALIGN(len, sizeof(s64))) = pf->timestamp; + + iio_push_to_buffers(indio_dev, sdata->buffer_data); + +st_sensors_get_buffer_element_error: + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} +EXPORT_SYMBOL(st_sensors_trigger_handler); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics ST-sensors buffer"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c new file mode 100644 index 0000000..fba6d68 --- /dev/null +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -0,0 +1,460 @@ +/* + * STMicroelectronics sensors core library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include + + +#define ST_SENSORS_WAI_ADDRESS 0x0f + +static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, + u8 reg_addr, u8 mask, u8 data) +{ + int err; + u8 new_data; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + err = sdata->tf->read_byte(&sdata->tb, sdata->dev, reg_addr, &new_data); + if (err < 0) + goto st_sensors_write_data_with_mask_error; + + new_data = ((new_data & (~mask)) | ((data << __ffs(mask)) & mask)); + err = sdata->tf->write_byte(&sdata->tb, sdata->dev, reg_addr, new_data); + +st_sensors_write_data_with_mask_error: + return err; +} + +int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev, char *buf) +{ + int i, len = 0; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + mutex_lock(&indio_dev->mlock); + for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { + if (sdata->sensor->odr.odr_avl[i].hz == 0) + break; + + len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", + sdata->sensor->odr.odr_avl[i].hz); + } + mutex_unlock(&indio_dev->mlock); + buf[len - 1] = '\n'; + + return len; +} +EXPORT_SYMBOL(st_sensors_get_sampling_frequency_avl); + +int st_sensors_get_scale_avl(struct iio_dev *indio_dev, char *buf) +{ + int i, len = 0; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + mutex_lock(&indio_dev->mlock); + for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { + if (sdata->sensor->fs.fs_avl[i].num == 0) + break; + + len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", + sdata->sensor->fs.fs_avl[i].gain); + } + mutex_unlock(&indio_dev->mlock); + buf[len - 1] = '\n'; + + return len; +} +EXPORT_SYMBOL(st_sensors_get_scale_avl); + +static int st_sensors_match_odr(struct st_sensors *sensor, + unsigned int odr, struct st_sensor_odr_avl *odr_out) +{ + int i, ret = -EINVAL; + + for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { + if (sensor->odr.odr_avl[i].hz == 0) + goto st_sensors_match_odr_error; + + if (sensor->odr.odr_avl[i].hz == odr) { + odr_out->hz = sensor->odr.odr_avl[i].hz; + odr_out->value = sensor->odr.odr_avl[i].value; + ret = 0; + break; + } + } + +st_sensors_match_odr_error: + return ret; +} + +int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr) +{ + int err; + struct st_sensor_odr_avl odr_out; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + err = st_sensors_match_odr(sdata->sensor, odr, &odr_out); + if (err < 0) + goto st_sensors_match_odr_error; + + if ((sdata->sensor->odr.addr == sdata->sensor->pw.addr) && + (sdata->sensor->odr.mask == sdata->sensor->pw.mask)) { + if (sdata->enabled == true) { + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->odr.addr, + sdata->sensor->odr.mask, + odr_out.value); + } else { + err = 0; + } + } else { + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->odr.addr, sdata->sensor->odr.mask, + odr_out.value); + } + if (err >= 0) + sdata->odr = odr_out.hz; + +st_sensors_match_odr_error: + return err; +} +EXPORT_SYMBOL(st_sensors_set_odr); + +static int st_sensors_match_fs(struct st_sensors *sensor, + unsigned int fs, int *index_fs_avl) +{ + int i, ret = -EINVAL; + + for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { + if (sensor->fs.fs_avl[i].num == 0) + goto st_sensors_match_odr_error; + + if (sensor->fs.fs_avl[i].num == fs) { + *index_fs_avl = i; + ret = 0; + break; + } + } + +st_sensors_match_odr_error: + return ret; +} + +static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs) +{ + int err, i; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + err = st_sensors_match_fs(sdata->sensor, fs, &i); + if (err < 0) + goto st_accel_set_fullscale_error; + + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->fs.addr, + sdata->sensor->fs.mask, + sdata->sensor->fs.fs_avl[i].value); + if (err < 0) + goto st_accel_set_fullscale_error; + + sdata->current_fullscale = (struct st_sensor_fullscale_avl *) + &sdata->sensor->fs.fs_avl[i]; + return err; + +st_accel_set_fullscale_error: + dev_err(&indio_dev->dev, "failed to set new fullscale.\n"); + return err; +} + +int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable) +{ + bool found; + u8 tmp_value; + int err = -EINVAL; + struct st_sensor_odr_avl odr_out; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + if (enable) { + found = false; + tmp_value = sdata->sensor->pw.value_on; + if ((sdata->sensor->odr.addr == sdata->sensor->pw.addr) && + (sdata->sensor->odr.mask == sdata->sensor->pw.mask)) { + err = st_sensors_match_odr(sdata->sensor, + sdata->odr, &odr_out); + if (err < 0) + goto set_enable_error; + tmp_value = odr_out.value; + found = true; + } + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->pw.addr, + sdata->sensor->pw.mask, tmp_value); + if (err < 0) + goto set_enable_error; + + sdata->enabled = true; + + if (found) + sdata->odr = odr_out.hz; + } else { + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->pw.addr, + sdata->sensor->pw.mask, + sdata->sensor->pw.value_off); + if (err < 0) + goto set_enable_error; + + sdata->enabled = false; + } + +set_enable_error: + return err; +} +EXPORT_SYMBOL(st_sensors_set_enable); + +int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable) +{ + struct st_sensor_data *sdata = iio_priv(indio_dev); + + return st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->enable_axis.addr, + sdata->sensor->enable_axis.mask, axis_enable); +} +EXPORT_SYMBOL(st_sensors_set_axis_enable); + +int st_sensors_init_sensor(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + mutex_init(&sdata->tb.buf_lock); + + err = st_sensors_set_enable(indio_dev, false); + if (err < 0) + goto init_error; + + err = st_sensors_set_fullscale(indio_dev, + sdata->current_fullscale->num); + if (err < 0) + goto init_error; + + err = st_sensors_set_odr(indio_dev, sdata->odr); + if (err < 0) + goto init_error; + + /* set BDU */ + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->bdu.addr, sdata->sensor->bdu.mask, true); + if (err < 0) + goto init_error; + + err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); + +init_error: + return err; +} +EXPORT_SYMBOL(st_sensors_init_sensor); + +int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable) +{ + int err; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + /* Enable/Disable the interrupt generator 1. */ + if (sdata->sensor->drdy_irq.ig1.en_addr > 0) { + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->drdy_irq.ig1.en_addr, + sdata->sensor->drdy_irq.ig1.en_mask, (int)enable); + if (err < 0) + goto st_accel_set_dataready_irq_error; + } + + /* Enable/Disable the interrupt generator for data ready. */ + err = st_sensors_write_data_with_mask(indio_dev, + sdata->sensor->drdy_irq.addr, + sdata->sensor->drdy_irq.mask, (int)enable); + +st_accel_set_dataready_irq_error: + return err; +} +EXPORT_SYMBOL(st_sensors_set_dataready_irq); + +int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale) +{ + int err = -EINVAL, i; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { + if ((sdata->sensor->fs.fs_avl[i].gain == scale) && + (sdata->sensor->fs.fs_avl[i].gain != 0)) { + err = 0; + break; + } + } + if (err < 0) + goto st_sensors_match_scale_error; + + err = st_sensors_set_fullscale(indio_dev, + sdata->sensor->fs.fs_avl[i].num); + +st_sensors_match_scale_error: + return err; +} +EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain); + +static int st_sensors_read_axis_data(struct iio_dev *indio_dev, + u8 ch_addr, int *data) +{ + int err; + u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL]; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, + ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL, + outdata, sdata->multiread_bit); + if (err < 0) + goto read_error; + + *data = (s16)get_unaligned_le16(outdata); + +read_error: + return err; +} + +int st_sensors_read_info_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *ch, int *val) +{ + int err; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + mutex_lock(&indio_dev->mlock); + if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { + err = -EBUSY; + goto read_error; + } else { + err = st_sensors_set_enable(indio_dev, true); + if (err < 0) + goto read_error; + + msleep((sdata->sensor->bootime * 1000) / sdata->odr); + err = st_sensors_read_axis_data(indio_dev, ch->address, val); + if (err < 0) + goto read_error; + + *val = *val >> ch->scan_type.shift; + } + mutex_unlock(&indio_dev->mlock); + + return err; + +read_error: + mutex_unlock(&indio_dev->mlock); + return err; +} +EXPORT_SYMBOL(st_sensors_read_info_raw); + +int st_sensors_check_device_support(struct iio_dev *indio_dev, + int num_sensors_list, const struct st_sensors *sensors) +{ + u8 wai; + int i, n, err; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + err = sdata->tf->read_byte(&sdata->tb, sdata->dev, + ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai); + if (err < 0) { + dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n"); + goto read_wai_error; + } + + for (i = 0; i < num_sensors_list; i++) { + if (sensors[i].wai == wai) + break; + } + if (i == num_sensors_list) + goto device_not_supported; + + for (n = 0; n < ARRAY_SIZE(sensors[i].sensors_supported); n++) { + if (strcmp(indio_dev->name, + &sensors[i].sensors_supported[n][0]) == 0) + break; + } + if (n == ARRAY_SIZE(sensors[i].sensors_supported)) { + dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n"); + goto sensor_name_mismatch; + } + + sdata->sensor = (struct st_sensors *)&sensors[i]; + + return i; + +device_not_supported: + dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai); +sensor_name_mismatch: + err = -ENODEV; +read_wai_error: + return err; +} +EXPORT_SYMBOL(st_sensors_check_device_support); + +ssize_t st_sensors_sysfs_get_sampling_frequency(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct st_sensor_data *adata = iio_priv(dev_get_drvdata(dev)); + + return sprintf(buf, "%d\n", adata->odr); +} +EXPORT_SYMBOL(st_sensors_sysfs_get_sampling_frequency); + +ssize_t st_sensors_sysfs_set_sampling_frequency(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + int err; + unsigned int odr; + struct iio_dev *indio_dev = dev_get_drvdata(dev); + + err = kstrtoint(buf, 10, &odr); + if (err < 0) + goto conversion_error; + + mutex_lock(&indio_dev->mlock); + err = st_sensors_set_odr(indio_dev, odr); + mutex_unlock(&indio_dev->mlock); + +conversion_error: + return err < 0 ? err : size; +} +EXPORT_SYMBOL(st_sensors_sysfs_set_sampling_frequency); + +ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + + return st_sensors_get_sampling_frequency_avl(indio_dev, buf); +} +EXPORT_SYMBOL(st_sensors_sysfs_sampling_frequency_avail); + +ssize_t st_sensors_sysfs_scale_avail(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + + return st_sensors_get_scale_avl(indio_dev, buf); +} +EXPORT_SYMBOL(st_sensors_sysfs_scale_avail); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics ST-sensors core"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c new file mode 100644 index 0000000..38af944 --- /dev/null +++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c @@ -0,0 +1,81 @@ +/* + * STMicroelectronics sensors i2c library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include + +#include + + +#define ST_SENSORS_I2C_MULTIREAD 0x80 + +static unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev) +{ + struct st_sensor_data *sdata = iio_priv(indio_dev); + + return to_i2c_client(sdata->dev)->irq; +} + +static int st_sensors_i2c_read_byte(struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, u8 *res_byte) +{ + int err; + + err = i2c_smbus_read_byte_data(to_i2c_client(dev), reg_addr); + if (err < 0) + goto st_accel_i2c_read_byte_error; + + *res_byte = err & 0xff; + +st_accel_i2c_read_byte_error: + return err < 0 ? err : 0; +} + +static int st_sensors_i2c_read_multiple_byte( + struct st_sensor_transfer_buffer *tb, struct device *dev, + u8 reg_addr, int len, u8 *data, bool multiread_bit) +{ + if (multiread_bit) + reg_addr |= ST_SENSORS_I2C_MULTIREAD; + + return i2c_smbus_read_i2c_block_data(to_i2c_client(dev), + reg_addr, len, data); +} + +static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, u8 data) +{ + return i2c_smbus_write_byte_data(to_i2c_client(dev), reg_addr, data); +} + +static const struct st_sensor_transfer_function st_sensors_tf_i2c = { + .read_byte = st_sensors_i2c_read_byte, + .write_byte = st_sensors_i2c_write_byte, + .read_multiple_byte = st_sensors_i2c_read_multiple_byte, +}; + +void st_sensors_i2c_configure(struct iio_dev *indio_dev, + struct i2c_client *client, struct st_sensor_data *sdata) +{ + i2c_set_clientdata(client, indio_dev); + + indio_dev->dev.parent = &client->dev; + indio_dev->name = client->name; + + sdata->tf = &st_sensors_tf_i2c; + sdata->get_irq_data_ready = st_sensors_i2c_get_irq; +} +EXPORT_SYMBOL(st_sensors_i2c_configure); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c new file mode 100644 index 0000000..f0aa2f1 --- /dev/null +++ b/drivers/iio/common/st_sensors/st_sensors_spi.c @@ -0,0 +1,128 @@ +/* + * STMicroelectronics sensors spi library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include + +#include + + +#define ST_SENSORS_SPI_MULTIREAD 0xc0 +#define ST_SENSORS_SPI_READ 0x80 + +static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev) +{ + struct st_sensor_data *sdata = iio_priv(indio_dev); + + return to_spi_device(sdata->dev)->irq; +} + +static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, int len, u8 *data, bool multiread_bit) +{ + struct spi_message msg; + int err; + + struct spi_transfer xfers[] = { + { + .tx_buf = tb->tx_buf, + .bits_per_word = 8, + .len = 1, + }, + { + .rx_buf = tb->rx_buf, + .bits_per_word = 8, + .len = len, + } + }; + + mutex_lock(&tb->buf_lock); + if ((multiread_bit) && (len > 1)) + tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_MULTIREAD; + else + tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_READ; + + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + err = spi_sync(to_spi_device(dev), &msg); + if (err) + goto acc_spi_read_error; + + memcpy(data, tb->rx_buf, len*sizeof(u8)); + mutex_unlock(&tb->buf_lock); + return len; + +acc_spi_read_error: + mutex_unlock(&tb->buf_lock); + return err; +} + +static int st_sensors_spi_read_byte(struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, u8 *res_byte) +{ + return st_sensors_spi_read(tb, dev, reg_addr, 1, res_byte, false); +} + +static int st_sensors_spi_read_multiple_byte( + struct st_sensor_transfer_buffer *tb, struct device *dev, + u8 reg_addr, int len, u8 *data, bool multiread_bit) +{ + return st_sensors_spi_read(tb, dev, reg_addr, len, data, multiread_bit); +} + +static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, u8 data) +{ + struct spi_message msg; + int err; + + struct spi_transfer xfers = { + .tx_buf = tb->tx_buf, + .bits_per_word = 8, + .len = 2, + }; + + mutex_lock(&tb->buf_lock); + tb->tx_buf[0] = reg_addr; + tb->tx_buf[1] = data; + + spi_message_init(&msg); + spi_message_add_tail(&xfers, &msg); + err = spi_sync(to_spi_device(dev), &msg); + mutex_unlock(&tb->buf_lock); + + return err; +} + +static const struct st_sensor_transfer_function st_sensors_tf_spi = { + .read_byte = st_sensors_spi_read_byte, + .write_byte = st_sensors_spi_write_byte, + .read_multiple_byte = st_sensors_spi_read_multiple_byte, +}; + +void st_sensors_spi_configure(struct iio_dev *indio_dev, + struct spi_device *spi, struct st_sensor_data *sdata) +{ + spi_set_drvdata(spi, indio_dev); + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi->modalias; + + sdata->tf = &st_sensors_tf_spi; + sdata->get_irq_data_ready = st_sensors_spi_get_irq; +} +EXPORT_SYMBOL(st_sensors_spi_configure); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics ST-sensors spi driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c new file mode 100644 index 0000000..139ed03 --- /dev/null +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c @@ -0,0 +1,77 @@ +/* + * STMicroelectronics sensors trigger library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include + + +int st_sensors_allocate_trigger(struct iio_dev *indio_dev, + const struct iio_trigger_ops *trigger_ops) +{ + int err; + struct st_sensor_data *sdata = iio_priv(indio_dev); + + sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name); + if (sdata->trig == NULL) { + err = -ENOMEM; + dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n"); + goto iio_trigger_alloc_error; + } + + err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev), + iio_trigger_generic_data_rdy_poll, + NULL, + IRQF_TRIGGER_RISING, + sdata->trig->name, + sdata->trig); + if (err) + goto request_irq_error; + + sdata->trig->private_data = indio_dev; + sdata->trig->ops = trigger_ops; + sdata->trig->dev.parent = sdata->dev; + + err = iio_trigger_register(sdata->trig); + if (err < 0) { + dev_err(&indio_dev->dev, "failed to register iio trigger.\n"); + goto iio_trigger_register_error; + } + indio_dev->trig = sdata->trig; + + return 0; + +iio_trigger_register_error: + free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig); +request_irq_error: + iio_trigger_free(sdata->trig); +iio_trigger_alloc_error: + return err; +} +EXPORT_SYMBOL(st_sensors_allocate_trigger); + +void st_sensors_deallocate_trigger(struct iio_dev *indio_dev) +{ + struct st_sensor_data *sdata = iio_priv(indio_dev); + + iio_trigger_unregister(sdata->trig); + free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig); + iio_trigger_free(sdata->trig); +} +EXPORT_SYMBOL(st_sensors_deallocate_trigger); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics ST-sensors trigger"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h new file mode 100644 index 0000000..3cc8571 --- /dev/null +++ b/include/linux/iio/common/st_sensors.h @@ -0,0 +1,274 @@ +/* + * STMicroelectronics sensors library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#ifndef ST_SENSORS_H +#define ST_SENSORS_H + +#include +#include +#include +#include + +#define ST_SENSORS_TX_MAX_LENGTH 2 +#define ST_SENSORS_RX_MAX_LENGTH 6 + +#define ST_SENSORS_ODR_LIST_MAX 10 +#define ST_SENSORS_FULLSCALE_AVL_MAX 10 + +#define ST_SENSORS_NUMBER_ALL_CHANNELS 4 +#define ST_SENSORS_NUMBER_DATA_CHANNELS 3 +#define ST_SENSORS_ENABLE_ALL_AXIS 0x07 +#define ST_SENSORS_BYTE_FOR_CHANNEL 2 +#define ST_SENSORS_SCAN_X 0 +#define ST_SENSORS_SCAN_Y 1 +#define ST_SENSORS_SCAN_Z 2 +#define ST_SENSORS_DEFAULT_12_REALBITS 12 +#define ST_SENSORS_DEFAULT_16_REALBITS 16 +#define ST_SENSORS_DEFAULT_POWER_ON_VALUE 0x01 +#define ST_SENSORS_DEFAULT_POWER_OFF_VALUE 0x00 +#define ST_SENSORS_DEFAULT_WAI_ADDRESS 0x0f +#define ST_SENSORS_DEFAULT_AXIS_ADDR 0x20 +#define ST_SENSORS_DEFAULT_AXIS_MASK 0x07 +#define ST_SENSORS_DEFAULT_AXIS_N_BIT 3 + +#define ST_SENSORS_MAX_NAME 17 +#define ST_SENSORS_MAX_4WAI 7 + +#define ST_SENSORS_LSM_CHANNELS(device_type, index, mod, endian, bits, addr) \ +{ \ + .type = device_type, \ + .modified = 1, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .scan_index = index, \ + .channel2 = mod, \ + .address = addr, \ + .scan_type = { \ + .sign = 's', \ + .realbits = bits, \ + .shift = 16 - bits, \ + .storagebits = 16, \ + .endianness = endian, \ + }, \ +} + +#define ST_SENSOR_DEV_ATTR_SAMP_FREQ() \ + IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, \ + st_sensors_sysfs_get_sampling_frequency, \ + st_sensors_sysfs_set_sampling_frequency) + +#define ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL() \ + IIO_DEV_ATTR_SAMP_FREQ_AVAIL( \ + st_sensors_sysfs_sampling_frequency_avail) + +#define ST_SENSORS_DEV_ATTR_SCALE_AVAIL(name) \ + IIO_DEVICE_ATTR(name, S_IRUGO, \ + st_sensors_sysfs_scale_avail, NULL , 0); + +struct st_sensor_odr_avl { + unsigned int hz; + u8 value; +}; + +struct st_sensor_odr { + u8 addr; + u8 mask; + struct st_sensor_odr_avl odr_avl[ST_SENSORS_ODR_LIST_MAX]; +}; + +struct st_sensor_power { + u8 addr; + u8 mask; + u8 value_off; + u8 value_on; +}; + +struct st_sensor_axis { + u8 addr; + u8 mask; +}; + +struct st_sensor_fullscale_avl { + unsigned int num; + u8 value; + unsigned int gain; + unsigned int gain2; +}; + +struct st_sensor_fullscale { + u8 addr; + u8 mask; + struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX]; +}; + +/** + * struct st_sensor_bdu - ST sensor device block data update + * @addr: address of the register. + * @mask: mask to write the block data update flag. + */ +struct st_sensor_bdu { + u8 addr; + u8 mask; +}; + +/** + * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt + * @addr: address of the register. + * @mask: mask to write the on/off value. + * struct ig1 - represents the Interrupt Generator 1 of sensors. + * @en_addr: address of the enable ig1 register. + * @en_mask: mask to write the on/off value for enable. + */ +struct st_sensor_data_ready_irq { + u8 addr; + u8 mask; + struct { + u8 en_addr; + u8 en_mask; + } ig1; +}; + +/** + * struct st_sensor_transfer_buffer - ST sensor device I/O buffer + * @buf_lock: Mutex to protect rx and tx buffers. + * @tx_buf: Buffer used by SPI transfer function to send data to the sensors. + * This buffer is used to avoid DMA not-aligned issue. + * @rx_buf: Buffer used by SPI transfer to receive data from sensors. + * This buffer is used to avoid DMA not-aligned issue. + */ +struct st_sensor_transfer_buffer { + struct mutex buf_lock; + u8 rx_buf[ST_SENSORS_RX_MAX_LENGTH]; + u8 tx_buf[ST_SENSORS_TX_MAX_LENGTH] ____cacheline_aligned; +}; + +/** + * struct st_sensor_transfer_function - ST sensor device I/O function + * @read_byte: Function used to read one byte. + * @write_byte: Function used to write one byte. + * @read_multiple_byte: Function used to read multiple byte. + */ +struct st_sensor_transfer_function { + int (*read_byte) (struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, u8 *res_byte); + int (*write_byte) (struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, u8 data); + int (*read_multiple_byte) (struct st_sensor_transfer_buffer *tb, + struct device *dev, u8 reg_addr, int len, u8 *data, + bool multiread_bit); +}; + +/** + * struct st_sensors - ST sensors list + * @wai: Contents of WhoAmI register. + * @sensors_supported: List of supported sensors by struct itself. + * @ch: IIO channels for the sensor. + * @odr: Output data rate register and ODR list available. + * @pw: Power register of the sensor. + * @enable_axis: Enable one or more axis of the sensor. + * @fs: Full scale register and full scale list available. + * @bdu: Block data update register. + * @drdy_irq: Data ready register of the sensor. + * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read. + * @bootime: samples to discard when sensor passing from power-down to power-up. + */ +struct st_sensors { + u8 wai; + char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME]; + struct iio_chan_spec *ch; + struct st_sensor_odr odr; + struct st_sensor_power pw; + struct st_sensor_axis enable_axis; + struct st_sensor_fullscale fs; + struct st_sensor_bdu bdu; + struct st_sensor_data_ready_irq drdy_irq; + bool multi_read_bit; + unsigned int bootime; +}; + +/** + * struct st_sensor_data - ST sensor device status + * @dev: Pointer to instance of struct device (I2C or SPI). + * @trig: The trigger in use by the core driver. + * @sensor: Pointer to the current sensor struct in use. + * @current_fullscale: Maximum range of measure by the sensor. + * @enabled: Status of the sensor (false->off, true->on). + * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread. + * @buffer_data: Data used by buffer part. + * @odr: Output data rate of the sensor [Hz]. + * @get_irq_data_ready: Function to get the IRQ used for data ready signal. + * @tf: Transfer function structure used by I/O operations. + * @tb: Transfer buffers and mutex used by I/O operations. + */ +struct st_sensor_data { + struct device *dev; + struct iio_trigger *trig; + struct st_sensors *sensor; + struct st_sensor_fullscale_avl *current_fullscale; + + bool enabled; + bool multiread_bit; + + char *buffer_data; + + unsigned int odr; + + unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev); + + const struct st_sensor_transfer_function *tf; + struct st_sensor_transfer_buffer tb; +}; + +#ifdef CONFIG_IIO_BUFFER +int st_sensors_allocate_trigger(struct iio_dev *indio_dev, + const struct iio_trigger_ops *trigger_ops); + +void st_sensors_deallocate_trigger(struct iio_dev *indio_dev); + +irqreturn_t st_sensors_trigger_handler(int irq, void *p); + +int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf); +#endif + +int st_sensors_init_sensor(struct iio_dev *indio_dev); + +int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable); + +int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable); + +int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev, char *buf); + +int st_sensors_get_scale_avl(struct iio_dev *indio_dev, char *buf); + +int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr); + +int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable); + +int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale); + +int st_sensors_read_info_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *ch, int *val); + +int st_sensors_check_device_support(struct iio_dev *indio_dev, + int num_sensors_list, const struct st_sensors *sensors); + +ssize_t st_sensors_sysfs_get_sampling_frequency(struct device *dev, + struct device_attribute *attr, char *buf); + +ssize_t st_sensors_sysfs_set_sampling_frequency(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size); + +ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, + struct device_attribute *attr, char *buf); + +ssize_t st_sensors_sysfs_scale_avail(struct device *dev, + struct device_attribute *attr, char *buf); + +#endif /* ST_SENSORS_H */ diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h new file mode 100644 index 0000000..67d8453 --- /dev/null +++ b/include/linux/iio/common/st_sensors_i2c.h @@ -0,0 +1,20 @@ +/* + * STMicroelectronics sensors i2c library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#ifndef ST_SENSORS_I2C_H +#define ST_SENSORS_I2C_H + +#include +#include + +void st_sensors_i2c_configure(struct iio_dev *indio_dev, + struct i2c_client *client, struct st_sensor_data *sdata); + +#endif /* ST_SENSORS_I2C_H */ diff --git a/include/linux/iio/common/st_sensors_spi.h b/include/linux/iio/common/st_sensors_spi.h new file mode 100644 index 0000000..d964a35 --- /dev/null +++ b/include/linux/iio/common/st_sensors_spi.h @@ -0,0 +1,20 @@ +/* + * STMicroelectronics sensors spi library driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#ifndef ST_SENSORS_SPI_H +#define ST_SENSORS_SPI_H + +#include +#include + +void st_sensors_spi_configure(struct iio_dev *indio_dev, + struct spi_device *spi, struct st_sensor_data *sdata); + +#endif /* ST_SENSORS_SPI_H */ -- cgit v0.10.2 From d62511689de5d34d3a07c43db1f46a234bb77b5f Mon Sep 17 00:00:00 2001 From: Denis Ciocca Date: Fri, 25 Jan 2013 23:44:00 +0000 Subject: iio:accel: Add STMicroelectronics accelerometers driver This patch adds a generic accelerometer driver for STMicroelectronics accelerometers, currently it supports: LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, LIS331DLH, LSM303DL, LSM303DLM, LSM330. Signed-off-by: Denis Ciocca Reviewed-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index d600353..bb59496 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -21,4 +21,35 @@ config KXSD9 Say yes here to build support for the Kionix KXSD9 accelerometer. Currently this only supports the device via an SPI interface. +config IIO_ST_ACCEL_3AXIS + tristate "STMicroelectronics accelerometers 3-Axis Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_ACCEL_I2C_3AXIS if (I2C) + select IIO_ST_ACCEL_SPI_3AXIS if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + select IIO_ST_ACCEL_BUFFER if (IIO_TRIGGERED_BUFFER) + help + Say yes here to build support for STMicroelectronics accelerometers: + LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, + LIS331DLH, LSM303DL, LSM303DLM, LSM330. + + This driver can also be built as a module. If so, will be created + these modules: + - st_accel (core functions for the driver [it is mandatory]); + - st_accel_i2c (necessary for the I2C devices [optional*]); + - st_accel_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_ACCEL_I2C_3AXIS + tristate + depends on IIO_ST_ACCEL_3AXIS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_ACCEL_SPI_3AXIS + tristate + depends on IIO_ST_ACCEL_3AXIS + depends on IIO_ST_SENSORS_SPI + endmenu diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 4e1c859..87d8fa2 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -3,4 +3,12 @@ # obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o + +obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o +st_accel-y := st_accel_core.o +st_accel-$(CONFIG_IIO_BUFFER) += st_accel_buffer.o + +obj-$(CONFIG_IIO_ST_ACCEL_I2C_3AXIS) += st_accel_i2c.o +obj-$(CONFIG_IIO_ST_ACCEL_SPI_3AXIS) += st_accel_spi.o + obj-$(CONFIG_KXSD9) += kxsd9.o diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h new file mode 100644 index 0000000..37949b9 --- /dev/null +++ b/drivers/iio/accel/st_accel.h @@ -0,0 +1,47 @@ +/* + * STMicroelectronics accelerometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * v. 1.0.0 + * Licensed under the GPL-2. + */ + +#ifndef ST_ACCEL_H +#define ST_ACCEL_H + +#include +#include + +#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel" +#define LIS3DH_ACCEL_DEV_NAME "lis3dh" +#define LSM330D_ACCEL_DEV_NAME "lsm330d_accel" +#define LSM330DL_ACCEL_DEV_NAME "lsm330dl_accel" +#define LSM330DLC_ACCEL_DEV_NAME "lsm330dlc_accel" +#define LIS331DLH_ACCEL_DEV_NAME "lis331dlh" +#define LSM303DL_ACCEL_DEV_NAME "lsm303dl_accel" +#define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel" +#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel" +#define LSM330_ACCEL_DEV_NAME "lsm330_accel" + +int st_accel_common_probe(struct iio_dev *indio_dev); +void st_accel_common_remove(struct iio_dev *indio_dev); + +#ifdef CONFIG_IIO_BUFFER +int st_accel_allocate_ring(struct iio_dev *indio_dev); +void st_accel_deallocate_ring(struct iio_dev *indio_dev); +int st_accel_trig_set_state(struct iio_trigger *trig, bool state); +#define ST_ACCEL_TRIGGER_SET_STATE (&st_accel_trig_set_state) +#else /* CONFIG_IIO_BUFFER */ +static inline int st_accel_allocate_ring(struct iio_dev *indio_dev) +{ + return 0; +} +static inline void st_accel_deallocate_ring(struct iio_dev *indio_dev) +{ +} +#define ST_ACCEL_TRIGGER_SET_STATE NULL +#endif /* CONFIG_IIO_BUFFER */ + +#endif /* ST_ACCEL_H */ diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c new file mode 100644 index 0000000..6bd82c7 --- /dev/null +++ b/drivers/iio/accel/st_accel_buffer.c @@ -0,0 +1,114 @@ +/* + * STMicroelectronics accelerometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_accel.h" + +int st_accel_trig_set_state(struct iio_trigger *trig, bool state) +{ + struct iio_dev *indio_dev = trig->private_data; + + return st_sensors_set_dataready_irq(indio_dev, state); +} + +static int st_accel_buffer_preenable(struct iio_dev *indio_dev) +{ + int err; + + err = st_sensors_set_enable(indio_dev, true); + if (err < 0) + goto st_accel_set_enable_error; + + err = iio_sw_buffer_preenable(indio_dev); + +st_accel_set_enable_error: + return err; +} + +static int st_accel_buffer_postenable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *adata = iio_priv(indio_dev); + + adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + if (adata->buffer_data == NULL) { + err = -ENOMEM; + goto allocate_memory_error; + } + + err = st_sensors_set_axis_enable(indio_dev, + (u8)indio_dev->active_scan_mask[0]); + if (err < 0) + goto st_accel_buffer_postenable_error; + + err = iio_triggered_buffer_postenable(indio_dev); + if (err < 0) + goto st_accel_buffer_postenable_error; + + return err; + +st_accel_buffer_postenable_error: + kfree(adata->buffer_data); +allocate_memory_error: + return err; +} + +static int st_accel_buffer_predisable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *adata = iio_priv(indio_dev); + + err = iio_triggered_buffer_predisable(indio_dev); + if (err < 0) + goto st_accel_buffer_predisable_error; + + err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); + if (err < 0) + goto st_accel_buffer_predisable_error; + + err = st_sensors_set_enable(indio_dev, false); + +st_accel_buffer_predisable_error: + kfree(adata->buffer_data); + return err; +} + +static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = { + .preenable = &st_accel_buffer_preenable, + .postenable = &st_accel_buffer_postenable, + .predisable = &st_accel_buffer_predisable, +}; + +int st_accel_allocate_ring(struct iio_dev *indio_dev) +{ + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + &st_sensors_trigger_handler, &st_accel_buffer_setup_ops); +} + +void st_accel_deallocate_ring(struct iio_dev *indio_dev) +{ + iio_triggered_buffer_cleanup(indio_dev); +} + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics accelerometers buffer"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c new file mode 100644 index 0000000..a235de2 --- /dev/null +++ b/drivers/iio/accel/st_accel_core.c @@ -0,0 +1,495 @@ +/* + * STMicroelectronics accelerometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_accel.h" + +/* DEFAULT VALUE FOR SENSORS */ +#define ST_ACCEL_DEFAULT_OUT_X_L_ADDR 0x28 +#define ST_ACCEL_DEFAULT_OUT_Y_L_ADDR 0x2a +#define ST_ACCEL_DEFAULT_OUT_Z_L_ADDR 0x2c + +/* FULLSCALE */ +#define ST_ACCEL_FS_AVL_2G 2 +#define ST_ACCEL_FS_AVL_4G 4 +#define ST_ACCEL_FS_AVL_6G 6 +#define ST_ACCEL_FS_AVL_8G 8 +#define ST_ACCEL_FS_AVL_16G 16 + +/* CUSTOM VALUES FOR SENSOR 1 */ +#define ST_ACCEL_1_WAI_EXP 0x33 +#define ST_ACCEL_1_ODR_ADDR 0x20 +#define ST_ACCEL_1_ODR_MASK 0xf0 +#define ST_ACCEL_1_ODR_AVL_1HZ_VAL 0x01 +#define ST_ACCEL_1_ODR_AVL_10HZ_VAL 0x02 +#define ST_ACCEL_1_ODR_AVL_25HZ_VAL 0x03 +#define ST_ACCEL_1_ODR_AVL_50HZ_VAL 0x04 +#define ST_ACCEL_1_ODR_AVL_100HZ_VAL 0x05 +#define ST_ACCEL_1_ODR_AVL_200HZ_VAL 0x06 +#define ST_ACCEL_1_ODR_AVL_400HZ_VAL 0x07 +#define ST_ACCEL_1_ODR_AVL_1600HZ_VAL 0x08 +#define ST_ACCEL_1_FS_ADDR 0x23 +#define ST_ACCEL_1_FS_MASK 0x30 +#define ST_ACCEL_1_FS_AVL_2_VAL 0x00 +#define ST_ACCEL_1_FS_AVL_4_VAL 0x01 +#define ST_ACCEL_1_FS_AVL_8_VAL 0x02 +#define ST_ACCEL_1_FS_AVL_16_VAL 0x03 +#define ST_ACCEL_1_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000) +#define ST_ACCEL_1_FS_AVL_4_GAIN IIO_G_TO_M_S_2(2000) +#define ST_ACCEL_1_FS_AVL_8_GAIN IIO_G_TO_M_S_2(4000) +#define ST_ACCEL_1_FS_AVL_16_GAIN IIO_G_TO_M_S_2(12000) +#define ST_ACCEL_1_BDU_ADDR 0x23 +#define ST_ACCEL_1_BDU_MASK 0x80 +#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22 +#define ST_ACCEL_1_DRDY_IRQ_MASK 0x10 +#define ST_ACCEL_1_MULTIREAD_BIT true + +/* CUSTOM VALUES FOR SENSOR 2 */ +#define ST_ACCEL_2_WAI_EXP 0x32 +#define ST_ACCEL_2_ODR_ADDR 0x20 +#define ST_ACCEL_2_ODR_MASK 0x18 +#define ST_ACCEL_2_ODR_AVL_50HZ_VAL 0x00 +#define ST_ACCEL_2_ODR_AVL_100HZ_VAL 0x01 +#define ST_ACCEL_2_ODR_AVL_400HZ_VAL 0x02 +#define ST_ACCEL_2_ODR_AVL_1000HZ_VAL 0x03 +#define ST_ACCEL_2_PW_ADDR 0x20 +#define ST_ACCEL_2_PW_MASK 0xe0 +#define ST_ACCEL_2_FS_ADDR 0x23 +#define ST_ACCEL_2_FS_MASK 0x30 +#define ST_ACCEL_2_FS_AVL_2_VAL 0X00 +#define ST_ACCEL_2_FS_AVL_4_VAL 0X01 +#define ST_ACCEL_2_FS_AVL_8_VAL 0x03 +#define ST_ACCEL_2_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000) +#define ST_ACCEL_2_FS_AVL_4_GAIN IIO_G_TO_M_S_2(2000) +#define ST_ACCEL_2_FS_AVL_8_GAIN IIO_G_TO_M_S_2(3900) +#define ST_ACCEL_2_BDU_ADDR 0x23 +#define ST_ACCEL_2_BDU_MASK 0x80 +#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22 +#define ST_ACCEL_2_DRDY_IRQ_MASK 0x02 +#define ST_ACCEL_2_MULTIREAD_BIT true + +/* CUSTOM VALUES FOR SENSOR 3 */ +#define ST_ACCEL_3_WAI_EXP 0x40 +#define ST_ACCEL_3_ODR_ADDR 0x20 +#define ST_ACCEL_3_ODR_MASK 0xf0 +#define ST_ACCEL_3_ODR_AVL_3HZ_VAL 0x01 +#define ST_ACCEL_3_ODR_AVL_6HZ_VAL 0x02 +#define ST_ACCEL_3_ODR_AVL_12HZ_VAL 0x03 +#define ST_ACCEL_3_ODR_AVL_25HZ_VAL 0x04 +#define ST_ACCEL_3_ODR_AVL_50HZ_VAL 0x05 +#define ST_ACCEL_3_ODR_AVL_100HZ_VAL 0x06 +#define ST_ACCEL_3_ODR_AVL_200HZ_VAL 0x07 +#define ST_ACCEL_3_ODR_AVL_400HZ_VAL 0x08 +#define ST_ACCEL_3_ODR_AVL_800HZ_VAL 0x09 +#define ST_ACCEL_3_ODR_AVL_1600HZ_VAL 0x0a +#define ST_ACCEL_3_FS_ADDR 0x24 +#define ST_ACCEL_3_FS_MASK 0x38 +#define ST_ACCEL_3_FS_AVL_2_VAL 0X00 +#define ST_ACCEL_3_FS_AVL_4_VAL 0X01 +#define ST_ACCEL_3_FS_AVL_6_VAL 0x02 +#define ST_ACCEL_3_FS_AVL_8_VAL 0x03 +#define ST_ACCEL_3_FS_AVL_16_VAL 0x04 +#define ST_ACCEL_3_FS_AVL_2_GAIN IIO_G_TO_M_S_2(61) +#define ST_ACCEL_3_FS_AVL_4_GAIN IIO_G_TO_M_S_2(122) +#define ST_ACCEL_3_FS_AVL_6_GAIN IIO_G_TO_M_S_2(183) +#define ST_ACCEL_3_FS_AVL_8_GAIN IIO_G_TO_M_S_2(244) +#define ST_ACCEL_3_FS_AVL_16_GAIN IIO_G_TO_M_S_2(732) +#define ST_ACCEL_3_BDU_ADDR 0x20 +#define ST_ACCEL_3_BDU_MASK 0x08 +#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23 +#define ST_ACCEL_3_DRDY_IRQ_MASK 0x80 +#define ST_ACCEL_3_IG1_EN_ADDR 0x23 +#define ST_ACCEL_3_IG1_EN_MASK 0x08 +#define ST_ACCEL_3_MULTIREAD_BIT false + +static const struct iio_chan_spec st_accel_12bit_channels[] = { + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, + ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, + ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, + ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), + IIO_CHAN_SOFT_TIMESTAMP(3) +}; + +static const struct iio_chan_spec st_accel_16bit_channels[] = { + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), + IIO_CHAN_SOFT_TIMESTAMP(3) +}; + +static const struct st_sensors st_accel_sensors[] = { + { + .wai = ST_ACCEL_1_WAI_EXP, + .sensors_supported = { + [0] = LIS3DH_ACCEL_DEV_NAME, + [1] = LSM303DLHC_ACCEL_DEV_NAME, + [2] = LSM330D_ACCEL_DEV_NAME, + [3] = LSM330DL_ACCEL_DEV_NAME, + [4] = LSM330DLC_ACCEL_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_accel_12bit_channels, + .odr = { + .addr = ST_ACCEL_1_ODR_ADDR, + .mask = ST_ACCEL_1_ODR_MASK, + .odr_avl = { + { 1, ST_ACCEL_1_ODR_AVL_1HZ_VAL, }, + { 10, ST_ACCEL_1_ODR_AVL_10HZ_VAL, }, + { 25, ST_ACCEL_1_ODR_AVL_25HZ_VAL, }, + { 50, ST_ACCEL_1_ODR_AVL_50HZ_VAL, }, + { 100, ST_ACCEL_1_ODR_AVL_100HZ_VAL, }, + { 200, ST_ACCEL_1_ODR_AVL_200HZ_VAL, }, + { 400, ST_ACCEL_1_ODR_AVL_400HZ_VAL, }, + { 1600, ST_ACCEL_1_ODR_AVL_1600HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_ACCEL_1_ODR_ADDR, + .mask = ST_ACCEL_1_ODR_MASK, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .enable_axis = { + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, + }, + .fs = { + .addr = ST_ACCEL_1_FS_ADDR, + .mask = ST_ACCEL_1_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_ACCEL_FS_AVL_2G, + .value = ST_ACCEL_1_FS_AVL_2_VAL, + .gain = ST_ACCEL_1_FS_AVL_2_GAIN, + }, + [1] = { + .num = ST_ACCEL_FS_AVL_4G, + .value = ST_ACCEL_1_FS_AVL_4_VAL, + .gain = ST_ACCEL_1_FS_AVL_4_GAIN, + }, + [2] = { + .num = ST_ACCEL_FS_AVL_8G, + .value = ST_ACCEL_1_FS_AVL_8_VAL, + .gain = ST_ACCEL_1_FS_AVL_8_GAIN, + }, + [3] = { + .num = ST_ACCEL_FS_AVL_16G, + .value = ST_ACCEL_1_FS_AVL_16_VAL, + .gain = ST_ACCEL_1_FS_AVL_16_GAIN, + }, + }, + }, + .bdu = { + .addr = ST_ACCEL_1_BDU_ADDR, + .mask = ST_ACCEL_1_BDU_MASK, + }, + .drdy_irq = { + .addr = ST_ACCEL_1_DRDY_IRQ_ADDR, + .mask = ST_ACCEL_1_DRDY_IRQ_MASK, + }, + .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT, + .bootime = 2, + }, + { + .wai = ST_ACCEL_2_WAI_EXP, + .sensors_supported = { + [0] = LIS331DLH_ACCEL_DEV_NAME, + [1] = LSM303DL_ACCEL_DEV_NAME, + [2] = LSM303DLH_ACCEL_DEV_NAME, + [3] = LSM303DLM_ACCEL_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_accel_12bit_channels, + .odr = { + .addr = ST_ACCEL_2_ODR_ADDR, + .mask = ST_ACCEL_2_ODR_MASK, + .odr_avl = { + { 50, ST_ACCEL_2_ODR_AVL_50HZ_VAL, }, + { 100, ST_ACCEL_2_ODR_AVL_100HZ_VAL, }, + { 400, ST_ACCEL_2_ODR_AVL_400HZ_VAL, }, + { 1000, ST_ACCEL_2_ODR_AVL_1000HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_ACCEL_2_PW_ADDR, + .mask = ST_ACCEL_2_PW_MASK, + .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .enable_axis = { + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, + }, + .fs = { + .addr = ST_ACCEL_2_FS_ADDR, + .mask = ST_ACCEL_2_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_ACCEL_FS_AVL_2G, + .value = ST_ACCEL_2_FS_AVL_2_VAL, + .gain = ST_ACCEL_2_FS_AVL_2_GAIN, + }, + [1] = { + .num = ST_ACCEL_FS_AVL_4G, + .value = ST_ACCEL_2_FS_AVL_4_VAL, + .gain = ST_ACCEL_2_FS_AVL_4_GAIN, + }, + [2] = { + .num = ST_ACCEL_FS_AVL_8G, + .value = ST_ACCEL_2_FS_AVL_8_VAL, + .gain = ST_ACCEL_2_FS_AVL_8_GAIN, + }, + }, + }, + .bdu = { + .addr = ST_ACCEL_2_BDU_ADDR, + .mask = ST_ACCEL_2_BDU_MASK, + }, + .drdy_irq = { + .addr = ST_ACCEL_2_DRDY_IRQ_ADDR, + .mask = ST_ACCEL_2_DRDY_IRQ_MASK, + }, + .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT, + .bootime = 2, + }, + { + .wai = ST_ACCEL_3_WAI_EXP, + .sensors_supported = { + [0] = LSM330_ACCEL_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_accel_16bit_channels, + .odr = { + .addr = ST_ACCEL_3_ODR_ADDR, + .mask = ST_ACCEL_3_ODR_MASK, + .odr_avl = { + { 3, ST_ACCEL_3_ODR_AVL_3HZ_VAL }, + { 6, ST_ACCEL_3_ODR_AVL_6HZ_VAL, }, + { 12, ST_ACCEL_3_ODR_AVL_12HZ_VAL, }, + { 25, ST_ACCEL_3_ODR_AVL_25HZ_VAL, }, + { 50, ST_ACCEL_3_ODR_AVL_50HZ_VAL, }, + { 100, ST_ACCEL_3_ODR_AVL_100HZ_VAL, }, + { 200, ST_ACCEL_3_ODR_AVL_200HZ_VAL, }, + { 400, ST_ACCEL_3_ODR_AVL_400HZ_VAL, }, + { 800, ST_ACCEL_3_ODR_AVL_800HZ_VAL, }, + { 1600, ST_ACCEL_3_ODR_AVL_1600HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_ACCEL_3_ODR_ADDR, + .mask = ST_ACCEL_3_ODR_MASK, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .enable_axis = { + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, + }, + .fs = { + .addr = ST_ACCEL_3_FS_ADDR, + .mask = ST_ACCEL_3_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_ACCEL_FS_AVL_2G, + .value = ST_ACCEL_3_FS_AVL_2_VAL, + .gain = ST_ACCEL_3_FS_AVL_2_GAIN, + }, + [1] = { + .num = ST_ACCEL_FS_AVL_4G, + .value = ST_ACCEL_3_FS_AVL_4_VAL, + .gain = ST_ACCEL_3_FS_AVL_4_GAIN, + }, + [2] = { + .num = ST_ACCEL_FS_AVL_6G, + .value = ST_ACCEL_3_FS_AVL_6_VAL, + .gain = ST_ACCEL_3_FS_AVL_6_GAIN, + }, + [3] = { + .num = ST_ACCEL_FS_AVL_8G, + .value = ST_ACCEL_3_FS_AVL_8_VAL, + .gain = ST_ACCEL_3_FS_AVL_8_GAIN, + }, + [4] = { + .num = ST_ACCEL_FS_AVL_16G, + .value = ST_ACCEL_3_FS_AVL_16_VAL, + .gain = ST_ACCEL_3_FS_AVL_16_GAIN, + }, + }, + }, + .bdu = { + .addr = ST_ACCEL_3_BDU_ADDR, + .mask = ST_ACCEL_3_BDU_MASK, + }, + .drdy_irq = { + .addr = ST_ACCEL_3_DRDY_IRQ_ADDR, + .mask = ST_ACCEL_3_DRDY_IRQ_MASK, + .ig1 = { + .en_addr = ST_ACCEL_3_IG1_EN_ADDR, + .en_mask = ST_ACCEL_3_IG1_EN_MASK, + }, + }, + .multi_read_bit = ST_ACCEL_3_MULTIREAD_BIT, + .bootime = 2, + }, +}; + +static int st_accel_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *ch, int *val, + int *val2, long mask) +{ + int err; + struct st_sensor_data *adata = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + err = st_sensors_read_info_raw(indio_dev, ch, val); + if (err < 0) + goto read_error; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = adata->current_fullscale->gain; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + +read_error: + return err; +} + +static int st_accel_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, long mask) +{ + int err; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + err = st_sensors_set_fullscale_by_gain(indio_dev, val2); + break; + default: + return -EINVAL; + } + + return err; +} + +static ST_SENSOR_DEV_ATTR_SAMP_FREQ(); +static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL(); +static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_accel_scale_available); + +static struct attribute *st_accel_attributes[] = { + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_in_accel_scale_available.dev_attr.attr, + &iio_dev_attr_sampling_frequency.dev_attr.attr, + NULL, +}; + +static const struct attribute_group st_accel_attribute_group = { + .attrs = st_accel_attributes, +}; + +static const struct iio_info accel_info = { + .driver_module = THIS_MODULE, + .attrs = &st_accel_attribute_group, + .read_raw = &st_accel_read_raw, + .write_raw = &st_accel_write_raw, +}; + +static const struct iio_trigger_ops st_accel_trigger_ops = { + .owner = THIS_MODULE, + .set_trigger_state = ST_ACCEL_TRIGGER_SET_STATE, +}; + +int st_accel_common_probe(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *adata = iio_priv(indio_dev); + + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &accel_info; + + err = st_sensors_check_device_support(indio_dev, + ARRAY_SIZE(st_accel_sensors), st_accel_sensors); + if (err < 0) + goto st_accel_common_probe_error; + + adata->multiread_bit = adata->sensor->multi_read_bit; + indio_dev->channels = adata->sensor->ch; + indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; + + adata->current_fullscale = (struct st_sensor_fullscale_avl *) + &adata->sensor->fs.fs_avl[0]; + adata->odr = adata->sensor->odr.odr_avl[0].hz; + + err = st_sensors_init_sensor(indio_dev); + if (err < 0) + goto st_accel_common_probe_error; + + if (adata->get_irq_data_ready(indio_dev) > 0) { + err = st_accel_allocate_ring(indio_dev); + if (err < 0) + goto st_accel_common_probe_error; + + err = st_sensors_allocate_trigger(indio_dev, + &st_accel_trigger_ops); + if (err < 0) + goto st_accel_probe_trigger_error; + } + + err = iio_device_register(indio_dev); + if (err) + goto st_accel_device_register_error; + + return err; + +st_accel_device_register_error: + if (adata->get_irq_data_ready(indio_dev) > 0) + st_sensors_deallocate_trigger(indio_dev); +st_accel_probe_trigger_error: + if (adata->get_irq_data_ready(indio_dev) > 0) + st_accel_deallocate_ring(indio_dev); +st_accel_common_probe_error: + return err; +} +EXPORT_SYMBOL(st_accel_common_probe); + +void st_accel_common_remove(struct iio_dev *indio_dev) +{ + struct st_sensor_data *adata = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + if (adata->get_irq_data_ready(indio_dev) > 0) { + st_sensors_deallocate_trigger(indio_dev); + st_accel_deallocate_ring(indio_dev); + } + iio_device_free(indio_dev); +} +EXPORT_SYMBOL(st_accel_common_remove); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics accelerometers driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c new file mode 100644 index 0000000..90b8ddf --- /dev/null +++ b/drivers/iio/accel/st_accel_i2c.c @@ -0,0 +1,87 @@ +/* + * STMicroelectronics accelerometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "st_accel.h" + +static int st_accel_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *adata; + int err; + + indio_dev = iio_device_alloc(sizeof(*adata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + adata = iio_priv(indio_dev); + adata->dev = &client->dev; + + st_sensors_i2c_configure(indio_dev, client, adata); + + err = st_accel_common_probe(indio_dev); + if (err < 0) + goto st_accel_common_probe_error; + + return 0; + +st_accel_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_accel_i2c_remove(struct i2c_client *client) +{ + st_accel_common_remove(i2c_get_clientdata(client)); + + return 0; +} + +static const struct i2c_device_id st_accel_id_table[] = { + { LSM303DLH_ACCEL_DEV_NAME }, + { LSM303DLHC_ACCEL_DEV_NAME }, + { LIS3DH_ACCEL_DEV_NAME }, + { LSM330D_ACCEL_DEV_NAME }, + { LSM330DL_ACCEL_DEV_NAME }, + { LSM330DLC_ACCEL_DEV_NAME }, + { LIS331DLH_ACCEL_DEV_NAME }, + { LSM303DL_ACCEL_DEV_NAME }, + { LSM303DLM_ACCEL_DEV_NAME }, + { LSM330_ACCEL_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(i2c, st_accel_id_table); + +static struct i2c_driver st_accel_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-accel-i2c", + }, + .probe = st_accel_i2c_probe, + .remove = st_accel_i2c_remove, + .id_table = st_accel_id_table, +}; +module_i2c_driver(st_accel_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c new file mode 100644 index 0000000..dbd45c0 --- /dev/null +++ b/drivers/iio/accel/st_accel_spi.c @@ -0,0 +1,86 @@ +/* + * STMicroelectronics accelerometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "st_accel.h" + +static int st_accel_spi_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *adata; + int err; + + indio_dev = iio_device_alloc(sizeof(*adata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + adata = iio_priv(indio_dev); + adata->dev = &spi->dev; + + st_sensors_spi_configure(indio_dev, spi, adata); + + err = st_accel_common_probe(indio_dev); + if (err < 0) + goto st_accel_common_probe_error; + + return 0; + +st_accel_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_accel_spi_remove(struct spi_device *spi) +{ + st_accel_common_remove(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id st_accel_id_table[] = { + { LSM303DLH_ACCEL_DEV_NAME }, + { LSM303DLHC_ACCEL_DEV_NAME }, + { LIS3DH_ACCEL_DEV_NAME }, + { LSM330D_ACCEL_DEV_NAME }, + { LSM330DL_ACCEL_DEV_NAME }, + { LSM330DLC_ACCEL_DEV_NAME }, + { LIS331DLH_ACCEL_DEV_NAME }, + { LSM303DL_ACCEL_DEV_NAME }, + { LSM303DLM_ACCEL_DEV_NAME }, + { LSM330_ACCEL_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(spi, st_accel_id_table); + +static struct spi_driver st_accel_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-accel-spi", + }, + .probe = st_accel_spi_probe, + .remove = st_accel_spi_remove, + .id_table = st_accel_id_table, +}; +module_spi_driver(st_accel_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics accelerometers spi driver"); +MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 7be56a8f57b57cca1651fb97886e20246c168e25 Mon Sep 17 00:00:00 2001 From: Denis Ciocca Date: Fri, 25 Jan 2013 23:44:00 +0000 Subject: iio:gyro: Add STMicroelectronics gyroscopes driver This patch adds a generic gyroscope driver for STMicroelectronics gyroscopes, currently it supports: L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330. Signed-off-by: Denis Ciocca Reviewed-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 752ac8a..c9f177d 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -30,4 +30,34 @@ config HID_SENSOR_GYRO_3D Say yes here to build support for the HID SENSOR Gyroscope 3D. +config IIO_ST_GYRO_3AXIS + tristate "STMicroelectronics gyroscopes 3-Axis Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_GYRO_I2C_3AXIS if (I2C) + select IIO_ST_GYRO_SPI_3AXIS if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + select IIO_ST_GYRO_BUFFER if (IIO_TRIGGERED_BUFFER) + help + Say yes here to build support for STMicroelectronics gyroscopes: + L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330. + + This driver can also be built as a module. If so, will be created + these modules: + - st_gyro (core functions for the driver [it is mandatory]); + - st_gyro_i2c (necessary for the I2C devices [optional*]); + - st_gyro_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_GYRO_I2C_3AXIS + tristate + depends on IIO_ST_GYRO_3AXIS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_GYRO_SPI_3AXIS + tristate + depends on IIO_ST_GYRO_3AXIS + depends on IIO_ST_SENSORS_SPI + endmenu diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index 9b090ee..66b517d 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -5,3 +5,10 @@ obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16136) += adis16136.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o + +obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o +st_gyro-y := st_gyro_core.o +st_gyro-$(CONFIG_IIO_BUFFER) += st_gyro_buffer.o + +obj-$(CONFIG_IIO_ST_GYRO_I2C_3AXIS) += st_gyro_i2c.o +obj-$(CONFIG_IIO_ST_GYRO_SPI_3AXIS) += st_gyro_spi.o diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h new file mode 100644 index 0000000..3ad9907 --- /dev/null +++ b/drivers/iio/gyro/st_gyro.h @@ -0,0 +1,45 @@ +/* + * STMicroelectronics gyroscopes driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * v. 1.0.0 + * Licensed under the GPL-2. + */ + +#ifndef ST_GYRO_H +#define ST_GYRO_H + +#include +#include + +#define L3G4200D_GYRO_DEV_NAME "l3g4200d" +#define LSM330D_GYRO_DEV_NAME "lsm330d_gyro" +#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro" +#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro" +#define L3GD20_GYRO_DEV_NAME "l3gd20" +#define L3GD20H_GYRO_DEV_NAME "l3gd20h" +#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui" +#define LSM330_GYRO_DEV_NAME "lsm330_gyro" + +int st_gyro_common_probe(struct iio_dev *indio_dev); +void st_gyro_common_remove(struct iio_dev *indio_dev); + +#ifdef CONFIG_IIO_BUFFER +int st_gyro_allocate_ring(struct iio_dev *indio_dev); +void st_gyro_deallocate_ring(struct iio_dev *indio_dev); +int st_gyro_trig_set_state(struct iio_trigger *trig, bool state); +#define ST_GYRO_TRIGGER_SET_STATE (&st_gyro_trig_set_state) +#else /* CONFIG_IIO_BUFFER */ +static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev) +{ + return 0; +} +static inline void st_gyro_deallocate_ring(struct iio_dev *indio_dev) +{ +} +#define ST_GYRO_TRIGGER_SET_STATE NULL +#endif /* CONFIG_IIO_BUFFER */ + +#endif /* ST_GYRO_H */ diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c new file mode 100644 index 0000000..da4d122 --- /dev/null +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -0,0 +1,114 @@ +/* + * STMicroelectronics gyroscopes driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_gyro.h" + +int st_gyro_trig_set_state(struct iio_trigger *trig, bool state) +{ + struct iio_dev *indio_dev = trig->private_data; + + return st_sensors_set_dataready_irq(indio_dev, state); +} + +static int st_gyro_buffer_preenable(struct iio_dev *indio_dev) +{ + int err; + + err = st_sensors_set_enable(indio_dev, true); + if (err < 0) + goto st_gyro_set_enable_error; + + err = iio_sw_buffer_preenable(indio_dev); + +st_gyro_set_enable_error: + return err; +} + +static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *gdata = iio_priv(indio_dev); + + gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + if (gdata->buffer_data == NULL) { + err = -ENOMEM; + goto allocate_memory_error; + } + + err = st_sensors_set_axis_enable(indio_dev, + (u8)indio_dev->active_scan_mask[0]); + if (err < 0) + goto st_gyro_buffer_postenable_error; + + err = iio_triggered_buffer_postenable(indio_dev); + if (err < 0) + goto st_gyro_buffer_postenable_error; + + return err; + +st_gyro_buffer_postenable_error: + kfree(gdata->buffer_data); +allocate_memory_error: + return err; +} + +static int st_gyro_buffer_predisable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *gdata = iio_priv(indio_dev); + + err = iio_triggered_buffer_predisable(indio_dev); + if (err < 0) + goto st_gyro_buffer_predisable_error; + + err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); + if (err < 0) + goto st_gyro_buffer_predisable_error; + + err = st_sensors_set_enable(indio_dev, false); + +st_gyro_buffer_predisable_error: + kfree(gdata->buffer_data); + return err; +} + +static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = { + .preenable = &st_gyro_buffer_preenable, + .postenable = &st_gyro_buffer_postenable, + .predisable = &st_gyro_buffer_predisable, +}; + +int st_gyro_allocate_ring(struct iio_dev *indio_dev) +{ + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops); +} + +void st_gyro_deallocate_ring(struct iio_dev *indio_dev) +{ + iio_triggered_buffer_cleanup(indio_dev); +} + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics gyroscopes buffer"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c new file mode 100644 index 0000000..0a09998 --- /dev/null +++ b/drivers/iio/gyro/st_gyro_core.c @@ -0,0 +1,363 @@ +/* + * STMicroelectronics gyroscopes driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_gyro.h" + +/* DEFAULT VALUE FOR SENSORS */ +#define ST_GYRO_DEFAULT_OUT_X_L_ADDR 0x28 +#define ST_GYRO_DEFAULT_OUT_Y_L_ADDR 0x2a +#define ST_GYRO_DEFAULT_OUT_Z_L_ADDR 0x2c + +/* FULLSCALE */ +#define ST_GYRO_FS_AVL_250DPS 250 +#define ST_GYRO_FS_AVL_500DPS 500 +#define ST_GYRO_FS_AVL_2000DPS 2000 + +/* CUSTOM VALUES FOR SENSOR 1 */ +#define ST_GYRO_1_WAI_EXP 0xd3 +#define ST_GYRO_1_ODR_ADDR 0x20 +#define ST_GYRO_1_ODR_MASK 0xc0 +#define ST_GYRO_1_ODR_AVL_100HZ_VAL 0x00 +#define ST_GYRO_1_ODR_AVL_200HZ_VAL 0x01 +#define ST_GYRO_1_ODR_AVL_400HZ_VAL 0x02 +#define ST_GYRO_1_ODR_AVL_800HZ_VAL 0x03 +#define ST_GYRO_1_PW_ADDR 0x20 +#define ST_GYRO_1_PW_MASK 0x08 +#define ST_GYRO_1_FS_ADDR 0x23 +#define ST_GYRO_1_FS_MASK 0x30 +#define ST_GYRO_1_FS_AVL_250_VAL 0x00 +#define ST_GYRO_1_FS_AVL_500_VAL 0x01 +#define ST_GYRO_1_FS_AVL_2000_VAL 0x02 +#define ST_GYRO_1_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750) +#define ST_GYRO_1_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500) +#define ST_GYRO_1_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000) +#define ST_GYRO_1_BDU_ADDR 0x23 +#define ST_GYRO_1_BDU_MASK 0x80 +#define ST_GYRO_1_DRDY_IRQ_ADDR 0x22 +#define ST_GYRO_1_DRDY_IRQ_MASK 0x08 +#define ST_GYRO_1_MULTIREAD_BIT true + +/* CUSTOM VALUES FOR SENSOR 2 */ +#define ST_GYRO_2_WAI_EXP 0xd4 +#define ST_GYRO_2_ODR_ADDR 0x20 +#define ST_GYRO_2_ODR_MASK 0xc0 +#define ST_GYRO_2_ODR_AVL_95HZ_VAL 0x00 +#define ST_GYRO_2_ODR_AVL_190HZ_VAL 0x01 +#define ST_GYRO_2_ODR_AVL_380HZ_VAL 0x02 +#define ST_GYRO_2_ODR_AVL_760HZ_VAL 0x03 +#define ST_GYRO_2_PW_ADDR 0x20 +#define ST_GYRO_2_PW_MASK 0x08 +#define ST_GYRO_2_FS_ADDR 0x23 +#define ST_GYRO_2_FS_MASK 0x30 +#define ST_GYRO_2_FS_AVL_250_VAL 0x00 +#define ST_GYRO_2_FS_AVL_500_VAL 0x01 +#define ST_GYRO_2_FS_AVL_2000_VAL 0x02 +#define ST_GYRO_2_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750) +#define ST_GYRO_2_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500) +#define ST_GYRO_2_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000) +#define ST_GYRO_2_BDU_ADDR 0x23 +#define ST_GYRO_2_BDU_MASK 0x80 +#define ST_GYRO_2_DRDY_IRQ_ADDR 0x22 +#define ST_GYRO_2_DRDY_IRQ_MASK 0x08 +#define ST_GYRO_2_MULTIREAD_BIT true + +static const struct iio_chan_spec st_gyro_16bit_channels[] = { + ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_X, + IIO_MOD_X, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS, + ST_GYRO_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Y, + IIO_MOD_Y, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS, + ST_GYRO_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Z, + IIO_MOD_Z, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS, + ST_GYRO_DEFAULT_OUT_Z_L_ADDR), + IIO_CHAN_SOFT_TIMESTAMP(3) +}; + +static const struct st_sensors st_gyro_sensors[] = { + { + .wai = ST_GYRO_1_WAI_EXP, + .sensors_supported = { + [0] = L3G4200D_GYRO_DEV_NAME, + [1] = LSM330DL_GYRO_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_gyro_16bit_channels, + .odr = { + .addr = ST_GYRO_1_ODR_ADDR, + .mask = ST_GYRO_1_ODR_MASK, + .odr_avl = { + { 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, }, + { 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, }, + { 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, }, + { 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_GYRO_1_PW_ADDR, + .mask = ST_GYRO_1_PW_MASK, + .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .enable_axis = { + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, + }, + .fs = { + .addr = ST_GYRO_1_FS_ADDR, + .mask = ST_GYRO_1_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_GYRO_FS_AVL_250DPS, + .value = ST_GYRO_1_FS_AVL_250_VAL, + .gain = ST_GYRO_1_FS_AVL_250_GAIN, + }, + [1] = { + .num = ST_GYRO_FS_AVL_500DPS, + .value = ST_GYRO_1_FS_AVL_500_VAL, + .gain = ST_GYRO_1_FS_AVL_500_GAIN, + }, + [2] = { + .num = ST_GYRO_FS_AVL_2000DPS, + .value = ST_GYRO_1_FS_AVL_2000_VAL, + .gain = ST_GYRO_1_FS_AVL_2000_GAIN, + }, + }, + }, + .bdu = { + .addr = ST_GYRO_1_BDU_ADDR, + .mask = ST_GYRO_1_BDU_MASK, + }, + .drdy_irq = { + .addr = ST_GYRO_1_DRDY_IRQ_ADDR, + .mask = ST_GYRO_1_DRDY_IRQ_MASK, + }, + .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT, + .bootime = 2, + }, + { + .wai = ST_GYRO_2_WAI_EXP, + .sensors_supported = { + [0] = L3GD20_GYRO_DEV_NAME, + [1] = L3GD20H_GYRO_DEV_NAME, + [2] = LSM330D_GYRO_DEV_NAME, + [3] = LSM330DLC_GYRO_DEV_NAME, + [4] = L3G4IS_GYRO_DEV_NAME, + [5] = LSM330_GYRO_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_gyro_16bit_channels, + .odr = { + .addr = ST_GYRO_2_ODR_ADDR, + .mask = ST_GYRO_2_ODR_MASK, + .odr_avl = { + { 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, }, + { 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, }, + { 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, }, + { 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_GYRO_2_PW_ADDR, + .mask = ST_GYRO_2_PW_MASK, + .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .enable_axis = { + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, + }, + .fs = { + .addr = ST_GYRO_2_FS_ADDR, + .mask = ST_GYRO_2_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_GYRO_FS_AVL_250DPS, + .value = ST_GYRO_2_FS_AVL_250_VAL, + .gain = ST_GYRO_2_FS_AVL_250_GAIN, + }, + [1] = { + .num = ST_GYRO_FS_AVL_500DPS, + .value = ST_GYRO_2_FS_AVL_500_VAL, + .gain = ST_GYRO_2_FS_AVL_500_GAIN, + }, + [2] = { + .num = ST_GYRO_FS_AVL_2000DPS, + .value = ST_GYRO_2_FS_AVL_2000_VAL, + .gain = ST_GYRO_2_FS_AVL_2000_GAIN, + }, + }, + }, + .bdu = { + .addr = ST_GYRO_2_BDU_ADDR, + .mask = ST_GYRO_2_BDU_MASK, + }, + .drdy_irq = { + .addr = ST_GYRO_2_DRDY_IRQ_ADDR, + .mask = ST_GYRO_2_DRDY_IRQ_MASK, + }, + .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT, + .bootime = 2, + }, +}; + +static int st_gyro_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *ch, int *val, + int *val2, long mask) +{ + int err; + struct st_sensor_data *gdata = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + err = st_sensors_read_info_raw(indio_dev, ch, val); + if (err < 0) + goto read_error; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = gdata->current_fullscale->gain; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + +read_error: + return err; +} + +static int st_gyro_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, long mask) +{ + int err; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + err = st_sensors_set_fullscale_by_gain(indio_dev, val2); + break; + default: + err = -EINVAL; + } + + return err; +} + +static ST_SENSOR_DEV_ATTR_SAMP_FREQ(); +static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL(); +static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_anglvel_scale_available); + +static struct attribute *st_gyro_attributes[] = { + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr, + &iio_dev_attr_sampling_frequency.dev_attr.attr, + NULL, +}; + +static const struct attribute_group st_gyro_attribute_group = { + .attrs = st_gyro_attributes, +}; + +static const struct iio_info gyro_info = { + .driver_module = THIS_MODULE, + .attrs = &st_gyro_attribute_group, + .read_raw = &st_gyro_read_raw, + .write_raw = &st_gyro_write_raw, +}; + +static const struct iio_trigger_ops st_gyro_trigger_ops = { + .owner = THIS_MODULE, + .set_trigger_state = ST_GYRO_TRIGGER_SET_STATE, +}; + +int st_gyro_common_probe(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *gdata = iio_priv(indio_dev); + + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &gyro_info; + + err = st_sensors_check_device_support(indio_dev, + ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors); + if (err < 0) + goto st_gyro_common_probe_error; + + gdata->multiread_bit = gdata->sensor->multi_read_bit; + indio_dev->channels = gdata->sensor->ch; + indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; + + gdata->current_fullscale = (struct st_sensor_fullscale_avl *) + &gdata->sensor->fs.fs_avl[0]; + gdata->odr = gdata->sensor->odr.odr_avl[0].hz; + + err = st_sensors_init_sensor(indio_dev); + if (err < 0) + goto st_gyro_common_probe_error; + + if (gdata->get_irq_data_ready(indio_dev) > 0) { + err = st_gyro_allocate_ring(indio_dev); + if (err < 0) + goto st_gyro_common_probe_error; + + err = st_sensors_allocate_trigger(indio_dev, + &st_gyro_trigger_ops); + if (err < 0) + goto st_gyro_probe_trigger_error; + } + + err = iio_device_register(indio_dev); + if (err) + goto st_gyro_device_register_error; + + return err; + +st_gyro_device_register_error: + if (gdata->get_irq_data_ready(indio_dev) > 0) + st_sensors_deallocate_trigger(indio_dev); +st_gyro_probe_trigger_error: + if (gdata->get_irq_data_ready(indio_dev) > 0) + st_gyro_deallocate_ring(indio_dev); +st_gyro_common_probe_error: + return err; +} +EXPORT_SYMBOL(st_gyro_common_probe); + +void st_gyro_common_remove(struct iio_dev *indio_dev) +{ + struct st_sensor_data *gdata = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + if (gdata->get_irq_data_ready(indio_dev) > 0) { + st_sensors_deallocate_trigger(indio_dev); + st_gyro_deallocate_ring(indio_dev); + } + iio_device_free(indio_dev); +} +EXPORT_SYMBOL(st_gyro_common_remove); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics gyroscopes driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c new file mode 100644 index 0000000..a44b5b4 --- /dev/null +++ b/drivers/iio/gyro/st_gyro_i2c.c @@ -0,0 +1,85 @@ +/* + * STMicroelectronics gyroscopes driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "st_gyro.h" + +static int st_gyro_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *gdata; + int err; + + indio_dev = iio_device_alloc(sizeof(*gdata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + gdata = iio_priv(indio_dev); + gdata->dev = &client->dev; + + st_sensors_i2c_configure(indio_dev, client, gdata); + + err = st_gyro_common_probe(indio_dev); + if (err < 0) + goto st_gyro_common_probe_error; + + return 0; + +st_gyro_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_gyro_i2c_remove(struct i2c_client *client) +{ + st_gyro_common_remove(i2c_get_clientdata(client)); + + return 0; +} + +static const struct i2c_device_id st_gyro_id_table[] = { + { L3G4200D_GYRO_DEV_NAME }, + { LSM330D_GYRO_DEV_NAME }, + { LSM330DL_GYRO_DEV_NAME }, + { LSM330DLC_GYRO_DEV_NAME }, + { L3GD20_GYRO_DEV_NAME }, + { L3GD20H_GYRO_DEV_NAME }, + { L3G4IS_GYRO_DEV_NAME }, + { LSM330_GYRO_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(i2c, st_gyro_id_table); + +static struct i2c_driver st_gyro_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-gyro-i2c", + }, + .probe = st_gyro_i2c_probe, + .remove = st_gyro_i2c_remove, + .id_table = st_gyro_id_table, +}; +module_i2c_driver(st_gyro_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c new file mode 100644 index 0000000..8b4dcc5 --- /dev/null +++ b/drivers/iio/gyro/st_gyro_spi.c @@ -0,0 +1,84 @@ +/* + * STMicroelectronics gyroscopes driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "st_gyro.h" + +static int st_gyro_spi_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *gdata; + int err; + + indio_dev = iio_device_alloc(sizeof(*gdata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + gdata = iio_priv(indio_dev); + gdata->dev = &spi->dev; + + st_sensors_spi_configure(indio_dev, spi, gdata); + + err = st_gyro_common_probe(indio_dev); + if (err < 0) + goto st_gyro_common_probe_error; + + return 0; + +st_gyro_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_gyro_spi_remove(struct spi_device *spi) +{ + st_gyro_common_remove(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id st_gyro_id_table[] = { + { L3G4200D_GYRO_DEV_NAME }, + { LSM330D_GYRO_DEV_NAME }, + { LSM330DL_GYRO_DEV_NAME }, + { LSM330DLC_GYRO_DEV_NAME }, + { L3GD20_GYRO_DEV_NAME }, + { L3GD20H_GYRO_DEV_NAME }, + { L3G4IS_GYRO_DEV_NAME }, + { LSM330_GYRO_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(spi, st_gyro_id_table); + +static struct spi_driver st_gyro_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-gyro-spi", + }, + .probe = st_gyro_spi_probe, + .remove = st_gyro_spi_remove, + .id_table = st_gyro_id_table, +}; +module_spi_driver(st_gyro_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics gyroscopes spi driver"); +MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 872e79add7561645b130fba63aa7ca12098a9361 Mon Sep 17 00:00:00 2001 From: Denis Ciocca Date: Fri, 25 Jan 2013 23:44:00 +0000 Subject: iio:magnetometer: Add STMicroelectronics magnetometers driver This patch adds a generic magnetometer driver for STMicroelectronics magnetometers, currently it supports: LSM303DLHC, LSM303DLM, LIS3MDL. Signed-off-by: Denis Ciocca Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index ff11d68..cd29be5 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -14,4 +14,34 @@ config HID_SENSOR_MAGNETOMETER_3D Say yes here to build support for the HID SENSOR Magnetometer 3D. +config IIO_ST_MAGN_3AXIS + tristate "STMicroelectronics magnetometers 3-Axis Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_MAGN_I2C_3AXIS if (I2C) + select IIO_ST_MAGN_SPI_3AXIS if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + select IIO_ST_MAGN_BUFFER if (IIO_TRIGGERED_BUFFER) + help + Say yes here to build support for STMicroelectronics magnetometers: + LSM303DLHC, LSM303DLM, LIS3MDL. + + This driver can also be built as a module. If so, will be created + these modules: + - st_magn (core functions for the driver [it is mandatory]); + - st_magn_i2c (necessary for the I2C devices [optional*]); + - st_magn_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_MAGN_I2C_3AXIS + tristate + depends on IIO_ST_MAGN_3AXIS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_MAGN_SPI_3AXIS + tristate + depends on IIO_ST_MAGN_3AXIS + depends on IIO_ST_SENSORS_SPI + endmenu diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile index 60dc4f2..e786728 100644 --- a/drivers/iio/magnetometer/Makefile +++ b/drivers/iio/magnetometer/Makefile @@ -3,3 +3,10 @@ # obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o + +obj-$(CONFIG_IIO_ST_MAGN_3AXIS) += st_magn.o +st_magn-y := st_magn_core.o +st_magn-$(CONFIG_IIO_BUFFER) += st_magn_buffer.o + +obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o +obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h new file mode 100644 index 0000000..7e81d00 --- /dev/null +++ b/drivers/iio/magnetometer/st_magn.h @@ -0,0 +1,45 @@ +/* + * STMicroelectronics magnetometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * v. 1.0.0 + * Licensed under the GPL-2. + */ + +#ifndef ST_MAGN_H +#define ST_MAGN_H + +#include +#include + +#define LSM303DLHC_MAGN_DEV_NAME "lsm303dlhc_magn" +#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn" +#define LIS3MDL_MAGN_DEV_NAME "lis3mdl" + +int st_magn_common_probe(struct iio_dev *indio_dev); +void st_magn_common_remove(struct iio_dev *indio_dev); + +#ifdef CONFIG_IIO_BUFFER +int st_magn_allocate_ring(struct iio_dev *indio_dev); +void st_magn_deallocate_ring(struct iio_dev *indio_dev); +#else /* CONFIG_IIO_BUFFER */ +static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq) +{ + return 0; +} +static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq) +{ + return; +} +static inline int st_magn_allocate_ring(struct iio_dev *indio_dev) +{ + return 0; +} +static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev) +{ +} +#endif /* CONFIG_IIO_BUFFER */ + +#endif /* ST_MAGN_H */ diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c new file mode 100644 index 0000000..708857b --- /dev/null +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -0,0 +1,98 @@ +/* + * STMicroelectronics magnetometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_magn.h" + +static int st_magn_buffer_preenable(struct iio_dev *indio_dev) +{ + int err; + + err = st_sensors_set_enable(indio_dev, true); + if (err < 0) + goto st_magn_set_enable_error; + + err = iio_sw_buffer_preenable(indio_dev); + +st_magn_set_enable_error: + return err; +} + +static int st_magn_buffer_postenable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *mdata = iio_priv(indio_dev); + + mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + if (mdata->buffer_data == NULL) { + err = -ENOMEM; + goto allocate_memory_error; + } + + err = iio_triggered_buffer_postenable(indio_dev); + if (err < 0) + goto st_magn_buffer_postenable_error; + + return err; + +st_magn_buffer_postenable_error: + kfree(mdata->buffer_data); +allocate_memory_error: + return err; +} + +static int st_magn_buffer_predisable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *mdata = iio_priv(indio_dev); + + err = iio_triggered_buffer_predisable(indio_dev); + if (err < 0) + goto st_magn_buffer_predisable_error; + + err = st_sensors_set_enable(indio_dev, false); + +st_magn_buffer_predisable_error: + kfree(mdata->buffer_data); + return err; +} + +static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = { + .preenable = &st_magn_buffer_preenable, + .postenable = &st_magn_buffer_postenable, + .predisable = &st_magn_buffer_predisable, +}; + +int st_magn_allocate_ring(struct iio_dev *indio_dev) +{ + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + &st_sensors_trigger_handler, &st_magn_buffer_setup_ops); +} + +void st_magn_deallocate_ring(struct iio_dev *indio_dev) +{ + iio_triggered_buffer_cleanup(indio_dev); +} + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics magnetometers buffer"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c new file mode 100644 index 0000000..a69fbe1 --- /dev/null +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -0,0 +1,401 @@ +/* + * STMicroelectronics magnetometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_magn.h" + +/* DEFAULT VALUE FOR SENSORS */ +#define ST_MAGN_DEFAULT_OUT_X_L_ADDR 0X04 +#define ST_MAGN_DEFAULT_OUT_Y_L_ADDR 0X08 +#define ST_MAGN_DEFAULT_OUT_Z_L_ADDR 0X06 + +/* FULLSCALE */ +#define ST_MAGN_FS_AVL_1300MG 1300 +#define ST_MAGN_FS_AVL_1900MG 1900 +#define ST_MAGN_FS_AVL_2500MG 2500 +#define ST_MAGN_FS_AVL_4000MG 4000 +#define ST_MAGN_FS_AVL_4700MG 4700 +#define ST_MAGN_FS_AVL_5600MG 5600 +#define ST_MAGN_FS_AVL_8000MG 8000 +#define ST_MAGN_FS_AVL_8100MG 8100 +#define ST_MAGN_FS_AVL_10000MG 10000 + +/* CUSTOM VALUES FOR SENSOR 1 */ +#define ST_MAGN_1_WAI_EXP 0x3c +#define ST_MAGN_1_ODR_ADDR 0x00 +#define ST_MAGN_1_ODR_MASK 0x1c +#define ST_MAGN_1_ODR_AVL_1HZ_VAL 0x00 +#define ST_MAGN_1_ODR_AVL_2HZ_VAL 0x01 +#define ST_MAGN_1_ODR_AVL_3HZ_VAL 0x02 +#define ST_MAGN_1_ODR_AVL_8HZ_VAL 0x03 +#define ST_MAGN_1_ODR_AVL_15HZ_VAL 0x04 +#define ST_MAGN_1_ODR_AVL_30HZ_VAL 0x05 +#define ST_MAGN_1_ODR_AVL_75HZ_VAL 0x06 +#define ST_MAGN_1_ODR_AVL_220HZ_VAL 0x07 +#define ST_MAGN_1_PW_ADDR 0x02 +#define ST_MAGN_1_PW_MASK 0x03 +#define ST_MAGN_1_PW_ON 0x00 +#define ST_MAGN_1_PW_OFF 0x03 +#define ST_MAGN_1_FS_ADDR 0x01 +#define ST_MAGN_1_FS_MASK 0xe0 +#define ST_MAGN_1_FS_AVL_1300_VAL 0x01 +#define ST_MAGN_1_FS_AVL_1900_VAL 0x02 +#define ST_MAGN_1_FS_AVL_2500_VAL 0x03 +#define ST_MAGN_1_FS_AVL_4000_VAL 0x04 +#define ST_MAGN_1_FS_AVL_4700_VAL 0x05 +#define ST_MAGN_1_FS_AVL_5600_VAL 0x06 +#define ST_MAGN_1_FS_AVL_8100_VAL 0x07 +#define ST_MAGN_1_FS_AVL_1300_GAIN_XY 1100 +#define ST_MAGN_1_FS_AVL_1900_GAIN_XY 855 +#define ST_MAGN_1_FS_AVL_2500_GAIN_XY 670 +#define ST_MAGN_1_FS_AVL_4000_GAIN_XY 450 +#define ST_MAGN_1_FS_AVL_4700_GAIN_XY 400 +#define ST_MAGN_1_FS_AVL_5600_GAIN_XY 330 +#define ST_MAGN_1_FS_AVL_8100_GAIN_XY 230 +#define ST_MAGN_1_FS_AVL_1300_GAIN_Z 980 +#define ST_MAGN_1_FS_AVL_1900_GAIN_Z 760 +#define ST_MAGN_1_FS_AVL_2500_GAIN_Z 600 +#define ST_MAGN_1_FS_AVL_4000_GAIN_Z 400 +#define ST_MAGN_1_FS_AVL_4700_GAIN_Z 355 +#define ST_MAGN_1_FS_AVL_5600_GAIN_Z 295 +#define ST_MAGN_1_FS_AVL_8100_GAIN_Z 205 +#define ST_MAGN_1_MULTIREAD_BIT false + +/* CUSTOM VALUES FOR SENSOR 2 */ +#define ST_MAGN_2_WAI_EXP 0x3d +#define ST_MAGN_2_ODR_ADDR 0x20 +#define ST_MAGN_2_ODR_MASK 0x1c +#define ST_MAGN_2_ODR_AVL_1HZ_VAL 0x00 +#define ST_MAGN_2_ODR_AVL_2HZ_VAL 0x01 +#define ST_MAGN_2_ODR_AVL_3HZ_VAL 0x02 +#define ST_MAGN_2_ODR_AVL_5HZ_VAL 0x03 +#define ST_MAGN_2_ODR_AVL_10HZ_VAL 0x04 +#define ST_MAGN_2_ODR_AVL_20HZ_VAL 0x05 +#define ST_MAGN_2_ODR_AVL_40HZ_VAL 0x06 +#define ST_MAGN_2_ODR_AVL_80HZ_VAL 0x07 +#define ST_MAGN_2_PW_ADDR 0x22 +#define ST_MAGN_2_PW_MASK 0x03 +#define ST_MAGN_2_PW_ON 0x00 +#define ST_MAGN_2_PW_OFF 0x03 +#define ST_MAGN_2_FS_ADDR 0x21 +#define ST_MAGN_2_FS_MASK 0x60 +#define ST_MAGN_2_FS_AVL_4000_VAL 0x00 +#define ST_MAGN_2_FS_AVL_8000_VAL 0x01 +#define ST_MAGN_2_FS_AVL_10000_VAL 0x02 +#define ST_MAGN_2_FS_AVL_4000_GAIN 430 +#define ST_MAGN_2_FS_AVL_8000_GAIN 230 +#define ST_MAGN_2_FS_AVL_10000_GAIN 230 +#define ST_MAGN_2_MULTIREAD_BIT false +#define ST_MAGN_2_OUT_X_L_ADDR 0x28 +#define ST_MAGN_2_OUT_Y_L_ADDR 0x2a +#define ST_MAGN_2_OUT_Z_L_ADDR 0x2c + +static const struct iio_chan_spec st_magn_16bit_channels[] = { + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Z_L_ADDR), + IIO_CHAN_SOFT_TIMESTAMP(3) +}; + +static const struct iio_chan_spec st_magn_2_16bit_channels[] = { + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, + ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Z_L_ADDR), + IIO_CHAN_SOFT_TIMESTAMP(3) +}; + +static const struct st_sensors st_magn_sensors[] = { + { + .wai = ST_MAGN_1_WAI_EXP, + .sensors_supported = { + [0] = LSM303DLHC_MAGN_DEV_NAME, + [1] = LSM303DLM_MAGN_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_magn_16bit_channels, + .odr = { + .addr = ST_MAGN_1_ODR_ADDR, + .mask = ST_MAGN_1_ODR_MASK, + .odr_avl = { + { 1, ST_MAGN_1_ODR_AVL_1HZ_VAL, }, + { 2, ST_MAGN_1_ODR_AVL_2HZ_VAL, }, + { 3, ST_MAGN_1_ODR_AVL_3HZ_VAL, }, + { 8, ST_MAGN_1_ODR_AVL_8HZ_VAL, }, + { 15, ST_MAGN_1_ODR_AVL_15HZ_VAL, }, + { 30, ST_MAGN_1_ODR_AVL_30HZ_VAL, }, + { 75, ST_MAGN_1_ODR_AVL_75HZ_VAL, }, + { 220, ST_MAGN_1_ODR_AVL_220HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_MAGN_1_PW_ADDR, + .mask = ST_MAGN_1_PW_MASK, + .value_on = ST_MAGN_1_PW_ON, + .value_off = ST_MAGN_1_PW_OFF, + }, + .fs = { + .addr = ST_MAGN_1_FS_ADDR, + .mask = ST_MAGN_1_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_MAGN_FS_AVL_1300MG, + .value = ST_MAGN_1_FS_AVL_1300_VAL, + .gain = ST_MAGN_1_FS_AVL_1300_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_1300_GAIN_Z, + }, + [1] = { + .num = ST_MAGN_FS_AVL_1900MG, + .value = ST_MAGN_1_FS_AVL_1900_VAL, + .gain = ST_MAGN_1_FS_AVL_1900_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_1900_GAIN_Z, + }, + [2] = { + .num = ST_MAGN_FS_AVL_2500MG, + .value = ST_MAGN_1_FS_AVL_2500_VAL, + .gain = ST_MAGN_1_FS_AVL_2500_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_2500_GAIN_Z, + }, + [3] = { + .num = ST_MAGN_FS_AVL_4000MG, + .value = ST_MAGN_1_FS_AVL_4000_VAL, + .gain = ST_MAGN_1_FS_AVL_4000_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_4000_GAIN_Z, + }, + [4] = { + .num = ST_MAGN_FS_AVL_4700MG, + .value = ST_MAGN_1_FS_AVL_4700_VAL, + .gain = ST_MAGN_1_FS_AVL_4700_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_4700_GAIN_Z, + }, + [5] = { + .num = ST_MAGN_FS_AVL_5600MG, + .value = ST_MAGN_1_FS_AVL_5600_VAL, + .gain = ST_MAGN_1_FS_AVL_5600_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_5600_GAIN_Z, + }, + [6] = { + .num = ST_MAGN_FS_AVL_8100MG, + .value = ST_MAGN_1_FS_AVL_8100_VAL, + .gain = ST_MAGN_1_FS_AVL_8100_GAIN_XY, + .gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z, + }, + }, + }, + .multi_read_bit = ST_MAGN_1_MULTIREAD_BIT, + .bootime = 2, + }, + { + .wai = ST_MAGN_2_WAI_EXP, + .sensors_supported = { + [0] = LIS3MDL_MAGN_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_magn_2_16bit_channels, + .odr = { + .addr = ST_MAGN_2_ODR_ADDR, + .mask = ST_MAGN_2_ODR_MASK, + .odr_avl = { + { 1, ST_MAGN_2_ODR_AVL_1HZ_VAL, }, + { 2, ST_MAGN_2_ODR_AVL_2HZ_VAL, }, + { 3, ST_MAGN_2_ODR_AVL_3HZ_VAL, }, + { 5, ST_MAGN_2_ODR_AVL_5HZ_VAL, }, + { 10, ST_MAGN_2_ODR_AVL_10HZ_VAL, }, + { 20, ST_MAGN_2_ODR_AVL_20HZ_VAL, }, + { 40, ST_MAGN_2_ODR_AVL_40HZ_VAL, }, + { 80, ST_MAGN_2_ODR_AVL_80HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_MAGN_2_PW_ADDR, + .mask = ST_MAGN_2_PW_MASK, + .value_on = ST_MAGN_2_PW_ON, + .value_off = ST_MAGN_2_PW_OFF, + }, + .fs = { + .addr = ST_MAGN_2_FS_ADDR, + .mask = ST_MAGN_2_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_MAGN_FS_AVL_4000MG, + .value = ST_MAGN_2_FS_AVL_4000_VAL, + .gain = ST_MAGN_2_FS_AVL_4000_GAIN, + }, + [1] = { + .num = ST_MAGN_FS_AVL_8000MG, + .value = ST_MAGN_2_FS_AVL_8000_VAL, + .gain = ST_MAGN_2_FS_AVL_8000_GAIN, + }, + [2] = { + .num = ST_MAGN_FS_AVL_10000MG, + .value = ST_MAGN_2_FS_AVL_10000_VAL, + .gain = ST_MAGN_2_FS_AVL_10000_GAIN, + }, + }, + }, + .multi_read_bit = ST_MAGN_2_MULTIREAD_BIT, + .bootime = 2, + }, +}; + +static int st_magn_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *ch, int *val, + int *val2, long mask) +{ + int err; + struct st_sensor_data *mdata = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + err = st_sensors_read_info_raw(indio_dev, ch, val); + if (err < 0) + goto read_error; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + if ((ch->scan_index == ST_SENSORS_SCAN_Z) && + (mdata->current_fullscale->gain2 != 0)) + *val2 = mdata->current_fullscale->gain2; + else + *val2 = mdata->current_fullscale->gain; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + +read_error: + return err; +} + +static int st_magn_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, long mask) +{ + int err; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + err = st_sensors_set_fullscale_by_gain(indio_dev, val2); + break; + default: + err = -EINVAL; + } + + return err; +} + +static ST_SENSOR_DEV_ATTR_SAMP_FREQ(); +static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL(); +static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_magn_scale_available); + +static struct attribute *st_magn_attributes[] = { + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_in_magn_scale_available.dev_attr.attr, + &iio_dev_attr_sampling_frequency.dev_attr.attr, + NULL, +}; + +static const struct attribute_group st_magn_attribute_group = { + .attrs = st_magn_attributes, +}; + +static const struct iio_info magn_info = { + .driver_module = THIS_MODULE, + .attrs = &st_magn_attribute_group, + .read_raw = &st_magn_read_raw, + .write_raw = &st_magn_write_raw, +}; + +int st_magn_common_probe(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *mdata = iio_priv(indio_dev); + + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &magn_info; + + err = st_sensors_check_device_support(indio_dev, + ARRAY_SIZE(st_magn_sensors), st_magn_sensors); + if (err < 0) + goto st_magn_common_probe_error; + + mdata->multiread_bit = mdata->sensor->multi_read_bit; + indio_dev->channels = mdata->sensor->ch; + indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; + + mdata->current_fullscale = (struct st_sensor_fullscale_avl *) + &mdata->sensor->fs.fs_avl[0]; + mdata->odr = mdata->sensor->odr.odr_avl[0].hz; + + err = st_sensors_init_sensor(indio_dev); + if (err < 0) + goto st_magn_common_probe_error; + + if (mdata->get_irq_data_ready(indio_dev) > 0) { + err = st_magn_allocate_ring(indio_dev); + if (err < 0) + goto st_magn_common_probe_error; + err = st_sensors_allocate_trigger(indio_dev, NULL); + if (err < 0) + goto st_magn_probe_trigger_error; + } + + err = iio_device_register(indio_dev); + if (err) + goto st_magn_device_register_error; + + return err; + +st_magn_device_register_error: + if (mdata->get_irq_data_ready(indio_dev) > 0) + st_sensors_deallocate_trigger(indio_dev); +st_magn_probe_trigger_error: + if (mdata->get_irq_data_ready(indio_dev) > 0) + st_magn_deallocate_ring(indio_dev); +st_magn_common_probe_error: + return err; +} +EXPORT_SYMBOL(st_magn_common_probe); + +void st_magn_common_remove(struct iio_dev *indio_dev) +{ + struct st_sensor_data *mdata = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + if (mdata->get_irq_data_ready(indio_dev) > 0) { + st_sensors_deallocate_trigger(indio_dev); + st_magn_deallocate_ring(indio_dev); + } + iio_device_free(indio_dev); +} +EXPORT_SYMBOL(st_magn_common_remove); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics magnetometers driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c new file mode 100644 index 0000000..710b256a5 --- /dev/null +++ b/drivers/iio/magnetometer/st_magn_i2c.c @@ -0,0 +1,81 @@ +/* + * STMicroelectronics magnetometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "st_magn.h" + +static int st_magn_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *mdata; + int err; + + indio_dev = iio_device_alloc(sizeof(*mdata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + mdata = iio_priv(indio_dev); + mdata->dev = &client->dev; + + st_sensors_i2c_configure(indio_dev, client, mdata); + + err = st_magn_common_probe(indio_dev); + if (err < 0) + goto st_magn_common_probe_error; + + return 0; + +st_magn_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_magn_i2c_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + st_magn_common_remove(indio_dev); + + return 0; +} + +static const struct i2c_device_id st_magn_id_table[] = { + { LSM303DLHC_MAGN_DEV_NAME }, + { LSM303DLM_MAGN_DEV_NAME }, + { LIS3MDL_MAGN_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(i2c, st_magn_id_table); + +static struct i2c_driver st_magn_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-magn-i2c", + }, + .probe = st_magn_i2c_probe, + .remove = st_magn_i2c_remove, + .id_table = st_magn_id_table, +}; +module_i2c_driver(st_magn_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics magnetometers i2c driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c new file mode 100644 index 0000000..94547e7 --- /dev/null +++ b/drivers/iio/magnetometer/st_magn_spi.c @@ -0,0 +1,80 @@ +/* + * STMicroelectronics magnetometers driver + * + * Copyright 2012-2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "st_magn.h" + +static int st_magn_spi_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *mdata; + int err; + + indio_dev = iio_device_alloc(sizeof(*mdata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + mdata = iio_priv(indio_dev); + mdata->dev = &spi->dev; + + st_sensors_spi_configure(indio_dev, spi, mdata); + + err = st_magn_common_probe(indio_dev); + if (err < 0) + goto st_magn_common_probe_error; + + return 0; + +st_magn_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_magn_spi_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + st_magn_common_remove(indio_dev); + + return 0; +} + +static const struct spi_device_id st_magn_id_table[] = { + { LSM303DLHC_MAGN_DEV_NAME }, + { LSM303DLM_MAGN_DEV_NAME }, + { LIS3MDL_MAGN_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(spi, st_magn_id_table); + +static struct spi_driver st_magn_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-magn-spi", + }, + .probe = st_magn_spi_probe, + .remove = st_magn_spi_remove, + .id_table = st_magn_id_table, +}; +module_spi_driver(st_magn_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver"); +MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 999517f6742b4ca4692c041752afc4298fbbf0da Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 28 Jan 2013 10:12:00 +0000 Subject: staging:iio: Remove noop call to __iio_update_buffer __iio_update_buffer updates the buffer's bytes_per_datum and length fields. But the only user of this function just passes in these exact fields, so the call basically looks like this: buffer->bytes_per_datum = buffer->bytes_per_datum; buffer->length = buffer->length; Which means it is a noop and can be removed. Also remove the function itself, since it is now unused. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c index 5bc5c86..a923c78 100644 --- a/drivers/iio/kfifo_buf.c +++ b/drivers/iio/kfifo_buf.c @@ -22,7 +22,6 @@ static inline int __iio_allocate_kfifo(struct iio_kfifo *buf, if ((length == 0) || (bytes_per_datum == 0)) return -EINVAL; - __iio_update_buffer(&buf->buffer, bytes_per_datum, length); return __kfifo_alloc((struct __kfifo *)&buf->kf, length, bytes_per_datum, GFP_KERNEL); } diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h index f3eea18..2bac0eb 100644 --- a/include/linux/iio/buffer.h +++ b/include/linux/iio/buffer.h @@ -103,19 +103,6 @@ int iio_update_buffers(struct iio_dev *indio_dev, **/ void iio_buffer_init(struct iio_buffer *buffer); -/** - * __iio_update_buffer() - update common elements of buffers - * @buffer: buffer that is the event source - * @bytes_per_datum: size of individual datum including timestamp - * @length: number of datums in buffer - **/ -static inline void __iio_update_buffer(struct iio_buffer *buffer, - int bytes_per_datum, int length) -{ - buffer->bytes_per_datum = bytes_per_datum; - buffer->length = length; -} - int iio_scan_mask_query(struct iio_dev *indio_dev, struct iio_buffer *buffer, int bit); -- cgit v0.10.2 From 6a6df2d9113856a4371ca4f1cb29221790320307 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: Partially revert "staging:iio:gyro:adxrs450 make more use of spi_read and spi_write." This partially reverts commit cb4496876f03631eff913b3c608c964d48d61eb9. There is no apparent reason why we should split a transaction which consists out of multiple transfers into multiple transactions each having one transfer. While this works it introduces a bunch of unnecessary context switch and additional setup costs. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index f0ce81d..318e8c9 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -34,8 +34,21 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, u8 reg_address, u16 *val) { + struct spi_message msg; struct adxrs450_state *st = iio_priv(indio_dev); int ret; + struct spi_transfer xfers[] = { + { + .tx_buf = st->tx, + .bits_per_word = 8, + .len = 4, + .cs_change = 1, + }, { + .rx_buf = st->rx, + .bits_per_word = 8, + .len = 4, + }, + }; mutex_lock(&st->buf_lock); st->tx[0] = ADXRS450_READ_DATA | (reg_address >> 7); @@ -46,13 +59,10 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1)) st->tx[3] |= ADXRS450_P; - ret = spi_write(st->us, st->tx, 4); - if (ret) { - dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", - reg_address); - goto error_ret; - } - ret = spi_read(st->us, st->rx, 4); + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); if (ret) { dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", reg_address); @@ -105,8 +115,21 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, **/ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) { + struct spi_message msg; struct adxrs450_state *st = iio_priv(indio_dev); int ret; + struct spi_transfer xfers[] = { + { + .tx_buf = st->tx, + .bits_per_word = 8, + .len = 4, + .cs_change = 1, + }, { + .rx_buf = st->rx, + .bits_per_word = 8, + .len = 4, + }, + }; mutex_lock(&st->buf_lock); st->tx[0] = ADXRS450_SENSOR_DATA; @@ -114,13 +137,10 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) st->tx[2] = 0; st->tx[3] = 0; - ret = spi_write(st->us, st->tx, 4); - if (ret) { - dev_err(&st->us->dev, "Problem while reading sensor data\n"); - goto error_ret; - } - - ret = spi_read(st->us, st->rx, 4); + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); if (ret) { dev_err(&st->us->dev, "Problem while reading sensor data\n"); goto error_ret; -- cgit v0.10.2 From 1a87e4fba63cd82d74f23b6e0b75ad6b01b15774 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Make transfer buffers __be32 Fixes the following sparse warnings: drivers/staging/iio/gyro/adxrs450_core.c:46:15: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:62:17: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:89:15: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:129:17: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:168:16: warning: cast to restricted __be32 Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450.h b/drivers/staging/iio/gyro/adxrs450.h index f8cf21f..97abea3 100644 --- a/drivers/staging/iio/gyro/adxrs450.h +++ b/drivers/staging/iio/gyro/adxrs450.h @@ -4,9 +4,9 @@ #define ADXRS450_STARTUP_DELAY 50 /* ms */ /* The MSB for the spi commands */ -#define ADXRS450_SENSOR_DATA 0x20 -#define ADXRS450_WRITE_DATA 0x40 -#define ADXRS450_READ_DATA 0x80 +#define ADXRS450_SENSOR_DATA (0x20 << 24) +#define ADXRS450_WRITE_DATA (0x40 << 24) +#define ADXRS450_READ_DATA (0x80 << 24) #define ADXRS450_RATE1 0x00 /* Rate Registers */ #define ADXRS450_TEMP1 0x02 /* Temperature Registers */ @@ -54,8 +54,8 @@ enum { struct adxrs450_state { struct spi_device *us; struct mutex buf_lock; - u8 tx[ADXRS450_MAX_RX] ____cacheline_aligned; - u8 rx[ADXRS450_MAX_TX]; + __be32 tx ____cacheline_aligned; + __be32 rx; }; diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index 318e8c9..91a2fae 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -36,29 +36,28 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, { struct spi_message msg; struct adxrs450_state *st = iio_priv(indio_dev); + u32 tx; int ret; struct spi_transfer xfers[] = { { - .tx_buf = st->tx, + .tx_buf = &st->tx, .bits_per_word = 8, - .len = 4, + .len = sizeof(st->tx), .cs_change = 1, }, { - .rx_buf = st->rx, + .rx_buf = &st->rx, .bits_per_word = 8, - .len = 4, + .len = sizeof(st->rx), }, }; mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_READ_DATA | (reg_address >> 7); - st->tx[1] = reg_address << 1; - st->tx[2] = 0; - st->tx[3] = 0; + tx = ADXRS450_READ_DATA | (reg_address << 17); - if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1)) - st->tx[3] |= ADXRS450_P; + if (!(hweight32(tx) & 1)) + tx |= ADXRS450_P; + st->tx = cpu_to_be32(tx); spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); spi_message_add_tail(&xfers[1], &msg); @@ -69,7 +68,7 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, goto error_ret; } - *val = (be32_to_cpu(*(u32 *)st->rx) >> 5) & 0xFFFF; + *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF; error_ret: mutex_unlock(&st->buf_lock); @@ -88,18 +87,17 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, u16 val) { struct adxrs450_state *st = iio_priv(indio_dev); + u32 tx; int ret; mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_WRITE_DATA | reg_address >> 7; - st->tx[1] = reg_address << 1 | val >> 15; - st->tx[2] = val >> 7; - st->tx[3] = val << 1; + tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1); - if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1)) - st->tx[3] |= ADXRS450_P; + if (!(hweight32(tx) & 1)) + tx |= ADXRS450_P; - ret = spi_write(st->us, st->tx, 4); + st->tx = cpu_to_be32(tx); + ret = spi_write(st->us, &st->tx, sizeof(st->tx)); if (ret) dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", reg_address); @@ -120,22 +118,19 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) int ret; struct spi_transfer xfers[] = { { - .tx_buf = st->tx, + .tx_buf = &st->tx, .bits_per_word = 8, - .len = 4, + .len = sizeof(st->tx), .cs_change = 1, }, { - .rx_buf = st->rx, + .rx_buf = &st->rx, .bits_per_word = 8, - .len = 4, + .len = sizeof(st->rx), }, }; mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_SENSOR_DATA; - st->tx[1] = 0; - st->tx[2] = 0; - st->tx[3] = 0; + st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA); spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); @@ -146,7 +141,7 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) goto error_ret; } - *val = (be32_to_cpu(*(u32 *)st->rx) >> 10) & 0xFFFF; + *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF; error_ret: mutex_unlock(&st->buf_lock); @@ -163,20 +158,19 @@ static int adxrs450_spi_initial(struct adxrs450_state *st, { struct spi_message msg; int ret; + u32 tx; struct spi_transfer xfers = { - .tx_buf = st->tx, - .rx_buf = st->rx, + .tx_buf = &st->tx, + .rx_buf = &st->rx, .bits_per_word = 8, - .len = 4, + .len = sizeof(st->tx), }; mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_SENSOR_DATA; - st->tx[1] = 0; - st->tx[2] = 0; - st->tx[3] = 0; + tx = ADXRS450_SENSOR_DATA; if (chk) - st->tx[3] |= (ADXRS450_CHK | ADXRS450_P); + tx |= (ADXRS450_CHK | ADXRS450_P); + st->tx = cpu_to_be32(tx); spi_message_init(&msg); spi_message_add_tail(&xfers, &msg); ret = spi_sync(st->us, &msg); @@ -185,7 +179,7 @@ static int adxrs450_spi_initial(struct adxrs450_state *st, goto error_ret; } - *val = be32_to_cpu(*(u32 *)st->rx); + *val = be32_to_cpu(st->rx); error_ret: mutex_unlock(&st->buf_lock); -- cgit v0.10.2 From c62b89c713ebd5e4a67c9b9229591adab8953a3c Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Perform sign extension for the calibbias register The calibbias (DNC) register contains a 10-bit twos complement value. Perform a proper sign extension when reading the register, otherwise negative will incorrectly be displayed as large positive values. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index 91a2fae..4c462d3 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -326,7 +326,7 @@ static int adxrs450_read_raw(struct iio_dev *indio_dev, ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t); if (ret) break; - *val = t; + *val = sign_extend32(t, 9); ret = IIO_VAL_INT; break; default: -- cgit v0.10.2 From 9a26578c811e6f4de24d81ef734b17c401e5080f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Reject out of range calibscale values Instead of silently discarding the upper bits reject out of range values for the calibscale property. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index 4c462d3..96e5284 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -258,9 +258,10 @@ static int adxrs450_write_raw(struct iio_dev *indio_dev, int ret; switch (mask) { case IIO_CHAN_INFO_CALIBBIAS: + if (val < -0x400 || val >= 0x400) + return -EINVAL; ret = adxrs450_spi_write_reg_16(indio_dev, - ADXRS450_DNC1, - val & 0x3FF); + ADXRS450_DNC1, val); break; default: ret = -EINVAL; -- cgit v0.10.2 From ceac0cf209842e49c277ac301d4ce69b4db8239b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Don't spam the bootlog Don't spam the bootlog with the devices part id and serial number. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index 96e5284..24b7a0f 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -231,20 +231,6 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev) dev_err(&st->us->dev, "The device is not in normal status!\n"); return -EINVAL; } - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_PID1, &data); - if (ret) - return ret; - dev_info(&st->us->dev, "The Part ID is 0x%x\n", data); - - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_SNL, &data); - if (ret) - return ret; - t = data; - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_SNH, &data); - if (ret) - return ret; - t |= data << 16; - dev_info(&st->us->dev, "The Serial Number is 0x%x\n", t); return 0; } -- cgit v0.10.2 From 1439b6e8d1a1b158c11ecf398dd9bf3fcceb4861 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Reflow overlong lines Reflow two lines to meet the 80 characters per line limit. Fixes the following checkpatch warnings: WARNING: line over 80 characters #29: FILE: staging/iio/gyro/adxrs450_core.c:29: + * @reg_address: the address of the lower of the two registers,which should be an even address, WARNING: line over 80 characters #81: FILE: staging/iio/gyro/adxrs450_core.c:81: + * @reg_address: the address of the lower of the two registers,which should be an even address, Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index 24b7a0f..dd0b744 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -26,8 +26,8 @@ /** * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair * @dev: device associated with child of actual iio_dev - * @reg_address: the address of the lower of the two registers,which should be an even address, - * Second register's address is reg_address + 1. + * @reg_address: the address of the lower of the two registers, which should be + * an even address, the second register's address is reg_address + 1. * @val: somewhere to pass back the value read **/ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, @@ -78,8 +78,8 @@ error_ret: /** * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair * @dev: device associated with child of actual actual iio_dev - * @reg_address: the address of the lower of the two registers,which should be an even address, - * Second register's address is reg_address + 1. + * @reg_address: the address of the lower of the two registers,which should be + * an even address, the second register's address is reg_address + 1. * @val: value to be written. **/ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, -- cgit v0.10.2 From 457b71df27e4e6125b6627ad3d4ae1da023fc908 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Don't split string across multiple lines This is one of the exceptions to the 80 chars per line rule since breaking the string in half it badly affects the grep-ability. Fixes the following checkpatch warning: WARNING: quoted string split across lines #203: FILE: staging/iio/gyro/adxrs450_core.c:203: + dev_warn(&st->us->dev, "The initial power on response " + "is not correct! Restart without reset?\n"); Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index dd0b744..ea10f84 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -199,8 +199,7 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev) if (ret) return ret; if (t != 0x01) - dev_warn(&st->us->dev, "The initial power on response " - "is not correct! Restart without reset?\n"); + dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n"); msleep(ADXRS450_STARTUP_DELAY); ret = adxrs450_spi_initial(st, &t, 0); -- cgit v0.10.2 From 619036e216ce4d34f6d51ad2cf50380a54734c18 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Use usleep_range for the sequential transfer dealy The adxrs450 requires a delay of at least 0.1 ms between register writes. Using msleep() for such small delays is not recommended. So use usleep_range instead. Fixes the following checkpatch warning: WARNING: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt + msleep(1); Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index ea10f84..4115fe1 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -101,7 +101,7 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, if (ret) dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", reg_address); - msleep(1); /* enforce sequential transfer delay 0.1ms */ + usleep_range(100, 1000); /* enforce sequential transfer delay 0.1ms */ mutex_unlock(&st->buf_lock); return ret; } -- cgit v0.10.2 From d5e69c8350bbcf3c6058b0aceff32a2f2972485e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Fixup kernel doc comments Fix the name of the iio_device parameter for a few functions and add documentation for one missing function parameter. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index 4115fe1..714e323 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -25,7 +25,7 @@ /** * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair - * @dev: device associated with child of actual iio_dev + * @indio_dev: device associated with child of actual iio_dev * @reg_address: the address of the lower of the two registers, which should be * an even address, the second register's address is reg_address + 1. * @val: somewhere to pass back the value read @@ -77,7 +77,7 @@ error_ret: /** * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair - * @dev: device associated with child of actual actual iio_dev + * @indio_dev: device associated with child of actual actual iio_dev * @reg_address: the address of the lower of the two registers,which should be * an even address, the second register's address is reg_address + 1. * @val: value to be written. @@ -108,7 +108,7 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, /** * adxrs450_spi_sensor_data() - read 2 bytes sensor data - * @dev: device associated with child of actual iio_dev + * @indio_dev: device associated with child of actual iio_dev * @val: somewhere to pass back the value read **/ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) @@ -152,6 +152,7 @@ error_ret: * adxrs450_spi_initial() - use for initializing procedure. * @st: device instance specific data * @val: somewhere to pass back the value read + * @chk: Whether to perform fault check **/ static int adxrs450_spi_initial(struct adxrs450_state *st, u32 *val, char chk) -- cgit v0.10.2 From 53ac8500ba9badae82b0412d08e1db9f5b21b3d5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio:adxrs450: Move header file contents to main file The contents of the adxrs450 header file is not used outside the main drivers file, so just move the contents from the header file into the drivers main file. Also rename the adxrs450 driver file from adxrs450_core.c to adxrs450.c. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile index ef33161..6b4e60a 100644 --- a/drivers/staging/iio/gyro/Makefile +++ b/drivers/staging/iio/gyro/Makefile @@ -11,5 +11,4 @@ obj-$(CONFIG_ADIS16130) += adis16130.o adis16260-y := adis16260_core.o obj-$(CONFIG_ADIS16260) += adis16260.o -adxrs450-y := adxrs450_core.o obj-$(CONFIG_ADXRS450) += adxrs450.o diff --git a/drivers/staging/iio/gyro/adxrs450.c b/drivers/staging/iio/gyro/adxrs450.c new file mode 100644 index 0000000..d9d4383 --- /dev/null +++ b/drivers/staging/iio/gyro/adxrs450.c @@ -0,0 +1,497 @@ +/* + * ADXRS450/ADXRS453 Digital Output Gyroscope Driver + * + * Copyright 2011 Analog Devices Inc. + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define ADXRS450_STARTUP_DELAY 50 /* ms */ + +/* The MSB for the spi commands */ +#define ADXRS450_SENSOR_DATA (0x20 << 24) +#define ADXRS450_WRITE_DATA (0x40 << 24) +#define ADXRS450_READ_DATA (0x80 << 24) + +#define ADXRS450_RATE1 0x00 /* Rate Registers */ +#define ADXRS450_TEMP1 0x02 /* Temperature Registers */ +#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */ +#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */ +#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */ +#define ADXRS450_FAULT1 0x0A /* Fault Registers */ +#define ADXRS450_PID1 0x0C /* Part ID Register 1 */ +#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */ +#define ADXRS450_SNL 0x10 +#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */ +/* Check bits */ +#define ADXRS450_P 0x01 +#define ADXRS450_CHK 0x02 +#define ADXRS450_CST 0x04 +#define ADXRS450_PWR 0x08 +#define ADXRS450_POR 0x10 +#define ADXRS450_NVM 0x20 +#define ADXRS450_Q 0x40 +#define ADXRS450_PLL 0x80 +#define ADXRS450_UV 0x100 +#define ADXRS450_OV 0x200 +#define ADXRS450_AMP 0x400 +#define ADXRS450_FAIL 0x800 + +#define ADXRS450_WRERR_MASK (0x7 << 29) + +#define ADXRS450_MAX_RX 4 +#define ADXRS450_MAX_TX 4 + +#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3) + +enum { + ID_ADXRS450, + ID_ADXRS453, +}; + +/** + * struct adxrs450_state - device instance specific data + * @us: actual spi_device + * @buf_lock: mutex to protect tx and rx + * @tx: transmit buffer + * @rx: receive buffer + **/ +struct adxrs450_state { + struct spi_device *us; + struct mutex buf_lock; + __be32 tx ____cacheline_aligned; + __be32 rx; + +}; + +/** + * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair + * @indio_dev: device associated with child of actual iio_dev + * @reg_address: the address of the lower of the two registers, which should be + * an even address, the second register's address is reg_address + 1. + * @val: somewhere to pass back the value read + **/ +static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, + u8 reg_address, + u16 *val) +{ + struct spi_message msg; + struct adxrs450_state *st = iio_priv(indio_dev); + u32 tx; + int ret; + struct spi_transfer xfers[] = { + { + .tx_buf = &st->tx, + .bits_per_word = 8, + .len = sizeof(st->tx), + .cs_change = 1, + }, { + .rx_buf = &st->rx, + .bits_per_word = 8, + .len = sizeof(st->rx), + }, + }; + + mutex_lock(&st->buf_lock); + tx = ADXRS450_READ_DATA | (reg_address << 17); + + if (!(hweight32(tx) & 1)) + tx |= ADXRS450_P; + + st->tx = cpu_to_be32(tx); + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); + if (ret) { + dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", + reg_address); + goto error_ret; + } + + *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF; + +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +/** + * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair + * @indio_dev: device associated with child of actual actual iio_dev + * @reg_address: the address of the lower of the two registers,which should be + * an even address, the second register's address is reg_address + 1. + * @val: value to be written. + **/ +static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, + u8 reg_address, + u16 val) +{ + struct adxrs450_state *st = iio_priv(indio_dev); + u32 tx; + int ret; + + mutex_lock(&st->buf_lock); + tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1); + + if (!(hweight32(tx) & 1)) + tx |= ADXRS450_P; + + st->tx = cpu_to_be32(tx); + ret = spi_write(st->us, &st->tx, sizeof(st->tx)); + if (ret) + dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", + reg_address); + usleep_range(100, 1000); /* enforce sequential transfer delay 0.1ms */ + mutex_unlock(&st->buf_lock); + return ret; +} + +/** + * adxrs450_spi_sensor_data() - read 2 bytes sensor data + * @indio_dev: device associated with child of actual iio_dev + * @val: somewhere to pass back the value read + **/ +static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) +{ + struct spi_message msg; + struct adxrs450_state *st = iio_priv(indio_dev); + int ret; + struct spi_transfer xfers[] = { + { + .tx_buf = &st->tx, + .bits_per_word = 8, + .len = sizeof(st->tx), + .cs_change = 1, + }, { + .rx_buf = &st->rx, + .bits_per_word = 8, + .len = sizeof(st->rx), + }, + }; + + mutex_lock(&st->buf_lock); + st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA); + + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); + if (ret) { + dev_err(&st->us->dev, "Problem while reading sensor data\n"); + goto error_ret; + } + + *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF; + +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +/** + * adxrs450_spi_initial() - use for initializing procedure. + * @st: device instance specific data + * @val: somewhere to pass back the value read + * @chk: Whether to perform fault check + **/ +static int adxrs450_spi_initial(struct adxrs450_state *st, + u32 *val, char chk) +{ + struct spi_message msg; + int ret; + u32 tx; + struct spi_transfer xfers = { + .tx_buf = &st->tx, + .rx_buf = &st->rx, + .bits_per_word = 8, + .len = sizeof(st->tx), + }; + + mutex_lock(&st->buf_lock); + tx = ADXRS450_SENSOR_DATA; + if (chk) + tx |= (ADXRS450_CHK | ADXRS450_P); + st->tx = cpu_to_be32(tx); + spi_message_init(&msg); + spi_message_add_tail(&xfers, &msg); + ret = spi_sync(st->us, &msg); + if (ret) { + dev_err(&st->us->dev, "Problem while reading initializing data\n"); + goto error_ret; + } + + *val = be32_to_cpu(st->rx); + +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +/* Recommended Startup Sequence by spec */ +static int adxrs450_initial_setup(struct iio_dev *indio_dev) +{ + u32 t; + u16 data; + int ret; + struct adxrs450_state *st = iio_priv(indio_dev); + + msleep(ADXRS450_STARTUP_DELAY*2); + ret = adxrs450_spi_initial(st, &t, 1); + if (ret) + return ret; + if (t != 0x01) + dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n"); + + msleep(ADXRS450_STARTUP_DELAY); + ret = adxrs450_spi_initial(st, &t, 0); + if (ret) + return ret; + + msleep(ADXRS450_STARTUP_DELAY); + ret = adxrs450_spi_initial(st, &t, 0); + if (ret) + return ret; + if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { + dev_err(&st->us->dev, "The second response is not correct!\n"); + return -EIO; + + } + ret = adxrs450_spi_initial(st, &t, 0); + if (ret) + return ret; + if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { + dev_err(&st->us->dev, "The third response is not correct!\n"); + return -EIO; + + } + ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_FAULT1, &data); + if (ret) + return ret; + if (data & 0x0fff) { + dev_err(&st->us->dev, "The device is not in normal status!\n"); + return -EINVAL; + } + + return 0; +} + +static int adxrs450_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long mask) +{ + int ret; + switch (mask) { + case IIO_CHAN_INFO_CALIBBIAS: + if (val < -0x400 || val >= 0x400) + return -EINVAL; + ret = adxrs450_spi_write_reg_16(indio_dev, + ADXRS450_DNC1, val); + break; + default: + ret = -EINVAL; + break; + } + return ret; +} + +static int adxrs450_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) +{ + int ret; + s16 t; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_ANGL_VEL: + ret = adxrs450_spi_sensor_data(indio_dev, &t); + if (ret) + break; + *val = t; + ret = IIO_VAL_INT; + break; + case IIO_TEMP: + ret = adxrs450_spi_read_reg_16(indio_dev, + ADXRS450_TEMP1, &t); + if (ret) + break; + *val = (t >> 6) + 225; + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } + break; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = 0; + *val2 = 218166; + return IIO_VAL_INT_PLUS_NANO; + case IIO_TEMP: + *val = 200; + *val2 = 0; + return IIO_VAL_INT; + default: + return -EINVAL; + } + break; + case IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW: + ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_QUAD1, &t); + if (ret) + break; + *val = t; + ret = IIO_VAL_INT; + break; + case IIO_CHAN_INFO_CALIBBIAS: + ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t); + if (ret) + break; + *val = sign_extend32(t, 9); + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static const struct iio_chan_spec adxrs450_channels[2][2] = { + [ID_ADXRS450] = { + { + .type = IIO_ANGL_VEL, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | + IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + }, { + .type = IIO_TEMP, + .indexed = 1, + .channel = 0, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + } + }, + [ID_ADXRS453] = { + { + .type = IIO_ANGL_VEL, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT, + }, { + .type = IIO_TEMP, + .indexed = 1, + .channel = 0, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + } + }, +}; + +static const struct iio_info adxrs450_info = { + .driver_module = THIS_MODULE, + .read_raw = &adxrs450_read_raw, + .write_raw = &adxrs450_write_raw, +}; + +static int adxrs450_probe(struct spi_device *spi) +{ + int ret; + struct adxrs450_state *st; + struct iio_dev *indio_dev; + + /* setup the industrialio driver allocated elements */ + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) { + ret = -ENOMEM; + goto error_ret; + } + st = iio_priv(indio_dev); + st->us = spi; + mutex_init(&st->buf_lock); + /* This is only used for removal purposes */ + spi_set_drvdata(spi, indio_dev); + + indio_dev->dev.parent = &spi->dev; + indio_dev->info = &adxrs450_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = + adxrs450_channels[spi_get_device_id(spi)->driver_data]; + indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); + indio_dev->name = spi->dev.driver->name; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_free_dev; + + /* Get the device into a sane initial state */ + ret = adxrs450_initial_setup(indio_dev); + if (ret) + goto error_initial; + return 0; +error_initial: + iio_device_unregister(indio_dev); +error_free_dev: + iio_device_free(indio_dev); + +error_ret: + return ret; +} + +static int adxrs450_remove(struct spi_device *spi) +{ + iio_device_unregister(spi_get_drvdata(spi)); + iio_device_free(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id adxrs450_id[] = { + {"adxrs450", ID_ADXRS450}, + {"adxrs453", ID_ADXRS453}, + {} +}; +MODULE_DEVICE_TABLE(spi, adxrs450_id); + +static struct spi_driver adxrs450_driver = { + .driver = { + .name = "adxrs450", + .owner = THIS_MODULE, + }, + .probe = adxrs450_probe, + .remove = adxrs450_remove, + .id_table = adxrs450_id, +}; +module_spi_driver(adxrs450_driver); + +MODULE_AUTHOR("Cliff Cai "); +MODULE_DESCRIPTION("Analog Devices ADXRS450/ADXRS453 Gyroscope SPI driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/gyro/adxrs450.h b/drivers/staging/iio/gyro/adxrs450.h deleted file mode 100644 index 97abea3..0000000 --- a/drivers/staging/iio/gyro/adxrs450.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef SPI_ADXRS450_H_ -#define SPI_ADXRS450_H_ - -#define ADXRS450_STARTUP_DELAY 50 /* ms */ - -/* The MSB for the spi commands */ -#define ADXRS450_SENSOR_DATA (0x20 << 24) -#define ADXRS450_WRITE_DATA (0x40 << 24) -#define ADXRS450_READ_DATA (0x80 << 24) - -#define ADXRS450_RATE1 0x00 /* Rate Registers */ -#define ADXRS450_TEMP1 0x02 /* Temperature Registers */ -#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */ -#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */ -#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */ -#define ADXRS450_FAULT1 0x0A /* Fault Registers */ -#define ADXRS450_PID1 0x0C /* Part ID Register 1 */ -#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */ -#define ADXRS450_SNL 0x10 -#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */ -/* Check bits */ -#define ADXRS450_P 0x01 -#define ADXRS450_CHK 0x02 -#define ADXRS450_CST 0x04 -#define ADXRS450_PWR 0x08 -#define ADXRS450_POR 0x10 -#define ADXRS450_NVM 0x20 -#define ADXRS450_Q 0x40 -#define ADXRS450_PLL 0x80 -#define ADXRS450_UV 0x100 -#define ADXRS450_OV 0x200 -#define ADXRS450_AMP 0x400 -#define ADXRS450_FAIL 0x800 - -#define ADXRS450_WRERR_MASK (0x7 << 29) - -#define ADXRS450_MAX_RX 4 -#define ADXRS450_MAX_TX 4 - -#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3) - -enum { - ID_ADXRS450, - ID_ADXRS453, -}; - -/** - * struct adxrs450_state - device instance specific data - * @us: actual spi_device - * @buf_lock: mutex to protect tx and rx - * @tx: transmit buffer - * @rx: receive buffer - **/ -struct adxrs450_state { - struct spi_device *us; - struct mutex buf_lock; - __be32 tx ____cacheline_aligned; - __be32 rx; - -}; - -#endif /* SPI_ADXRS450_H_ */ diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c deleted file mode 100644 index 714e323..0000000 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * ADXRS450/ADXRS453 Digital Output Gyroscope Driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "adxrs450.h" - -/** - * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair - * @indio_dev: device associated with child of actual iio_dev - * @reg_address: the address of the lower of the two registers, which should be - * an even address, the second register's address is reg_address + 1. - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, - u8 reg_address, - u16 *val) -{ - struct spi_message msg; - struct adxrs450_state *st = iio_priv(indio_dev); - u32 tx; - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = &st->tx, - .bits_per_word = 8, - .len = sizeof(st->tx), - .cs_change = 1, - }, { - .rx_buf = &st->rx, - .bits_per_word = 8, - .len = sizeof(st->rx), - }, - }; - - mutex_lock(&st->buf_lock); - tx = ADXRS450_READ_DATA | (reg_address << 17); - - if (!(hweight32(tx) & 1)) - tx |= ADXRS450_P; - - st->tx = cpu_to_be32(tx); - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", - reg_address); - goto error_ret; - } - - *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair - * @indio_dev: device associated with child of actual actual iio_dev - * @reg_address: the address of the lower of the two registers,which should be - * an even address, the second register's address is reg_address + 1. - * @val: value to be written. - **/ -static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, - u8 reg_address, - u16 val) -{ - struct adxrs450_state *st = iio_priv(indio_dev); - u32 tx; - int ret; - - mutex_lock(&st->buf_lock); - tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1); - - if (!(hweight32(tx) & 1)) - tx |= ADXRS450_P; - - st->tx = cpu_to_be32(tx); - ret = spi_write(st->us, &st->tx, sizeof(st->tx)); - if (ret) - dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", - reg_address); - usleep_range(100, 1000); /* enforce sequential transfer delay 0.1ms */ - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_sensor_data() - read 2 bytes sensor data - * @indio_dev: device associated with child of actual iio_dev - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) -{ - struct spi_message msg; - struct adxrs450_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = &st->tx, - .bits_per_word = 8, - .len = sizeof(st->tx), - .cs_change = 1, - }, { - .rx_buf = &st->rx, - .bits_per_word = 8, - .len = sizeof(st->rx), - }, - }; - - mutex_lock(&st->buf_lock); - st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA); - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading sensor data\n"); - goto error_ret; - } - - *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_initial() - use for initializing procedure. - * @st: device instance specific data - * @val: somewhere to pass back the value read - * @chk: Whether to perform fault check - **/ -static int adxrs450_spi_initial(struct adxrs450_state *st, - u32 *val, char chk) -{ - struct spi_message msg; - int ret; - u32 tx; - struct spi_transfer xfers = { - .tx_buf = &st->tx, - .rx_buf = &st->rx, - .bits_per_word = 8, - .len = sizeof(st->tx), - }; - - mutex_lock(&st->buf_lock); - tx = ADXRS450_SENSOR_DATA; - if (chk) - tx |= (ADXRS450_CHK | ADXRS450_P); - st->tx = cpu_to_be32(tx); - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading initializing data\n"); - goto error_ret; - } - - *val = be32_to_cpu(st->rx); - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/* Recommended Startup Sequence by spec */ -static int adxrs450_initial_setup(struct iio_dev *indio_dev) -{ - u32 t; - u16 data; - int ret; - struct adxrs450_state *st = iio_priv(indio_dev); - - msleep(ADXRS450_STARTUP_DELAY*2); - ret = adxrs450_spi_initial(st, &t, 1); - if (ret) - return ret; - if (t != 0x01) - dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n"); - - msleep(ADXRS450_STARTUP_DELAY); - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - - msleep(ADXRS450_STARTUP_DELAY); - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { - dev_err(&st->us->dev, "The second response is not correct!\n"); - return -EIO; - - } - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { - dev_err(&st->us->dev, "The third response is not correct!\n"); - return -EIO; - - } - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_FAULT1, &data); - if (ret) - return ret; - if (data & 0x0fff) { - dev_err(&st->us->dev, "The device is not in normal status!\n"); - return -EINVAL; - } - - return 0; -} - -static int adxrs450_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - int ret; - switch (mask) { - case IIO_CHAN_INFO_CALIBBIAS: - if (val < -0x400 || val >= 0x400) - return -EINVAL; - ret = adxrs450_spi_write_reg_16(indio_dev, - ADXRS450_DNC1, val); - break; - default: - ret = -EINVAL; - break; - } - return ret; -} - -static int adxrs450_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long mask) -{ - int ret; - s16 t; - - switch (mask) { - case IIO_CHAN_INFO_RAW: - switch (chan->type) { - case IIO_ANGL_VEL: - ret = adxrs450_spi_sensor_data(indio_dev, &t); - if (ret) - break; - *val = t; - ret = IIO_VAL_INT; - break; - case IIO_TEMP: - ret = adxrs450_spi_read_reg_16(indio_dev, - ADXRS450_TEMP1, &t); - if (ret) - break; - *val = (t >> 6) + 225; - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - break; - } - break; - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_ANGL_VEL: - *val = 0; - *val2 = 218166; - return IIO_VAL_INT_PLUS_NANO; - case IIO_TEMP: - *val = 200; - *val2 = 0; - return IIO_VAL_INT; - default: - return -EINVAL; - } - break; - case IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW: - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_QUAD1, &t); - if (ret) - break; - *val = t; - ret = IIO_VAL_INT; - break; - case IIO_CHAN_INFO_CALIBBIAS: - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t); - if (ret) - break; - *val = sign_extend32(t, 9); - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - break; - } - - return ret; -} - -static const struct iio_chan_spec adxrs450_channels[2][2] = { - [ID_ADXRS450] = { - { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - } - }, - [ID_ADXRS453] = { - { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - } - }, -}; - -static const struct iio_info adxrs450_info = { - .driver_module = THIS_MODULE, - .read_raw = &adxrs450_read_raw, - .write_raw = &adxrs450_write_raw, -}; - -static int adxrs450_probe(struct spi_device *spi) -{ - int ret; - struct adxrs450_state *st; - struct iio_dev *indio_dev; - - /* setup the industrialio driver allocated elements */ - indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } - st = iio_priv(indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - /* This is only used for removal purposes */ - spi_set_drvdata(spi, indio_dev); - - indio_dev->dev.parent = &spi->dev; - indio_dev->info = &adxrs450_info; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = - adxrs450_channels[spi_get_device_id(spi)->driver_data]; - indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); - indio_dev->name = spi->dev.driver->name; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_free_dev; - - /* Get the device into a sane initial state */ - ret = adxrs450_initial_setup(indio_dev); - if (ret) - goto error_initial; - return 0; -error_initial: - iio_device_unregister(indio_dev); -error_free_dev: - iio_device_free(indio_dev); - -error_ret: - return ret; -} - -static int adxrs450_remove(struct spi_device *spi) -{ - iio_device_unregister(spi_get_drvdata(spi)); - iio_device_free(spi_get_drvdata(spi)); - - return 0; -} - -static const struct spi_device_id adxrs450_id[] = { - {"adxrs450", ID_ADXRS450}, - {"adxrs453", ID_ADXRS453}, - {} -}; -MODULE_DEVICE_TABLE(spi, adxrs450_id); - -static struct spi_driver adxrs450_driver = { - .driver = { - .name = "adxrs450", - .owner = THIS_MODULE, - }, - .probe = adxrs450_probe, - .remove = adxrs450_remove, - .id_table = adxrs450_id, -}; -module_spi_driver(adxrs450_driver); - -MODULE_AUTHOR("Cliff Cai "); -MODULE_DESCRIPTION("Analog Devices ADXRS450/ADXRS453 Gyroscope SPI driver"); -MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 420b0fcb523b61eefb347317d3956db3249e968d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 31 Jan 2013 14:27:00 +0000 Subject: staging:iio: Move adxrs450 driver out of staging The adxrs450 is in a reasonable shape now. It follows the IIO ABI and non of the standard code checker tools report any issue, so move it out of staging. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index c9f177d..51ac6bc 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -19,6 +19,16 @@ config ADIS16136 Say yes here to build support for the Analog Devices ADIS16133, ADIS16135, ADIS16136 gyroscope devices. +config ADXRS450 + tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADXRS450 and ADXRS453 + programmable digital output gyroscope. + + This driver can also be built as a module. If so, the module + will be called adxrs450. + config HID_SENSOR_GYRO_3D depends on HID_SENSOR_HUB select IIO_BUFFER diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index 66b517d..eff9bb0 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -4,6 +4,8 @@ obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16136) += adis16136.o +obj-$(CONFIG_ADXRS450) += adxrs450.o + obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o diff --git a/drivers/iio/gyro/adxrs450.c b/drivers/iio/gyro/adxrs450.c new file mode 100644 index 0000000..d9d4383 --- /dev/null +++ b/drivers/iio/gyro/adxrs450.c @@ -0,0 +1,497 @@ +/* + * ADXRS450/ADXRS453 Digital Output Gyroscope Driver + * + * Copyright 2011 Analog Devices Inc. + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define ADXRS450_STARTUP_DELAY 50 /* ms */ + +/* The MSB for the spi commands */ +#define ADXRS450_SENSOR_DATA (0x20 << 24) +#define ADXRS450_WRITE_DATA (0x40 << 24) +#define ADXRS450_READ_DATA (0x80 << 24) + +#define ADXRS450_RATE1 0x00 /* Rate Registers */ +#define ADXRS450_TEMP1 0x02 /* Temperature Registers */ +#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */ +#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */ +#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */ +#define ADXRS450_FAULT1 0x0A /* Fault Registers */ +#define ADXRS450_PID1 0x0C /* Part ID Register 1 */ +#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */ +#define ADXRS450_SNL 0x10 +#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */ +/* Check bits */ +#define ADXRS450_P 0x01 +#define ADXRS450_CHK 0x02 +#define ADXRS450_CST 0x04 +#define ADXRS450_PWR 0x08 +#define ADXRS450_POR 0x10 +#define ADXRS450_NVM 0x20 +#define ADXRS450_Q 0x40 +#define ADXRS450_PLL 0x80 +#define ADXRS450_UV 0x100 +#define ADXRS450_OV 0x200 +#define ADXRS450_AMP 0x400 +#define ADXRS450_FAIL 0x800 + +#define ADXRS450_WRERR_MASK (0x7 << 29) + +#define ADXRS450_MAX_RX 4 +#define ADXRS450_MAX_TX 4 + +#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3) + +enum { + ID_ADXRS450, + ID_ADXRS453, +}; + +/** + * struct adxrs450_state - device instance specific data + * @us: actual spi_device + * @buf_lock: mutex to protect tx and rx + * @tx: transmit buffer + * @rx: receive buffer + **/ +struct adxrs450_state { + struct spi_device *us; + struct mutex buf_lock; + __be32 tx ____cacheline_aligned; + __be32 rx; + +}; + +/** + * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair + * @indio_dev: device associated with child of actual iio_dev + * @reg_address: the address of the lower of the two registers, which should be + * an even address, the second register's address is reg_address + 1. + * @val: somewhere to pass back the value read + **/ +static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, + u8 reg_address, + u16 *val) +{ + struct spi_message msg; + struct adxrs450_state *st = iio_priv(indio_dev); + u32 tx; + int ret; + struct spi_transfer xfers[] = { + { + .tx_buf = &st->tx, + .bits_per_word = 8, + .len = sizeof(st->tx), + .cs_change = 1, + }, { + .rx_buf = &st->rx, + .bits_per_word = 8, + .len = sizeof(st->rx), + }, + }; + + mutex_lock(&st->buf_lock); + tx = ADXRS450_READ_DATA | (reg_address << 17); + + if (!(hweight32(tx) & 1)) + tx |= ADXRS450_P; + + st->tx = cpu_to_be32(tx); + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); + if (ret) { + dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", + reg_address); + goto error_ret; + } + + *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF; + +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +/** + * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair + * @indio_dev: device associated with child of actual actual iio_dev + * @reg_address: the address of the lower of the two registers,which should be + * an even address, the second register's address is reg_address + 1. + * @val: value to be written. + **/ +static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, + u8 reg_address, + u16 val) +{ + struct adxrs450_state *st = iio_priv(indio_dev); + u32 tx; + int ret; + + mutex_lock(&st->buf_lock); + tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1); + + if (!(hweight32(tx) & 1)) + tx |= ADXRS450_P; + + st->tx = cpu_to_be32(tx); + ret = spi_write(st->us, &st->tx, sizeof(st->tx)); + if (ret) + dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", + reg_address); + usleep_range(100, 1000); /* enforce sequential transfer delay 0.1ms */ + mutex_unlock(&st->buf_lock); + return ret; +} + +/** + * adxrs450_spi_sensor_data() - read 2 bytes sensor data + * @indio_dev: device associated with child of actual iio_dev + * @val: somewhere to pass back the value read + **/ +static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) +{ + struct spi_message msg; + struct adxrs450_state *st = iio_priv(indio_dev); + int ret; + struct spi_transfer xfers[] = { + { + .tx_buf = &st->tx, + .bits_per_word = 8, + .len = sizeof(st->tx), + .cs_change = 1, + }, { + .rx_buf = &st->rx, + .bits_per_word = 8, + .len = sizeof(st->rx), + }, + }; + + mutex_lock(&st->buf_lock); + st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA); + + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + ret = spi_sync(st->us, &msg); + if (ret) { + dev_err(&st->us->dev, "Problem while reading sensor data\n"); + goto error_ret; + } + + *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF; + +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +/** + * adxrs450_spi_initial() - use for initializing procedure. + * @st: device instance specific data + * @val: somewhere to pass back the value read + * @chk: Whether to perform fault check + **/ +static int adxrs450_spi_initial(struct adxrs450_state *st, + u32 *val, char chk) +{ + struct spi_message msg; + int ret; + u32 tx; + struct spi_transfer xfers = { + .tx_buf = &st->tx, + .rx_buf = &st->rx, + .bits_per_word = 8, + .len = sizeof(st->tx), + }; + + mutex_lock(&st->buf_lock); + tx = ADXRS450_SENSOR_DATA; + if (chk) + tx |= (ADXRS450_CHK | ADXRS450_P); + st->tx = cpu_to_be32(tx); + spi_message_init(&msg); + spi_message_add_tail(&xfers, &msg); + ret = spi_sync(st->us, &msg); + if (ret) { + dev_err(&st->us->dev, "Problem while reading initializing data\n"); + goto error_ret; + } + + *val = be32_to_cpu(st->rx); + +error_ret: + mutex_unlock(&st->buf_lock); + return ret; +} + +/* Recommended Startup Sequence by spec */ +static int adxrs450_initial_setup(struct iio_dev *indio_dev) +{ + u32 t; + u16 data; + int ret; + struct adxrs450_state *st = iio_priv(indio_dev); + + msleep(ADXRS450_STARTUP_DELAY*2); + ret = adxrs450_spi_initial(st, &t, 1); + if (ret) + return ret; + if (t != 0x01) + dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n"); + + msleep(ADXRS450_STARTUP_DELAY); + ret = adxrs450_spi_initial(st, &t, 0); + if (ret) + return ret; + + msleep(ADXRS450_STARTUP_DELAY); + ret = adxrs450_spi_initial(st, &t, 0); + if (ret) + return ret; + if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { + dev_err(&st->us->dev, "The second response is not correct!\n"); + return -EIO; + + } + ret = adxrs450_spi_initial(st, &t, 0); + if (ret) + return ret; + if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { + dev_err(&st->us->dev, "The third response is not correct!\n"); + return -EIO; + + } + ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_FAULT1, &data); + if (ret) + return ret; + if (data & 0x0fff) { + dev_err(&st->us->dev, "The device is not in normal status!\n"); + return -EINVAL; + } + + return 0; +} + +static int adxrs450_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long mask) +{ + int ret; + switch (mask) { + case IIO_CHAN_INFO_CALIBBIAS: + if (val < -0x400 || val >= 0x400) + return -EINVAL; + ret = adxrs450_spi_write_reg_16(indio_dev, + ADXRS450_DNC1, val); + break; + default: + ret = -EINVAL; + break; + } + return ret; +} + +static int adxrs450_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) +{ + int ret; + s16 t; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_ANGL_VEL: + ret = adxrs450_spi_sensor_data(indio_dev, &t); + if (ret) + break; + *val = t; + ret = IIO_VAL_INT; + break; + case IIO_TEMP: + ret = adxrs450_spi_read_reg_16(indio_dev, + ADXRS450_TEMP1, &t); + if (ret) + break; + *val = (t >> 6) + 225; + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } + break; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = 0; + *val2 = 218166; + return IIO_VAL_INT_PLUS_NANO; + case IIO_TEMP: + *val = 200; + *val2 = 0; + return IIO_VAL_INT; + default: + return -EINVAL; + } + break; + case IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW: + ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_QUAD1, &t); + if (ret) + break; + *val = t; + ret = IIO_VAL_INT; + break; + case IIO_CHAN_INFO_CALIBBIAS: + ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t); + if (ret) + break; + *val = sign_extend32(t, 9); + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static const struct iio_chan_spec adxrs450_channels[2][2] = { + [ID_ADXRS450] = { + { + .type = IIO_ANGL_VEL, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | + IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + }, { + .type = IIO_TEMP, + .indexed = 1, + .channel = 0, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + } + }, + [ID_ADXRS453] = { + { + .type = IIO_ANGL_VEL, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT, + }, { + .type = IIO_TEMP, + .indexed = 1, + .channel = 0, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + } + }, +}; + +static const struct iio_info adxrs450_info = { + .driver_module = THIS_MODULE, + .read_raw = &adxrs450_read_raw, + .write_raw = &adxrs450_write_raw, +}; + +static int adxrs450_probe(struct spi_device *spi) +{ + int ret; + struct adxrs450_state *st; + struct iio_dev *indio_dev; + + /* setup the industrialio driver allocated elements */ + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) { + ret = -ENOMEM; + goto error_ret; + } + st = iio_priv(indio_dev); + st->us = spi; + mutex_init(&st->buf_lock); + /* This is only used for removal purposes */ + spi_set_drvdata(spi, indio_dev); + + indio_dev->dev.parent = &spi->dev; + indio_dev->info = &adxrs450_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = + adxrs450_channels[spi_get_device_id(spi)->driver_data]; + indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); + indio_dev->name = spi->dev.driver->name; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_free_dev; + + /* Get the device into a sane initial state */ + ret = adxrs450_initial_setup(indio_dev); + if (ret) + goto error_initial; + return 0; +error_initial: + iio_device_unregister(indio_dev); +error_free_dev: + iio_device_free(indio_dev); + +error_ret: + return ret; +} + +static int adxrs450_remove(struct spi_device *spi) +{ + iio_device_unregister(spi_get_drvdata(spi)); + iio_device_free(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id adxrs450_id[] = { + {"adxrs450", ID_ADXRS450}, + {"adxrs453", ID_ADXRS453}, + {} +}; +MODULE_DEVICE_TABLE(spi, adxrs450_id); + +static struct spi_driver adxrs450_driver = { + .driver = { + .name = "adxrs450", + .owner = THIS_MODULE, + }, + .probe = adxrs450_probe, + .remove = adxrs450_remove, + .id_table = adxrs450_id, +}; +module_spi_driver(adxrs450_driver); + +MODULE_AUTHOR("Cliff Cai "); +MODULE_DESCRIPTION("Analog Devices ADXRS450/ADXRS453 Gyroscope SPI driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig index 658b367..8360662 100644 --- a/drivers/staging/iio/gyro/Kconfig +++ b/drivers/staging/iio/gyro/Kconfig @@ -29,14 +29,4 @@ config ADIS16260 This driver can also be built as a module. If so, the module will be called adis16260. -config ADXRS450 - tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver" - depends on SPI - help - Say yes here to build support for Analog Devices ADXRS450 and ADXRS453 - programmable digital output gyroscope. - - This driver can also be built as a module. If so, the module - will be called adxrs450. - endmenu diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile index 6b4e60a..98e6500 100644 --- a/drivers/staging/iio/gyro/Makefile +++ b/drivers/staging/iio/gyro/Makefile @@ -10,5 +10,3 @@ obj-$(CONFIG_ADIS16130) += adis16130.o adis16260-y := adis16260_core.o obj-$(CONFIG_ADIS16260) += adis16260.o - -obj-$(CONFIG_ADXRS450) += adxrs450.o diff --git a/drivers/staging/iio/gyro/adxrs450.c b/drivers/staging/iio/gyro/adxrs450.c deleted file mode 100644 index d9d4383..0000000 --- a/drivers/staging/iio/gyro/adxrs450.c +++ /dev/null @@ -1,497 +0,0 @@ -/* - * ADXRS450/ADXRS453 Digital Output Gyroscope Driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define ADXRS450_STARTUP_DELAY 50 /* ms */ - -/* The MSB for the spi commands */ -#define ADXRS450_SENSOR_DATA (0x20 << 24) -#define ADXRS450_WRITE_DATA (0x40 << 24) -#define ADXRS450_READ_DATA (0x80 << 24) - -#define ADXRS450_RATE1 0x00 /* Rate Registers */ -#define ADXRS450_TEMP1 0x02 /* Temperature Registers */ -#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */ -#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */ -#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */ -#define ADXRS450_FAULT1 0x0A /* Fault Registers */ -#define ADXRS450_PID1 0x0C /* Part ID Register 1 */ -#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */ -#define ADXRS450_SNL 0x10 -#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */ -/* Check bits */ -#define ADXRS450_P 0x01 -#define ADXRS450_CHK 0x02 -#define ADXRS450_CST 0x04 -#define ADXRS450_PWR 0x08 -#define ADXRS450_POR 0x10 -#define ADXRS450_NVM 0x20 -#define ADXRS450_Q 0x40 -#define ADXRS450_PLL 0x80 -#define ADXRS450_UV 0x100 -#define ADXRS450_OV 0x200 -#define ADXRS450_AMP 0x400 -#define ADXRS450_FAIL 0x800 - -#define ADXRS450_WRERR_MASK (0x7 << 29) - -#define ADXRS450_MAX_RX 4 -#define ADXRS450_MAX_TX 4 - -#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3) - -enum { - ID_ADXRS450, - ID_ADXRS453, -}; - -/** - * struct adxrs450_state - device instance specific data - * @us: actual spi_device - * @buf_lock: mutex to protect tx and rx - * @tx: transmit buffer - * @rx: receive buffer - **/ -struct adxrs450_state { - struct spi_device *us; - struct mutex buf_lock; - __be32 tx ____cacheline_aligned; - __be32 rx; - -}; - -/** - * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair - * @indio_dev: device associated with child of actual iio_dev - * @reg_address: the address of the lower of the two registers, which should be - * an even address, the second register's address is reg_address + 1. - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, - u8 reg_address, - u16 *val) -{ - struct spi_message msg; - struct adxrs450_state *st = iio_priv(indio_dev); - u32 tx; - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = &st->tx, - .bits_per_word = 8, - .len = sizeof(st->tx), - .cs_change = 1, - }, { - .rx_buf = &st->rx, - .bits_per_word = 8, - .len = sizeof(st->rx), - }, - }; - - mutex_lock(&st->buf_lock); - tx = ADXRS450_READ_DATA | (reg_address << 17); - - if (!(hweight32(tx) & 1)) - tx |= ADXRS450_P; - - st->tx = cpu_to_be32(tx); - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", - reg_address); - goto error_ret; - } - - *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair - * @indio_dev: device associated with child of actual actual iio_dev - * @reg_address: the address of the lower of the two registers,which should be - * an even address, the second register's address is reg_address + 1. - * @val: value to be written. - **/ -static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, - u8 reg_address, - u16 val) -{ - struct adxrs450_state *st = iio_priv(indio_dev); - u32 tx; - int ret; - - mutex_lock(&st->buf_lock); - tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1); - - if (!(hweight32(tx) & 1)) - tx |= ADXRS450_P; - - st->tx = cpu_to_be32(tx); - ret = spi_write(st->us, &st->tx, sizeof(st->tx)); - if (ret) - dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", - reg_address); - usleep_range(100, 1000); /* enforce sequential transfer delay 0.1ms */ - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_sensor_data() - read 2 bytes sensor data - * @indio_dev: device associated with child of actual iio_dev - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) -{ - struct spi_message msg; - struct adxrs450_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = &st->tx, - .bits_per_word = 8, - .len = sizeof(st->tx), - .cs_change = 1, - }, { - .rx_buf = &st->rx, - .bits_per_word = 8, - .len = sizeof(st->rx), - }, - }; - - mutex_lock(&st->buf_lock); - st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA); - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading sensor data\n"); - goto error_ret; - } - - *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_initial() - use for initializing procedure. - * @st: device instance specific data - * @val: somewhere to pass back the value read - * @chk: Whether to perform fault check - **/ -static int adxrs450_spi_initial(struct adxrs450_state *st, - u32 *val, char chk) -{ - struct spi_message msg; - int ret; - u32 tx; - struct spi_transfer xfers = { - .tx_buf = &st->tx, - .rx_buf = &st->rx, - .bits_per_word = 8, - .len = sizeof(st->tx), - }; - - mutex_lock(&st->buf_lock); - tx = ADXRS450_SENSOR_DATA; - if (chk) - tx |= (ADXRS450_CHK | ADXRS450_P); - st->tx = cpu_to_be32(tx); - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading initializing data\n"); - goto error_ret; - } - - *val = be32_to_cpu(st->rx); - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/* Recommended Startup Sequence by spec */ -static int adxrs450_initial_setup(struct iio_dev *indio_dev) -{ - u32 t; - u16 data; - int ret; - struct adxrs450_state *st = iio_priv(indio_dev); - - msleep(ADXRS450_STARTUP_DELAY*2); - ret = adxrs450_spi_initial(st, &t, 1); - if (ret) - return ret; - if (t != 0x01) - dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n"); - - msleep(ADXRS450_STARTUP_DELAY); - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - - msleep(ADXRS450_STARTUP_DELAY); - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { - dev_err(&st->us->dev, "The second response is not correct!\n"); - return -EIO; - - } - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { - dev_err(&st->us->dev, "The third response is not correct!\n"); - return -EIO; - - } - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_FAULT1, &data); - if (ret) - return ret; - if (data & 0x0fff) { - dev_err(&st->us->dev, "The device is not in normal status!\n"); - return -EINVAL; - } - - return 0; -} - -static int adxrs450_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - int ret; - switch (mask) { - case IIO_CHAN_INFO_CALIBBIAS: - if (val < -0x400 || val >= 0x400) - return -EINVAL; - ret = adxrs450_spi_write_reg_16(indio_dev, - ADXRS450_DNC1, val); - break; - default: - ret = -EINVAL; - break; - } - return ret; -} - -static int adxrs450_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long mask) -{ - int ret; - s16 t; - - switch (mask) { - case IIO_CHAN_INFO_RAW: - switch (chan->type) { - case IIO_ANGL_VEL: - ret = adxrs450_spi_sensor_data(indio_dev, &t); - if (ret) - break; - *val = t; - ret = IIO_VAL_INT; - break; - case IIO_TEMP: - ret = adxrs450_spi_read_reg_16(indio_dev, - ADXRS450_TEMP1, &t); - if (ret) - break; - *val = (t >> 6) + 225; - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - break; - } - break; - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_ANGL_VEL: - *val = 0; - *val2 = 218166; - return IIO_VAL_INT_PLUS_NANO; - case IIO_TEMP: - *val = 200; - *val2 = 0; - return IIO_VAL_INT; - default: - return -EINVAL; - } - break; - case IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW: - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_QUAD1, &t); - if (ret) - break; - *val = t; - ret = IIO_VAL_INT; - break; - case IIO_CHAN_INFO_CALIBBIAS: - ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t); - if (ret) - break; - *val = sign_extend32(t, 9); - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - break; - } - - return ret; -} - -static const struct iio_chan_spec adxrs450_channels[2][2] = { - [ID_ADXRS450] = { - { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - } - }, - [ID_ADXRS453] = { - { - .type = IIO_ANGL_VEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - } - }, -}; - -static const struct iio_info adxrs450_info = { - .driver_module = THIS_MODULE, - .read_raw = &adxrs450_read_raw, - .write_raw = &adxrs450_write_raw, -}; - -static int adxrs450_probe(struct spi_device *spi) -{ - int ret; - struct adxrs450_state *st; - struct iio_dev *indio_dev; - - /* setup the industrialio driver allocated elements */ - indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } - st = iio_priv(indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - /* This is only used for removal purposes */ - spi_set_drvdata(spi, indio_dev); - - indio_dev->dev.parent = &spi->dev; - indio_dev->info = &adxrs450_info; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = - adxrs450_channels[spi_get_device_id(spi)->driver_data]; - indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); - indio_dev->name = spi->dev.driver->name; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_free_dev; - - /* Get the device into a sane initial state */ - ret = adxrs450_initial_setup(indio_dev); - if (ret) - goto error_initial; - return 0; -error_initial: - iio_device_unregister(indio_dev); -error_free_dev: - iio_device_free(indio_dev); - -error_ret: - return ret; -} - -static int adxrs450_remove(struct spi_device *spi) -{ - iio_device_unregister(spi_get_drvdata(spi)); - iio_device_free(spi_get_drvdata(spi)); - - return 0; -} - -static const struct spi_device_id adxrs450_id[] = { - {"adxrs450", ID_ADXRS450}, - {"adxrs453", ID_ADXRS453}, - {} -}; -MODULE_DEVICE_TABLE(spi, adxrs450_id); - -static struct spi_driver adxrs450_driver = { - .driver = { - .name = "adxrs450", - .owner = THIS_MODULE, - }, - .probe = adxrs450_probe, - .remove = adxrs450_remove, - .id_table = adxrs450_id, -}; -module_spi_driver(adxrs450_driver); - -MODULE_AUTHOR("Cliff Cai "); -MODULE_DESCRIPTION("Analog Devices ADXRS450/ADXRS453 Gyroscope SPI driver"); -MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 9dbf091da080508e9f632d307f357beb79a0766b Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Fri, 1 Feb 2013 08:51:00 +0000 Subject: iio: gyro: Add itg3200 This patch adds support for the InvenSense itg3200. The itg3200 is a three-axis gyro with 16-bit ADC and I2C interface. Signed-off-by: Manuel Stahl Reviewed-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 51ac6bc..6be4628 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -70,4 +70,12 @@ config IIO_ST_GYRO_SPI_3AXIS depends on IIO_ST_GYRO_3AXIS depends on IIO_ST_SENSORS_SPI +config ITG3200 + tristate "InvenSense ITG3200 Digital 3-Axis Gyroscope I2C driver" + depends on I2C + select IIO_TRIGGERED_BUFFER if IIO_BUFFER + help + Say yes here to add support for the InvenSense ITG3200 digital + 3-axis gyroscope sensor. + endmenu diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index eff9bb0..225d289 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -8,6 +8,10 @@ obj-$(CONFIG_ADXRS450) += adxrs450.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o +itg3200-y := itg3200_core.o +itg3200-$(CONFIG_IIO_BUFFER) += itg3200_buffer.o +obj-$(CONFIG_ITG3200) += itg3200.o + obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o st_gyro-y := st_gyro_core.o st_gyro-$(CONFIG_IIO_BUFFER) += st_gyro_buffer.o diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c new file mode 100644 index 0000000..f667d2c --- /dev/null +++ b/drivers/iio/gyro/itg3200_buffer.c @@ -0,0 +1,156 @@ +/* + * itg3200_buffer.c -- support InvenSense ITG3200 + * Digital 3-Axis Gyroscope driver + * + * Copyright (c) 2011 Christian Strobel + * Copyright (c) 2011 Manuel Stahl + * Copyright (c) 2012 Thorsten Nowak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +static int itg3200_read_all_channels(struct i2c_client *i2c, __be16 *buf) +{ + u8 tx = 0x80 | ITG3200_REG_TEMP_OUT_H; + struct i2c_msg msg[2] = { + { + .addr = i2c->addr, + .flags = i2c->flags, + .len = 1, + .buf = &tx, + }, + { + .addr = i2c->addr, + .flags = i2c->flags | I2C_M_RD, + .len = ITG3200_SCAN_ELEMENTS * sizeof(s16), + .buf = (char *)&buf, + }, + }; + + return i2c_transfer(i2c->adapter, msg, 2); +} + +static irqreturn_t itg3200_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct itg3200 *st = iio_priv(indio_dev); + __be16 buf[ITG3200_SCAN_ELEMENTS + sizeof(s64)/sizeof(u16)]; + + int ret = itg3200_read_all_channels(st->i2c, buf); + if (ret < 0) + goto error_ret; + + if (indio_dev->scan_timestamp) + memcpy(buf + indio_dev->scan_bytes - sizeof(s64), + &pf->timestamp, sizeof(pf->timestamp)); + + iio_push_to_buffers(indio_dev, (u8 *)buf); + iio_trigger_notify_done(indio_dev->trig); + +error_ret: + return IRQ_HANDLED; +} + +int itg3200_buffer_configure(struct iio_dev *indio_dev) +{ + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + itg3200_trigger_handler, NULL); +} + +void itg3200_buffer_unconfigure(struct iio_dev *indio_dev) +{ + iio_triggered_buffer_cleanup(indio_dev); +} + + +static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + struct iio_dev *indio_dev = trig->private_data; + int ret; + u8 msc; + + ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_IRQ_CONFIG, &msc); + if (ret) + goto error_ret; + + if (state) + msc |= ITG3200_IRQ_DATA_RDY_ENABLE; + else + msc &= ~ITG3200_IRQ_DATA_RDY_ENABLE; + + ret = itg3200_write_reg_8(indio_dev, ITG3200_REG_IRQ_CONFIG, msc); + if (ret) + goto error_ret; + +error_ret: + return ret; + +} + +static const struct iio_trigger_ops itg3200_trigger_ops = { + .owner = THIS_MODULE, + .set_trigger_state = &itg3200_data_rdy_trigger_set_state, +}; + +int itg3200_probe_trigger(struct iio_dev *indio_dev) +{ + int ret; + struct itg3200 *st = iio_priv(indio_dev); + + st->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, + indio_dev->id); + if (!st->trig) + return -ENOMEM; + + ret = request_irq(st->i2c->irq, + &iio_trigger_generic_data_rdy_poll, + IRQF_TRIGGER_RISING, + "itg3200_data_rdy", + st->trig); + if (ret) + goto error_free_trig; + + + st->trig->dev.parent = &st->i2c->dev; + st->trig->ops = &itg3200_trigger_ops; + st->trig->private_data = indio_dev; + ret = iio_trigger_register(st->trig); + if (ret) + goto error_free_irq; + + /* select default trigger */ + indio_dev->trig = st->trig; + + return 0; + +error_free_irq: + free_irq(st->i2c->irq, st->trig); +error_free_trig: + iio_trigger_free(st->trig); + return ret; +} + +void itg3200_remove_trigger(struct iio_dev *indio_dev) +{ + struct itg3200 *st = iio_priv(indio_dev); + + iio_trigger_unregister(st->trig); + free_irq(st->i2c->irq, st->trig); + iio_trigger_free(st->trig); +} diff --git a/drivers/iio/gyro/itg3200_core.c b/drivers/iio/gyro/itg3200_core.c new file mode 100644 index 0000000..df2e6aa --- /dev/null +++ b/drivers/iio/gyro/itg3200_core.c @@ -0,0 +1,401 @@ +/* + * itg3200_core.c -- support InvenSense ITG3200 + * Digital 3-Axis Gyroscope driver + * + * Copyright (c) 2011 Christian Strobel + * Copyright (c) 2011 Manuel Stahl + * Copyright (c) 2012 Thorsten Nowak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * TODO: + * - Support digital low pass filter + * - Support power management + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + + +int itg3200_write_reg_8(struct iio_dev *indio_dev, + u8 reg_address, u8 val) +{ + struct itg3200 *st = iio_priv(indio_dev); + + return i2c_smbus_write_byte_data(st->i2c, 0x80 | reg_address, val); +} + +int itg3200_read_reg_8(struct iio_dev *indio_dev, + u8 reg_address, u8 *val) +{ + struct itg3200 *st = iio_priv(indio_dev); + int ret; + + ret = i2c_smbus_read_byte_data(st->i2c, reg_address); + if (ret < 0) + return ret; + *val = ret; + return 0; +} + +static int itg3200_read_reg_s16(struct iio_dev *indio_dev, u8 lower_reg_address, + int *val) +{ + struct itg3200 *st = iio_priv(indio_dev); + struct i2c_client *client = st->i2c; + int ret; + s16 out; + + struct i2c_msg msg[2] = { + { + .addr = client->addr, + .flags = client->flags, + .len = 1, + .buf = (char *)&lower_reg_address, + }, + { + .addr = client->addr, + .flags = client->flags | I2C_M_RD, + .len = 2, + .buf = (char *)&out, + }, + }; + + lower_reg_address |= 0x80; + ret = i2c_transfer(client->adapter, msg, 2); + be16_to_cpus(&out); + *val = out; + + return (ret == 2) ? 0 : ret; +} + +static int itg3200_read_raw(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + int *val, int *val2, long info) +{ + int ret = 0; + u8 reg; + + switch (info) { + case IIO_CHAN_INFO_RAW: + reg = (u8)chan->address; + ret = itg3200_read_reg_s16(indio_dev, reg, val); + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + if (chan->type == IIO_TEMP) + *val2 = 1000000000/280; + else + *val2 = 1214142; /* (1 / 14,375) * (PI / 180) */ + return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_OFFSET: + /* Only the temperature channel has an offset */ + *val = 23000; + return IIO_VAL_INT; + default: + return -EINVAL; + } + + return ret; +} + +static ssize_t itg3200_read_frequency(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + int ret, sps; + u8 val; + + ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &val); + if (ret) + return ret; + + sps = (val & ITG3200_DLPF_CFG_MASK) ? 1000 : 8000; + + ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_SAMPLE_RATE_DIV, &val); + if (ret) + return ret; + + sps /= val + 1; + + return sprintf(buf, "%d\n", sps); +} + +static ssize_t itg3200_write_frequency(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + unsigned val; + int ret; + u8 t; + + ret = kstrtouint(buf, 10, &val); + if (ret) + return ret; + + mutex_lock(&indio_dev->mlock); + + ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &t); + if (ret) + goto err_ret; + + if (val == 0) { + ret = -EINVAL; + goto err_ret; + } + t = ((t & ITG3200_DLPF_CFG_MASK) ? 1000u : 8000u) / val - 1; + + ret = itg3200_write_reg_8(indio_dev, ITG3200_REG_SAMPLE_RATE_DIV, t); + +err_ret: + mutex_unlock(&indio_dev->mlock); + + return ret ? ret : len; +} + +/* + * Reset device and internal registers to the power-up-default settings + * Use the gyro clock as reference, as suggested by the datasheet + */ +static int itg3200_reset(struct iio_dev *indio_dev) +{ + struct itg3200 *st = iio_priv(indio_dev); + int ret; + + dev_dbg(&st->i2c->dev, "reset device"); + + ret = itg3200_write_reg_8(indio_dev, + ITG3200_REG_POWER_MANAGEMENT, + ITG3200_RESET); + if (ret) { + dev_err(&st->i2c->dev, "error resetting device"); + goto error_ret; + } + + /* Wait for PLL (1ms according to datasheet) */ + udelay(1500); + + ret = itg3200_write_reg_8(indio_dev, + ITG3200_REG_IRQ_CONFIG, + ITG3200_IRQ_ACTIVE_HIGH | + ITG3200_IRQ_PUSH_PULL | + ITG3200_IRQ_LATCH_50US_PULSE | + ITG3200_IRQ_LATCH_CLEAR_ANY); + + if (ret) + dev_err(&st->i2c->dev, "error init device"); + +error_ret: + return ret; +} + +/* itg3200_enable_full_scale() - Disables the digital low pass filter */ +static int itg3200_enable_full_scale(struct iio_dev *indio_dev) +{ + u8 val; + int ret; + + ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &val); + if (ret) + goto err_ret; + + val |= ITG3200_DLPF_FS_SEL_2000; + return itg3200_write_reg_8(indio_dev, ITG3200_REG_DLPF, val); + +err_ret: + return ret; +} + +static int itg3200_initial_setup(struct iio_dev *indio_dev) +{ + struct itg3200 *st = iio_priv(indio_dev); + int ret; + u8 val; + + ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_ADDRESS, &val); + if (ret) + goto err_ret; + + if (((val >> 1) & 0x3f) != 0x34) { + dev_err(&st->i2c->dev, "invalid reg value 0x%02x", val); + ret = -ENXIO; + goto err_ret; + } + + ret = itg3200_reset(indio_dev); + if (ret) + goto err_ret; + + ret = itg3200_enable_full_scale(indio_dev); +err_ret: + return ret; +} + +#define ITG3200_TEMP_INFO_MASK (IIO_CHAN_INFO_OFFSET_SHARED_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_RAW_SEPARATE_BIT) +#define ITG3200_GYRO_INFO_MASK (IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_RAW_SEPARATE_BIT) + +#define ITG3200_ST \ + { .sign = 's', .realbits = 16, .storagebits = 16, .endianness = IIO_BE } + +#define ITG3200_GYRO_CHAN(_mod) { \ + .type = IIO_ANGL_VEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## _mod, \ + .info_mask = ITG3200_GYRO_INFO_MASK, \ + .address = ITG3200_REG_GYRO_ ## _mod ## OUT_H, \ + .scan_index = ITG3200_SCAN_GYRO_ ## _mod, \ + .scan_type = ITG3200_ST, \ +} + +static const struct iio_chan_spec itg3200_channels[] = { + { + .type = IIO_TEMP, + .channel2 = IIO_NO_MOD, + .info_mask = ITG3200_TEMP_INFO_MASK, + .address = ITG3200_REG_TEMP_OUT_H, + .scan_index = ITG3200_SCAN_TEMP, + .scan_type = ITG3200_ST, + }, + ITG3200_GYRO_CHAN(X), + ITG3200_GYRO_CHAN(Y), + ITG3200_GYRO_CHAN(Z), + IIO_CHAN_SOFT_TIMESTAMP(ITG3200_SCAN_ELEMENTS), +}; + +/* IIO device attributes */ +static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, itg3200_read_frequency, + itg3200_write_frequency); + +static struct attribute *itg3200_attributes[] = { + &iio_dev_attr_sampling_frequency.dev_attr.attr, + NULL +}; + +static const struct attribute_group itg3200_attribute_group = { + .attrs = itg3200_attributes, +}; + +static const struct iio_info itg3200_info = { + .attrs = &itg3200_attribute_group, + .read_raw = &itg3200_read_raw, + .driver_module = THIS_MODULE, +}; + +static const unsigned long itg3200_available_scan_masks[] = { 0xffffffff, 0x0 }; + +static int itg3200_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int ret; + struct itg3200 *st; + struct iio_dev *indio_dev; + + dev_dbg(&client->dev, "probe I2C dev with IRQ %i", client->irq); + + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) { + ret = -ENOMEM; + goto error_ret; + } + + st = iio_priv(indio_dev); + + i2c_set_clientdata(client, indio_dev); + st->i2c = client; + + indio_dev->dev.parent = &client->dev; + indio_dev->name = client->dev.driver->name; + indio_dev->channels = itg3200_channels; + indio_dev->num_channels = ARRAY_SIZE(itg3200_channels); + indio_dev->available_scan_masks = itg3200_available_scan_masks; + indio_dev->info = &itg3200_info; + indio_dev->modes = INDIO_DIRECT_MODE; + + ret = itg3200_buffer_configure(indio_dev); + if (ret) + goto error_free_dev; + + if (client->irq) { + ret = itg3200_probe_trigger(indio_dev); + if (ret) + goto error_unconfigure_buffer; + } + + ret = itg3200_initial_setup(indio_dev); + if (ret) + goto error_remove_trigger; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_remove_trigger; + + return 0; + +error_remove_trigger: + if (client->irq) + itg3200_remove_trigger(indio_dev); +error_unconfigure_buffer: + itg3200_buffer_unconfigure(indio_dev); +error_free_dev: + iio_device_free(indio_dev); +error_ret: + return ret; +} + +static int itg3200_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + + iio_device_unregister(indio_dev); + + if (client->irq) + itg3200_remove_trigger(indio_dev); + + itg3200_buffer_unconfigure(indio_dev); + + iio_device_free(indio_dev); + + return 0; +} + +static const struct i2c_device_id itg3200_id[] = { + { "itg3200", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, itg3200_id); + +static struct i2c_driver itg3200_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "itg3200", + }, + .id_table = itg3200_id, + .probe = itg3200_probe, + .remove = itg3200_remove, +}; + +module_i2c_driver(itg3200_driver); + +MODULE_AUTHOR("Christian Strobel "); +MODULE_DESCRIPTION("ITG3200 Gyroscope I2C driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/iio/gyro/itg3200.h b/include/linux/iio/gyro/itg3200.h new file mode 100644 index 0000000..c53f169 --- /dev/null +++ b/include/linux/iio/gyro/itg3200.h @@ -0,0 +1,154 @@ +/* + * itg3200.h -- support InvenSense ITG3200 + * Digital 3-Axis Gyroscope driver + * + * Copyright (c) 2011 Christian Strobel + * Copyright (c) 2011 Manuel Stahl + * Copyright (c) 2012 Thorsten Nowak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef I2C_ITG3200_H_ +#define I2C_ITG3200_H_ + +#include + +/* Register with I2C address (34h) */ +#define ITG3200_REG_ADDRESS 0x00 + +/* Sample rate divider + * Range: 0 to 255 + * Default value: 0x00 */ +#define ITG3200_REG_SAMPLE_RATE_DIV 0x15 + +/* Digital low pass filter settings */ +#define ITG3200_REG_DLPF 0x16 +/* DLPF full scale range */ +#define ITG3200_DLPF_FS_SEL_2000 0x18 +/* Bandwidth (Hz) and internal sample rate + * (kHz) of DLPF */ +#define ITG3200_DLPF_256_8 0x00 +#define ITG3200_DLPF_188_1 0x01 +#define ITG3200_DLPF_98_1 0x02 +#define ITG3200_DLPF_42_1 0x03 +#define ITG3200_DLPF_20_1 0x04 +#define ITG3200_DLPF_10_1 0x05 +#define ITG3200_DLPF_5_1 0x06 + +#define ITG3200_DLPF_CFG_MASK 0x07 + +/* Configuration for interrupt operations */ +#define ITG3200_REG_IRQ_CONFIG 0x17 +/* Logic level */ +#define ITG3200_IRQ_ACTIVE_LOW 0x80 +#define ITG3200_IRQ_ACTIVE_HIGH 0x00 +/* Drive type */ +#define ITG3200_IRQ_OPEN_DRAIN 0x40 +#define ITG3200_IRQ_PUSH_PULL 0x00 +/* Latch mode */ +#define ITG3200_IRQ_LATCH_UNTIL_CLEARED 0x20 +#define ITG3200_IRQ_LATCH_50US_PULSE 0x00 +/* Latch clear method */ +#define ITG3200_IRQ_LATCH_CLEAR_ANY 0x10 +#define ITG3200_IRQ_LATCH_CLEAR_STATUS 0x00 +/* Enable interrupt when device is ready */ +#define ITG3200_IRQ_DEVICE_RDY_ENABLE 0x04 +/* Enable interrupt when data is available */ +#define ITG3200_IRQ_DATA_RDY_ENABLE 0x01 + +/* Determine the status of ITG-3200 interrupts */ +#define ITG3200_REG_IRQ_STATUS 0x1A +/* Status of 'device is ready'-interrupt */ +#define ITG3200_IRQ_DEVICE_RDY_STATUS 0x04 +/* Status of 'data is available'-interrupt */ +#define ITG3200_IRQ_DATA_RDY_STATUS 0x01 + +/* Sensor registers */ +#define ITG3200_REG_TEMP_OUT_H 0x1B +#define ITG3200_REG_TEMP_OUT_L 0x1C +#define ITG3200_REG_GYRO_XOUT_H 0x1D +#define ITG3200_REG_GYRO_XOUT_L 0x1E +#define ITG3200_REG_GYRO_YOUT_H 0x1F +#define ITG3200_REG_GYRO_YOUT_L 0x20 +#define ITG3200_REG_GYRO_ZOUT_H 0x21 +#define ITG3200_REG_GYRO_ZOUT_L 0x22 + +/* Power management */ +#define ITG3200_REG_POWER_MANAGEMENT 0x3E +/* Reset device and internal registers to the + * power-up-default settings */ +#define ITG3200_RESET 0x80 +/* Enable low power sleep mode */ +#define ITG3200_SLEEP 0x40 +/* Put according gyroscope in standby mode */ +#define ITG3200_STANDBY_GYRO_X 0x20 +#define ITG3200_STANDBY_GYRO_Y 0x10 +#define ITG3200_STANDBY_GYRO_Z 0x08 +/* Determine the device clock source */ +#define ITG3200_CLK_INTERNAL 0x00 +#define ITG3200_CLK_GYRO_X 0x01 +#define ITG3200_CLK_GYRO_Y 0x02 +#define ITG3200_CLK_GYRO_Z 0x03 +#define ITG3200_CLK_EXT_32K 0x04 +#define ITG3200_CLK_EXT_19M 0x05 + + +/** + * struct itg3200 - device instance specific data + * @i2c: actual i2c_client + * @trig: data ready trigger from itg3200 pin + **/ +struct itg3200 { + struct i2c_client *i2c; + struct iio_trigger *trig; +}; + +enum ITG3200_SCAN_INDEX { + ITG3200_SCAN_TEMP, + ITG3200_SCAN_GYRO_X, + ITG3200_SCAN_GYRO_Y, + ITG3200_SCAN_GYRO_Z, + ITG3200_SCAN_ELEMENTS, +}; + +int itg3200_write_reg_8(struct iio_dev *indio_dev, + u8 reg_address, u8 val); + +int itg3200_read_reg_8(struct iio_dev *indio_dev, + u8 reg_address, u8 *val); + + +#ifdef CONFIG_IIO_BUFFER + +void itg3200_remove_trigger(struct iio_dev *indio_dev); +int itg3200_probe_trigger(struct iio_dev *indio_dev); + +int itg3200_buffer_configure(struct iio_dev *indio_dev); +void itg3200_buffer_unconfigure(struct iio_dev *indio_dev); + +#else /* CONFIG_IIO_BUFFER */ + +static inline void itg3200_remove_trigger(struct iio_dev *indio_dev) +{ +} + +static inline int itg3200_probe_trigger(struct iio_dev *indio_dev) +{ + return 0; +} + +static inline int itg3200_buffer_configure(struct iio_dev *indio_dev) +{ + return 0; +} + +static inline void itg3200_buffer_unconfigure(struct iio_dev *indio_dev) +{ +} + +#endif /* CONFIG_IIO_RING_BUFFER */ + +#endif /* ITG3200_H_ */ -- cgit v0.10.2 From 4d2e4fc224d0d5e56fdb0baa7cd135d1557b0a25 Mon Sep 17 00:00:00 2001 From: Denis CIOCCA Date: Wed, 30 Jan 2013 09:15:00 +0000 Subject: iio:common: removed unused functions outside st_sensors library This patch remove st_sensors_get_sampling_frequency_avl and st_sensors_get_scale_avl functions used only in st_sensors_sysfs_sampling_frequency_avail and st_sensors_sysfs_scale_avail sysfs functions. Signed-off-by: Denis Ciocca Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index fba6d68..0198324 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -38,46 +38,6 @@ st_sensors_write_data_with_mask_error: return err; } -int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev, char *buf) -{ - int i, len = 0; - struct st_sensor_data *sdata = iio_priv(indio_dev); - - mutex_lock(&indio_dev->mlock); - for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { - if (sdata->sensor->odr.odr_avl[i].hz == 0) - break; - - len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", - sdata->sensor->odr.odr_avl[i].hz); - } - mutex_unlock(&indio_dev->mlock); - buf[len - 1] = '\n'; - - return len; -} -EXPORT_SYMBOL(st_sensors_get_sampling_frequency_avl); - -int st_sensors_get_scale_avl(struct iio_dev *indio_dev, char *buf) -{ - int i, len = 0; - struct st_sensor_data *sdata = iio_priv(indio_dev); - - mutex_lock(&indio_dev->mlock); - for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { - if (sdata->sensor->fs.fs_avl[i].num == 0) - break; - - len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", - sdata->sensor->fs.fs_avl[i].gain); - } - mutex_unlock(&indio_dev->mlock); - buf[len - 1] = '\n'; - - return len; -} -EXPORT_SYMBOL(st_sensors_get_scale_avl); - static int st_sensors_match_odr(struct st_sensors *sensor, unsigned int odr, struct st_sensor_odr_avl *odr_out) { @@ -440,18 +400,44 @@ EXPORT_SYMBOL(st_sensors_sysfs_set_sampling_frequency); ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, struct device_attribute *attr, char *buf) { + int i, len = 0; struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct st_sensor_data *sdata = iio_priv(indio_dev); + + mutex_lock(&indio_dev->mlock); + for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { + if (sdata->sensor->odr.odr_avl[i].hz == 0) + break; + + len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", + sdata->sensor->odr.odr_avl[i].hz); + } + mutex_unlock(&indio_dev->mlock); + buf[len - 1] = '\n'; - return st_sensors_get_sampling_frequency_avl(indio_dev, buf); + return len; } EXPORT_SYMBOL(st_sensors_sysfs_sampling_frequency_avail); ssize_t st_sensors_sysfs_scale_avail(struct device *dev, struct device_attribute *attr, char *buf) { + int i, len = 0; struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct st_sensor_data *sdata = iio_priv(indio_dev); + + mutex_lock(&indio_dev->mlock); + for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { + if (sdata->sensor->fs.fs_avl[i].num == 0) + break; + + len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", + sdata->sensor->fs.fs_avl[i].gain); + } + mutex_unlock(&indio_dev->mlock); + buf[len - 1] = '\n'; - return st_sensors_get_scale_avl(indio_dev, buf); + return len; } EXPORT_SYMBOL(st_sensors_sysfs_scale_avail); diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index 3cc8571..c40fdf5 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -243,10 +243,6 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable); int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable); -int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev, char *buf); - -int st_sensors_get_scale_avl(struct iio_dev *indio_dev, char *buf); - int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr); int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable); -- cgit v0.10.2 From c4ac7b98bdeb04ffe867512f938a77d517cd9c6e Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:42:00 +0000 Subject: staging/iio: (iio_hwmon) Use devm_kzalloc Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c index 97ad645..fba8605 100644 --- a/drivers/staging/iio/iio_hwmon.c +++ b/drivers/staging/iio/iio_hwmon.c @@ -55,63 +55,47 @@ static ssize_t iio_hwmon_read_val(struct device *dev, return sprintf(buf, "%d\n", result); } -static void iio_hwmon_free_attrs(struct iio_hwmon_state *st) -{ - int i; - struct sensor_device_attribute *a; - for (i = 0; i < st->num_channels; i++) - if (st->attrs[i]) { - a = to_sensor_dev_attr( - container_of(st->attrs[i], - struct device_attribute, - attr)); - kfree(a); - } -} - static int iio_hwmon_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct iio_hwmon_state *st; struct sensor_device_attribute *a; int ret, i; int in_i = 1, temp_i = 1, curr_i = 1; enum iio_chan_type type; - st = kzalloc(sizeof(*st), GFP_KERNEL); - if (st == NULL) { - ret = -ENOMEM; - goto error_ret; - } + st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + if (st == NULL) + return -ENOMEM; - st->channels = iio_channel_get_all(dev_name(&pdev->dev)); - if (IS_ERR(st->channels)) { - ret = PTR_ERR(st->channels); - goto error_free_state; - } + st->channels = iio_channel_get_all(dev_name(dev)); + if (IS_ERR(st->channels)) + return PTR_ERR(st->channels); /* count how many attributes we have */ while (st->channels[st->num_channels].indio_dev) st->num_channels++; - st->attrs = kzalloc(sizeof(*st->attrs) * (st->num_channels + 1), - GFP_KERNEL); + st->attrs = devm_kzalloc(dev, + sizeof(*st->attrs) * (st->num_channels + 1), + GFP_KERNEL); if (st->attrs == NULL) { ret = -ENOMEM; goto error_release_channels; } + for (i = 0; i < st->num_channels; i++) { - a = kzalloc(sizeof(*a), GFP_KERNEL); + a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL); if (a == NULL) { ret = -ENOMEM; - goto error_free_attrs; + goto error_release_channels; } sysfs_attr_init(&a->dev_attr.attr); ret = iio_get_channel_type(&st->channels[i], &type); - if (ret < 0) { - kfree(a); - goto error_free_attrs; - } + if (ret < 0) + goto error_release_channels; + switch (type) { case IIO_VOLTAGE: a->dev_attr.attr.name = kasprintf(GFP_KERNEL, @@ -130,13 +114,11 @@ static int iio_hwmon_probe(struct platform_device *pdev) break; default: ret = -EINVAL; - kfree(a); - goto error_free_attrs; + goto error_release_channels; } if (a->dev_attr.attr.name == NULL) { - kfree(a); ret = -ENOMEM; - goto error_free_attrs; + goto error_release_channels; } a->dev_attr.show = iio_hwmon_read_val; a->dev_attr.attr.mode = S_IRUGO; @@ -146,11 +128,11 @@ static int iio_hwmon_probe(struct platform_device *pdev) st->attr_group.attrs = st->attrs; platform_set_drvdata(pdev, st); - ret = sysfs_create_group(&pdev->dev.kobj, &st->attr_group); + ret = sysfs_create_group(&dev->kobj, &st->attr_group); if (ret < 0) - goto error_free_attrs; + goto error_release_channels; - st->hwmon_dev = hwmon_device_register(&pdev->dev); + st->hwmon_dev = hwmon_device_register(dev); if (IS_ERR(st->hwmon_dev)) { ret = PTR_ERR(st->hwmon_dev); goto error_remove_group; @@ -158,15 +140,9 @@ static int iio_hwmon_probe(struct platform_device *pdev) return 0; error_remove_group: - sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); -error_free_attrs: - iio_hwmon_free_attrs(st); - kfree(st->attrs); + sysfs_remove_group(&dev->kobj, &st->attr_group); error_release_channels: iio_channel_release_all(st->channels); -error_free_state: - kfree(st); -error_ret: return ret; } @@ -176,8 +152,6 @@ static int iio_hwmon_remove(struct platform_device *pdev) hwmon_device_unregister(st->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); - iio_hwmon_free_attrs(st); - kfree(st->attrs); iio_channel_release_all(st->channels); return 0; -- cgit v0.10.2 From 1daed9becdd4c9a3f75a84ebdb4d05b4dade8512 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:42:00 +0000 Subject: staging/iio: (iio_hwmon) Add support for sysfs name attribute The 'name' attribute is mandatory for hwmon devices. Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c index fba8605..a9f3b64 100644 --- a/drivers/staging/iio/iio_hwmon.c +++ b/drivers/staging/iio/iio_hwmon.c @@ -55,6 +55,14 @@ static ssize_t iio_hwmon_read_val(struct device *dev, return sprintf(buf, "%d\n", result); } +static ssize_t show_name(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "iio_hwmon\n"); +} + +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); + static int iio_hwmon_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -77,7 +85,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) st->num_channels++; st->attrs = devm_kzalloc(dev, - sizeof(*st->attrs) * (st->num_channels + 1), + sizeof(*st->attrs) * (st->num_channels + 2), GFP_KERNEL); if (st->attrs == NULL) { ret = -ENOMEM; @@ -125,7 +133,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) a->index = i; st->attrs[i] = &a->dev_attr.attr; } - + st->attrs[st->num_channels] = &dev_attr_name.attr; st->attr_group.attrs = st->attrs; platform_set_drvdata(pdev, st); ret = sysfs_create_group(&dev->kobj, &st->attr_group); -- cgit v0.10.2 From a11e619b80ff39d081e1a18d26b652e15069503e Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: staging/iio: (iio_hwmon) Basic devicetree support Add 'iio-hwmon' OF compatibility table entry to enable OF matches. Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c index a9f3b64..d4ef34f 100644 --- a/drivers/staging/iio/iio_hwmon.c +++ b/drivers/staging/iio/iio_hwmon.c @@ -165,10 +165,16 @@ static int iio_hwmon_remove(struct platform_device *pdev) return 0; } +static struct of_device_id iio_hwmon_of_match[] = { + { .compatible = "iio-hwmon", }, + { } +}; + static struct platform_driver __refdata iio_hwmon_driver = { .driver = { .name = "iio_hwmon", .owner = THIS_MODULE, + .of_match_table = iio_hwmon_of_match, }, .probe = iio_hwmon_probe, .remove = iio_hwmon_remove, -- cgit v0.10.2 From c3a69e6c11d0c341c5c610be219bfcb56bbfcfb1 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio/adc: (lp8788) Provide OF node information to iio device Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c index f8bcb1f..d02704c 100644 --- a/drivers/iio/adc/lp8788_adc.c +++ b/drivers/iio/adc/lp8788_adc.c @@ -208,6 +208,7 @@ static int lp8788_adc_probe(struct platform_device *pdev) adc->lp = lp; platform_set_drvdata(pdev, indio_dev); + indio_dev->dev.of_node = pdev->dev.of_node; ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc); if (ret) goto err_iio_map; -- cgit v0.10.2 From 315ce4b882ad616139a811f5274c16556c5abdf3 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio/adc: (max1363) Provide OF node information to iio device Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index eba1034..65eceed 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1538,6 +1538,7 @@ static int max1363_probe(struct i2c_client *client, goto error_out; } + indio_dev->dev.of_node = client->dev.of_node; ret = iio_map_array_register(indio_dev, client->dev.platform_data); if (ret < 0) goto error_free_device; -- cgit v0.10.2 From dcb9ca0a25e1ccab9ad6827887c08e2b6b65f38e Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio/adc: (max1363) Remove duplicate code Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 65eceed..77c123f 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1572,8 +1572,6 @@ static int max1363_probe(struct i2c_client *client, indio_dev->num_channels = st->chip_info->num_channels; indio_dev->info = st->chip_info->info; indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = st->chip_info->channels; - indio_dev->num_channels = st->chip_info->num_channels; ret = max1363_initial_setup(st); if (ret < 0) goto error_free_available_scan_masks; -- cgit v0.10.2 From 482bb4e6c648a68598cde9d4a56b066df26d5ae6 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio/adc: (max1363) Fix data conversion problems For chips with more than 8 bit ADC resolution, received data was always masked against 0xfff, ie with a 12 bit mask. This can result in bad data for chips with 10 bit resolution if those chips have higher bits set (seen with MAX1139). The receive buffer was defined as char array. This could result in unintentional sign extensions if the upper bit in a received byte was set. Since the chip is configured for unipolar mode, we never have to handle negative values, and sign extensions are never needed. Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 77c123f..4673238 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -335,7 +335,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, { int ret = 0; s32 data; - char rxbuf[2]; + u8 rxbuf[2]; struct max1363_state *st = iio_priv(indio_dev); struct i2c_client *client = st->client; @@ -367,7 +367,8 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, ret = data; goto error_ret; } - data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; + data = (rxbuf[1] | rxbuf[0] << 8) & + ((1 << st->chip_info->bits) - 1); } else { /* Get reading */ data = i2c_master_recv(client, rxbuf, 1); -- cgit v0.10.2 From ca7d98dbd7db6aa8bc4b08e26be1249436d21af3 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio: Update iio_channel_get_all and iio_channel_get_all_cb API Pass device pointer instead of device name as parameter to iio_channel_get_all and iio_channel_get_all_cb. This will enable us to use OF information to retrieve consumer channel information. Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/buffer_cb.c b/drivers/iio/buffer_cb.c index 4d40e24..9201022 100644 --- a/drivers/iio/buffer_cb.c +++ b/drivers/iio/buffer_cb.c @@ -25,7 +25,7 @@ static struct iio_buffer_access_funcs iio_cb_access = { .store_to = &iio_buffer_cb_store_to, }; -struct iio_cb_buffer *iio_channel_get_all_cb(const char *name, +struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, int (*cb)(u8 *data, void *private), void *private) @@ -46,7 +46,7 @@ struct iio_cb_buffer *iio_channel_get_all_cb(const char *name, cb_buff->buffer.access = &iio_cb_access; INIT_LIST_HEAD(&cb_buff->buffer.demux_list); - cb_buff->channels = iio_channel_get_all(name); + cb_buff->channels = iio_channel_get_all(dev); if (IS_ERR(cb_buff->channels)) { ret = PTR_ERR(cb_buff->channels); goto error_free_cb_buff; diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index d55e98f..58d0ffe 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -167,16 +167,18 @@ void iio_channel_release(struct iio_channel *channel) } EXPORT_SYMBOL_GPL(iio_channel_release); -struct iio_channel *iio_channel_get_all(const char *name) +struct iio_channel *iio_channel_get_all(struct device *dev) { + const char *name; struct iio_channel *chans; struct iio_map_internal *c = NULL; int nummaps = 0; int mapind = 0; int i, ret; - if (name == NULL) + if (dev == NULL) return ERR_PTR(-EINVAL); + name = dev_name(dev); mutex_lock(&iio_map_list_lock); /* first count the matching maps */ diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c index d4ef34f..93af756 100644 --- a/drivers/staging/iio/iio_hwmon.c +++ b/drivers/staging/iio/iio_hwmon.c @@ -71,14 +71,17 @@ static int iio_hwmon_probe(struct platform_device *pdev) int ret, i; int in_i = 1, temp_i = 1, curr_i = 1; enum iio_chan_type type; + struct iio_channel *channels; + + channels = iio_channel_get_all(dev); + if (IS_ERR(channels)) + return PTR_ERR(channels); st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); if (st == NULL) return -ENOMEM; - st->channels = iio_channel_get_all(dev_name(dev)); - if (IS_ERR(st->channels)) - return PTR_ERR(st->channels); + st->channels = channels; /* count how many attributes we have */ while (st->channels[st->num_channels].indio_dev) diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 16c35ac..a85787a 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -15,6 +15,7 @@ struct iio_dev; struct iio_chan_spec; +struct device; /** * struct iio_channel - everything needed for a consumer to use a channel @@ -48,14 +49,14 @@ void iio_channel_release(struct iio_channel *chan); /** * iio_channel_get_all() - get all channels associated with a client - * @name: name of consumer device. + * @dev: Pointer to consumer device. * * Returns an array of iio_channel structures terminated with one with * null iio_dev pointer. * This function is used by fairly generic consumers to get all the * channels registered as having this consumer. */ -struct iio_channel *iio_channel_get_all(const char *name); +struct iio_channel *iio_channel_get_all(struct device *dev); /** * iio_channel_release_all() - reverse iio_channel_get_all @@ -66,7 +67,7 @@ void iio_channel_release_all(struct iio_channel *chan); struct iio_cb_buffer; /** * iio_channel_get_all_cb() - register callback for triggered capture - * @name: Name of client device. + * @dev: Pointer to client device. * @cb: Callback function. * @private: Private data passed to callback. * @@ -74,7 +75,7 @@ struct iio_cb_buffer; * So if the channels requested come from different devices this will * fail. */ -struct iio_cb_buffer *iio_channel_get_all_cb(const char *name, +struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, int (*cb)(u8 *data, void *private), void *private); -- cgit v0.10.2 From 6cb2afd7c0abb93bd9dc6d36b858b1e312e2407d Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio: Simplify iio_map_array_unregister API Instead of requiring the map to unregister, simply unregister all map entries associated with the given iio device. This simplifies map removal and also works for maps generated through devicetree. Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c index d02704c..763f575 100644 --- a/drivers/iio/adc/lp8788_adc.c +++ b/drivers/iio/adc/lp8788_adc.c @@ -187,12 +187,6 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev, return 0; } -static inline void lp8788_iio_map_unregister(struct iio_dev *indio_dev, - struct lp8788_adc *adc) -{ - iio_map_array_unregister(indio_dev, adc->map); -} - static int lp8788_adc_probe(struct platform_device *pdev) { struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); @@ -231,7 +225,7 @@ static int lp8788_adc_probe(struct platform_device *pdev) return 0; err_iio_device: - lp8788_iio_map_unregister(indio_dev, adc); + iio_map_array_unregister(indio_dev); err_iio_map: iio_device_free(indio_dev); return ret; @@ -240,10 +234,9 @@ err_iio_map: static int lp8788_adc_remove(struct platform_device *pdev) { struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct lp8788_adc *adc = iio_priv(indio_dev); iio_device_unregister(indio_dev); - lp8788_iio_map_unregister(indio_dev, adc); + iio_map_array_unregister(indio_dev); iio_device_free(indio_dev); return 0; diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 4673238..ef868c9 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1611,7 +1611,7 @@ error_disable_reg: error_put_reg: regulator_put(st->reg); error_unregister_map: - iio_map_array_unregister(indio_dev, client->dev.platform_data); + iio_map_array_unregister(indio_dev); error_free_device: iio_device_free(indio_dev); error_out: @@ -1630,7 +1630,7 @@ static int max1363_remove(struct i2c_client *client) kfree(indio_dev->available_scan_masks); regulator_disable(st->reg); regulator_put(st->reg); - iio_map_array_unregister(indio_dev, client->dev.platform_data); + iio_map_array_unregister(indio_dev); iio_device_free(indio_dev); return 0; diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 58d0ffe..c42aba6 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -54,39 +54,25 @@ error_ret: EXPORT_SYMBOL_GPL(iio_map_array_register); -/* Assumes the exact same array (e.g. memory locations) - * used at unregistration as used at registration rather than - * more complex checking of contents. +/* + * Remove all map entries associated with the given iio device */ -int iio_map_array_unregister(struct iio_dev *indio_dev, - struct iio_map *maps) +int iio_map_array_unregister(struct iio_dev *indio_dev) { - int i = 0, ret = 0; - bool found_it; + int ret = -ENODEV; struct iio_map_internal *mapi; - - if (maps == NULL) - return 0; + struct list_head *pos, *tmp; mutex_lock(&iio_map_list_lock); - while (maps[i].consumer_dev_name != NULL) { - found_it = false; - list_for_each_entry(mapi, &iio_map_list, l) - if (&maps[i] == mapi->map) { - list_del(&mapi->l); - kfree(mapi); - found_it = true; - break; - } - if (!found_it) { - ret = -ENODEV; - goto error_ret; + list_for_each_safe(pos, tmp, &iio_map_list) { + mapi = list_entry(pos, struct iio_map_internal, l); + if (indio_dev == mapi->indio_dev) { + list_del(&mapi->l); + kfree(mapi); + ret = 0; } - i++; } -error_ret: mutex_unlock(&iio_map_list_lock); - return ret; } EXPORT_SYMBOL_GPL(iio_map_array_unregister); diff --git a/include/linux/iio/driver.h b/include/linux/iio/driver.h index a4f8b2e..7dfb10e 100644 --- a/include/linux/iio/driver.h +++ b/include/linux/iio/driver.h @@ -22,13 +22,10 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *map); /** - * iio_map_array_unregister() - tell the core to remove consumer mappings + * iio_map_array_unregister() - tell the core to remove consumer mappings for + * the given provider device * @indio_dev: provider device - * @map: array of mappings to remove. Note these must have same memory - * addresses as those originally added not just equal parameter - * values. */ -int iio_map_array_unregister(struct iio_dev *indio_dev, - struct iio_map *map); +int iio_map_array_unregister(struct iio_dev *indio_dev); #endif -- cgit v0.10.2 From e2d979ccb73928bb22201a9d9035d0169aa37691 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 2 Feb 2013 10:47:08 +0000 Subject: iio:max1363 remove some functions left after merge merge commit 17cb3be61b45d716f6b21a9380925493413ce0ed seems to have resulted in two functions that were removed in 4389fbec5b8fd0577c1e854ff5d7139329558c20 reappearing. Spotted due to a build kicking out drivers/iio/adc/max1363.c:1486:12: warning: 'max1363_register_buffered_funcs_and_init' defined but not used drivers/iio/adc/max1363.c:1521:13: warning: 'max1363_buffer_cleanup' defined but not used This patch just removes them again. Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index eba1034..5db56f5 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1483,48 +1483,6 @@ static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = { .predisable = &iio_triggered_buffer_predisable, }; -static int max1363_register_buffered_funcs_and_init(struct iio_dev *indio_dev) -{ - struct max1363_state *st = iio_priv(indio_dev); - int ret = 0; - - indio_dev->buffer = iio_kfifo_allocate(indio_dev); - if (!indio_dev->buffer) { - ret = -ENOMEM; - goto error_ret; - } - indio_dev->pollfunc = iio_alloc_pollfunc(NULL, - &max1363_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - st->client->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_deallocate_sw_rb; - } - /* Buffer functions - here trigger setup related */ - indio_dev->setup_ops = &max1363_buffered_setup_ops; - - /* Flag that polled buffering is possible */ - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - - return 0; - -error_deallocate_sw_rb: - iio_kfifo_free(indio_dev->buffer); -error_ret: - return ret; -} - -static void max1363_buffer_cleanup(struct iio_dev *indio_dev) -{ - /* ensure that the trigger has been detached */ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_kfifo_free(indio_dev->buffer); -} - static int max1363_probe(struct i2c_client *client, const struct i2c_device_id *id) { -- cgit v0.10.2 From ecfaa00c00904270ecff5b5e4c44b514be62645f Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 04:08:41 +0100 Subject: staging/xgifb: Remove unused variables and dead assignments The variables A,HBS and VBS are never read in XGIfb_mode_rate_to_ddata and the assignment has no side effects -> so we can simply remove them. Removing them causes VT, HT and cr_data3 to be unused -> remove them as well and remove the assignmens to cr_data which are shadowed by a different assignment a few lines later. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index 68a216f..ca9f583 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -91,11 +91,10 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, unsigned short ModeIdIndex, index = 0; unsigned short RefreshRateTableIndex = 0; - unsigned short VRE, VBE, VRS, VBS, VDE, VT; - unsigned short HRE, HBE, HRS, HBS, HDE, HT; + unsigned short VRE, VBE, VRS, VDE; + unsigned short HRE, HBE, HRS, HDE; unsigned char sr_data, cr_data, cr_data2; - unsigned long cr_data3; - int A, B, C, D, E, F, temp, j; + int B, C, D, E, F, temp, j; InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr); if (!XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr)) return 0; @@ -105,12 +104,6 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, sr_data = XGI_CRT1Table[index].CR[5]; - cr_data = XGI_CRT1Table[index].CR[0]; - - /* Horizontal total */ - HT = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8); - A = HT + 5; - HDE = (XGI330_RefIndex[RefreshRateTableIndex].XRes >> 3) - 1; E = HDE + 1; @@ -120,11 +113,6 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, HRS = (cr_data & 0xff) | ((unsigned short) (sr_data & 0xC0) << 2); F = HRS - E - 3; - cr_data = XGI_CRT1Table[index].CR[1]; - - /* Horizontal blank start */ - HBS = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x30) << 4); - sr_data = XGI_CRT1Table[index].CR[6]; cr_data = XGI_CRT1Table[index].CR[2]; @@ -152,16 +140,8 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, sr_data = XGI_CRT1Table[index].CR[14]; - cr_data = XGI_CRT1Table[index].CR[8]; - cr_data2 = XGI_CRT1Table[index].CR[9]; - /* Vertical total */ - VT = (cr_data & 0xFF) | ((unsigned short) (cr_data2 & 0x01) << 8) - | ((unsigned short) (cr_data2 & 0x20) << 4) - | ((unsigned short) (sr_data & 0x01) << 10); - A = VT + 2; - VDE = XGI330_RefIndex[RefreshRateTableIndex].YRes - 1; E = VDE + 1; @@ -173,15 +153,6 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, | ((unsigned short) (sr_data & 0x08) << 7); F = VRS + 1 - E; - cr_data = XGI_CRT1Table[index].CR[12]; - - cr_data3 = (XGI_CRT1Table[index].CR[14] & 0x80) << 5; - - /* Vertical blank start */ - VBS = (cr_data & 0xff) | ((unsigned short) (cr_data2 & 0x08) << 5) - | ((unsigned short) (cr_data3 & 0x20) << 4) - | ((unsigned short) (sr_data & 0x04) << 8); - cr_data = XGI_CRT1Table[index].CR[13]; /* Vertical blank end */ -- cgit v0.10.2 From e91b50ecf3c427b56db3a4b4792f7a89321e3fa1 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 04:08:42 +0100 Subject: staging/xgifb: Remove unused variable Index is not used here -> remove. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 53b5557..a7fb52f 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -1390,14 +1390,10 @@ static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex, struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo) { - unsigned char index; unsigned short i; struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL; struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL; - index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; - index = index & IndexMask; - if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo); -- cgit v0.10.2 From ef9a6b99a033b136741c1022e539e9c3e8b6ed56 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 04:08:43 +0100 Subject: staging/xgifb: Remove unused variable and dead assignment modeflag is unused in XGI_SetSeqRegs, XGI_GetTVInfo, XGI_SetLCDRegs, XGI_GetRatePtrCRT2 -> remove resinfo is unused in XGI_PreSetGroup1, XGI_SetGroup1, XGI_SetGroup2, XGI_SetLCDRegs -> remove push1,push2 are unused in XGI_SetLCDRegs -> remove CRT1Index is unused in XGI_PreSetGroup1, XGI_SetLockRegs, XGI_SetLCDRegs -> remove tempcx in XGI_PreSetGroup1 only holds the values 4,5,6 -> change its type to u8 crt2crtc is unused in XGI_SetGroup2 -> remove CRT2Index is unused in XGI_GetVCLK2Ptr -> remove. Assignment to i is dead in XGI_SetSeqRegs since it is not used before the next assignment -> remove the dead assignment. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index a7fb52f..10b9cb6 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -65,14 +65,11 @@ static void XGI_SetSeqRegs(unsigned short ModeNo, struct vb_device_info *pVBInfo) { unsigned char tempah, SRdata; - unsigned short i, modeflag; - - modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + unsigned short i; xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */ tempah = XGI330_StandTable.SR[0]; - i = XGI_SetCRT2ToLCDA; if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { tempah |= 0x01; } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) { @@ -877,16 +874,12 @@ static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo, struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo) { - unsigned short CRT2Index, VCLKIndex; - unsigned short modeflag, resinfo; + unsigned short VCLKIndex, modeflag; /* si+Ext_ResInfo */ modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; - resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; - CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; if (pVBInfo->IF_DEF_LVDS == 0) { - CRT2Index = CRT2Index >> 6; /* for LCD */ if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/ if (pVBInfo->LCDResInfo != Panel_1024x768) @@ -2290,13 +2283,12 @@ static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex, static unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { - unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex; + unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex; pVBInfo->LCDResInfo = 0; pVBInfo->LCDTypeInfo = 0; pVBInfo->LCDInfo = 0; - modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; /* si+Ext_ResInfo // */ resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */ @@ -3019,11 +3011,7 @@ static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex, struct vb_device_info *pVBInfo) { - unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0; - - CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; - CRT1Index &= IndexMask; - resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; + u8 tempcx; XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, HwDeviceExtension, pVBInfo); @@ -3042,11 +3030,10 @@ static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0, - pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0; + pushbx = 0, CRT1Index, modeflag; CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; CRT1Index &= IndexMask; - resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; /* bainy change table name */ @@ -3201,13 +3188,11 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo, - modeflag, CRT1Index; + modeflag; /* si+Ext_ResInfo */ modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; - CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; - CRT1Index &= IndexMask; if (!(pVBInfo->VBInfo & SetInSlaveMode)) return; @@ -3498,15 +3483,13 @@ static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2, - modeflag, resinfo, crt2crtc; + modeflag; unsigned char const *TimingPoint; unsigned long longtemp, tempeax, tempebx, temp2, tempecx; /* si+Ext_ResInfo */ modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; - resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; - crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; tempax = 0; @@ -3937,17 +3920,12 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex, struct vb_device_info *pVBInfo) { - unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp, - tempah, tempbh, tempch, resinfo, modeflag, CRT1Index; + unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah, + tempbh, tempch; struct XGI_LCDDesStruct const *LCDBDesPtr = NULL; /* si+Ext_ResInfo */ - modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; - resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; - CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; - CRT1Index &= IndexMask; - if (!(pVBInfo->VBInfo & SetCRT2ToLCD)) return; @@ -3966,7 +3944,6 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex, xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp); tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */ - push1 = tempbx; tempbx--; temp = tempbx & 0x00FF; xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp); @@ -3974,7 +3951,6 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex, xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp); tempcx = pVBInfo->VT - 1; - push2 = tempcx + 1; temp = tempcx & 0x00FF; /* RVTVT=VT-1 */ xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp); temp = (tempcx & 0xFF00) >> 8; @@ -5511,9 +5487,7 @@ unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE, LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01 }; - unsigned short RefreshRateTableIndex, i, modeflag, index, temp; - - modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + unsigned short RefreshRateTableIndex, i, index, temp; index = xgifb_reg_get(pVBInfo->P3d4, 0x33); index = index >> pVBInfo->SelectCRT2Rate; -- cgit v0.10.2 From a9e29e6d410f492ccefbf3fdeb58d0193ec343f6 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 04:08:44 +0100 Subject: staging/xgifb: Remove unused variables Pindex and Pdata are unused -> remove tempbx is unused -> remove Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 10b9cb6..2e7277e 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -4432,10 +4432,6 @@ static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo) static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { - unsigned short Pindex, Pdata; - - Pindex = pVBInfo->Part5Port; - Pdata = pVBInfo->Part5Port + 1; if (pVBInfo->ModeType == ModeVGA) { if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag | DisableCRT2Display))) { @@ -5588,9 +5584,8 @@ static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo, struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo) { - unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex; + unsigned short ModeIdIndex, RefreshRateTableIndex; - tempbx = pVBInfo->VBInfo; pVBInfo->SetFlag |= ProgrammingCRT2; XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo); pVBInfo->SelectCRT2Rate = 4; -- cgit v0.10.2 From 5fc699f6089913e3a691209243bf6bc2a6178ddd Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 04:08:45 +0100 Subject: staging/xgifb: Remove redundant if statement The code checks twice for if (pVBInfo->VBInfo & SetCRT2ToTV) without any changes in between -> we can remove the second check. And while at it we can also save the temp variable and use tempbx directly. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 2e7277e..93f5d46 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2197,31 +2197,25 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex, static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { - unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1; - - tempbx = 0; - resinfo = 0; + unsigned short tempbx = 0, resinfo = 0, modeflag, index1; if (pVBInfo->VBInfo & SetCRT2ToTV) { modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; - if (pVBInfo->VBInfo & SetCRT2ToTV) { - temp = xgifb_reg_get(pVBInfo->P3d4, 0x35); - tempbx = temp; - if (tempbx & TVSetPAL) { - tempbx &= (SetCHTVOverScan | - TVSetPALM | - TVSetPALN | - TVSetPAL); - if (tempbx & TVSetPALM) - /* set to NTSC if PAL-M */ - tempbx &= ~TVSetPAL; - } else - tempbx &= (SetCHTVOverScan | - TVSetNTSCJ | - TVSetPAL); - } + tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35); + if (tempbx & TVSetPAL) { + tempbx &= (SetCHTVOverScan | + TVSetPALM | + TVSetPALN | + TVSetPAL); + if (tempbx & TVSetPALM) + /* set to NTSC if PAL-M */ + tempbx &= ~TVSetPAL; + } else + tempbx &= (SetCHTVOverScan | + TVSetNTSCJ | + TVSetPAL); if (pVBInfo->IF_DEF_LVDS == 0) { if (pVBInfo->VBInfo & SetCRT2ToSCART) -- cgit v0.10.2 From e2e544c9d5c3cbdb1cefad65f40b00706034ef25 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 04:08:46 +0100 Subject: staging/xgifb: remove unused variables XGI_P3cc is unused and the assignment without side effects -> remove; Data can be simply replaced by the Temp variable, which was changed to temp in order to make checkpatch happy. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 93f5d46..8eb23a4 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -638,10 +638,7 @@ static void xgifb_set_lcd(int chip_id, unsigned short RefreshRateTableIndex, unsigned short ModeNo) { - unsigned short Data, Temp; - unsigned short XGI_P3cc; - - XGI_P3cc = pVBInfo->P3cc; + unsigned short temp; xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00); xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00); @@ -649,8 +646,8 @@ static void xgifb_set_lcd(int chip_id, xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00); if (chip_id == XG27) { - Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); - if ((Temp & 0x03) == 0) { /* dual 12 */ + temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); + if ((temp & 0x03) == 0) { /* dual 12 */ xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13); xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13); } @@ -659,8 +656,8 @@ static void xgifb_set_lcd(int chip_id, if (chip_id == XG27) { XGI_SetXG27FPBits(pVBInfo); } else { - Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); - if (Temp & 0x01) { + temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); + if (temp & 0x01) { /* 18 bits FP */ xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40); xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40); @@ -672,11 +669,11 @@ static void xgifb_set_lcd(int chip_id, xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */ xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */ - Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; - if (Data & 0x4000) + temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; + if (temp & 0x4000) /* Hsync polarity */ xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20); - if (Data & 0x8000) + if (temp & 0x8000) /* Vsync polarity */ xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80); } -- cgit v0.10.2 From 573c43f30ec6e357138dac163bdf29a572133aed Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:41:21 -0700 Subject: staging: comedi: ni_daq_dio24: move MODULE_* info to end of file For aesthetic reasons, move all the MODULE_* information to the end of the file. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index dd22691..9b7d60e 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -303,10 +303,6 @@ static const struct pcmcia_device_id dio24_cs_ids[] = { }; MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids); -MODULE_AUTHOR("Daniel Vecino Castel "); -MODULE_DESCRIPTION("Comedi driver for National Instruments " - "PCMCIA DAQ-Card DIO-24"); -MODULE_LICENSE("GPL"); static struct pcmcia_driver dio24_cs_driver = { .probe = dio24_cs_attach, @@ -319,3 +315,8 @@ static struct pcmcia_driver dio24_cs_driver = { }; module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver); + +MODULE_AUTHOR("Daniel Vecino Castel "); +MODULE_DESCRIPTION( + "Comedi driver for National Instruments PCMCIA DAQ-Card DIO-24"); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From 7b725aaedd687361e3fdd8e61d3af24482557e3c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:41:45 -0700 Subject: staging: comedi: ni_daq_dio24: cleanup pcmcia_driver For aesthetic reasons, reorder the pcmcia_driver variables and add some whitespace. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 9b7d60e..f1754ee 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -301,19 +301,17 @@ static const struct pcmcia_device_id dio24_cs_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ PCMCIA_DEVICE_NULL }; - MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids); static struct pcmcia_driver dio24_cs_driver = { - .probe = dio24_cs_attach, - .remove = dio24_cs_detach, - .suspend = dio24_cs_suspend, - .resume = dio24_cs_resume, - .id_table = dio24_cs_ids, - .owner = THIS_MODULE, - .name = "ni_daq_dio24", + .name = "ni_daq_dio24", + .owner = THIS_MODULE, + .id_table = dio24_cs_ids, + .probe = dio24_cs_attach, + .remove = dio24_cs_detach, + .suspend = dio24_cs_suspend, + .resume = dio24_cs_resume, }; - module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver); MODULE_AUTHOR("Daniel Vecino Castel "); -- cgit v0.10.2 From de46fb7776da0565fa71cb407c7eb45ce87676b9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:42:06 -0700 Subject: staging: comedi: ni_daq_dio24: remove dio24_release() This function simply calls pcmcia_disable_device(). Remove it and just call pcmcia_disable_device() where needed. Also, remove a couple unnecessary forward declarations. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index f1754ee..a9b38dd 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -185,12 +185,6 @@ static void dio24_detach(struct comedi_device *dev) }; static void dio24_config(struct pcmcia_device *link); -static void dio24_release(struct pcmcia_device *link); -static int dio24_cs_suspend(struct pcmcia_device *p_dev); -static int dio24_cs_resume(struct pcmcia_device *p_dev); - -static int dio24_cs_attach(struct pcmcia_device *); -static void dio24_cs_detach(struct pcmcia_device *); struct local_info_t { struct pcmcia_device *link; @@ -223,7 +217,7 @@ static int dio24_cs_attach(struct pcmcia_device *link) static void dio24_cs_detach(struct pcmcia_device *link) { ((struct local_info_t *)link->priv)->stop = 1; - dio24_release(link); + pcmcia_disable_device(link); /* This points to the parent local_info_t struct */ kfree(link->priv); @@ -266,16 +260,8 @@ static void dio24_config(struct pcmcia_device *link) failed: dev_info(&link->dev, "Fallo"); - dio24_release(link); - -} /* dio24_config */ - -static void dio24_release(struct pcmcia_device *link) -{ - dev_dbg(&link->dev, "dio24_release\n"); - pcmcia_disable_device(link); -} /* dio24_release */ +} static int dio24_cs_suspend(struct pcmcia_device *link) { -- cgit v0.10.2 From 0bfc02b8e58abcc0c1f03638a34650c3eaee36f9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:42:31 -0700 Subject: staging: comedi: ni_daq_dio24: remove 'stop' from private pcmcia data The pcmcia_driver suspend and remove functions set the 'stop' variable and the resume function clears it. Nothing in the comedi_driver code uses the 'stop' variable. Just remove it so we can get rid of the suspend/resume. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index a9b38dd..51c25ac 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -188,7 +188,6 @@ static void dio24_config(struct pcmcia_device *link); struct local_info_t { struct pcmcia_device *link; - int stop; struct bus_operations *bus; }; @@ -216,7 +215,6 @@ static int dio24_cs_attach(struct pcmcia_device *link) static void dio24_cs_detach(struct pcmcia_device *link) { - ((struct local_info_t *)link->priv)->stop = 1; pcmcia_disable_device(link); /* This points to the parent local_info_t struct */ @@ -265,18 +263,11 @@ failed: static int dio24_cs_suspend(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; - - /* Mark the device as stopped, to block IO until later */ - local->stop = 1; return 0; } /* dio24_cs_suspend */ static int dio24_cs_resume(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; - - local->stop = 0; return 0; } /* dio24_cs_resume */ -- cgit v0.10.2 From 7044ae812bd0c3a483d860efd6fd2f0e2ff5d22b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:43:22 -0700 Subject: staging: comedi: ni_daq_dio24: remove pcmcia_driver suspend/resume The pcmcia_driver suspend and resume functions in this driver don't do anything. Since they are optional just remove them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 51c25ac..4cdf928 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -261,18 +261,6 @@ failed: pcmcia_disable_device(link); } -static int dio24_cs_suspend(struct pcmcia_device *link) -{ - return 0; -} /* dio24_cs_suspend */ - -static int dio24_cs_resume(struct pcmcia_device *link) -{ - return 0; -} /* dio24_cs_resume */ - -/*====================================================================*/ - static const struct pcmcia_device_id dio24_cs_ids[] = { /* N.B. These IDs should match those in dio24_boards */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ @@ -286,8 +274,6 @@ static struct pcmcia_driver dio24_cs_driver = { .id_table = dio24_cs_ids, .probe = dio24_cs_attach, .remove = dio24_cs_detach, - .suspend = dio24_cs_suspend, - .resume = dio24_cs_resume, }; module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver); -- cgit v0.10.2 From 07c5b441de2caf7e12c5a3e6caf7ae536f2adc2f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:43:48 -0700 Subject: staging: comedi: ni_daq_dio24: cleanup pcmcia probe/remove Absorb the code from dio24_config() into the probe function, dio24_cs_attach() and properly return the error code when the probe fails. This also gets rid of an unnecessary forward declaration. For aesthetic reasons, move the remove functio, dio24_cs_detach(), so it's after the probe function. Remove a number of dev_{level} noise messages in the probe/remove functions. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 4cdf928..6cdf45e 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -184,45 +184,13 @@ static void dio24_detach(struct comedi_device *dev) free_irq(dev->irq, dev); }; -static void dio24_config(struct pcmcia_device *link); - struct local_info_t { struct pcmcia_device *link; struct bus_operations *bus; }; -static int dio24_cs_attach(struct pcmcia_device *link) -{ - struct local_info_t *local; - - dev_info(&link->dev, "ni_daq_dio24: HOLA SOY YO - CS-attach!\n"); - - dev_dbg(&link->dev, "dio24_cs_attach()\n"); - - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); - if (!local) - return -ENOMEM; - local->link = link; - link->priv = local; - - pcmcia_cur_dev = link; - - dio24_config(link); - - return 0; -} /* dio24_cs_attach */ - -static void dio24_cs_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); - - /* This points to the parent local_info_t struct */ - kfree(link->priv); -} - static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) + void *priv_data) { if (p_dev->config_index == 0) return -EINVAL; @@ -230,13 +198,18 @@ static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, return pcmcia_request_io(p_dev); } -static void dio24_config(struct pcmcia_device *link) +static int dio24_cs_attach(struct pcmcia_device *link) { + struct local_info_t *local; int ret; - dev_info(&link->dev, "ni_daq_dio24: HOLA SOY YO! - config\n"); + local = kzalloc(sizeof(*local), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; - dev_dbg(&link->dev, "dio24_config\n"); + pcmcia_cur_dev = link; link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; @@ -254,11 +227,19 @@ static void dio24_config(struct pcmcia_device *link) if (ret) goto failed; - return; + return 0; failed: - dev_info(&link->dev, "Fallo"); pcmcia_disable_device(link); + return ret; +} + +static void dio24_cs_detach(struct pcmcia_device *link) +{ + pcmcia_disable_device(link); + + /* This points to the parent local_info_t struct */ + kfree(link->priv); } static const struct pcmcia_device_id dio24_cs_ids[] = { -- cgit v0.10.2 From 112215012f42e2db1f7e2965e25936c4809e89b1 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:44:25 -0700 Subject: staging: comedi: ni_daq_dio24: remove pcmcia_device private data The private data, struct local_info_t, is not being used in the driver. Remove it as well as the kzalloc/kfree. Also, don't set the 'pcmcia_cur_dev' variable unless the pcmcia probe is successful. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 6cdf45e..826bea9 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -184,11 +184,6 @@ static void dio24_detach(struct comedi_device *dev) free_irq(dev->irq, dev); }; -struct local_info_t { - struct pcmcia_device *link; - struct bus_operations *bus; -}; - static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { @@ -200,17 +195,8 @@ static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, static int dio24_cs_attach(struct pcmcia_device *link) { - struct local_info_t *local; int ret; - local = kzalloc(sizeof(*local), GFP_KERNEL); - if (!local) - return -ENOMEM; - local->link = link; - link->priv = local; - - pcmcia_cur_dev = link; - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; @@ -227,6 +213,8 @@ static int dio24_cs_attach(struct pcmcia_device *link) if (ret) goto failed; + pcmcia_cur_dev = link; + return 0; failed: @@ -237,9 +225,6 @@ failed: static void dio24_cs_detach(struct pcmcia_device *link) { pcmcia_disable_device(link); - - /* This points to the parent local_info_t struct */ - kfree(link->priv); } static const struct pcmcia_device_id dio24_cs_ids[] = { -- cgit v0.10.2 From 25602bd7350dc180128376db9772277818f041f2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:44:47 -0700 Subject: staging: comedi: ni_daq_dio24: move comedi_driver declaration Move the comedi_driver declaration down in the file. This removes the need for the forward declarations. For aesthetic reasons, add some whitespace to the declaration. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 826bea9..acfef6e 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -56,9 +56,6 @@ static struct pcmcia_device *pcmcia_cur_dev; #define DIO24_SIZE 4 /* size of io region used by board */ -static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it); -static void dio24_detach(struct comedi_device *dev); - enum dio24_bustype { pcmcia_bustype }; struct dio24_board_struct { @@ -96,16 +93,6 @@ struct dio24_private { int data; /* number of data points left to be taken */ }; -static struct comedi_driver driver_dio24 = { - .driver_name = "ni_daq_dio24", - .module = THIS_MODULE, - .attach = dio24_attach, - .detach = dio24_detach, - .num_names = ARRAY_SIZE(dio24_boards), - .board_name = &dio24_boards[0].name, - .offset = sizeof(struct dio24_board_struct), -}; - static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) { struct dio24_private *devpriv; @@ -184,6 +171,16 @@ static void dio24_detach(struct comedi_device *dev) free_irq(dev->irq, dev); }; +static struct comedi_driver driver_dio24 = { + .driver_name = "ni_daq_dio24", + .module = THIS_MODULE, + .attach = dio24_attach, + .detach = dio24_detach, + .num_names = ARRAY_SIZE(dio24_boards), + .board_name = &dio24_boards[0].name, + .offset = sizeof(struct dio24_board_struct), +}; + static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { -- cgit v0.10.2 From fb89942cb3bff23a3bf8b799ae6f255a137eb775 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:45:09 -0700 Subject: staging: comedi: ni_daq_dio24: remove thisboard macro The 'thisboard' macro relies on a local variable having a specific name and yields a pointer derived from that local variable. Replace the macro with a local variable and use the comedi_board() helper to get the pointer. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index acfef6e..4982cc7 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -83,11 +83,6 @@ static const struct dio24_board_struct dio24_boards[] = { }, }; -/* - * Useful for shorthand access to the particular board structure - */ -#define thisboard ((const struct dio24_board_struct *)dev->board_ptr) - struct dio24_private { int data; /* number of data points left to be taken */ @@ -95,6 +90,7 @@ struct dio24_private { static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) { + const struct dio24_board_struct *thisboard = comedi_board(dev); struct dio24_private *devpriv; struct comedi_subdevice *s; unsigned long iobase = 0; @@ -159,6 +155,7 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) static void dio24_detach(struct comedi_device *dev) { + const struct dio24_board_struct *thisboard = comedi_board(dev); struct comedi_subdevice *s; if (dev->subdevices) { -- cgit v0.10.2 From 41722460b70763eea69a76b4eb743b7295dfaa62 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:45:32 -0700 Subject: staging: comedi: ni_daq_dio24: remove the '#ifdef incomplete' code All the '#ifdef incomplete' code deals with interrupt support in this driver. For now just remove all this #if'defed out code. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 4982cc7..9aca9dd 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -94,9 +94,6 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) struct dio24_private *devpriv; struct comedi_subdevice *s; unsigned long iobase = 0; -#ifdef incomplete - unsigned int irq = 0; -#endif struct pcmcia_device *link; int ret; @@ -112,9 +109,6 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (!link) return -EIO; iobase = link->resource[0]->start; -#ifdef incomplete - irq = link->irq; -#endif break; default: pr_err("bug! couldn't determine board type\n"); @@ -123,10 +117,6 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) } pr_debug("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor, thisboard->name, iobase); -#ifdef incomplete - if (irq) - pr_debug("irq %u\n", irq); -#endif if (iobase == 0) { pr_err("io base address is zero!\n"); @@ -135,11 +125,6 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) dev->iobase = iobase; -#ifdef incomplete - /* grab our IRQ */ - dev->irq = irq; -#endif - dev->board_name = thisboard->name; ret = comedi_alloc_subdevices(dev, 1); -- cgit v0.10.2 From 61f828ec59e949379ce9e00a99785c1d395bc9e0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:45:55 -0700 Subject: staging: comedi: ni_daq_dio24: remove comedi private data The comedi private data, struct dio24_private, is not used in the driver. Remove it and the kzalloc. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 9aca9dd..e0bdb70 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -83,25 +83,14 @@ static const struct dio24_board_struct dio24_boards[] = { }, }; -struct dio24_private { - - int data; /* number of data points left to be taken */ -}; - static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) { const struct dio24_board_struct *thisboard = comedi_board(dev); - struct dio24_private *devpriv; struct comedi_subdevice *s; unsigned long iobase = 0; struct pcmcia_device *link; int ret; - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - /* get base address, irq etc. based on bustype */ switch (thisboard->bustype) { case pcmcia_bustype: -- cgit v0.10.2 From 5316ec545372cc991f9c48482db2febd7a6091ea Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:46:16 -0700 Subject: staging: comedi: ni_daq_dio24: remove '#undef LABPC_DEBUG' The LABPC_DEBUG define is not used in this driver. Just remove the Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index e0bdb70..123c4be 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -37,9 +37,6 @@ This is just a wrapper around the 8255.o driver to properly handle the PCMCIA interface. */ - /* #define LABPC_DEBUG *//* enable debugging messages */ -#undef LABPC_DEBUG - #include #include #include "../comedidev.h" -- cgit v0.10.2 From 6746dc6340ea90e04f51825042d4e5e47472b951 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:46:39 -0700 Subject: staging: comedi: ni_daq_dio24: cleanup dio24_detach Simplify the call to subdev_8255_cleanup() to remove the need for a local variable. This driver only attaches to pcmcia devices so the test for thisboard != pcmcia_bustype will always fail. Remove the test and the unreachable release_region(). This driver also never does a request_irq() so remove the free_irq(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 123c4be..47268dd 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -126,18 +126,9 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) static void dio24_detach(struct comedi_device *dev) { - const struct dio24_board_struct *thisboard = comedi_board(dev); - struct comedi_subdevice *s; - - if (dev->subdevices) { - s = &dev->subdevices[0]; - subdev_8255_cleanup(dev, s); - } - if (thisboard->bustype != pcmcia_bustype && dev->iobase) - release_region(dev->iobase, DIO24_SIZE); - if (dev->irq) - free_irq(dev->irq, dev); -}; + if (dev->subdevices) + subdev_8255_cleanup(dev, &dev->subdevices[0]); +} static struct comedi_driver driver_dio24 = { .driver_name = "ni_daq_dio24", -- cgit v0.10.2 From 5a1daad46a99f1f33b2559ff87a0fb9b01a07c87 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:47:01 -0700 Subject: staging: comedi: ni_daq_dio24: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver as well as the now unnecessary boardinfo. Check the call to subdev_8255_init() for success. That function does a kzalloc and could return -ENOMEM. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 47268dd..e491375 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -49,69 +49,35 @@ the PCMCIA interface. #include #include -static struct pcmcia_device *pcmcia_cur_dev; - -#define DIO24_SIZE 4 /* size of io region used by board */ - -enum dio24_bustype { pcmcia_bustype }; - -struct dio24_board_struct { - const char *name; - int device_id; /* device id for pcmcia board */ - enum dio24_bustype bustype; /* PCMCIA */ - int have_dio; /* have 8255 chip */ - /* function pointers so we can use inb/outb or readb/writeb as appropriate */ - unsigned int (*read_byte) (unsigned int address); - void (*write_byte) (unsigned int byte, unsigned int address); -}; +static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, + void *priv_data) +{ + if (p_dev->config_index == 0) + return -EINVAL; -static const struct dio24_board_struct dio24_boards[] = { - { - .name = "daqcard-dio24", - .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */ - .bustype = pcmcia_bustype, - .have_dio = 1, - }, - { - .name = "ni_daq_dio24", - .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */ - .bustype = pcmcia_bustype, - .have_dio = 1, - }, -}; + return pcmcia_request_io(p_dev); +} -static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int dio24_auto_attach(struct comedi_device *dev, + unsigned long context) { - const struct dio24_board_struct *thisboard = comedi_board(dev); + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); struct comedi_subdevice *s; - unsigned long iobase = 0; - struct pcmcia_device *link; int ret; - /* get base address, irq etc. based on bustype */ - switch (thisboard->bustype) { - case pcmcia_bustype: - link = pcmcia_cur_dev; /* XXX hack */ - if (!link) - return -EIO; - iobase = link->resource[0]->start; - break; - default: - pr_err("bug! couldn't determine board type\n"); - return -EINVAL; - break; - } - pr_debug("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor, - thisboard->name, iobase); + dev->board_name = dev->driver->driver_name; - if (iobase == 0) { - pr_err("io base address is zero!\n"); - return -EINVAL; - } + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | + CONF_AUTO_SET_IO; - dev->iobase = iobase; + ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL); + if (ret) + return ret; - dev->board_name = thisboard->name; + ret = pcmcia_enable_device(link); + if (ret) + return ret; + dev->iobase = link->resource[0]->start; ret = comedi_alloc_subdevices(dev, 1); if (ret) @@ -119,72 +85,36 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) /* 8255 dio */ s = &dev->subdevices[0]; - subdev_8255_init(dev, s, NULL, dev->iobase); + ret = subdev_8255_init(dev, s, NULL, dev->iobase); + if (ret) + return ret; return 0; -}; +} static void dio24_detach(struct comedi_device *dev) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + if (dev->subdevices) subdev_8255_cleanup(dev, &dev->subdevices[0]); + if (dev->iobase) + pcmcia_disable_device(link); } static struct comedi_driver driver_dio24 = { .driver_name = "ni_daq_dio24", .module = THIS_MODULE, - .attach = dio24_attach, + .auto_attach = dio24_auto_attach, .detach = dio24_detach, - .num_names = ARRAY_SIZE(dio24_boards), - .board_name = &dio24_boards[0].name, - .offset = sizeof(struct dio24_board_struct), }; -static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int dio24_cs_attach(struct pcmcia_device *link) { - int ret; - - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | - CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL); - if (ret) { - dev_warn(&link->dev, "no configuration found\n"); - goto failed; - } - - if (!link->irq) - goto failed; - - ret = pcmcia_enable_device(link); - if (ret) - goto failed; - - pcmcia_cur_dev = link; - - return 0; - -failed: - pcmcia_disable_device(link); - return ret; -} - -static void dio24_cs_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); + return comedi_pcmcia_auto_config(link, &driver_dio24); } static const struct pcmcia_device_id dio24_cs_ids[] = { - /* N.B. These IDs should match those in dio24_boards */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ PCMCIA_DEVICE_NULL }; @@ -195,7 +125,7 @@ static struct pcmcia_driver dio24_cs_driver = { .owner = THIS_MODULE, .id_table = dio24_cs_ids, .probe = dio24_cs_attach, - .remove = dio24_cs_detach, + .remove = comedi_pcmcia_auto_unconfig, }; module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver); -- cgit v0.10.2 From 89d714ce630cef6f6106f23a89458699cc595b04 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 16:48:15 -0700 Subject: staging: comedi: ni_daq_dio24: remove some unnecessary includes This driver does not use anything from the interrupt.h, slab.h, and ioport.h headers. Don't bother including them. For aesthetic reasons, move the include of the comedi specific 8255.h header to the end of the includes. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index e491375..53fd4d0 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -37,18 +37,14 @@ This is just a wrapper around the 8255.o driver to properly handle the PCMCIA interface. */ -#include -#include #include "../comedidev.h" -#include - -#include "8255.h" - #include #include #include +#include "8255.h" + static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { -- cgit v0.10.2 From 42e4472ef16dbed3b1bb876b7ea6e0bdc4c111d2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 17:08:05 -0700 Subject: staging: comedi: ni_labpc_cs: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. We still need the boardinfo because the ni_labpc driver uses it. But we can get rid of the duplicate that allowed attaching with the driver name. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index c459881..d239775 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -73,8 +73,6 @@ NI manuals: #include #include -static struct pcmcia_device *pcmcia_cur_dev; - static const struct labpc_board_struct labpc_cs_boards[] = { { .name = "daqcard-1200", @@ -86,60 +84,9 @@ static const struct labpc_board_struct labpc_cs_boards[] = { .ai_range_table = &range_labpc_1200_ai, .ai_range_code = labpc_1200_ai_gain_bits, .ai_range_is_unipolar = labpc_1200_is_unipolar, - }, { - /* duplicate entry, to support using alternate name */ - .name = "ni_labpc_cs", - .device_id = 0x103, - .ai_speed = 10000, - .bustype = pcmcia_bustype, - .register_layout = labpc_1200_layout, - .has_ao = 1, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, - .ai_range_is_unipolar = labpc_1200_is_unipolar, }, }; -static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) -{ - const struct labpc_board_struct *thisboard = comedi_board(dev); - struct labpc_private *devpriv; - unsigned long iobase = 0; - unsigned int irq = 0; - struct pcmcia_device *link; - - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - - /* get base address, irq etc. based on bustype */ - switch (thisboard->bustype) { - case pcmcia_bustype: - link = pcmcia_cur_dev; /* XXX hack */ - if (!link) - return -EIO; - iobase = link->resource[0]->start; - irq = link->irq; - break; - default: - pr_err("bug! couldn't determine board type\n"); - return -EINVAL; - break; - } - return labpc_common_attach(dev, iobase, irq, 0); -} - -static struct comedi_driver driver_labpc_cs = { - .driver_name = "ni_labpc_cs", - .module = THIS_MODULE, - .attach = labpc_attach, - .detach = labpc_common_detach, - .num_names = ARRAY_SIZE(labpc_cs_boards), - .board_name = &labpc_cs_boards[0].name, - .offset = sizeof(struct labpc_board_struct), -}; - static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { @@ -149,42 +96,61 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, return pcmcia_request_io(p_dev); } -static int labpc_cs_attach(struct pcmcia_device *link) +static int labpc_auto_attach(struct comedi_device *dev, + unsigned long context) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + struct labpc_private *devpriv; int ret; + /* The ni_labpc driver needs the board_ptr */ + dev->board_ptr = &labpc_cs_boards[0]; + link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ | - CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; + CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; ret = pcmcia_loop_config(link, labpc_pcmcia_config_loop, NULL); - if (ret) { - dev_warn(&link->dev, "no configuration found\n"); - goto failed; - } + if (ret) + return ret; if (!link->irq) - goto failed; + return -EINVAL; ret = pcmcia_enable_device(link); if (ret) - goto failed; + return ret; + dev->iobase = link->resource[0]->start; - pcmcia_cur_dev = link; + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; - return 0; + return labpc_common_attach(dev, dev->iobase, link->irq, 0); +} -failed: - pcmcia_disable_device(link); - return ret; +static void labpc_detach(struct comedi_device *dev) +{ + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + + labpc_common_detach(dev); + if (dev->iobase) + pcmcia_disable_device(link); } -static void labpc_cs_detach(struct pcmcia_device *link) +static struct comedi_driver driver_labpc_cs = { + .driver_name = "ni_labpc_cs", + .module = THIS_MODULE, + .auto_attach = labpc_auto_attach, + .detach = labpc_detach, +}; + +static int labpc_cs_attach(struct pcmcia_device *link) { - pcmcia_disable_device(link); + return comedi_pcmcia_auto_config(link, &driver_labpc_cs); } static const struct pcmcia_device_id labpc_cs_ids[] = { - /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ PCMCIA_DEVICE_NULL }; @@ -195,7 +161,7 @@ static struct pcmcia_driver labpc_cs_driver = { .owner = THIS_MODULE, .id_table = labpc_cs_ids, .probe = labpc_cs_attach, - .remove = labpc_cs_detach, + .remove = comedi_pcmcia_auto_unconfig, }; module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver); -- cgit v0.10.2 From 42d1aeea844874961af00621f0a5584aa9b9e1a5 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 17:38:02 -0700 Subject: staging: comedi: ni_mio_cs: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. We still need the boardinfo because ni_mio_common.c uses it. Cleanup ni_getboardtype() so it returns a pointer to the boardinto instead of the index. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 07e4bd8..4151aba 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -207,37 +207,62 @@ static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr) #include "ni_mio_common.c" -static struct pcmcia_device *cur_dev; - -static int ni_getboardtype(struct comedi_device *dev, - struct pcmcia_device *link) +static const void *ni_getboardtype(struct comedi_device *dev, + struct pcmcia_device *link) { + static const struct ni_board_struct *board; int i; - for (i = 0; i < n_ni_boards; i++) { - if (ni_boards[i].device_id == link->card_id) - return i; + for (i = 0; i < ARRAY_SIZE(ni_boards); i++) { + board = &ni_boards[i]; + if (board->device_id == link->card_id) + return board; } + return NULL; +} + +static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) +{ + int base, ret; - dev_err(dev->class_dev, - "unknown board 0x%04x -- pretend it is a ", link->card_id); + p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; + p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; - return 0; + for (base = 0x000; base < 0x400; base += 0x20) { + p_dev->resource[0]->start = base; + ret = pcmcia_request_io(p_dev); + if (!ret) + return 0; + } + return -ENODEV; } -static int mio_cs_attach(struct comedi_device *dev, - struct comedi_devconfig *it) +static int mio_cs_auto_attach(struct comedi_device *dev, + unsigned long context) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + static const struct ni_board_struct *board; struct ni_private *devpriv; - struct pcmcia_device *link; int ret; - link = cur_dev; /* XXX hack */ - if (!link) - return -EIO; + board = ni_getboardtype(dev, link); + if (!board) + return -ENODEV; + dev->board_ptr = board; + dev->board_name = board->name; + + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; + + ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); + if (ret) + return ret; + + if (!link->irq) + return -EINVAL; - dev->board_ptr = ni_boards + ni_getboardtype(dev, link); - dev->board_name = boardtype.name; + ret = pcmcia_enable_device(link); + if (ret) + return ret; dev->iobase = link->resource[0]->start; ret = request_irq(link->irq, ni_E_interrupt, NI_E_IRQ_FLAGS, @@ -261,57 +286,25 @@ static int mio_cs_attach(struct comedi_device *dev, static void mio_cs_detach(struct comedi_device *dev) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + mio_common_detach(dev); if (dev->irq) free_irq(dev->irq, dev); + if (dev->iobase) + pcmcia_disable_device(link); } static struct comedi_driver driver_ni_mio_cs = { .driver_name = "ni_mio_cs", .module = THIS_MODULE, - .attach = mio_cs_attach, + .auto_attach = mio_cs_auto_attach, .detach = mio_cs_detach, }; -static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) -{ - int base, ret; - - p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; - p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; - - for (base = 0x000; base < 0x400; base += 0x20) { - p_dev->resource[0]->start = base; - ret = pcmcia_request_io(p_dev); - if (!ret) - return 0; - } - return -ENODEV; -} - static int cs_attach(struct pcmcia_device *link) { - int ret; - - cur_dev = link; - - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); - if (ret) { - dev_warn(&link->dev, "no configuration found\n"); - return ret; - } - - if (!link->irq) - dev_info(&link->dev, "no IRQ available\n"); - - return pcmcia_enable_device(link); -} - -static void cs_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); + return comedi_pcmcia_auto_config(link, &driver_ni_mio_cs); } static const struct pcmcia_device_id ni_mio_cs_ids[] = { @@ -329,7 +322,7 @@ static struct pcmcia_driver ni_mio_cs_driver = { .owner = THIS_MODULE, .id_table = ni_mio_cs_ids, .probe = cs_attach, - .remove = cs_detach, + .remove = comedi_pcmcia_auto_unconfig, }; module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver); -- cgit v0.10.2 From 77970254b0b8f93fbd6bffe8e669133461ed99c7 Mon Sep 17 00:00:00 2001 From: Andres More Date: Thu, 31 Jan 2013 14:33:19 -0500 Subject: staging: vt6656: cleared 'do not use C99 // comments' checkpatch errors switched all // comments on file to respective /**/ Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/80211mgr.h b/drivers/staging/vt6656/80211mgr.h index 29fad08..f8e16d8 100644 --- a/drivers/staging/vt6656/80211mgr.h +++ b/drivers/staging/vt6656/80211mgr.h @@ -38,7 +38,7 @@ #define WLAN_MIN_ARRAY 1 -// Information Element ID value +/* Information Element ID value */ #define WLAN_EID_SSID 0 #define WLAN_EID_SUPP_RATES 1 #define WLAN_EID_FH_PARMS 2 @@ -59,10 +59,10 @@ #define WLAN_EID_QUIET 40 #define WLAN_EID_IBSS_DFS 41 #define WLAN_EID_ERP 42 -// reference 802.11i 7.3.2 table 20 +/* reference 802.11i 7.3.2 table 20 */ #define WLAN_EID_RSN 48 #define WLAN_EID_EXTSUPP_RATES 50 -// reference WiFi WPA spec. +/* reference WiFi WPA spec */ #define WLAN_EID_RSN_WPA 221 #ifdef Cisco_ccx @@ -75,7 +75,7 @@ #define WLAN_EID_ERP_USE_PROTECTION 0x02 #define WLAN_EID_ERP_BARKER_MODE 0x04 -// Reason Codes +/* reason codes */ #define WLAN_MGMT_REASON_RSVD 0 #define WLAN_MGMT_REASON_UNSPEC 1 #define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2 @@ -100,7 +100,7 @@ #define WLAN_MGMT_REASON_RSNE_CAP_INVALID 22 #define WLAN_MGMT_REASON_80211X_AUTH_FAILED 23 -// Status Codes +/* status codes */ #define WLAN_MGMT_STATUS_SUCCESS 0 #define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1 #define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10 @@ -116,19 +116,16 @@ #define WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC 20 #define WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY 21 -// reference 802.11h 7.3.1.9 -// +/* reference 802.11h 7.3.1.9 */ #define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SPECTRUM_MNG 22 #define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_PWR_CAP 23 #define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SUPP_CH 24 -// -// reference 802.11g 7.3.1.9 -// + +/* reference 802.11g 7.3.1.9 */ #define WLAN_MGMT_STATUS_SHORTSLOTTIME_UNSUPPORTED 25 #define WLAN_MGMT_STATUS_DSSSOFDM_UNSUPPORTED 26 -// -// reference 802.11i 7.3.1.9 table 19 -// + +/* reference 802.11i 7.3.1.9 table 19 */ #define WLAN_MGMT_STATUS_INVALID_IE 40 #define WLAN_MGMT_STATUS_GROUP_CIPHER_INVALID 41 #define WLAN_MGMT_STATUS_PAIRWISE_CIPHER_INVALID 42 @@ -137,17 +134,16 @@ #define WLAN_MGMT_STATUS_INVALID_RSN_IE_CAP 45 #define WLAN_MGMT_STATUS_CIPHER_REJECT 46 - - -// Auth Algorithm +/* auth algorithm */ #define WLAN_AUTH_ALG_OPENSYSTEM 0 #define WLAN_AUTH_ALG_SHAREDKEY 1 +/* management frame field offsets */ - -// Management Frame Field Offsets -// Note: Not all fields are listed because of variable lengths. -// Note: These offsets are from the start of the frame data +/* + * Note: Not all fields are listed because of variable lengths + * Note: These offsets are from the start of the frame data + */ #define WLAN_BEACON_OFF_TS 0 #define WLAN_BEACON_OFF_BCN_INT 8 @@ -189,10 +185,7 @@ #define WLAN_DEAUTHEN_OFF_REASON 0 - -// -// Cipher Suite Selectors defined in 802.11i -// +/* cipher suite selectors defined in 802.11i */ #define WLAN_11i_CSS_USE_GROUP 0 #define WLAN_11i_CSS_WEP40 1 #define WLAN_11i_CSS_TKIP 2 @@ -200,24 +193,22 @@ #define WLAN_11i_CSS_WEP104 5 #define WLAN_11i_CSS_UNKNOWN 255 -// -// Authentication and Key Management Suite Selectors defined in 802.11i -// +/* authentication and key management suite selectors defined in 802.11i */ #define WLAN_11i_AKMSS_802_1X 1 #define WLAN_11i_AKMSS_PSK 2 #define WLAN_11i_AKMSS_UNKNOWN 255 -// Measurement type definitions reference ieee 802.11h Table 20b +/* measurement type definitions reference IEEE 802.11h table 20b */ #define MEASURE_TYPE_BASIC 0 #define MEASURE_TYPE_CCA 1 #define MEASURE_TYPE_RPI 2 -// Measurement request mode definitions reference ieee 802.11h Figure 46h +/* measurement request mode definitions reference IEEE 802.11h figure 46h */ #define MEASURE_MODE_ENABLE 0x02 #define MEASURE_MODE_REQ 0x04 #define MEASURE_MODE_REP 0x08 -// Measurement report mode definitions reference ieee 802.11h Figure 46m +/* measurement report mode definitions reference IEEE 802.11h figure 46m */ #define MEASURE_MODE_LATE 0x01 #define MEASURE_MODE_INCAPABLE 0x02 #define MEASURE_MODE_REFUSED 0x04 @@ -228,7 +219,7 @@ /*--------------------- Export Types ------------------------------*/ -// Information Element Types +/* Information Element types */ #pragma pack(1) typedef struct tagWLAN_IE { @@ -237,7 +228,7 @@ typedef struct tagWLAN_IE { } __attribute__ ((__packed__)) WLAN_IE, *PWLAN_IE; -// Service Set Identity (SSID) +/* Service Set IDentity (SSID) */ #pragma pack(1) typedef struct tagWLAN_IE_SSID { BYTE byElementID; @@ -246,7 +237,7 @@ typedef struct tagWLAN_IE_SSID { } __attribute__ ((__packed__)) WLAN_IE_SSID, *PWLAN_IE_SSID; -// Supported Rates +/* Supported Rates */ #pragma pack(1) typedef struct tagWLAN_IE_SUPP_RATES { BYTE byElementID; @@ -255,7 +246,7 @@ typedef struct tagWLAN_IE_SUPP_RATES { } __attribute__ ((__packed__)) WLAN_IE_SUPP_RATES, *PWLAN_IE_SUPP_RATES; -// FH Parameter Set +/* FH Parameter Set */ #pragma pack(1) typedef struct _WLAN_IE_FH_PARMS { BYTE byElementID; @@ -266,7 +257,7 @@ typedef struct _WLAN_IE_FH_PARMS { BYTE byHopIndex; } WLAN_IE_FH_PARMS, *PWLAN_IE_FH_PARMS; -// DS Parameter Set +/* DS Parameter Set */ #pragma pack(1) typedef struct tagWLAN_IE_DS_PARMS { BYTE byElementID; @@ -275,7 +266,7 @@ typedef struct tagWLAN_IE_DS_PARMS { } __attribute__ ((__packed__)) WLAN_IE_DS_PARMS, *PWLAN_IE_DS_PARMS; -// CF Parameter Set +/* CF Parameter Set */ #pragma pack(1) typedef struct tagWLAN_IE_CF_PARMS { BYTE byElementID; @@ -287,7 +278,7 @@ typedef struct tagWLAN_IE_CF_PARMS { } __attribute__ ((__packed__)) WLAN_IE_CF_PARMS, *PWLAN_IE_CF_PARMS; -// TIM +/* TIM */ #pragma pack(1) typedef struct tagWLAN_IE_TIM { BYTE byElementID; @@ -299,7 +290,7 @@ typedef struct tagWLAN_IE_TIM { } __attribute__ ((__packed__)) WLAN_IE_TIM, *PWLAN_IE_TIM; -// IBSS Parameter Set +/* IBSS Parameter Set */ #pragma pack(1) typedef struct tagWLAN_IE_IBSS_PARMS { BYTE byElementID; @@ -308,7 +299,7 @@ typedef struct tagWLAN_IE_IBSS_PARMS { } __attribute__ ((__packed__)) WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS; -// Challenge Text +/* Challenge Text */ #pragma pack(1) typedef struct tagWLAN_IE_CHALLENGE { BYTE byElementID; @@ -325,10 +316,10 @@ typedef struct tagWLAN_IE_RSN_EXT { WORD wVersion; BYTE abyMulticast[4]; WORD wPKCount; - struct { - BYTE abyOUI[4]; - } PKSList[1]; // the rest is variable so need to - // overlay ieauth structure + struct { + BYTE abyOUI[4]; + } PKSList[1]; + /* the rest is variable so need to overlay ieauth structure */ } WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT; #pragma pack(1) @@ -339,7 +330,7 @@ typedef struct tagWLAN_IE_RSN_AUTH { } AuthKSList[1]; } WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH; -// RSN Identity +/* RSN Identity */ #pragma pack(1) typedef struct tagWLAN_IE_RSN { BYTE byElementID; @@ -348,8 +339,7 @@ typedef struct tagWLAN_IE_RSN { BYTE abyRSN[WLAN_MIN_ARRAY]; } WLAN_IE_RSN, *PWLAN_IE_RSN; - -// CCX Identity DavidWang +/* CCX Identity DavidWang */ #pragma pack(1) typedef struct tagWLAN_IE_CCX { BYTE byElementID; @@ -371,9 +361,7 @@ BYTE len; BYTE abyCCXVer[5]; } WLAN_IE_CCX_Ver, *PWLAN_IE_CCX_Ver; - - -// ERP +/* ERP */ #pragma pack(1) typedef struct tagWLAN_IE_ERP { BYTE byElementID; @@ -505,10 +493,9 @@ typedef struct _WLAN_IE_IBSS_DFS { #pragma pack() +/* frame types */ - -// Frame Types -// prototype structure, all mgmt frame types will start with these members +/* prototype structure, all mgmt frame types will start with these members */ typedef struct tagWLAN_FR_MGMT { unsigned int uType; @@ -518,21 +505,21 @@ typedef struct tagWLAN_FR_MGMT { } WLAN_FR_MGMT, *PWLAN_FR_MGMT; -// Beacon frame +/* beacon frame */ typedef struct tagWLAN_FR_BEACON { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - // fixed fields + /* fixed fields */ u64 *pqwTimestamp; PWORD pwBeaconInterval; PWORD pwCapInfo; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_SSID pSSID; PWLAN_IE_SUPP_RATES pSuppRates; -// PWLAN_IE_FH_PARMS pFHParms; +/* PWLAN_IE_FH_PARMS pFHParms; */ PWLAN_IE_DS_PARMS pDSParms; PWLAN_IE_CF_PARMS pCFParms; PWLAN_IE_TIM pTIM; @@ -549,8 +536,7 @@ typedef struct tagWLAN_FR_BEACON { } WLAN_FR_BEACON, *PWLAN_FR_BEACON; - -// IBSS ATIM frame +/* IBSS ATIM frame */ typedef struct tagWLAN_FR_IBSSATIM { unsigned int uType; @@ -558,36 +544,36 @@ typedef struct tagWLAN_FR_IBSSATIM { PBYTE pBuf; PUWLAN_80211HDR pHdr; - // fixed fields - // info elements - // this frame type has a null body + /* fixed fields */ + /* info elements */ + /* this frame type has a null body */ } WLAN_FR_IBSSATIM, *PWLAN_FR_IBSSATIM; -// Disassociation +/* disassociation */ typedef struct tagWLAN_FR_DISASSOC { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwReason; - /*-- info elements ----------*/ + /* info elements */ } WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC; -// Association Request +/* association request */ typedef struct tagWLAN_FR_ASSOCREQ { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwCapInfo; PWORD pwListenInterval; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_SSID pSSID; PWLAN_IE_SUPP_RATES pSuppRates; PWLAN_IE_RSN pRSN; @@ -601,24 +587,24 @@ typedef struct tagWLAN_FR_ASSOCREQ { } WLAN_FR_ASSOCREQ, *PWLAN_FR_ASSOCREQ; -// Association Response +/* association response */ typedef struct tagWLAN_FR_ASSOCRESP { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwCapInfo; PWORD pwStatus; PWORD pwAid; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_SUPP_RATES pSuppRates; PWLAN_IE_SUPP_RATES pExtSuppRates; } WLAN_FR_ASSOCRESP, *PWLAN_FR_ASSOCRESP; -// Reassociation Request +/* reassociation request */ typedef struct tagWLAN_FR_REASSOCREQ { unsigned int uType; @@ -626,12 +612,12 @@ typedef struct tagWLAN_FR_REASSOCREQ { PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwCapInfo; PWORD pwListenInterval; PIEEE_ADDR pAddrCurrAP; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_SSID pSSID; PWLAN_IE_SUPP_RATES pSuppRates; PWLAN_IE_RSN pRSN; @@ -643,50 +629,50 @@ typedef struct tagWLAN_FR_REASSOCREQ { } WLAN_FR_REASSOCREQ, *PWLAN_FR_REASSOCREQ; -// Reassociation Response +/* reassociation response */ typedef struct tagWLAN_FR_REASSOCRESP { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwCapInfo; PWORD pwStatus; PWORD pwAid; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_SUPP_RATES pSuppRates; PWLAN_IE_SUPP_RATES pExtSuppRates; } WLAN_FR_REASSOCRESP, *PWLAN_FR_REASSOCRESP; -// Probe Request +/* probe request */ typedef struct tagWLAN_FR_PROBEREQ { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ - /*-- info elements ----------*/ + /* fixed fields */ + /* info elements */ PWLAN_IE_SSID pSSID; PWLAN_IE_SUPP_RATES pSuppRates; PWLAN_IE_SUPP_RATES pExtSuppRates; } WLAN_FR_PROBEREQ, *PWLAN_FR_PROBEREQ; -// Probe Response +/* probe response */ typedef struct tagWLAN_FR_PROBERESP { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ u64 *pqwTimestamp; PWORD pwBeaconInterval; PWORD pwCapInfo; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_SSID pSSID; PWLAN_IE_SUPP_RATES pSuppRates; PWLAN_IE_DS_PARMS pDSParms; @@ -704,37 +690,38 @@ typedef struct tagWLAN_FR_PROBERESP { } WLAN_FR_PROBERESP, *PWLAN_FR_PROBERESP; -// Authentication +/* authentication */ typedef struct tagWLAN_FR_AUTHEN { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwAuthAlgorithm; PWORD pwAuthSequence; PWORD pwStatus; - /*-- info elements ----------*/ + /* info elements */ PWLAN_IE_CHALLENGE pChallenge; } WLAN_FR_AUTHEN, *PWLAN_FR_AUTHEN; -// Deauthentication +/* deauthentication */ typedef struct tagWLAN_FR_DEAUTHEN { unsigned int uType; unsigned int len; PBYTE pBuf; PUWLAN_80211HDR pHdr; - /*-- fixed fields -----------*/ + /* fixed fields */ PWORD pwReason; - /*-- info elements ----------*/ + /* info elements */ } WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN; /*--------------------- Export Functions --------------------------*/ + void vMgrEncodeBeacon( PWLAN_FR_BEACON pFrame @@ -845,4 +832,4 @@ vMgrDecodeReassocResponse( PWLAN_FR_REASSOCRESP pFrame ); -#endif// __80211MGR_H__ +#endif /* __80211MGR_H__ */ -- cgit v0.10.2 From 74ecdc5e4bbd6a7f399e4a3cb61270b46d2e62d3 Mon Sep 17 00:00:00 2001 From: Andres More Date: Thu, 31 Jan 2013 14:55:58 -0500 Subject: staging: vt6656: cleared 'do not use C99 // comments' checkpatch errors Switched // comments into respective /**/ ones Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/baseband.h b/drivers/staging/vt6656/baseband.h index df5cf0d..fba6160 100644 --- a/drivers/staging/vt6656/baseband.h +++ b/drivers/staging/vt6656/baseband.h @@ -42,31 +42,30 @@ #define PREAMBLE_LONG 0 #define PREAMBLE_SHORT 1 -// -// Registers in the BASEBAND -// +/* + * Registers in the BASEBAND + */ #define BB_MAX_CONTEXT_SIZE 256 -#define C_SIFS_A 16 // micro sec. +#define C_SIFS_A 16 /* usec */ #define C_SIFS_BG 10 -#define C_EIFS 80 // micro sec. - +#define C_EIFS 80 /* usec */ -#define C_SLOT_SHORT 9 // micro sec. +#define C_SLOT_SHORT 9 /* usec */ #define C_SLOT_LONG 20 -#define C_CWMIN_A 15 // slot time +#define C_CWMIN_A 15 /* slot time */ #define C_CWMIN_B 31 -#define C_CWMAX 1023 // slot time +#define C_CWMAX 1023 /* slot time */ -//0:11A 1:11B 2:11G +/* 0:11A 1:11B 2:11G */ #define BB_TYPE_11A 0 #define BB_TYPE_11B 1 #define BB_TYPE_11G 2 -//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) +/* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga (OFDM in BasicRate) */ #define PK_TYPE_11A 0 #define PK_TYPE_11B 1 #define PK_TYPE_11GB 2 @@ -108,7 +107,7 @@ void BBvCalculateParameter(struct vnt_private *, u32 cbFrameLength, u16 wRate, u8 byPacketType, u16 *pwPhyLen, u8 *pbyPhySrv, u8 *pbyPhySgn); -// timer for antenna diversity +/* timer for antenna diversity */ void TimerSQ3CallBack(struct vnt_private *); void TimerSQ3Tmax3CallBack(struct vnt_private *); -- cgit v0.10.2 From c16fdffc2d83d4be2925e05ce1a2fb27f2f2962f Mon Sep 17 00:00:00 2001 From: Andres More Date: Thu, 31 Jan 2013 15:40:14 -0500 Subject: staging: vt6656: fixed C99 // comments Cleared 'do not use C99 // comments' checkpatch errors in two headers. Several obvious comments were removed. Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/datarate.h b/drivers/staging/vt6656/datarate.h index 1320507..8dc55bd 100644 --- a/drivers/staging/vt6656/datarate.h +++ b/drivers/staging/vt6656/datarate.h @@ -32,16 +32,15 @@ /*--------------------- Export Definitions -------------------------*/ -#define FALLBACK_PKT_COLLECT_TR_H 50 // pkts -#define FALLBACK_PKT_COLLECT_TR_L 10 // pkts -#define FALLBACK_POLL_SECOND 5 // 5 sec -#define FALLBACK_RECOVER_SECOND 30 // 30 sec -#define FALLBACK_THRESHOLD 15 // percent -#define UPGRADE_THRESHOLD 5 // percent -#define UPGRADE_CNT_THRD 3 // times -#define RETRY_TIMES_THRD_H 2 // times -#define RETRY_TIMES_THRD_L 1 // times - +#define FALLBACK_PKT_COLLECT_TR_H 50 /* pkts */ +#define FALLBACK_PKT_COLLECT_TR_L 10 /* pkts */ +#define FALLBACK_POLL_SECOND 5 /* 5 sec */ +#define FALLBACK_RECOVER_SECOND 30 /* 30 sec */ +#define FALLBACK_THRESHOLD 15 /* percent */ +#define UPGRADE_THRESHOLD 5 /* percent */ +#define UPGRADE_CNT_THRD 3 /* times */ +#define RETRY_TIMES_THRD_H 2 /* times */ +#define RETRY_TIMES_THRD_L 1 /* times */ #define RATE_1M 0 #define RATE_2M 1 diff --git a/drivers/staging/vt6656/desc.h b/drivers/staging/vt6656/desc.h index 5007e98..0c0b614 100644 --- a/drivers/staging/vt6656/desc.h +++ b/drivers/staging/vt6656/desc.h @@ -36,92 +36,95 @@ #include "ttype.h" #include "tether.h" -// max transmit or receive buffer size -#define CB_MAX_BUF_SIZE 2900U // max buffer size - // NOTE: must be multiple of 4 +/* max transmit or receive buffer size */ +#define CB_MAX_BUF_SIZE 2900U /* NOTE: must be multiple of 4 */ -#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE // max Tx buffer size -#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE // max Rx buffer size when not use Multi-RD +/* max TX buffer size */ +#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE +/* max RX buffer size when not use Multi-RD */ +#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE -#define CB_BEACON_BUF_SIZE 512U // default beacon buffer size +#define CB_BEACON_BUF_SIZE 512U /* default beacon buffer size */ #define MAX_TOTAL_SIZE_WITH_ALL_HEADERS CB_MAX_BUF_SIZE #define MAX_INTERRUPT_SIZE 32 -#define RX_BLOCKS 64 // form 0x60 to 0xA0 -#define TX_BLOCKS 32 // from 0xA0 to 0xC0 - -#define CB_MAX_RX_DESC 128 // max # of descriptor -#define CB_MIN_RX_DESC 16 // min # of rx descriptor -#define CB_MAX_TX_DESC 128 // max # of descriptor -#define CB_MIN_TX_DESC 16 // min # of tx descriptor - -#define CB_RD_NUM 64 // default # of RD -#define CB_TD_NUM 64 // default # of TD - -// -// Bits in the RSR register -// -#define RSR_ADDRBROAD 0x80 // 1000 0000 -#define RSR_ADDRMULTI 0x40 // 0100 0000 -#define RSR_ADDRUNI 0x00 // 0000 0000 -#define RSR_IVLDTYP 0x20 // 0010 0000 , invalid packet type -#define RSR_IVLDLEN 0x10 // 0001 0000 , invalid len (> 2312 byte) -#define RSR_BSSIDOK 0x08 // 0000 1000 -#define RSR_CRCOK 0x04 // 0000 0100 -#define RSR_BCNSSIDOK 0x02 // 0000 0010 -#define RSR_ADDROK 0x01 // 0000 0001 - -// -// Bits in the new RSR register -// -#define NEWRSR_DECRYPTOK 0x10 // 0001 0000 -#define NEWRSR_CFPIND 0x08 // 0000 1000 -#define NEWRSR_HWUTSF 0x04 // 0000 0100 -#define NEWRSR_BCNHITAID 0x02 // 0000 0010 -#define NEWRSR_BCNHITAID0 0x01 // 0000 0001 - -// -// Bits in the TSR register -// -#define TSR_RETRYTMO 0x08 // 0000 1000 -#define TSR_TMO 0x04 // 0000 0100 -#define TSR_ACKDATA 0x02 // 0000 0010 -#define TSR_VALID 0x01 // 0000 0001 +#define RX_BLOCKS 64 /* from 0x60 to 0xA0 */ +#define TX_BLOCKS 32 /* from 0xA0 to 0xC0 */ + +#define CB_MAX_RX_DESC 128 /* max # of descriptors */ +#define CB_MIN_RX_DESC 16 /* min # of RX descriptors */ +#define CB_MAX_TX_DESC 128 /* max # of descriptors */ +#define CB_MIN_TX_DESC 16 /* min # of TX descriptors */ + +#define CB_RD_NUM 64 /* default # of RD */ +#define CB_TD_NUM 64 /* default # of TD */ + +/* + * bits in the RSR register + */ +#define RSR_ADDRBROAD 0x80 +#define RSR_ADDRMULTI 0x40 +#define RSR_ADDRUNI 0x00 +#define RSR_IVLDTYP 0x20 /* invalid packet type */ +#define RSR_IVLDLEN 0x10 /* invalid len (> 2312 byte) */ +#define RSR_BSSIDOK 0x08 +#define RSR_CRCOK 0x04 +#define RSR_BCNSSIDOK 0x02 +#define RSR_ADDROK 0x01 + +/* + * bits in the new RSR register + */ +#define NEWRSR_DECRYPTOK 0x10 +#define NEWRSR_CFPIND 0x08 +#define NEWRSR_HWUTSF 0x04 +#define NEWRSR_BCNHITAID 0x02 +#define NEWRSR_BCNHITAID0 0x01 + +/* + * bits in the TSR register + */ +#define TSR_RETRYTMO 0x08 +#define TSR_TMO 0x04 +#define TSR_ACKDATA 0x02 +#define TSR_VALID 0x01 #define CB_PROTOCOL_RESERVED_SECTION 16 -// if retrys excess 15 times , tx will abort, and -// if tx fifo underflow, tx will fail -// we should try to resend it +/* + * if retries exceed 15 times, TX will abort, and + * if TX fifo underflow, TX will fail + * we should try to resend it + */ #define CB_MAX_TX_ABORT_RETRY 3 -#define FIFOCTL_AUTO_FB_1 0x1000 // 0001 0000 0000 0000 -#define FIFOCTL_AUTO_FB_0 0x0800 // 0000 1000 0000 0000 -#define FIFOCTL_GRPACK 0x0400 // 0000 0100 0000 0000 -#define FIFOCTL_11GA 0x0300 // 0000 0011 0000 0000 -#define FIFOCTL_11GB 0x0200 // 0000 0010 0000 0000 -#define FIFOCTL_11B 0x0100 // 0000 0001 0000 0000 -#define FIFOCTL_11A 0x0000 // 0000 0000 0000 0000 -#define FIFOCTL_RTS 0x0080 // 0000 0000 1000 0000 -#define FIFOCTL_ISDMA0 0x0040 // 0000 0000 0100 0000 -#define FIFOCTL_GENINT 0x0020 // 0000 0000 0010 0000 -#define FIFOCTL_TMOEN 0x0010 // 0000 0000 0001 0000 -#define FIFOCTL_LRETRY 0x0008 // 0000 0000 0000 1000 -#define FIFOCTL_CRCDIS 0x0004 // 0000 0000 0000 0100 -#define FIFOCTL_NEEDACK 0x0002 // 0000 0000 0000 0010 -#define FIFOCTL_LHEAD 0x0001 // 0000 0000 0000 0001 - -//WMAC definition Frag Control -#define FRAGCTL_AES 0x0300 // 0000 0011 0000 0000 -#define FRAGCTL_TKIP 0x0200 // 0000 0010 0000 0000 -#define FRAGCTL_LEGACY 0x0100 // 0000 0001 0000 0000 -#define FRAGCTL_NONENCRYPT 0x0000 // 0000 0000 0000 0000 -#define FRAGCTL_ENDFRAG 0x0003 // 0000 0000 0000 0011 -#define FRAGCTL_MIDFRAG 0x0002 // 0000 0000 0000 0010 -#define FRAGCTL_STAFRAG 0x0001 // 0000 0000 0000 0001 -#define FRAGCTL_NONFRAG 0x0000 // 0000 0000 0000 0000 +#define FIFOCTL_AUTO_FB_1 0x1000 +#define FIFOCTL_AUTO_FB_0 0x0800 +#define FIFOCTL_GRPACK 0x0400 +#define FIFOCTL_11GA 0x0300 +#define FIFOCTL_11GB 0x0200 +#define FIFOCTL_11B 0x0100 +#define FIFOCTL_11A 0x0000 +#define FIFOCTL_RTS 0x0080 +#define FIFOCTL_ISDMA0 0x0040 +#define FIFOCTL_GENINT 0x0020 +#define FIFOCTL_TMOEN 0x0010 +#define FIFOCTL_LRETRY 0x0008 +#define FIFOCTL_CRCDIS 0x0004 +#define FIFOCTL_NEEDACK 0x0002 +#define FIFOCTL_LHEAD 0x0001 + +/* WMAC definition Frag Control */ +#define FRAGCTL_AES 0x0300 +#define FRAGCTL_TKIP 0x0200 +#define FRAGCTL_LEGACY 0x0100 +#define FRAGCTL_NONENCRYPT 0x0000 +#define FRAGCTL_ENDFRAG 0x0003 +#define FRAGCTL_MIDFRAG 0x0002 +#define FRAGCTL_STAFRAG 0x0001 +#define FRAGCTL_NONFRAG 0x0000 #define TYPE_TXDMA0 0 #define TYPE_AC0DMA 1 @@ -135,14 +138,14 @@ #define TYPE_RXDMA1 1 #define TYPE_MAXRD 2 -// TD_INFO flags control bit -#define TD_FLAGS_NETIF_SKB 0x01 // check if need release skb -#define TD_FLAGS_PRIV_SKB 0x02 // check if called from private skb(hostap) -#define TD_FLAGS_PS_RETRY 0x04 // check if PS STA frame re-transmit +/* TD_INFO flags control bit */ +#define TD_FLAGS_NETIF_SKB 0x01 /* check if need release skb */ +#define TD_FLAGS_PRIV_SKB 0x02 /* check if called from private skb(hostap) */ +#define TD_FLAGS_PS_RETRY 0x04 /* check if PS STA frame re-transmit */ -// -// RsvTime buffer header -// +/* + * RsvTime buffer header + */ typedef struct tagSRrvTime_gRTS { WORD wRTSTxRrvTime_ba; WORD wRTSTxRrvTime_aa; @@ -181,9 +184,9 @@ SRrvTime_atim, *PSRrvTime_atim; typedef const SRrvTime_atim *PCSRrvTime_atim; -// -// RTS buffer header -// +/* + * RTS buffer header + */ typedef struct tagSRTSData { WORD wFrameControl; WORD wDurationID; @@ -257,9 +260,9 @@ SRTS_a_FB, *PSRTS_a_FB; typedef const SRTS_a_FB *PCSRTS_a_FB; -// -// CTS buffer header -// +/* + * CTS buffer header + */ typedef struct tagSCTSData { WORD wFrameControl; WORD wDurationID; @@ -294,9 +297,9 @@ SCTS_FB, *PSCTS_FB; typedef const SCTS_FB *PCSCTS_FB; -// -// Tx FIFO header -// +/* + * TX FIFO header + */ typedef struct tagSTxBufHead { u32 adwTxKey[4]; WORD wFIFOCtl; @@ -314,9 +317,9 @@ typedef struct tagSTxShortBufHead { STxShortBufHead, *PSTxShortBufHead; typedef const STxShortBufHead *PCSTxShortBufHead; -// -// Tx data header -// +/* + * TX data header + */ typedef struct tagSTxDataHead_g { BYTE bySignalField_b; BYTE byServiceField_b; @@ -372,9 +375,9 @@ typedef struct tagSTxDataHead_a_FB { STxDataHead_a_FB, *PSTxDataHead_a_FB; typedef const STxDataHead_a_FB *PCSTxDataHead_a_FB; -// -// MICHDR data header -// +/* + * MICHDR data header + */ typedef struct tagSMICHDRHead { u32 adwHDR0[4]; u32 adwHDR1[4]; -- cgit v0.10.2 From 84cf5fcbb581fc8d8f5a0469511c53bd765029d8 Mon Sep 17 00:00:00 2001 From: Andres More Date: Thu, 31 Jan 2013 15:20:42 -0500 Subject: staging: vt6656: cleared C99 // comments in datarate.c Cleared 'do not use C99 // comments' checkpatch error, several warnings about code indentation and camel casing were not resolved. Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/datarate.c b/drivers/staging/vt6656/datarate.c index eefe7bb..4a234e5 100644 --- a/drivers/staging/vt6656/datarate.c +++ b/drivers/staging/vt6656/datarate.c @@ -54,7 +54,8 @@ /*--------------------- Static Variables --------------------------*/ -//static int msglevel =MSG_LEVEL_DEBUG; + +/* static int msglevel = MSG_LEVEL_DEBUG; */ static int msglevel =MSG_LEVEL_INFO; const BYTE acbyIERate[MAX_RATE] = {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; @@ -71,7 +72,7 @@ void s_vResetCounter(PKnownNodeDB psNodeDBTable) { BYTE ii; - // clear statistic counter for auto_rate + /* clear statistics counter for auto_rate */ for (ii = 0; ii <= MAX_RATE; ii++) { psNodeDBTable->uTxOk[ii] = 0; psNodeDBTable->uTxFail[ii] = 0; @@ -105,8 +106,8 @@ DATARATEbyGetRateIdx ( { BYTE ii; - //Erase basicRate flag. - byRate = byRate & 0x7F;//0111 1111 + /* erase BasicRate flag */ + byRate = byRate & 0x7F; for (ii = 0; ii < MAX_RATE; ii ++) { if (acbyIERate[ii] == byRate) @@ -159,8 +160,8 @@ RATEwGetRateIdx( { WORD ii; - //Erase basicRate flag. - byRate = byRate & 0x7F;//0111 1111 + /* erase BasicRate flag */ + byRate = byRate & 0x7F; for (ii = 0; ii < MAX_RATE; ii ++) { if (acbyIERate[ii] == byRate) @@ -218,7 +219,10 @@ void RATEvParseMaxRate(struct vnt_private *pDevice, byRate = (BYTE)(pItemRates->abyRates[ii]); if (WLAN_MGMT_IS_BASICRATE(byRate) && (bUpdateBasicRate == TRUE)) { - // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate + /* + * add to basic rate set, update pDevice->byTopCCKBasicRate and + * pDevice->byTopOFDMBasicRate + */ CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate)); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate)); } @@ -239,9 +243,12 @@ void RATEvParseMaxRate(struct vnt_private *pDevice, for (ii = 0; ii < uExtRateLen ; ii++) { byRate = (BYTE)(pItemExtRates->abyRates[ii]); - // select highest basic rate + /* select highest basic rate */ if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) { - // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate + /* + * add to basic rate set, update pDevice->byTopCCKBasicRate and + * pDevice->byTopOFDMBasicRate + */ CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate)); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate)); } @@ -251,9 +258,11 @@ void RATEvParseMaxRate(struct vnt_private *pDevice, if (byRate > byHighSuppRate) byHighSuppRate = byRate; *pwSuppRate |= (1<byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) { @@ -363,7 +372,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice, (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) { psNodeDBTable->wTxDataRate = wIdxUpRate; } - }else { // adhoc, if uTxOk(total) =0 & uTxFail(total) = 0 + } else { /* adhoc, if uTxOk(total) == 0 & uTxFail(total) == 0 */ if (psNodeDBTable->uTxFail[MAX_RATE] == 0) psNodeDBTable->wTxDataRate = wIdxUpRate; } -- cgit v0.10.2 From d3e2395154499a846b3210b45b046e9f0d3a5044 Mon Sep 17 00:00:00 2001 From: Andres More Date: Thu, 31 Jan 2013 15:57:19 -0500 Subject: staging: vt6656: fixed C99 // comments in two headers Cleared 'do not use C99 // comments' checkpatch error in device.h and device_cfg.h Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index e153beb..82af871 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -53,7 +53,7 @@ #undef DEVICE_ETHTOOL_IOCTL_SUPPORT #endif -//please copy below macro to driver_event.c for API +/* please copy below macro to driver_event.c for API */ #define RT_INSMOD_EVENT_FLAG 0x0101 #define RT_UPDEV_EVENT_FLAG 0x0102 #define RT_DISCONNECTED_EVENT_FLAG 0x0103 @@ -61,9 +61,9 @@ #define RT_DOWNDEV_EVENT_FLAG 0x0105 #define RT_RMMOD_EVENT_FLAG 0x0106 -// -// device specific -// +/* + * device specific + */ #include "device_cfg.h" #include "ttype.h" @@ -110,7 +110,7 @@ #define FB_RATE0 0 #define FB_RATE1 1 -// Antenna Mode +/* Antenna Mode */ #define ANT_A 0 #define ANT_B 1 #define ANT_DIVERSITY 2 @@ -125,7 +125,7 @@ #define MAXCHECKHANGCNT 4 -//Packet type +/* Packet type */ #define TX_PKT_UNI 0x00 #define TX_PKT_MULTI 0x01 #define TX_PKT_BROAD 0x02 @@ -137,7 +137,7 @@ #define RUN_AT(x) (jiffies+(x)) #endif -// DMA related +/* DMA related */ #define RESERV_AC0DMA 4 #define PRIVATE_Message 0 @@ -161,17 +161,17 @@ typedef enum __device_init_type { DEVICE_INIT_DXPL /* Dx to D0 power lost init */ } DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE; -//USB +/* USB */ -// -// Enum of context types for SendPacket -// +/* + * Enum of context types for SendPacket + */ typedef enum _CONTEXT_TYPE { CONTEXT_DATA_PACKET = 1, CONTEXT_MGMT_PACKET } CONTEXT_TYPE; -// RCB (Receive Control Block) +/* RCB (Receive Control Block) */ typedef struct _RCB { void *Next; @@ -184,7 +184,7 @@ typedef struct _RCB } RCB, *PRCB; -// used to track bulk out irps +/* used to track bulk out irps */ typedef struct _USB_SEND_CONTEXT { void *pDevice; struct sk_buff *pPacket; @@ -207,17 +207,17 @@ typedef struct _DEFAULT_CONFIG { signed int eEncryptionStatus; } DEFAULT_CONFIG, *PDEFAULT_CONFIG; -// -// Structure to keep track of usb interrupt packets -// +/* + * Structure to keep track of USB interrupt packets + */ typedef struct { unsigned int uDataLen; PBYTE pDataBuf; -// struct urb *pUrb; + /* struct urb *pUrb; */ BOOL bInUse; } INT_BUFFER, *PINT_BUFFER; -//0:11A 1:11B 2:11G +/* 0:11A 1:11B 2:11G */ typedef enum _VIA_BB_TYPE { BB_TYPE_11A = 0, @@ -225,7 +225,7 @@ typedef enum _VIA_BB_TYPE BB_TYPE_11G } VIA_BB_TYPE, *PVIA_BB_TYPE; -//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) +/* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga(OFDM in BasicRate) */ typedef enum _VIA_PKT_TYPE { PK_TYPE_11A = 0, @@ -234,7 +234,7 @@ typedef enum _VIA_PKT_TYPE PK_TYPE_11GA } VIA_PKT_TYPE, *PVIA_PKT_TYPE; -//++ NDIS related +/*++ NDIS related */ typedef enum __DEVICE_NDIS_STATUS { STATUS_SUCCESS = 0, @@ -245,10 +245,10 @@ typedef enum __DEVICE_NDIS_STATUS { #define MAX_BSSIDINFO_4_PMKID 16 #define MAX_PMKIDLIST 5 -//Flags for PMKID Candidate list structure +/* flags for PMKID Candidate list structure */ #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01 -// PMKID Structures +/* PMKID Structures */ typedef unsigned char NDIS_802_11_PMKID_VALUE[16]; @@ -272,13 +272,13 @@ typedef enum _NDIS_802_11_WEP_STATUS typedef enum _NDIS_802_11_STATUS_TYPE { - Ndis802_11StatusType_Authentication, - Ndis802_11StatusType_MediaStreamMode, - Ndis802_11StatusType_PMKID_CandidateList, - Ndis802_11StatusTypeMax // not a real type, defined as an upper bound + Ndis802_11StatusType_Authentication, + Ndis802_11StatusType_MediaStreamMode, + Ndis802_11StatusType_PMKID_CandidateList, + Ndis802_11StatusTypeMax, /* not a real type, defined as upper bound */ } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE; -//Added new types for PMKID Candidate lists. +/* added new types for PMKID Candidate lists */ typedef struct _PMKID_CANDIDATE { NDIS_802_11_MAC_ADDRESS BSSID; unsigned long Flags; @@ -304,9 +304,7 @@ typedef struct tagSPMKIDCandidateEvent { PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST]; } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent; -//-- - -//++ 802.11h related +/*++ 802.11h related */ #define MAX_QUIET_COUNT 8 typedef struct tagSQuietControl { @@ -316,10 +314,7 @@ typedef struct tagSQuietControl { WORD wDuration; } SQuietControl, *PSQuietControl; -//-- - - -// The receive duplicate detection cache entry +/* The receive duplicate detection cache entry */ typedef struct tagSCacheEntry{ WORD wFmSequence; BYTE abyAddr2[ETH_ALEN]; @@ -329,13 +324,15 @@ typedef struct tagSCacheEntry{ typedef struct tagSCache{ /* The receive cache is updated circularly. The next entry to be written is * indexed by the "InPtr". -*/ + */ unsigned int uInPtr; /* Place to use next */ SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH]; } SCache, *PSCache; #define CB_MAX_RX_FRAG 64 -// DeFragment Control Block, used for collecting fragments prior to reassembly +/* + * DeFragment Control Block, used for collecting fragments prior to reassembly + */ typedef struct tagSDeFragControlBlock { WORD wSequence; @@ -348,24 +345,22 @@ typedef struct tagSDeFragControlBlock BOOL bInUse; } SDeFragControlBlock, *PSDeFragControlBlock; - - -//flags for options +/* flags for options */ #define DEVICE_FLAGS_UNPLUG 0x00000001UL #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL #define DEVICE_FLAGS_OP_MODE 0x00000004UL #define DEVICE_FLAGS_PS_MODE 0x00000008UL #define DEVICE_FLAGS_80211h_MODE 0x00000010UL -//flags for driver status +/* flags for driver status */ #define DEVICE_FLAGS_OPENED 0x00010000UL #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL -//flags for capbilities +/* flags for capabilities */ #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL -//flags for MII status +/* flags for MII status */ #define DEVICE_LINK_FAIL 0x00000001UL #define DEVICE_SPEED_10 0x00000002UL #define DEVICE_SPEED_100 0x00000004UL @@ -373,14 +368,14 @@ typedef struct tagSDeFragControlBlock #define DEVICE_DUPLEX_FULL 0x00000010UL #define DEVICE_AUTONEG_ENABLE 0x00000020UL #define DEVICE_FORCED_BY_EEPROM 0x00000040UL -//for device_set_media_duplex +/* for device_set_media_duplex */ #define DEVICE_LINK_CHANGE 0x00000001UL typedef struct __device_opt { - int nRxDescs0; //Number of RX descriptors0 - int nTxDescs0; //Number of TX descriptors 0, 1, 2, 3 - int rts_thresh; //rts threshold + int nRxDescs0; /* number of RX descriptors 0 */ + int nTxDescs0; /* number of TX descriptors 0, 1, 2, 3 */ + int rts_thresh; /* RTS threshold */ int frag_thresh; int OpMode; int data_rate; diff --git a/drivers/staging/vt6656/device_cfg.h b/drivers/staging/vt6656/device_cfg.h index a0b8216..98600d6 100644 --- a/drivers/staging/vt6656/device_cfg.h +++ b/drivers/staging/vt6656/device_cfg.h @@ -67,14 +67,14 @@ struct _version { #define DEVICE_VERSION "1.19_12" #endif -//config file +/* config file */ #include #include #ifndef CONFIG_PATH #define CONFIG_PATH "/etc/vntconfiguration.dat" #endif -//Max: 2378=2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR +/* Max: 2378 = 2312 Payload + 30HD + 4CRC + 2Padding + 4Len + 8TSF + 4RSR */ #define PKT_BUF_SZ 2390 #define MAX_UINTS 8 -- cgit v0.10.2 From ec6e0f63d6363c0a1aac8444732bb14393a39a87 Mon Sep 17 00:00:00 2001 From: Andres More Date: Thu, 31 Jan 2013 18:23:07 -0500 Subject: staging: vt6656: fix C99 // comments in main_usb.c Resolved 'do not use C99 // comments' checkpatch errors. Many warnings about odd indentation were left. Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index 99ac7eb..d258cb2 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -73,15 +73,16 @@ #include "iowpa.h" /*--------------------- Static Definitions -------------------------*/ -//static int msglevel =MSG_LEVEL_DEBUG; +/* static int msglevel = MSG_LEVEL_DEBUG; */ static int msglevel =MSG_LEVEL_INFO; -// -// Define module options -// +/* + * define module options + */ -// Version Information -#define DRIVER_AUTHOR "VIA Networking Technologies, Inc., " +/* version information */ +#define DRIVER_AUTHOR \ + "VIA Networking Technologies, Inc., " MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM); @@ -184,16 +185,16 @@ DEVICE_PARAM(BasebandType, "baseband type"); DEVICE_PARAM(b80211hEnable, "802.11h mode"); -// -// Static vars definitions -// +/* + * Static vars definitions + */ static struct usb_device_id vt6656_table[] = { {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, {} }; -// Frequency list (map channels to frequencies) +/* frequency list (map channels to frequencies) */ /* static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484, @@ -288,7 +289,7 @@ device_set_options(struct vnt_private *pDevice) { pDevice->wCTSDuration = 0; pDevice->byPreambleType = 0; pDevice->bExistSWNetAddr = FALSE; -// pDevice->bDiversityRegCtlON = TRUE; + /* pDevice->bDiversityRegCtlON = TRUE; */ pDevice->bDiversityRegCtlON = FALSE; } @@ -314,9 +315,9 @@ static void device_init_diversity_timer(struct vnt_private *pDevice) } -// -// Initialization of MAC & BBP registers -// +/* + * initialization of MAC & BBP registers + */ static int device_init_registers(struct vnt_private *pDevice, DEVICE_INIT_TYPE InitType) @@ -372,7 +373,7 @@ static int device_init_registers(struct vnt_private *pDevice, sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit; sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit; - //issue Card_init command to device + /* issue card_init command to device */ ntStatus = CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_CARDINIT, 0, @@ -395,7 +396,7 @@ static int device_init_registers(struct vnt_private *pDevice, return FALSE; } - //Local ID for AES functions + /* local ID for AES functions */ ntStatus = CONTROLnsRequestIn(pDevice, MESSAGE_TYPE_READ, MAC_REG_LOCALID, @@ -408,10 +409,12 @@ static int device_init_registers(struct vnt_private *pDevice, return FALSE; } - // Do MACbSoftwareReset in MACvInitialize - // force CCK + /* do MACbSoftwareReset in MACvInitialize */ + + /* force CCK */ pDevice->bCCK = TRUE; - pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE + pDevice->bProtectMode = FALSE; + /* only used in 11g type, sync with ERP IE */ pDevice->bNonERPPresent = FALSE; pDevice->bBarkerPreambleMd = FALSE; if ( pDevice->bFixRate ) { @@ -427,13 +430,14 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->byTopOFDMBasicRate = RATE_24M; pDevice->byTopCCKBasicRate = RATE_1M; - pDevice->byRevId = 0; //Target to IF pin while programming to RF chip. + pDevice->byRevId = 0; + /* target to IF pin while programming to RF chip */ pDevice->byCurPwr = 0xFF; pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK]; pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG]; - // Load power Table - for (ii=0;ii<14;ii++) { + /* load power table */ + for (ii = 0; ii < 14; ii++) { pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL]; if (pDevice->abyCCKPwrTbl[ii] == 0) pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr; @@ -442,8 +446,10 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG; } - //original zonetype is USA,but customize zonetype is europe, - // then need recover 12,13 ,14 channel with 11 channel + /* + * original zonetype is USA, but custom zonetype is Europe, + * then need to recover 12, 13, 14 channels with 11 channel + */ if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) || (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&& (pDevice->byOriginalZonetype == ZoneType_USA)) { @@ -453,15 +459,14 @@ static int device_init_registers(struct vnt_private *pDevice, } } - //{{ RobertYu: 20041124 - pDevice->byOFDMPwrA = 0x34; // same as RFbMA2829SelectChannel - // Load OFDM A Power Table - for (ii=0;iibyOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */ + + /* load OFDM A power table */ + for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL]; if (pDevice->abyOFDMAPwrTbl[ii] == 0) pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA; } - //}} RobertYu byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA]; if (byAntenna & EEP_ANTINV) @@ -471,7 +476,7 @@ static int device_init_registers(struct vnt_private *pDevice, byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); - if (byAntenna == 0) // if not set default is All + if (byAntenna == 0) /* if not set default is both */ byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) { @@ -513,35 +518,34 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->byTMax2 = 4; pDevice->ulSQ3TH = 0; pDevice->byTMax3 = 64; - // ----------------------------------------------------------------- - //Get Auto Fall Back Type + /* get Auto Fall Back type */ pDevice->byAutoFBCtrl = AUTO_FB_0; - // Set SCAN Time + /* set SCAN Time */ pDevice->uScanTime = WLAN_SCAN_MINITIME; - // default Auto Mode - //pDevice->NetworkType = Ndis802_11Automode; + /* default Auto Mode */ + /* pDevice->NetworkType = Ndis802_11Automode; */ pDevice->eConfigPHYMode = PHY_TYPE_AUTO; pDevice->byBBType = BB_TYPE_11G; - // initialize BBP registers + /* initialize BBP registers */ pDevice->ulTxPower = 25; - // Get Channel range + /* get channel range */ pDevice->byMinChannel = 1; pDevice->byMaxChannel = CB_MAX_CHANNEL; - // Get RFType + /* get RFType */ pDevice->byRFType = sInitRsp.byRFType; if ((pDevice->byRFType & RF_EMU) != 0) { - // force change RevID for VT3253 emu - pDevice->byRevId = 0x80; + /* force change RevID for VT3253 emu */ + pDevice->byRevId = 0x80; } - // Load EEPROM calibrated vt3266 parameters + /* load vt3266 calibration parameters in EEPROM */ if (pDevice->byRFType == RF_VT3226D0) { if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) && (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) { @@ -549,13 +553,32 @@ static int device_init_registers(struct vnt_private *pDevice, byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC]; byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ]; if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) { - ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x03); // CR255, Set BB to support TX/RX IQ and DC compensation Mode - ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFB, byCalibTXIQ); // CR251, TX I/Q Imbalance Calibration - ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFC, byCalibTXDC); // CR252, TX DC-Offset Calibration - ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFD, byCalibRXIQ); // CR253, RX I/Q Imbalance Calibration + /* CR255, enable TX/RX IQ and DC compensation mode */ + ControlvWriteByte(pDevice, + MESSAGE_REQUEST_BBREG, + 0xFF, + 0x03); + /* CR251, TX I/Q Imbalance Calibration */ + ControlvWriteByte(pDevice, + MESSAGE_REQUEST_BBREG, + 0xFB, + byCalibTXIQ); + /* CR252, TX DC-Offset Calibration */ + ControlvWriteByte(pDevice, + MESSAGE_REQUEST_BBREG, + 0xFC, + byCalibTXDC); + /* CR253, RX I/Q Imbalance Calibration */ + ControlvWriteByte(pDevice, + MESSAGE_REQUEST_BBREG, + 0xFD, + byCalibRXIQ); } else { - // turn off BB Calibration compensation - ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x0); // CR255 + /* CR255, turn off BB Calibration compensation */ + ControlvWriteByte(pDevice, + MESSAGE_REQUEST_BBREG, + 0xFF, + 0x0); } } } @@ -564,20 +587,21 @@ static int device_init_registers(struct vnt_private *pDevice, pMgmt->uIBSSChannel = pDevice->uChannel; CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel); - // get Permanent network address + /* get permanent network address */ memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6); memcpy(pDevice->abyCurrentNetAddr, pDevice->abyPermanentNetAddr, ETH_ALEN); - // if exist SW network address, use SW network address. - + /* if exist SW network address, use it */ DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n", pDevice->abyCurrentNetAddr); } - // Set BB and packet type at the same time. - // Set Short Slot Time, xIFS, and RSPINF. + /* + * set BB and packet type at the same time + * set Short Slot Time, xIFS, and RSPINF + */ if (pDevice->byBBType == BB_TYPE_11A) { CARDbAddBasicRate(pDevice, RATE_6M); pDevice->bShortSlotTime = TRUE; @@ -616,7 +640,7 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->bHWRadioOff = FALSE; } - } //EEP_RADIOCTL_ENABLE + } ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38); ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); @@ -741,7 +765,7 @@ static void device_free_tx_bufs(struct vnt_private *pDevice) for (ii = 0; ii < pDevice->cbTD; ii++) { pTxContext = pDevice->apTD[ii]; - //de-allocate URBs + /* deallocate URBs */ if (pTxContext->pUrb) { usb_kill_urb(pTxContext->pUrb); usb_free_urb(pTxContext->pUrb); @@ -760,12 +784,12 @@ static void device_free_rx_bufs(struct vnt_private *pDevice) for (ii = 0; ii < pDevice->cbRD; ii++) { pRCB = pDevice->apRCB[ii]; - //de-allocate URBs + /* deallocate URBs */ if (pRCB->pUrb) { usb_kill_urb(pRCB->pUrb); usb_free_urb(pRCB->pUrb); } - //de-allocate skb + /* deallocate skb */ if (pRCB->skb) dev_kfree_skb(pRCB->skb); } @@ -807,7 +831,7 @@ static BOOL device_alloc_bufs(struct vnt_private *pDevice) } pDevice->apTD[ii] = pTxContext; pTxContext->pDevice = (void *) pDevice; - //allocate URBs + /* allocate URBs */ pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC); if (pTxContext->pUrb == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n"); @@ -816,7 +840,7 @@ static BOOL device_alloc_bufs(struct vnt_private *pDevice) pTxContext->bBoolInUse = FALSE; } - // allocate rcb mem + /* allocate RCB mem */ pDevice->pRCBMem = kzalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL); if (pDevice->pRCBMem == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name); @@ -835,7 +859,7 @@ static BOOL device_alloc_bufs(struct vnt_private *pDevice) pDevice->apRCB[ii] = pRCB; pRCB->pDevice = (void *) pDevice; - //allocate URBs + /* allocate URBs */ pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC); if (pRCB->pUrb == NULL) { @@ -974,7 +998,7 @@ static int device_open(struct net_device *dev) MP_SET_FLAG(pDevice, fMP_POST_READS); MP_SET_FLAG(pDevice, fMP_POST_WRITES); - //read config file + /* read config file */ Read_config_file(pDevice); if (device_init_registers(pDevice, DEVICE_INIT_COLD) == FALSE) { @@ -983,8 +1007,8 @@ static int device_open(struct net_device *dev) } device_set_multi(pDevice->dev); - // Init for Key Management + /* init for key management */ KeyvInitTable(pDevice,&pDevice->sKey); memcpy(pDevice->vnt_mgmt.abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN); @@ -1003,7 +1027,7 @@ static int device_open(struct net_device *dev) tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice); tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice); add_timer(&pDevice->vnt_mgmt.sTimerSecondCallback); - pDevice->int_interval = 100; //Max 100 microframes. + pDevice->int_interval = 100; /* max 100 microframes */ pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; pDevice->bIsRxWorkItemQueued = TRUE; @@ -1021,7 +1045,7 @@ static int device_open(struct net_device *dev) RXvWorkItem(pDevice); INTvWorkItem(pDevice); - // Patch: if WEP key already set by iwconfig but device not yet open + /* if WEP key already set by iwconfig but device not yet open */ if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) { spin_lock_irq(&pDevice->lock); KeybSetDefaultKey( pDevice, @@ -1221,7 +1245,7 @@ static inline u32 ether_crc(int length, unsigned char *data) return crc; } -//find out the start position of str2 from str1 +/* find out the start position of str2 from str1 */ static unsigned char *kstrstr(const unsigned char *str1, const unsigned char *str2) { int str1_len = strlen(str1); @@ -1250,12 +1274,12 @@ static int Config_FileGetParameter(unsigned char *string, strcat(buf1, "="); source+=strlen(buf1); -//find target string start point + /* find target string start point */ start_p = kstrstr(source,buf1); if (start_p == NULL) return FALSE; -//check if current config line is marked by "#" ?? + /* check if current config line is marked by "#" */ for (ii = 1; ; ii++) { if (memcmp(start_p - ii, "\n", 1) == 0) break; @@ -1263,24 +1287,24 @@ static int Config_FileGetParameter(unsigned char *string, return FALSE; } -//find target string end point + /* find target string end point */ end_p = kstrstr(start_p,"\n"); - if (end_p == NULL) { //can't find "\n",but don't care - end_p=start_p+strlen(start_p); //no include "\n" - } + if (end_p == NULL) { /* can't find "\n", but don't care */ + end_p = start_p + strlen(start_p); /* no include "\n" */ + } memset(buf2,0,100); - memcpy(buf2,start_p,end_p-start_p); //get the target line + memcpy(buf2, start_p, end_p-start_p); /* get the target line */ buf2[end_p-start_p]='\0'; - //find value + /* find value */ start_p = kstrstr(buf2,"="); if (start_p == NULL) return FALSE; memset(buf1,0,100); strcpy(buf1,start_p+1); - //except space + /* except space */ tmp_p = buf1; while(*tmp_p != 0x00) { if(*tmp_p==' ') @@ -1293,26 +1317,19 @@ static int Config_FileGetParameter(unsigned char *string, return TRUE; } -//if read fail,return NULL,or return data pointer; +/* if read fails, return NULL, or return data pointer */ static unsigned char *Config_FileOperation(struct vnt_private *pDevice) { unsigned char *config_path = CONFIG_PATH; unsigned char *buffer = NULL; struct file *filp=NULL; mm_segment_t old_fs = get_fs(); - //int oldfsuid=0,oldfsgid=0; + int result = 0; set_fs (KERNEL_DS); - /* Can't do this anymore, so we rely on correct filesystem permissions: - //Make sure a caller can read or write power as root - oldfsuid=current->fsuid; - oldfsgid=current->fsgid; - current->fsuid = 0; - current->fsgid = 0; - */ - - //open file + + /* open file */ filp = filp_open(config_path, O_RDWR, 0); if (IS_ERR(filp)) { printk("Config_FileOperation file Not exist\n"); @@ -1345,11 +1362,6 @@ error1: error2: set_fs (old_fs); - /* - current->fsuid=oldfsuid; - current->fsgid=oldfsgid; - */ - if(result!=0) { kfree(buffer); buffer=NULL; @@ -1357,14 +1369,14 @@ if(result!=0) { return buffer; } -//return --->-1:fail; >=0:successful +/* return --->-1:fail; >=0:successful */ static int Read_config_file(struct vnt_private *pDevice) { int result = 0; unsigned char tmpbuffer[100]; unsigned char *buffer = NULL; - //init config setting + /* init config setting */ pDevice->config_file.ZoneType = -1; pDevice->config_file.eAuthenMode = -1; pDevice->config_file.eEncryptionStatus = -1; @@ -1375,7 +1387,7 @@ static int Read_config_file(struct vnt_private *pDevice) return result; } -//get zonetype +/* get zonetype */ { memset(tmpbuffer,0,sizeof(tmpbuffer)); if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==TRUE) { @@ -1394,7 +1406,7 @@ static int Read_config_file(struct vnt_private *pDevice) } } -//get other parameter +/* get other parameter */ { memset(tmpbuffer,0,sizeof(tmpbuffer)); if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==TRUE) { @@ -1435,9 +1447,9 @@ static void device_set_multi(struct net_device *dev) DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode); - if (dev->flags & IFF_PROMISC) { // Set promiscuous. + if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */ DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name); - // Unconditionally log net taps. + /* unconditionally log net taps */ pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST); } else if ((netdev_mc_count(dev) > pDevice->multicast_limit) || @@ -1466,7 +1478,10 @@ static void device_set_multi(struct net_device *dev) } if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { - // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac. + /* + * If AP mode, don't enable RCR_UNICAST since HW only compares + * addr1 with local MAC + */ pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); pDevice->byRxMode &= ~(RCR_UNICAST); } @@ -1530,9 +1545,6 @@ static int ethtool_ioctl(struct net_device *dev, void *useraddr) return -EOPNOTSUPP; } - -/*------------------------------------------------------------------*/ - MODULE_DEVICE_TABLE(usb, vt6656_table); static struct usb_driver vt6656_driver = { -- cgit v0.10.2 From f91f9beaa1654ce76a783fbb65fcd51a2dde29c1 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 31 Jan 2013 15:25:49 -0700 Subject: staging: comedi: das08: split out bus specific code Split the bus specific ISA/PC-104 and PCI code out of this driver and create two new drivers, das08_isa and das08_pci. This allows removing all the #ifdef'ery in the das08 driver that handled if the CONFIG_COMEDI_DAS08_{ISA,PCI} options were enabled. It also makes the PCI driver cleanly Plug-and-Play since the comedi driver only has an auto_attach callback. Previously it also had an attach callback in order to handle the ISA cards. Since the PCMCIA support was already split out, we can also remove the now unused enum das08_bustype and it's use in the boardinfo. The bus specific code deals with the bustype automatically before it calls the common attach function in das08. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 2da9290..1967852 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -274,7 +274,7 @@ config COMEDI_DAS08_ISA DAS08/JR-16-AO, PC104-DAS08, DAS08/JR/16. To compile this driver as a module, choose M here: the module will be - called das08. + called das08_isa. config COMEDI_DAS16 tristate "DAS-16 compatible ISA and PC/104 card support" @@ -802,7 +802,7 @@ config COMEDI_DAS08_PCI Enable support for PCI DAS-08 cards. To compile this driver as a module, choose M here: the module will be - called das08. + called das08_pci. config COMEDI_DT3000 tristate "Data Translation DT3000 series support" diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index fd74e7e..315e836 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_COMEDI_PCM3730) += pcm3730.o obj-$(CONFIG_COMEDI_RTI800) += rti800.o obj-$(CONFIG_COMEDI_RTI802) += rti802.o obj-$(CONFIG_COMEDI_DAS16M1) += das16m1.o +obj-$(CONFIG_COMEDI_DAS08_ISA) += das08_isa.o obj-$(CONFIG_COMEDI_DAS16) += das16.o obj-$(CONFIG_COMEDI_DAS800) += das800.o obj-$(CONFIG_COMEDI_DAS1800) += das1800.o @@ -81,6 +82,7 @@ obj-$(CONFIG_COMEDI_AMPLC_PC263) += amplc_pc263.o obj-$(CONFIG_COMEDI_AMPLC_PCI224) += amplc_pci224.o obj-$(CONFIG_COMEDI_AMPLC_PCI230) += amplc_pci230.o obj-$(CONFIG_COMEDI_CONTEC_PCI_DIO) += contec_pci_dio.o +obj-$(CONFIG_COMEDI_DAS08_PCI) += das08_pci.o obj-$(CONFIG_COMEDI_DT3000) += dt3000.o obj-$(CONFIG_COMEDI_DYNA_PCI10XX) += dyna_pci10xx.o obj-$(CONFIG_COMEDI_UNIOXX5) += unioxx5.o diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c index 45a937e..9823aa0 100644 --- a/drivers/staging/comedi/drivers/das08.c +++ b/drivers/staging/comedi/drivers/das08.c @@ -1,6 +1,6 @@ /* * comedi/drivers/das08.c - * DAS08 driver + * comedi driver for common DAS08 support (used by ISA/PCI/PCMCIA drivers) * * COMEDI - Linux Control and Measurement Device Interface * Copyright (C) 2000 David A. Schleef @@ -27,31 +27,18 @@ /* * Driver: das08 * Description: DAS-08 compatible boards + * Devices: various, see das08_isa, das08_cs, and das08_pci drivers * Author: Warren Jasper, ds, Frank Hess - * Devices: [Keithley Metrabyte] DAS08 (isa-das08), - * [ComputerBoards] DAS08 (isa-das08), DAS08-PGM (das08-pgm), - * DAS08-PGH (das08-pgh), DAS08-PGL (das08-pgl), DAS08-AOH (das08-aoh), - * DAS08-AOL (das08-aol), DAS08-AOM (das08-aom), DAS08/JR-AO (das08/jr-ao), - * DAS08/JR-16-AO (das08jr-16-ao), PCI-DAS08 (pci-das08), - * PC104-DAS08 (pc104-das08), DAS08/JR/16 (das08jr/16) * Updated: Fri, 31 Aug 2012 19:19:06 +0100 * Status: works * - * This is a rewrite of the das08 and das08jr drivers. + * This driver is used by the das08_isa, das08_cs, and das08_pci + * drivers to provide the common support for the DAS-08 hardware. * - * Options (for ISA cards): - * [0] - base io address - * - * Manual configuration of PCI cards is not supported; they are - * configured automatically. - * - * The das08 driver doesn't support asynchronous commands, since - * the cheap das08 hardware doesn't really support them. The - * comedi_rt_timer driver can be used to emulate commands for this - * driver. + * The driver doesn't support asynchronous commands, since the + * cheap das08 hardware doesn't really support them. */ -#include #include #include "../comedidev.h" @@ -60,25 +47,6 @@ #include "8253.h" #include "das08.h" -#define DRV_NAME "das08" - -#define DO_ISA IS_ENABLED(CONFIG_COMEDI_DAS08_ISA) -#define DO_PCI IS_ENABLED(CONFIG_COMEDI_DAS08_PCI) -#define DO_COMEDI_DRIVER_REGISTER (DO_ISA || DO_PCI) - -#define PCI_DEVICE_ID_PCIDAS08 0x29 -#define PCIDAS08_SIZE 0x54 - -/* pci configuration registers */ -#define INTCSR 0x4c -#define INTR1_ENABLE 0x1 -#define INTR1_HIGH_POLARITY 0x2 -#define PCI_INTR_ENABLE 0x40 -#define INTR1_EDGE_TRIG 0x100 /* requires high polarity */ -#define CNTRL 0x50 -#define CNTRL_DIR 0x2 -#define CNTRL_INTR 0x4 - /* cio-das08.pdf @@ -236,16 +204,6 @@ static const int *const das08_gainlists[] = { das08_pgm_gainlist, }; -static inline bool is_isa_board(const struct das08_board_struct *board) -{ - return DO_ISA && board->bustype == isa; -} - -static inline bool is_pci_board(const struct das08_board_struct *board) -{ - return DO_PCI && board->bustype == pci; -} - #define TIMEOUT 100000 static int das08_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, @@ -502,159 +460,6 @@ static int das08_counter_config(struct comedi_device *dev, return 2; } -#if DO_COMEDI_DRIVER_REGISTER -static const struct das08_board_struct das08_boards[] = { -#if DO_ISA - { - .name = "isa-das08", /* cio-das08.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pg_none, - .ai_encoding = das08_encode12, - .di_nchan = 3, - .do_nchan = 4, - .i8255_offset = 8, - .i8254_offset = 4, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08-pgm", /* cio-das08pgx.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pgm, - .ai_encoding = das08_encode12, - .di_nchan = 3, - .do_nchan = 4, - .i8255_offset = 0, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08-pgh", /* cio-das08pgx.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pgh, - .ai_encoding = das08_encode12, - .di_nchan = 3, - .do_nchan = 4, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08-pgl", /* cio-das08pgx.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pgl, - .ai_encoding = das08_encode12, - .di_nchan = 3, - .do_nchan = 4, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08-aoh", /* cio-das08_aox.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pgh, - .ai_encoding = das08_encode12, - .ao_nbits = 12, - .di_nchan = 3, - .do_nchan = 4, - .i8255_offset = 0x0c, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08-aol", /* cio-das08_aox.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pgl, - .ai_encoding = das08_encode12, - .ao_nbits = 12, - .di_nchan = 3, - .do_nchan = 4, - .i8255_offset = 0x0c, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08-aom", /* cio-das08_aox.pdf */ - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pgm, - .ai_encoding = das08_encode12, - .ao_nbits = 12, - .di_nchan = 3, - .do_nchan = 4, - .i8255_offset = 0x0c, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08/jr-ao", /* cio-das08-jr-ao.pdf */ - .bustype = isa, - .is_jr = true, - .ai_nbits = 12, - .ai_pg = das08_pg_none, - .ai_encoding = das08_encode12, - .ao_nbits = 12, - .di_nchan = 8, - .do_nchan = 8, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08jr-16-ao", /* cio-das08jr-16-ao.pdf */ - .bustype = isa, - .is_jr = true, - .ai_nbits = 16, - .ai_pg = das08_pg_none, - .ai_encoding = das08_encode16, - .ao_nbits = 16, - .di_nchan = 8, - .do_nchan = 8, - .i8254_offset = 0x04, - .iosize = 16, /* unchecked */ - }, - { - .name = "pc104-das08", - .bustype = isa, - .ai_nbits = 12, - .ai_pg = das08_pg_none, - .ai_encoding = das08_encode12, - .di_nchan = 3, - .do_nchan = 4, - .i8254_offset = 4, - .iosize = 16, /* unchecked */ - }, - { - .name = "das08jr/16", - .bustype = isa, - .is_jr = true, - .ai_nbits = 16, - .ai_pg = das08_pg_none, - .ai_encoding = das08_encode16, - .di_nchan = 8, - .do_nchan = 8, - .iosize = 16, /* unchecked */ - }, -#endif /* DO_ISA */ -#if DO_PCI - { - .name = "pci-das08", /* pci-das08 */ - .id = PCI_DEVICE_ID_PCIDAS08, - .bustype = pci, - .ai_nbits = 12, - .ai_pg = das08_bipolar5, - .ai_encoding = das08_encode12, - .di_nchan = 3, - .do_nchan = 4, - .i8254_offset = 4, - .iosize = 8, - }, -#endif /* DO_PCI */ -}; -#endif /* DO_COMEDI_DRIVER_REGISTER */ - int das08_common_attach(struct comedi_device *dev, unsigned long iobase) { const struct das08_board_struct *thisboard = comedi_board(dev); @@ -761,84 +566,6 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase) } EXPORT_SYMBOL_GPL(das08_common_attach); -static const struct das08_board_struct * -das08_find_pci_board(struct pci_dev *pdev) -{ -#if DO_COMEDI_DRIVER_REGISTER - unsigned int i; - for (i = 0; i < ARRAY_SIZE(das08_boards); i++) - if (is_pci_board(&das08_boards[i]) && - pdev->device == das08_boards[i].id) - return &das08_boards[i]; -#endif - return NULL; -} - -/* only called in the PCI probe path, via comedi_pci_auto_config() */ -static int __maybe_unused -das08_auto_attach(struct comedi_device *dev, unsigned long context_unused) -{ - struct pci_dev *pdev; - struct das08_private_struct *devpriv; - unsigned long iobase; - - if (!DO_PCI) - return -EINVAL; - - pdev = comedi_to_pci_dev(dev); - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - - dev_info(dev->class_dev, "attach pci %s\n", pci_name(pdev)); - dev->board_ptr = das08_find_pci_board(pdev); - if (dev->board_ptr == NULL) { - dev_err(dev->class_dev, "BUG! cannot determine board type!\n"); - return -EINVAL; - } - - /* enable PCI device and reserve I/O spaces */ - if (comedi_pci_enable(pdev, dev->driver->driver_name)) { - dev_err(dev->class_dev, - "Error enabling PCI device and requesting regions\n"); - return -EIO; - } - /* read base addresses */ - iobase = pci_resource_start(pdev, 2); - return das08_common_attach(dev, iobase); -} - -static int __maybe_unused -das08_attach(struct comedi_device *dev, struct comedi_devconfig *it) -{ - const struct das08_board_struct *thisboard = comedi_board(dev); - struct das08_private_struct *devpriv; - unsigned long iobase; - - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - - dev_info(dev->class_dev, "attach\n"); - if (is_pci_board(thisboard)) { - dev_err(dev->class_dev, - "Manual configuration of PCI board '%s' is not supported\n", - thisboard->name); - return -EIO; - } else if (is_isa_board(thisboard)) { - iobase = it->options[0]; - dev_info(dev->class_dev, "iobase 0x%lx\n", iobase); - if (!request_region(iobase, thisboard->iosize, DRV_NAME)) { - dev_err(dev->class_dev, "I/O port conflict\n"); - return -EIO; - } - return das08_common_attach(dev, iobase); - } else - return -EIO; -} - void das08_common_detach(struct comedi_device *dev) { if (dev->subdevices) @@ -846,79 +573,16 @@ void das08_common_detach(struct comedi_device *dev) } EXPORT_SYMBOL_GPL(das08_common_detach); -static void __maybe_unused das08_detach(struct comedi_device *dev) -{ - const struct das08_board_struct *thisboard = comedi_board(dev); - - if (!thisboard) - return; - das08_common_detach(dev); - if (is_isa_board(thisboard)) { - if (dev->iobase) - release_region(dev->iobase, thisboard->iosize); - } else if (is_pci_board(thisboard)) { - struct pci_dev *pdev = comedi_to_pci_dev(dev); - if (pdev) { - if (dev->iobase) - comedi_pci_disable(pdev); - } - } -} - -#if DO_COMEDI_DRIVER_REGISTER -static struct comedi_driver das08_driver = { - .driver_name = DRV_NAME, - .module = THIS_MODULE, - .attach = das08_attach, - .auto_attach = das08_auto_attach, - .detach = das08_detach, - .board_name = &das08_boards[0].name, - .num_names = sizeof(das08_boards) / sizeof(struct das08_board_struct), - .offset = sizeof(struct das08_board_struct), -}; -#endif - -#if DO_PCI -static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = { - { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_PCIDAS08) }, - {0} -}; - -MODULE_DEVICE_TABLE(pci, das08_pci_table); - -static int das08_pci_probe(struct pci_dev *dev, - const struct pci_device_id *ent) -{ - return comedi_pci_auto_config(dev, &das08_driver); -} - -static struct pci_driver das08_pci_driver = { - .id_table = das08_pci_table, - .name = DRV_NAME, - .probe = &das08_pci_probe, - .remove = comedi_pci_auto_unconfig, -}; -#endif /* DO_PCI */ - -#if DO_COMEDI_DRIVER_REGISTER -#if DO_PCI -module_comedi_pci_driver(das08_driver, das08_pci_driver); -#else -module_comedi_driver(das08_driver); -#endif -#else /* DO_COMEDI_DRIVER_REGISTER */ static int __init das08_init(void) { return 0; } +module_init(das08_init); static void __exit das08_exit(void) { } - -module_init(das08_init); module_exit(das08_exit); -#endif /* DO_COMEDI_DRIVER_REGISTER */ MODULE_AUTHOR("Comedi http://www.comedi.org"); MODULE_DESCRIPTION("Comedi low-level driver"); diff --git a/drivers/staging/comedi/drivers/das08.h b/drivers/staging/comedi/drivers/das08.h index 0314bae..b102ad4 100644 --- a/drivers/staging/comedi/drivers/das08.h +++ b/drivers/staging/comedi/drivers/das08.h @@ -24,7 +24,6 @@ #ifndef _DAS08_H #define _DAS08_H -enum das08_bustype { isa, pci, pcmcia }; /* different ways ai data is encoded in first two registers */ enum das08_ai_encoding { das08_encode12, das08_encode16, das08_pcm_encode12 }; enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl, @@ -34,7 +33,6 @@ enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl, struct das08_board_struct { const char *name; unsigned int id; /* id for pci/pcmcia boards */ - enum das08_bustype bustype; bool is_jr; /* true for 'JR' boards */ unsigned int ai_nbits; enum das08_lrange ai_pg; diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index 23fdb11..4654b60 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -60,7 +60,6 @@ static const struct das08_board_struct das08_cs_boards[] = { { .name = "pcm-das08", .id = 0x0, /* XXX */ - .bustype = pcmcia, .ai_nbits = 12, .ai_pg = das08_bipolar5, .ai_encoding = das08_pcm_encode12, diff --git a/drivers/staging/comedi/drivers/das08_isa.c b/drivers/staging/comedi/drivers/das08_isa.c new file mode 100644 index 0000000..f120782 --- /dev/null +++ b/drivers/staging/comedi/drivers/das08_isa.c @@ -0,0 +1,217 @@ +/* + * das08_isa.c + * comedi driver for DAS08 ISA/PC-104 boards + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 David A. Schleef + * Copyright (C) 2001,2002,2003 Frank Mori Hess + * Copyright (C) 2004 Salvador E. Tropea + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * Driver: das08_isa + * Description: DAS-08 ISA/PC-104 compatible boards + * Devices: (Keithley Metrabyte) DAS08 [isa-das08], + * (ComputerBoards) DAS08 [isa-das08] + * (ComputerBoards) DAS08-PGM [das08-pgm] + * (ComputerBoards) DAS08-PGH [das08-pgh] + * (ComputerBoards) DAS08-PGL [das08-pgl] + * (ComputerBoards) DAS08-AOH [das08-aoh] + * (ComputerBoards) DAS08-AOL [das08-aol] + * (ComputerBoards) DAS08-AOM [das08-aom] + * (ComputerBoards) DAS08/JR-AO [das08/jr-ao] + * (ComputerBoards) DAS08/JR-16-AO [das08jr-16-ao] + * (ComputerBoards) PC104-DAS08 [pc104-das08] + * (ComputerBoards) DAS08/JR/16 [das08jr/16] + * Author: Warren Jasper, ds, Frank Hess + * Updated: Fri, 31 Aug 2012 19:19:06 +0100 + * Status: works + * + * This is the ISA/PC-104-specific support split off from the das08 driver. + * + * Configuration Options: + * [0] - base io address + */ + +#include "../comedidev.h" + +#include "das08.h" + +static const struct das08_board_struct das08_isa_boards[] = { + { + /* cio-das08.pdf */ + .name = "isa-das08", + .ai_nbits = 12, + .ai_pg = das08_pg_none, + .ai_encoding = das08_encode12, + .di_nchan = 3, + .do_nchan = 4, + .i8255_offset = 8, + .i8254_offset = 4, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08pgx.pdf */ + .name = "das08-pgm", + .ai_nbits = 12, + .ai_pg = das08_pgm, + .ai_encoding = das08_encode12, + .di_nchan = 3, + .do_nchan = 4, + .i8255_offset = 0, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08pgx.pdf */ + .name = "das08-pgh", + .ai_nbits = 12, + .ai_pg = das08_pgh, + .ai_encoding = das08_encode12, + .di_nchan = 3, + .do_nchan = 4, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08pgx.pdf */ + .name = "das08-pgl", + .ai_nbits = 12, + .ai_pg = das08_pgl, + .ai_encoding = das08_encode12, + .di_nchan = 3, + .do_nchan = 4, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08_aox.pdf */ + .name = "das08-aoh", + .ai_nbits = 12, + .ai_pg = das08_pgh, + .ai_encoding = das08_encode12, + .ao_nbits = 12, + .di_nchan = 3, + .do_nchan = 4, + .i8255_offset = 0x0c, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08_aox.pdf */ + .name = "das08-aol", + .ai_nbits = 12, + .ai_pg = das08_pgl, + .ai_encoding = das08_encode12, + .ao_nbits = 12, + .di_nchan = 3, + .do_nchan = 4, + .i8255_offset = 0x0c, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08_aox.pdf */ + .name = "das08-aom", + .ai_nbits = 12, + .ai_pg = das08_pgm, + .ai_encoding = das08_encode12, + .ao_nbits = 12, + .di_nchan = 3, + .do_nchan = 4, + .i8255_offset = 0x0c, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08-jr-ao.pdf */ + .name = "das08/jr-ao", + .is_jr = true, + .ai_nbits = 12, + .ai_pg = das08_pg_none, + .ai_encoding = das08_encode12, + .ao_nbits = 12, + .di_nchan = 8, + .do_nchan = 8, + .iosize = 16, /* unchecked */ + }, { + /* cio-das08jr-16-ao.pdf */ + .name = "das08jr-16-ao", + .is_jr = true, + .ai_nbits = 16, + .ai_pg = das08_pg_none, + .ai_encoding = das08_encode16, + .ao_nbits = 16, + .di_nchan = 8, + .do_nchan = 8, + .i8254_offset = 0x04, + .iosize = 16, /* unchecked */ + }, { + .name = "pc104-das08", + .ai_nbits = 12, + .ai_pg = das08_pg_none, + .ai_encoding = das08_encode12, + .di_nchan = 3, + .do_nchan = 4, + .i8254_offset = 4, + .iosize = 16, /* unchecked */ + }, { + .name = "das08jr/16", + .is_jr = true, + .ai_nbits = 16, + .ai_pg = das08_pg_none, + .ai_encoding = das08_encode16, + .di_nchan = 8, + .do_nchan = 8, + .iosize = 16, /* unchecked */ + }, +}; + +static int das08_isa_attach(struct comedi_device *dev, + struct comedi_devconfig *it) +{ + const struct das08_board_struct *thisboard = comedi_board(dev); + struct das08_private_struct *devpriv; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + if (!request_region(it->options[0], thisboard->iosize, + thisboard->name)) + return -EIO; + + return das08_common_attach(dev, it->options[0]); +} + +static void das08_isa_detach(struct comedi_device *dev) +{ + const struct das08_board_struct *thisboard = comedi_board(dev); + + das08_common_detach(dev); + if (dev->iobase) + release_region(dev->iobase, thisboard->iosize); +} + +static struct comedi_driver das08_isa_driver = { + .driver_name = "isa-das08", + .module = THIS_MODULE, + .attach = das08_isa_attach, + .detach = das08_isa_detach, + .board_name = &das08_isa_boards[0].name, + .num_names = ARRAY_SIZE(das08_isa_boards), + .offset = sizeof(das08_isa_boards[0]), +}; +module_comedi_driver(das08_isa_driver); + +MODULE_AUTHOR("Comedi http://www.comedi.org"); +MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/das08_pci.c b/drivers/staging/comedi/drivers/das08_pci.c new file mode 100644 index 0000000..c405876 --- /dev/null +++ b/drivers/staging/comedi/drivers/das08_pci.c @@ -0,0 +1,121 @@ +/* + * das08_pci.c + * comedi driver for DAS08 PCI boards + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 David A. Schleef + * Copyright (C) 2001,2002,2003 Frank Mori Hess + * Copyright (C) 2004 Salvador E. Tropea + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * Driver: das08_pci + * Description: DAS-08 PCI compatible boards + * Devices: (ComputerBoards) PCI-DAS08 [pci-das08] + * Author: Warren Jasper, ds, Frank Hess + * Updated: Fri, 31 Aug 2012 19:19:06 +0100 + * Status: works + * + * This is the PCI-specific support split off from the das08 driver. + * + * Configuration Options: not applicable, uses PCI auto config + */ + +#include + +#include "../comedidev.h" + +#include "das08.h" + +#define PCI_DEVICE_ID_PCIDAS08 0x0029 + +static const struct das08_board_struct das08_pci_boards[] = { + { + .name = "pci-das08", + .id = PCI_DEVICE_ID_PCIDAS08, + .ai_nbits = 12, + .ai_pg = das08_bipolar5, + .ai_encoding = das08_encode12, + .di_nchan = 3, + .do_nchan = 4, + .i8254_offset = 4, + .iosize = 8, + }, +}; + +static int das08_pci_auto_attach(struct comedi_device *dev, + unsigned long context_unused) +{ + struct pci_dev *pdev = comedi_to_pci_dev(dev); + struct das08_private_struct *devpriv; + int ret; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + /* The das08 driver needs the board_ptr */ + dev->board_ptr = &das08_pci_boards[0]; + + ret = comedi_pci_enable(pdev, dev->driver->driver_name); + if (ret) + return ret; + dev->iobase = pci_resource_start(pdev, 2); + + return das08_common_attach(dev, dev->iobase); +} + +static void das08_pci_detach(struct comedi_device *dev) +{ + struct pci_dev *pdev = comedi_to_pci_dev(dev); + + das08_common_detach(dev); + if (dev->iobase) + comedi_pci_disable(pdev); +} + +static struct comedi_driver das08_pci_comedi_driver = { + .driver_name = "pci-das08", + .module = THIS_MODULE, + .auto_attach = das08_pci_auto_attach, + .detach = das08_pci_detach, +}; + +static int das08_pci_probe(struct pci_dev *dev, + const struct pci_device_id *ent) +{ + return comedi_pci_auto_config(dev, &das08_pci_comedi_driver); +} + +static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = { + { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_PCIDAS08) }, + { 0 } +}; +MODULE_DEVICE_TABLE(pci, das08_pci_table); + +static struct pci_driver das08_pci_driver = { + .name = "pci-das08", + .id_table = das08_pci_table, + .probe = das08_pci_probe, + .remove = comedi_pci_auto_unconfig, +}; +module_comedi_pci_driver(das08_pci_comedi_driver, das08_pci_driver); + +MODULE_AUTHOR("Comedi http://www.comedi.org"); +MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From eec0d0dc4e16c0c412db337acc36f95411ef946e Mon Sep 17 00:00:00 2001 From: Garrick He Date: Fri, 1 Feb 2013 01:45:16 -0800 Subject: Staging: wlan-ng: Fix tab coding style issue in hfa384x.h Fix all 'please, no space before tabs' warning found by checkpatch.pl Signed-off-by: Garrick He Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h index 5631ad0..04c0433 100644 --- a/drivers/staging/wlan-ng/hfa384x.h +++ b/drivers/staging/wlan-ng/hfa384x.h @@ -81,8 +81,8 @@ #define HFA384x_WEPFLAGS_EXCLUDE ((u16)BIT(1)) #define HFA384x_WEPFLAGS_DISABLE_TXCRYPT ((u16)BIT(4)) #define HFA384x_WEPFLAGS_DISABLE_RXCRYPT ((u16)BIT(7)) -#define HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM ((u16)3) -#define HFA384x_PORTSTATUS_DISABLED ((u16)1) +#define HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM ((u16)3) +#define HFA384x_PORTSTATUS_DISABLED ((u16)1) #define HFA384x_RATEBIT_1 ((u16)1) #define HFA384x_RATEBIT_2 ((u16)2) #define HFA384x_RATEBIT_5dot5 ((u16)4) @@ -164,7 +164,7 @@ #define HFA384x_CMDCODE_DOWNLD ((u16)0x22) /*--- Debugging Commands -----------------------------*/ -#define HFA384x_CMDCODE_MONITOR ((u16)(0x38)) +#define HFA384x_CMDCODE_MONITOR ((u16)(0x38)) #define HFA384x_MONITOR_ENABLE ((u16)(0x0b)) #define HFA384x_MONITOR_DISABLE ((u16)(0x0f)) @@ -275,15 +275,15 @@ API ENHANCEMENTS (NOT ALREADY IMPLEMENTED) #define HFA384x_RID_CNFAUTHENTICATION ((u16)0xFC2A) #define HFA384x_RID_CNFROAMINGMODE ((u16)0xFC2D) #define HFA384x_RID_CNFAPBCNint ((u16)0xFC33) -#define HFA384x_RID_CNFDBMADJUST ((u16)0xFC46) -#define HFA384x_RID_CNFWPADATA ((u16)0xFC48) +#define HFA384x_RID_CNFDBMADJUST ((u16)0xFC46) +#define HFA384x_RID_CNFWPADATA ((u16)0xFC48) #define HFA384x_RID_CNFBASICRATES ((u16)0xFCB3) #define HFA384x_RID_CNFSUPPRATES ((u16)0xFCB4) #define HFA384x_RID_CNFPASSIVESCANCTRL ((u16)0xFCBA) -#define HFA384x_RID_TXPOWERMAX ((u16)0xFCBE) +#define HFA384x_RID_TXPOWERMAX ((u16)0xFCBE) #define HFA384x_RID_JOINREQUEST ((u16)0xFCE2) #define HFA384x_RID_AUTHENTICATESTA ((u16)0xFCE3) -#define HFA384x_RID_HOSTSCAN ((u16)0xFCE5) +#define HFA384x_RID_HOSTSCAN ((u16)0xFCE5) #define HFA384x_RID_CNFWEPDEFAULTKEY_LEN ((u16)6) #define HFA384x_RID_CNFWEP128DEFAULTKEY_LEN ((u16)14) @@ -311,7 +311,7 @@ PD Record codes #define HFA384x_PDR_HFA3861_IFRF ((u16)0x0204) #define HFA384x_PDR_HFA3861_CHCALSP ((u16)0x0300) #define HFA384x_PDR_HFA3861_CHCALI ((u16)0x0301) -#define HFA384x_PDR_MAX_TX_POWER ((u16)0x0302) +#define HFA384x_PDR_MAX_TX_POWER ((u16)0x0302) #define HFA384x_PDR_MASTER_CHAN_LIST ((u16)0x0303) #define HFA384x_PDR_3842_NIC_CONFIG ((u16)0x0400) #define HFA384x_PDR_USB_ID ((u16)0x0401) @@ -322,10 +322,10 @@ PD Record codes #define HFA384x_PDR_USB_POWER_TYPE ((u16)0x0407) #define HFA384x_PDR_USB_MAX_POWER ((u16)0x0409) #define HFA384x_PDR_USB_MANUFACTURER ((u16)0x0410) -#define HFA384x_PDR_USB_PRODUCT ((u16)0x0411) -#define HFA384x_PDR_ANT_DIVERSITY ((u16)0x0412) -#define HFA384x_PDR_HFO_DELAY ((u16)0x0413) -#define HFA384x_PDR_SCALE_THRESH ((u16)0x0414) +#define HFA384x_PDR_USB_PRODUCT ((u16)0x0411) +#define HFA384x_PDR_ANT_DIVERSITY ((u16)0x0412) +#define HFA384x_PDR_HFO_DELAY ((u16)0x0413) +#define HFA384x_PDR_SCALE_THRESH ((u16)0x0414) #define HFA384x_PDR_HFA3861_MANF_TESTSP ((u16)0x0900) #define HFA384x_PDR_HFA3861_MANF_TESTI ((u16)0x0901) @@ -383,7 +383,7 @@ typedef struct hfa384x_caplevel { /*-- Configuration Record: cnfAuthentication --*/ #define HFA384x_CNFAUTHENTICATION_OPENSYSTEM 0x0001 #define HFA384x_CNFAUTHENTICATION_SHAREDKEY 0x0002 -#define HFA384x_CNFAUTHENTICATION_LEAP 0x0004 +#define HFA384x_CNFAUTHENTICATION_LEAP 0x0004 /*-------------------------------------------------------------------- Configuration Record Structures: @@ -575,8 +575,8 @@ Information Types #define HFA384x_IT_AUTHREQ ((u16)0xF202UL) #define HFA384x_IT_PSUSERCNT ((u16)0xF203UL) #define HFA384x_IT_KEYIDCHANGED ((u16)0xF204UL) -#define HFA384x_IT_ASSOCREQ ((u16)0xF205UL) -#define HFA384x_IT_MICFAILURE ((u16)0xF206UL) +#define HFA384x_IT_ASSOCREQ ((u16)0xF205UL) +#define HFA384x_IT_MICFAILURE ((u16)0xF206UL) /*-------------------------------------------------------------------- Information Frames Structures -- cgit v0.10.2 From e9ab1c2f7eb6bc5d885429381e773bc1a61646ca Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 1 Feb 2013 10:20:29 +0000 Subject: staging: comedi: move comedi_alloc_subdevice_minor declarations Move the declarations of `comedi_alloc_subdevice_minor()` and `comedi_free_subdevice_minor()` from "comedidev.h" to "comedi_internal.h" since they are only of interest to the comedi core, and are not exported to the low-level comedi drivers. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index b36bb95..f4f0ff2 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -11,6 +11,9 @@ int do_rangeinfo_ioctl(struct comedi_device *dev, int comedi_alloc_board_minor(struct device *hardware_device); void comedi_free_board_minor(unsigned minor); int comedi_find_board_minor(struct device *hardware_device); +int comedi_alloc_subdevice_minor(struct comedi_device *dev, + struct comedi_subdevice *s); +void comedi_free_subdevice_minor(struct comedi_subdevice *s); int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, unsigned long new_size); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index f4541ae..484321d 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -348,10 +348,6 @@ void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, void *destination, unsigned int num_bytes); -int comedi_alloc_subdevice_minor(struct comedi_device *dev, - struct comedi_subdevice *s); -void comedi_free_subdevice_minor(struct comedi_subdevice *s); - /* drivers.c - general comedi driver functions */ int comedi_alloc_subdevices(struct comedi_device *, int); -- cgit v0.10.2 From f65cc5447eaea9f7be1ff54e27c9658a66c5910f Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 1 Feb 2013 10:20:30 +0000 Subject: staging: comedi: change comedi_alloc_subdevice_minor parameters `comedi_alloc_subdevice_minor()` doesn't really need a parameter pointing to a `struct comedi_device` as it can get this information from the parameter pointing to a `struct comedi_subdevice`. Just pass the subdevice parameter. Signed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index c7377d0..ee127b3 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2352,9 +2352,9 @@ int comedi_find_board_minor(struct device *hardware_device) return -ENODEV; } -int comedi_alloc_subdevice_minor(struct comedi_device *dev, - struct comedi_subdevice *s) +int comedi_alloc_subdevice_minor(struct comedi_subdevice *s) { + struct comedi_device *dev = s->device; struct comedi_file_info *info; struct device *csdev; unsigned i; diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index f4f0ff2..df4c676 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -11,8 +11,7 @@ int do_rangeinfo_ioctl(struct comedi_device *dev, int comedi_alloc_board_minor(struct device *hardware_device); void comedi_free_board_minor(unsigned minor); int comedi_find_board_minor(struct device *hardware_device); -int comedi_alloc_subdevice_minor(struct comedi_device *dev, - struct comedi_subdevice *s); +int comedi_alloc_subdevice_minor(struct comedi_subdevice *s); void comedi_free_subdevice_minor(struct comedi_subdevice *s); int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index fe91e75..cc6240a 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -209,7 +209,7 @@ static int __comedi_device_postconfig_async(struct comedi_device *dev, return ret; } - comedi_alloc_subdevice_minor(dev, s); + comedi_alloc_subdevice_minor(s); return 0; } -- cgit v0.10.2 From da71751177f35f0ca5494968cc237511c423a744 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 1 Feb 2013 13:23:19 +0000 Subject: staging: comedi: export comedi_set_hw_dev() Chnage the inline `comedi_set_hw_dev()` to an exported function and change it's return type from `void` to `int` so we can impose some restrictions (in a later patch) and return an error if necessary. Only a few comedi drivers call this, although they don't need to if the hardware device has been attached automatically via `comedi_auto_config()` and the comedi driver's `auto_attach()` method. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 484321d..1502fc4 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -324,14 +324,7 @@ static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) * known bus type. Set automatically for auto-configured devices. * Automatically set to NULL when detaching hardware device. */ -static inline void comedi_set_hw_dev(struct comedi_device *dev, - struct device *hw_dev) -{ - struct device *old_hw_dev = dev->hw_dev; - - dev->hw_dev = get_device(hw_dev); - put_device(old_hw_dev); -} +int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev); unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index cc6240a..5adf9fc 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -43,6 +43,16 @@ struct comedi_driver *comedi_drivers; +int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev) +{ + struct device *old_hw_dev = dev->hw_dev; + + dev->hw_dev = get_device(hw_dev); + put_device(old_hw_dev); + return 0; +} +EXPORT_SYMBOL_GPL(comedi_set_hw_dev); + int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) { struct comedi_subdevice *s; -- cgit v0.10.2 From de06d7c6b8e3b886eec0302ecbadf76944a42ca4 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 1 Feb 2013 13:23:20 +0000 Subject: staging: comedi: restrict comedi_set_hw_dev() usage Don't allow comedi drivers to change `dev->hw_dev` using `comedi_set_hw_dev()` if it's already been set. Return `-EEXIST` in that case. `dev->hw_dev` needs to be set to NULL by the core during clean-up of the comedi device, so add a local function `comedi_clear_hw_dev()` to do that. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 5adf9fc..d91b173 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -45,14 +45,21 @@ struct comedi_driver *comedi_drivers; int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev) { - struct device *old_hw_dev = dev->hw_dev; - + if (hw_dev == dev->hw_dev) + return 0; + if (dev->hw_dev != NULL) + return -EEXIST; dev->hw_dev = get_device(hw_dev); - put_device(old_hw_dev); return 0; } EXPORT_SYMBOL_GPL(comedi_set_hw_dev); +static void comedi_clear_hw_dev(struct comedi_device *dev) +{ + put_device(dev->hw_dev); + dev->hw_dev = NULL; +} + int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) { struct comedi_subdevice *s; @@ -108,7 +115,7 @@ static void cleanup_device(struct comedi_device *dev) dev->write_subdev = NULL; dev->open = NULL; dev->close = NULL; - comedi_set_hw_dev(dev, NULL); + comedi_clear_hw_dev(dev); } static void __comedi_device_detach(struct comedi_device *dev) -- cgit v0.10.2 From 22056e2b46246d97ff0f7c6e21a77b8daa07f02c Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 1 Feb 2013 14:51:57 +0000 Subject: staging: comedi: ni_labpc: set up command4 register *after* command3 Tuomas reported problems getting meaningful output from a Lab-PC+ in differential mode for AI cmds, but AI insn reads gave correct readings. He tracked it down to two problems, one of which is addressed by this patch. It seems that writing to the command3 register after writing to the command4 register in `labpc_ai_cmd()` messes up the differential reference bit setting in the command4 register. Set up the command4 register after the command3 register (as in `labpc_ai_rinsn()`) to avoid the problem. Thanks to Tuomas for suggesting the fix. Signed-off-by: Ian Abbott Cc: # 3.7.x, 3.8.x Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 9e4d2da..10bd2b3 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -1219,21 +1219,6 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG); } - /* setup any external triggering/pacing (command4 register) */ - devpriv->command4_bits = 0; - if (cmd->convert_src != TRIG_EXT) - devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT; - /* XXX should discard first scan when using interval scanning - * since manual says it is not synced with scan clock */ - if (labpc_use_continuous_mode(cmd, mode) == 0) { - devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT; - if (cmd->scan_begin_src == TRIG_EXT) - devpriv->command4_bits |= EXT_SCAN_EN_BIT; - } - /* single-ended/differential */ - if (aref == AREF_DIFF) - devpriv->command4_bits |= ADC_DIFF_BIT; - devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG); devpriv->write_byte(cmd->chanlist_len, dev->iobase + INTERVAL_COUNT_REG); @@ -1313,6 +1298,22 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) devpriv->command3_bits &= ~ADC_FNE_INTR_EN_BIT; devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG); + /* setup any external triggering/pacing (command4 register) */ + devpriv->command4_bits = 0; + if (cmd->convert_src != TRIG_EXT) + devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT; + /* XXX should discard first scan when using interval scanning + * since manual says it is not synced with scan clock */ + if (labpc_use_continuous_mode(cmd, mode) == 0) { + devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT; + if (cmd->scan_begin_src == TRIG_EXT) + devpriv->command4_bits |= EXT_SCAN_EN_BIT; + } + /* single-ended/differential */ + if (aref == AREF_DIFF) + devpriv->command4_bits |= ADC_DIFF_BIT; + devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG); + /* startup acquisition */ /* command2 reg */ -- cgit v0.10.2 From 4c4bc25d0fa6beaf054c0b4c3b324487f266c820 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 1 Feb 2013 14:51:58 +0000 Subject: staging: comedi: ni_labpc: correct differential channel sequence for AI commands Tuomas reported problems getting meaningful output from a Lab-PC+ in differential mode for AI cmds, but AI insn reads gave correct readings. He tracked it down to two problems, one of which is addressed by this patch. It seems the setting of the channel bits for particular scanning modes was incorrect for differential mode. (Only half the number of channels are available in differential mode; comedi refers to them as channels 0, 1, 2 and 3, but the hardware documentation refers to them as channels 0, 2, 4 and 6.) In differential mode, the setting of the channel enable bits in the command1 register should depend on whether the scan enable bit is set. Effectively, we need to double the comedi channel number when the scan enable bit is not set in differential mode. The scan enable bit gets set when the AI scan mode is `MODE_MULT_CHAN_UP` or `MODE_MULT_CHAN_DOWN`, and gets cleared when the AI scan mode is `MODE_SINGLE_CHAN` or `MODE_SINGLE_CHAN_INTERVAL`. The existing test for whether the comedi channel number needs to be doubled in differential mode is incorrect in `labpc_ai_cmd()`. This patch corrects the test. Thanks to Tuomas for suggesting the fix. Signed-off-by: Ian Abbott Cc: # 3.7.x, 3.8.x Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 10bd2b3..f851c54 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -1204,7 +1204,8 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) else channel = CR_CHAN(cmd->chanlist[0]); /* munge channel bits for differential / scan disabled mode */ - if (mode != MODE_SINGLE_CHAN && aref == AREF_DIFF) + if ((mode == MODE_SINGLE_CHAN || mode == MODE_SINGLE_CHAN_INTERVAL) && + aref == AREF_DIFF) channel *= 2; devpriv->command1_bits |= ADC_CHAN_BITS(channel); devpriv->command1_bits |= thisboard->ai_range_code[range]; -- cgit v0.10.2 From 7f70410fe03f9f31a99bb5074b5e3c48f3b90541 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 31 Jan 2013 14:42:16 -0700 Subject: pci_ids.h: add common pci vendor ids from comedi subsystem There are a number of pci vendor ids that are used in multiple drivers in the comedi subsystem. Move these ids to pci_ids.h. This also fixes some build warnings reported by the kbuild test robot about PCI_VENDOR_ID_AMPLICON being undeclared. Signed-off-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 1502fc4..b7bb120 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -377,12 +377,7 @@ int comedi_driver_unregister(struct comedi_driver *); #define PCI_VENDOR_ID_DT 0x1116 #define PCI_VENDOR_ID_IOTECH 0x1616 #define PCI_VENDOR_ID_CONTEC 0x1221 -#define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */ -#define PCI_VENDOR_ID_ADVANTECH 0x13fe -#define PCI_VENDOR_ID_MEILHAUS 0x1402 #define PCI_VENDOR_ID_RTD 0x1435 -#define PCI_VENDOR_ID_ADLINK 0x144a -#define PCI_VENDOR_ID_AMPLICON 0x14dc struct pci_dev; struct pci_driver; diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index 0eb6579..747c8b7 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h @@ -1807,6 +1807,8 @@ #define PCI_VENDOR_ID_ESDGMBH 0x12fe #define PCI_DEVICE_ID_ESDGMBH_CPCIASIO4 0x0111 +#define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */ + #define PCI_VENDOR_ID_SIIG 0x131f #define PCI_SUBVENDOR_ID_SIIG 0x131f #define PCI_DEVICE_ID_SIIG_1S_10x_550 0x1000 @@ -2013,6 +2015,10 @@ #define PCI_DEVICE_ID_CMEDIA_CM8738 0x0111 #define PCI_DEVICE_ID_CMEDIA_CM8738B 0x0112 +#define PCI_VENDOR_ID_ADVANTECH 0x13fe + +#define PCI_VENDOR_ID_MEILHAUS 0x1402 + #define PCI_VENDOR_ID_LAVA 0x1407 #define PCI_DEVICE_ID_LAVA_DSERIAL 0x0100 /* 2x 16550 */ #define PCI_DEVICE_ID_LAVA_QUATRO_A 0x0101 /* 2x 16550, half of 4 port */ @@ -2058,6 +2064,8 @@ #define PCI_VENDOR_ID_CHELSIO 0x1425 +#define PCI_VENDOR_ID_ADLINK 0x144a + #define PCI_VENDOR_ID_SAMSUNG 0x144d #define PCI_VENDOR_ID_GIGABYTE 0x1458 @@ -2091,6 +2099,8 @@ #define PCI_DEVICE_ID_AFAVLAB_P030 0x2182 #define PCI_SUBDEVICE_ID_AFAVLAB_P061 0x2150 +#define PCI_VENDOR_ID_AMPLICON 0x14dc + #define PCI_VENDOR_ID_BCM_GVC 0x14a4 #define PCI_VENDOR_ID_BROADCOM 0x14e4 #define PCI_DEVICE_ID_TIGON3_5752 0x1600 -- cgit v0.10.2 From 7e5a5104c6af709a8d97d5f4711e7c917761d464 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 30 Jan 2013 11:41:39 +0900 Subject: zram: Fix deadlock bug in partial read/write Now zram allocates new page with GFP_KERNEL in zram I/O path if IO is partial. Unfortunately, It may cause deadlock with reclaim path like below. write_page from fs fs_lock allocation(GFP_KERNEL) reclaim pageout write_page from fs fs_lock <-- deadlock This patch fixes it by using GFP_NOIO. In read path, we reorganize code flow so that kmap_atomic is called after the GFP_NOIO allocation. Cc: stable@vger.kernel.org Acked-by: Jerome Marchand Acked-by: Nitin Gupta [ penberg@kernel.org: don't use GFP_ATOMIC ] Signed-off-by: Pekka Enberg Signed-off-by: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 941b7c6..262265e 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -217,11 +217,12 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, return 0; } - user_mem = kmap_atomic(page); if (is_partial_io(bvec)) /* Use a temporary buffer to decompress the page */ - uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL); - else + uncmem = kmalloc(PAGE_SIZE, GFP_NOIO); + + user_mem = kmap_atomic(page); + if (!is_partial_io(bvec)) uncmem = user_mem; if (!uncmem) { @@ -268,7 +269,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, * This is a partial IO. We need to read the full page * before to write the changes. */ - uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL); + uncmem = kmalloc(PAGE_SIZE, GFP_NOIO); if (!uncmem) { pr_info("Error allocating temp memory!\n"); ret = -ENOMEM; -- cgit v0.10.2 From 0231c403bb065307493fe997ad170487b4d55eb8 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 30 Jan 2013 11:41:40 +0900 Subject: zram: force disksize setting before using zram Now zram document syas "set disksize is optional" but partly it's wrong. When you try to use zram firstly after booting, you must set disksize, otherwise zram can't work because zram gendisk's size is 0. But once you do it, you can use zram freely after reset because reset doesn't reset to zero paradoxically. So in this time, disksize setting is optional.:( It's inconsitent for user behavior and not straightforward. This patch forces always setting disksize firstly before using zram. Yes. It changes current behavior so someone could complain when he upgrades zram. Apparently it could be a problem if zram is mainline but it still lives in staging so behavior could be changed for right way to go. Let them excuse. Acked-by: Jerome Marchand Acked-by: Nitin Gupta Acked-by: Dan Magenheimer Signed-off-by: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram.txt b/drivers/staging/zram/zram.txt index 5f75d29..765d790 100644 --- a/drivers/staging/zram/zram.txt +++ b/drivers/staging/zram/zram.txt @@ -23,17 +23,17 @@ Following shows a typical sequence of steps for using zram. This creates 4 devices: /dev/zram{0,1,2,3} (num_devices parameter is optional. Default: 1) -2) Set Disksize (Optional): - Set disk size by writing the value to sysfs node 'disksize' - (in bytes). If disksize is not given, default value of 25% - of RAM is used. - - # Initialize /dev/zram0 with 50MB disksize - echo $((50*1024*1024)) > /sys/block/zram0/disksize - - NOTE: disksize cannot be changed if the disk contains any - data. So, for such a disk, you need to issue 'reset' (see below) - before you can change its disksize. +2) Set Disksize + Set disk size by writing the value to sysfs node 'disksize'. + The value can be either in bytes or you can use mem suffixes. + Examples: + # Initialize /dev/zram0 with 50MB disksize + echo $((50*1024*1024)) > /sys/block/zram0/disksize + + # Using mem suffixes + echo 256K > /sys/block/zram0/disksize + echo 512M > /sys/block/zram0/disksize + echo 1G > /sys/block/zram0/disksize 3) Activate: mkswap /dev/zram0 @@ -65,8 +65,9 @@ Following shows a typical sequence of steps for using zram. echo 1 > /sys/block/zram0/reset echo 1 > /sys/block/zram1/reset - (This frees all the memory allocated for the given device). - + This frees all the memory allocated for the given device and + resets the disksize to zero. You must set the disksize again + before reusing the device. Please report any problems at: - Mailing list: linux-mm-cc at laptop dot org diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 262265e..1114cad 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -94,34 +94,6 @@ static int page_zero_filled(void *ptr) return 1; } -static void zram_set_disksize(struct zram *zram, size_t totalram_bytes) -{ - if (!zram->disksize) { - pr_info( - "disk size not provided. You can use disksize_kb module " - "param to specify size.\nUsing default: (%u%% of RAM).\n", - default_disksize_perc_ram - ); - zram->disksize = default_disksize_perc_ram * - (totalram_bytes / 100); - } - - if (zram->disksize > 2 * (totalram_bytes)) { - pr_info( - "There is little point creating a zram of greater than " - "twice the size of memory since we expect a 2:1 compression " - "ratio. Note that zram uses about 0.1%% of the size of " - "the disk when not in use so a huge zram is " - "wasteful.\n" - "\tMemory Size: %zu kB\n" - "\tSize you selected: %llu kB\n" - "Continuing anyway ...\n", - totalram_bytes >> 10, zram->disksize >> 10); - } - - zram->disksize &= PAGE_MASK; -} - static void zram_free_page(struct zram *zram, size_t index) { unsigned long handle = zram->table[index].handle; @@ -497,6 +469,9 @@ void __zram_reset_device(struct zram *zram) { size_t index; + if (!zram->init_done) + return; + zram->init_done = 0; /* Free various per-device buffers */ @@ -525,6 +500,7 @@ void __zram_reset_device(struct zram *zram) memset(&zram->stats, 0, sizeof(zram->stats)); zram->disksize = 0; + set_capacity(zram->disk, 0); } void zram_reset_device(struct zram *zram) @@ -546,7 +522,19 @@ int zram_init_device(struct zram *zram) return 0; } - zram_set_disksize(zram, totalram_pages << PAGE_SHIFT); + if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) { + pr_info( + "There is little point creating a zram of greater than " + "twice the size of memory since we expect a 2:1 compression " + "ratio. Note that zram uses about 0.1%% of the size of " + "the disk when not in use so a huge zram is " + "wasteful.\n" + "\tMemory Size: %zu kB\n" + "\tSize you selected: %llu kB\n" + "Continuing anyway ...\n", + (totalram_pages << PAGE_SHIFT) >> 10, zram->disksize >> 10 + ); + } zram->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); if (!zram->compress_workmem) { @@ -571,8 +559,6 @@ int zram_init_device(struct zram *zram) goto fail_no_table; } - set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); - /* zram devices sort of resembles non-rotational disks */ queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); @@ -751,8 +737,7 @@ static void __exit zram_exit(void) zram = &zram_devices[i]; destroy_device(zram); - if (zram->init_done) - zram_reset_device(zram); + zram_reset_device(zram); } unregister_blkdev(zram_major, "zram"); diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h index df2eec4..5b671d1 100644 --- a/drivers/staging/zram/zram_drv.h +++ b/drivers/staging/zram/zram_drv.h @@ -28,9 +28,6 @@ static const unsigned max_num_devices = 32; /*-- Configurable parameters */ -/* Default zram disk size: 25% of total RAM */ -static const unsigned default_disksize_perc_ram = 25; - /* * Pages that compress to size greater than this are stored * uncompressed in memory. @@ -115,6 +112,6 @@ extern struct attribute_group zram_disk_attr_group; #endif extern int zram_init_device(struct zram *zram); -extern void __zram_reset_device(struct zram *zram); +extern void zram_reset_device(struct zram *zram); #endif diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index de1eacf..4143af9 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -110,11 +110,7 @@ static ssize_t reset_store(struct device *dev, if (bdev) fsync_bdev(bdev); - down_write(&zram->init_lock); - if (zram->init_done) - __zram_reset_device(zram); - up_write(&zram->init_lock); - + zram_reset_device(zram); return len; } -- cgit v0.10.2 From 3de738cd30306f754ea35d35b5dad29fdbec84c9 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 30 Jan 2013 11:41:41 +0900 Subject: zram: give up lazy initialization of zram metadata 1) User of zram normally do mkfs.xxx or mkswap before using the zram block device(ex, normally, do it at booting time) It ends up allocating such metadata of zram before real usage so benefit of lazy initialzation would be mitigated. 2) Some user want to use zram when memory pressure is high.(ie, load zram dynamically, NOT booting time). It does make sense because people don't want to waste memory until memory pressure is high(ie, where zram is really helpful time). In this case, lazy initialzation could be failed easily because we will use GFP_NOIO instead of GFP_KERNEL for avoiding deadlock. So the benefit of lazy initialzation would be mitigated, too. 3) Metadata overhead is not critical and Nitin has a plan to diet it. 4K : 12 byte(64bit machine) -> 64G : 192M so 0.3% isn't big overhead If insane user use such big zram device up to 20, it could consume 6% of ram but efficieny of zram will cover the waste. So this patch gives up lazy initialization and instead we initialize metadata at disksize setting time. Acked-by: Jerome Marchand Acked-by: Nitin Gupta Signed-off-by: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 1114cad..85055c4 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -442,16 +442,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) { struct zram *zram = queue->queuedata; - if (unlikely(!zram->init_done) && zram_init_device(zram)) - goto error; - down_read(&zram->init_lock); if (unlikely(!zram->init_done)) - goto error_unlock; + goto error; if (!valid_io_request(zram, bio)) { zram_stat64_inc(zram, &zram->stats.invalid_io); - goto error_unlock; + goto error; } __zram_make_request(zram, bio, bio_data_dir(bio)); @@ -459,9 +456,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) return; -error_unlock: - up_read(&zram->init_lock); error: + up_read(&zram->init_lock); bio_io_error(bio); } @@ -510,18 +506,12 @@ void zram_reset_device(struct zram *zram) up_write(&zram->init_lock); } +/* zram->init_lock should be held */ int zram_init_device(struct zram *zram) { int ret; size_t num_pages; - down_write(&zram->init_lock); - - if (zram->init_done) { - up_write(&zram->init_lock); - return 0; - } - if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) { pr_info( "There is little point creating a zram of greater than " @@ -570,7 +560,6 @@ int zram_init_device(struct zram *zram) } zram->init_done = 1; - up_write(&zram->init_lock); pr_debug("Initialization done!\n"); return 0; @@ -580,7 +569,6 @@ fail_no_table: zram->disksize = 0; fail: __zram_reset_device(zram); - up_write(&zram->init_lock); pr_err("Initialization failed: err=%d\n", ret); return ret; } diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index 4143af9..369db12 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -71,6 +71,7 @@ static ssize_t disksize_store(struct device *dev, zram->disksize = PAGE_ALIGN(disksize); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); + zram_init_device(zram); up_write(&zram->init_lock); return len; -- cgit v0.10.2 From f2c22605c5a12c605a7164585c96f0835e9e591c Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:30 +0100 Subject: staging/xgifb: Simplify XGI_GetRatePtrCRT2 Since the smaller LCDRefreshIndex is contained identically in LCDARefreshIndex we can simply use LCDARefreshIndex and skip the if/else. Since LCDARefreshIndex is only used readonly and contains only small unsigned values we also change its declaration to const u8. In order to prevent an out-of-bounds access I changed the mask from 0x0F to 0x07 and added a dummy value. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 8eb23a4..02e76c5 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -5470,9 +5470,8 @@ unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE, unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { - short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 }, - LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01, - 0x01, 0x01 }; + const u8 LCDARefreshIndex[] = { + 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 }; unsigned short RefreshRateTableIndex, i, index, temp; @@ -5489,15 +5488,8 @@ unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE, if (pVBInfo->SetFlag & ProgrammingCRT2) { if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { if (pVBInfo->IF_DEF_LVDS == 0) { - if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B - | VB_SIS301LV | VB_SIS302LV - | VB_XGI301C)) - /* 301b */ - temp = LCDARefreshIndex[ - pVBInfo->LCDResInfo & 0x0F]; - else - temp = LCDRefreshIndex[ - pVBInfo->LCDResInfo & 0x0F]; + temp = LCDARefreshIndex[ + pVBInfo->LCDResInfo & 0x07]; if (index > temp) index = temp; -- cgit v0.10.2 From 44e1312c68e71a25f9f88ada7d124f5bbeaf879e Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:31 +0100 Subject: staging/xgifb: Remove always false comparisons This patch removes some comparisons that always evaluate to false since xoffset and yoffset are defined as __u32 in fb_var_screeninfo in include/linux/fb.h and thus can never be negative. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index ca9f583..83f8a6a 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -1333,12 +1333,6 @@ static int XGIfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) /* Adapt RGB settings */ XGIfb_bpp_to_var(xgifb_info, var); - /* Sanity check for offsets */ - if (var->xoffset < 0) - var->xoffset = 0; - if (var->yoffset < 0) - var->yoffset = 0; - if (!XGIfb_ypan) { if (var->xres != var->xres_virtual) var->xres_virtual = var->xres; @@ -1373,8 +1367,7 @@ static int XGIfb_pan_display(struct fb_var_screeninfo *var, return -EINVAL; if (var->vmode & FB_VMODE_YWRAP) { - if (var->yoffset < 0 || var->yoffset >= info->var.yres_virtual - || var->xoffset) + if (var->yoffset >= info->var.yres_virtual || var->xoffset) return -EINVAL; } else if (var->xoffset + info->var.xres > info->var.xres_virtual || var->yoffset + info->var.yres -- cgit v0.10.2 From 8cedcc7022e40fa83339257e82e64754ca1c8b9a Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:32 +0100 Subject: staging/xgifb: mttr must be (signed) int The mttr field must be declared as signed int (as in every other fb driver) for the mttr functions to work properly. Moreover the value should be initialized with -1. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index 83f8a6a..fa351f9 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -1802,7 +1802,7 @@ static int xgifb_probe(struct pci_dev *pdev, if (!XGIInitNew(pdev)) dev_err(&pdev->dev, "XGIInitNew() failed!\n"); - xgifb_info->mtrr = (unsigned int) 0; + xgifb_info->mtrr = -1; xgifb_info->hasVB = HASVB_NONE; if ((xgifb_info->chip == XG20) || diff --git a/drivers/staging/xgifb/XGIfb.h b/drivers/staging/xgifb/XGIfb.h index 8054798..af50362 100644 --- a/drivers/staging/xgifb/XGIfb.h +++ b/drivers/staging/xgifb/XGIfb.h @@ -67,7 +67,7 @@ struct xgifb_video_info { unsigned long mmio_size; void __iomem *mmio_vbase; unsigned long vga_base; - unsigned long mtrr; + int mtrr; int video_bpp; int video_cmap_len; -- cgit v0.10.2 From fd1bbbb79eff1a4381328049b375c80c3fc8bff9 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:33 +0100 Subject: staging/xgifb: Fix return of uninitialized variable Clang warning: drivers/staging/xgifb/XGI_main_26.c: warning: variable 'ret' is used uninitialized whenever 'if' condition: if (xgifb_info->mode_idx < 0) { evaluates to true. drivers/staging/xgifb/XGI_main_26.c: note: uninitialized use occurs here return ret; This patch initializes the variable in this case. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index fa351f9..106abc8 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -1921,6 +1921,7 @@ static int xgifb_probe(struct pci_dev *pdev, if (xgifb_info->mode_idx < 0) { dev_err(&pdev->dev, "No supported video mode found\n"); + ret = -EINVAL; goto error_1; } -- cgit v0.10.2 From 76a5899b0ceeaeda7b457b7f55cd258bc0c49c34 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:34 +0100 Subject: staging/xgifb: Simplify XGI_SetSeqRegs Since SR[0] in the (readonly) XGI330_StandTable is always 0x01 we can skip or'ing with 0x01 and make the code simpler by removing the if statements. Since this function is the only user of the XGI330_StandTable we can also include the unconditional |= 0x20 into the input data and move the assignment to SR1 into the loop, which I prefer to start at 0. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 02e76c5..6f366f4 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -64,26 +64,15 @@ static void XGI_SetSeqRegs(unsigned short ModeNo, unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) { - unsigned char tempah, SRdata; - unsigned short i; + unsigned char SRdata, i; xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */ - tempah = XGI330_StandTable.SR[0]; - - if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { - tempah |= 0x01; - } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) { - if (pVBInfo->VBInfo & SetInSlaveMode) - tempah |= 0x01; - } - tempah |= 0x20; /* screen off */ - xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */ - - for (i = 02; i <= 04; i++) { - /* Get SR2,3,4 from file */ - SRdata = XGI330_StandTable.SR[i - 1]; - xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */ + for (i = 0; i < 4; i++) { + /* Get SR1,2,3,4 from file */ + /* SR1 is with screen off 0x20 */ + SRdata = XGI330_StandTable.SR[i]; + xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */ } } diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h index 39f528b..fca1a1d 100644 --- a/drivers/staging/xgifb/vb_table.h +++ b/drivers/staging/xgifb/vb_table.h @@ -195,7 +195,7 @@ const struct XGI_ExtStruct XGI330_EModeIDTable[] = { static const struct SiS_StandTable_S XGI330_StandTable = { /* ExtVGATable */ 0x00, 0x00, 0x00, 0x0000, - {0x01, 0x0f, 0x00, 0x0e}, + {0x21, 0x0f, 0x00, 0x0e}, /* 0x21 = 0x01 | (0x20 = screen off) */ 0x23, {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -- cgit v0.10.2 From bae31702cdc0db3d45d05aa6e073641c85918c50 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:35 +0100 Subject: staging/xgifb: rewrite XGIfb_get_cmap_len We don't need to use this switch-case here for a simple two case if-else. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index 106abc8..840b497 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -1131,22 +1131,10 @@ static int XGIfb_release(struct fb_info *info, int user) return 0; } +/* similar to sisfb_get_cmap_len */ static int XGIfb_get_cmap_len(const struct fb_var_screeninfo *var) { - int rc = 16; - - switch (var->bits_per_pixel) { - case 8: - rc = 256; - break; - case 16: - rc = 16; - break; - case 32: - rc = 16; - break; - } - return rc; + return (var->bits_per_pixel == 8) ? 256 : 16; } static int XGIfb_setcolreg(unsigned regno, unsigned red, unsigned green, -- cgit v0.10.2 From a5e080b83e28f2b67c198cb3be96f4b190522109 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:36 +0100 Subject: staging/xgifb: remove unnecessary temp variable in XGIfb_mode_rate_to_ddata Instead of subtracting one and then assign a different name and add 1 again we simply use HDE directly. HDE wasn't used directly before, so no change in functionality. Same applies to VDE. -> now we can remove the variable with the very descriptive name E ;) Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index 840b497..387d1bd 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -94,7 +94,7 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, unsigned short VRE, VBE, VRS, VDE; unsigned short HRE, HBE, HRS, HDE; unsigned char sr_data, cr_data, cr_data2; - int B, C, D, E, F, temp, j; + int B, C, D, F, temp, j; InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr); if (!XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr)) return 0; @@ -104,14 +104,13 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, sr_data = XGI_CRT1Table[index].CR[5]; - HDE = (XGI330_RefIndex[RefreshRateTableIndex].XRes >> 3) - 1; - E = HDE + 1; + HDE = (XGI330_RefIndex[RefreshRateTableIndex].XRes >> 3); cr_data = XGI_CRT1Table[index].CR[3]; /* Horizontal retrace (=sync) start */ HRS = (cr_data & 0xff) | ((unsigned short) (sr_data & 0xC0) << 2); - F = HRS - E - 3; + F = HRS - HDE - 3; sr_data = XGI_CRT1Table[index].CR[6]; @@ -126,10 +125,10 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, /* Horizontal retrace (=sync) end */ HRE = (cr_data2 & 0x1f) | ((sr_data & 0x04) << 3); - temp = HBE - ((E - 1) & 255); + temp = HBE - ((HDE - 1) & 255); B = (temp > 0) ? temp : (temp + 256); - temp = HRE - ((E + F + 3) & 63); + temp = HRE - ((HDE + F + 3) & 63); C = (temp > 0) ? temp : (temp + 64); D = B - F - C; @@ -142,8 +141,7 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, cr_data2 = XGI_CRT1Table[index].CR[9]; - VDE = XGI330_RefIndex[RefreshRateTableIndex].YRes - 1; - E = VDE + 1; + VDE = XGI330_RefIndex[RefreshRateTableIndex].YRes; cr_data = XGI_CRT1Table[index].CR[10]; @@ -151,20 +149,20 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr, VRS = (cr_data & 0xff) | ((unsigned short) (cr_data2 & 0x04) << 6) | ((unsigned short) (cr_data2 & 0x80) << 2) | ((unsigned short) (sr_data & 0x08) << 7); - F = VRS + 1 - E; + F = VRS + 1 - VDE; cr_data = XGI_CRT1Table[index].CR[13]; /* Vertical blank end */ VBE = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x10) << 4); - temp = VBE - ((E - 1) & 511); + temp = VBE - ((VDE - 1) & 511); B = (temp > 0) ? temp : (temp + 512); cr_data = XGI_CRT1Table[index].CR[11]; /* Vertical retrace (=sync) end */ VRE = (cr_data & 0x0f) | ((sr_data & 0x20) >> 1); - temp = VRE - ((E + F - 1) & 31); + temp = VRE - ((VDE + F - 1) & 31); C = (temp > 0) ? temp : (temp + 32); D = B - F - C; -- cgit v0.10.2 From 5d1c2a9b289d14ae96b98d33895571f9613ca4f6 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:37 +0100 Subject: staging/xgifb: Remove unnecessary bitshifts in XGI_SetCRT1ModeRegs Since data can only be 0x0000, 0x0035 or 0x0048 we can simply skip the bit shifting and masking as data & 0xFF is always equal to data and data & 0xFF00 is always 0. So we simply use data and 0 directly and save the assignment. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 6f366f4..1ff1178 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -1083,10 +1083,8 @@ static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension, data = 0x0048; } - data2 = data & 0x00FF; - xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2); - data2 = (data & 0xFF00) >> 8; - xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2); + xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data); + xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0); if (modeflag & HalfDCLK) xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08); -- cgit v0.10.2 From 06cc47b90b498dd4e6e33ec5fad276d1b1c68e43 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:38 +0100 Subject: staging/xgifb: Consolidate XGI_EnableChISLCD and XGI_DisableChISLCD These two functions share the same code except one line - thus we can simply merge them and add a parameter to switch between both variants. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 1ff1178..c5faa89 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -4684,43 +4684,21 @@ static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo) } /* --------------------------------------------------------------------- */ -/* Function : XGI_DisableChISLCD */ -/* Input : */ -/* Output : 0 -> Not LCD Mode */ -/* Description : */ -/* --------------------------------------------------------------------- */ -static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo) -{ - unsigned short tempbx, tempah; - - tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB); - tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E)); - - if (tempbx & (EnableChA | DisableChA)) { - if (!(tempah & 0x08)) /* Chk LCDA Mode */ - return 0; - } - - if (!(tempbx & (EnableChB | DisableChB))) - return 0; - - if (tempah & 0x01) /* Chk LCDB Mode */ - return 1; - - return 0; -} - -/* --------------------------------------------------------------------- */ /* Function : XGI_EnableChISLCD */ /* Input : */ /* Output : 0 -> Not LCD mode */ -/* Description : */ +/* Description : if bool enable = true -> enable, else disable */ /* --------------------------------------------------------------------- */ -static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo) +static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo, + bool enable) { unsigned short tempbx, tempah; - tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB); + if (enable) + tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB); + else + tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB); + tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E)); if (tempbx & (EnableChA | DisableChA)) { @@ -4772,9 +4750,9 @@ static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info, if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) { if (((pVBInfo->VBInfo & - (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) - || (XGI_DisableChISLCD(pVBInfo)) - || (XGI_IsLCDON(pVBInfo))) + (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) || + (XGI_EnableChISLCD(pVBInfo, false)) || + (XGI_IsLCDON(pVBInfo))) /* LVDS Driver power down */ xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80); } @@ -5731,8 +5709,8 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info, xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0, 0x20); /* shampoo 0129 */ if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) { - if (!XGI_DisableChISLCD(pVBInfo)) { - if (XGI_EnableChISLCD(pVBInfo) || + if (!XGI_EnableChISLCD(pVBInfo, false)) { + if (XGI_EnableChISLCD(pVBInfo, true) || (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) /* LVDS PLL power on */ -- cgit v0.10.2 From e44adfdb6740f5673612a3060b8d3120ccafd5d1 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Sun, 3 Feb 2013 22:54:39 +0100 Subject: staging/xgifb: Simplify XGISetModeNew This patch simplifies the code of XGISetModeNew by reordering the if/else if/case conditions when both branches are doing exactly the same. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index c5faa89..f44a254 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -5907,7 +5907,8 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info, XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo); XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo); - if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) { + if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) || + (!(pVBInfo->VBInfo & SwitchCRT2))) { XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo); @@ -5915,24 +5916,11 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info, XGI_SetLCDAGroup(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo); } - } else if (!(pVBInfo->VBInfo & SwitchCRT2)) { - XGI_SetCRT1Group(xgifb_info, - HwDeviceExtension, ModeNo, - ModeIdIndex, pVBInfo); - if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { - XGI_SetLCDAGroup(ModeNo, ModeIdIndex, - HwDeviceExtension, - pVBInfo); - } } if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) { switch (HwDeviceExtension->ujVBChipID) { - case VB_CHIP_301: - XGI_SetCRT2Group301(ModeNo, HwDeviceExtension, - pVBInfo); /*add for CRT2 */ - break; - + case VB_CHIP_301: /* fall through */ case VB_CHIP_302: XGI_SetCRT2Group301(ModeNo, HwDeviceExtension, pVBInfo); /*add for CRT2 */ -- cgit v0.10.2 From ddb2d0a0185583b268dfe0a32e2f70ee2f118bd0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:19:35 -0700 Subject: staging: comedi: comedi_pcmcia: introduce comedi_pcmcia_{enable, disable} Introduce some helper functions to enable/disable the PCMCIA device. This will allow removing some of the boilerplate code in the comedi PCMCIA drivers. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c index f10bcc5..925f128 100644 --- a/drivers/staging/comedi/comedi_pcmcia.c +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -37,6 +37,52 @@ struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev) } EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev); +static int comedi_pcmcia_conf_check(struct pcmcia_device *link, + void *priv_data) +{ + if (link->config_index == 0) + return -EINVAL; + + return pcmcia_request_io(link); +} + +/** + * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device. + * @dev: comedi_device struct + * + * The comedi PCMCIA driver needs to set the link->config_flags, as + * appropriate for that driver, before calling this function in order + * to allow pcmcia_loop_config() to do its internal autoconfiguration. + */ +int comedi_pcmcia_enable(struct comedi_device *dev) +{ + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + int ret; + + if (!link) + return -ENODEV; + + ret = pcmcia_loop_config(link, comedi_pcmcia_conf_check, NULL); + if (ret) + return ret; + + return pcmcia_enable_device(link); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_enable); + +/** + * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions. + * @dev: comedi_device struct + */ +void comedi_pcmcia_disable(struct comedi_device *dev) +{ + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + + if (link) + pcmcia_disable_device(link); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_disable); + /** * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver. * @link: pcmcia_device struct diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index b7bb120..4836fe6 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -440,6 +440,9 @@ struct pcmcia_device; struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *); +int comedi_pcmcia_enable(struct comedi_device *); +void comedi_pcmcia_disable(struct comedi_device *); + int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *); void comedi_pcmcia_auto_unconfig(struct pcmcia_device *); -- cgit v0.10.2 From 9e29ce104a83d801c7fc6bc57c189608195e831e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:20:08 -0700 Subject: staging: comedi: cb_das16_cs: use comedi_pcmcia_{enable, disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index efff059..8763726 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -397,15 +397,6 @@ static const void *das16cs_find_boardinfo(struct comedi_device *dev, return NULL; } -static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int das16cs_auto_attach(struct comedi_device *dev, unsigned long context) { @@ -421,21 +412,15 @@ static int das16cs_auto_attach(struct comedi_device *dev, dev->board_ptr = board; dev->board_name = board->name; - /* Do we need to allocate an interrupt? */ - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL); + link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; + ret = comedi_pcmcia_enable(dev); if (ret) return ret; + dev->iobase = link->resource[0]->start; if (!link->irq) return -EINVAL; - ret = pcmcia_enable_device(link); - if (ret) - return ret; - dev->iobase = link->resource[0]->start; - ret = request_irq(link->irq, das16cs_interrupt, IRQF_SHARED, dev->board_name, dev); if (ret < 0) @@ -497,12 +482,9 @@ static int das16cs_auto_attach(struct comedi_device *dev, static void das16cs_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - if (dev->irq) free_irq(dev->irq, dev); - if (dev->iobase) - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver driver_das16cs = { -- cgit v0.10.2 From bcd22e8ecee9f48f8668418cef5d523f219f7d1a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:20:29 -0700 Subject: staging: comedi: cb_das16_cs: use pcmcia_request_irq() Use pcmcia_request_irq() instead of request_irq() to request the irq for the PCMCIA device. This allows the PCMCIA core to clean up the registration in pcmcia_disable_device(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index 8763726..e1318fa 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -418,12 +418,9 @@ static int das16cs_auto_attach(struct comedi_device *dev, return ret; dev->iobase = link->resource[0]->start; - if (!link->irq) - return -EINVAL; - - ret = request_irq(link->irq, das16cs_interrupt, IRQF_SHARED, - dev->board_name, dev); - if (ret < 0) + link->priv = dev; + ret = pcmcia_request_irq(link, das16cs_interrupt); + if (ret) return ret; dev->irq = link->irq; @@ -482,8 +479,6 @@ static int das16cs_auto_attach(struct comedi_device *dev, static void das16cs_detach(struct comedi_device *dev) { - if (dev->irq) - free_irq(dev->irq, dev); comedi_pcmcia_disable(dev); } -- cgit v0.10.2 From 7fadd565f0f84ec4402ad33546d7eec7a98220ea Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:21:09 -0700 Subject: staging: comedi: cb_das16_cs: use comedi_pcmcia_disable() for (*detach) The (*detach) function, das16cs_detach() is a simple wrapper around comedi_pcmcia_disable(). Just use comedi_pcmcia_disable() directly for the (*detach). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index e1318fa..5bbffd9 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -477,16 +477,11 @@ static int das16cs_auto_attach(struct comedi_device *dev, return 0; } -static void das16cs_detach(struct comedi_device *dev) -{ - comedi_pcmcia_disable(dev); -} - static struct comedi_driver driver_das16cs = { .driver_name = "cb_das16_cs", .module = THIS_MODULE, .auto_attach = das16cs_auto_attach, - .detach = das16cs_detach, + .detach = comedi_pcmcia_disable, }; static int das16cs_pcmcia_attach(struct pcmcia_device *link) -- cgit v0.10.2 From 95f932cea3b59003fc019acbf32fadb53a529778 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:21:31 -0700 Subject: staging: comedi: das08_cs: use comedi_pcmcia_{enable, disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. This driver does not use interrupts so remove CONF_ENABLE_IRQ from the link->config_flags. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index 4654b60..818a609 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -69,15 +69,6 @@ static const struct das08_board_struct das08_cs_boards[] = { }, }; -static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int das08_cs_auto_attach(struct comedi_device *dev, unsigned long context) { @@ -89,16 +80,8 @@ static int das08_cs_auto_attach(struct comedi_device *dev, /* The das08 driver needs the board_ptr */ dev->board_ptr = &das08_cs_boards[0]; - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); - if (ret) - return ret; - - if (!link->irq) - return -EINVAL; - - ret = pcmcia_enable_device(link); + link->config_flags |= CONF_AUTO_SET_IO; + ret = comedi_pcmcia_enable(dev); if (ret) return ret; iobase = link->resource[0]->start; @@ -113,11 +96,8 @@ static int das08_cs_auto_attach(struct comedi_device *dev, static void das08_cs_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - das08_common_detach(dev); - if (dev->iobase) - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver driver_das08_cs = { -- cgit v0.10.2 From 7dc99109f53535f888bc13ea2aad3632acdda475 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:21:56 -0700 Subject: staging: comedi: ni_daq_700: use comedi_pcmcia_{enable, disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. This driver does not use interrupts and is not an audio device, remove CONF_ENABLE_IRQ and CONF_AUTO_AUDIO from the link->config_flags. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index e537b8f..0fe2888 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -195,15 +195,6 @@ static void daq700_ai_config(struct comedi_device *dev, inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */ } -static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int daq700_auto_attach(struct comedi_device *dev, unsigned long context) { @@ -213,14 +204,8 @@ static int daq700_auto_attach(struct comedi_device *dev, dev->board_name = dev->driver->driver_name; - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | - CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL); - if (ret) - return ret; - - ret = pcmcia_enable_device(link); + link->config_flags |= CONF_AUTO_SET_IO; + ret = comedi_pcmcia_enable(dev); if (ret) return ret; dev->iobase = link->resource[0]->start; @@ -262,10 +247,7 @@ static int daq700_auto_attach(struct comedi_device *dev, static void daq700_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - - if (dev->iobase) - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver daq700_driver = { -- cgit v0.10.2 From 5056d87a889d1bd7d998070b6827b384ccde487f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 14:22:17 -0700 Subject: staging: comedi: ni_daq_700: use comedi_pcmcia_disable() for (*detach) The (*detach) function, daq700_detach() is now a simple wrapper around comedi_pcmcia_disable(). Just use comedi_pcmcia_disable() directly for the (*detach). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index 0fe2888..c8f4c7d 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -245,16 +245,11 @@ static int daq700_auto_attach(struct comedi_device *dev, return 0; } -static void daq700_detach(struct comedi_device *dev) -{ - comedi_pcmcia_disable(dev); -} - static struct comedi_driver daq700_driver = { .driver_name = "ni_daq_700", .module = THIS_MODULE, .auto_attach = daq700_auto_attach, - .detach = daq700_detach, + .detach = comedi_pcmcia_disable, }; static int daq700_cs_attach(struct pcmcia_device *link) -- cgit v0.10.2 From 227dc1156c103b7e073ee81e642e15d7927af828 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 00:29:43 +0100 Subject: staging/xgifb: Replace XGI340_CR6B table with simple if/else The XGI340_CR6B lookup table consists of the entries {0xaa, 0xaa, 0xaa, 0xaa} for an index <= 2 and {0x00, 0x00, 0x00, 0x00} for all other indices. The only user XGINew_SetDRAMDefaultRegister340 loops over these 4 values of a line with a for loop and since all entries are the same for each line we can simply replace the whole lookup table with a simple if/else assignment. Tested-by: Aaro Koskinen Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index dd34570..a778df6 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -429,7 +429,7 @@ static void XGINew_SetDRAMDefaultRegister340( temp2 = 0; for (i = 0; i < 4; i++) { /* CR6B DQS fine tune delay */ - temp = XGI340_CR6B[pVBInfo->ram_type][i]; + temp = (pVBInfo->ram_type <= 2) ? 0xaa : 0x00; for (j = 0; j < 4; j++) { temp1 = ((temp >> (2 * j)) & 0x03) << 2; temp2 |= temp1; diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h index fca1a1d..34e1656 100644 --- a/drivers/staging/xgifb/vb_table.h +++ b/drivers/staging/xgifb/vb_table.h @@ -103,17 +103,6 @@ static const unsigned char XGI27_cr41[24][8] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 23 CRC5 */ }; -const unsigned char XGI340_CR6B[8][4] = { - {0xaa, 0xaa, 0xaa, 0xaa}, - {0xaa, 0xaa, 0xaa, 0xaa}, - {0xaa, 0xaa, 0xaa, 0xaa}, - {0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00} -}; - /* CR47,CR48,CR49,CR4A,CR4B,CR4C,CR70,CR71,CR74,CR75,CR76,CR77 */ const unsigned char XGI340_AGPReg[12] = { 0x28, 0x23, 0x00, 0x20, 0x00, 0x20, -- cgit v0.10.2 From 0141bb2ed95d87cbcc53ebd282b943d061881fce Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 00:29:44 +0100 Subject: staging/xgifb: Move duplicated code for dram to helper function XGINew_SetDRAMDefaultRegister340 uses the same code fragment 4 times with only a slight variation each time. -> Move this code to a helper function - this saves some lines and ~450bytes in the .o / .ko Tested-by: Aaro Koskinen Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index a778df6..25fc7bc 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -413,6 +413,19 @@ static void XGINew_DDR2_DefaultRegister( XGINew_DDR2_MRS_XG20(HwDeviceExtension, P3c4, pVBInfo); } +static void XGI_SetDRAM_Helper(unsigned long P3d4, u8 seed, u8 temp2, u8 reg, + u8 shift_factor, u8 mask1, u8 mask2) +{ + u8 j; + for (j = 0; j < 4; j++) { + temp2 |= (((seed >> (2 * j)) & 0x03) << shift_factor); + xgifb_reg_set(P3d4, reg, temp2); + xgifb_reg_get(P3d4, reg); + temp2 &= mask1; + temp2 += mask2; + } +} + static void XGINew_SetDRAMDefaultRegister340( struct xgi_hw_device_info *HwDeviceExtension, unsigned long Port, struct vb_device_info *pVBInfo) @@ -426,53 +439,24 @@ static void XGINew_SetDRAMDefaultRegister340( xgifb_reg_set(P3d4, 0x69, pVBInfo->CR40[6][pVBInfo->ram_type]); xgifb_reg_set(P3d4, 0x6A, pVBInfo->CR40[7][pVBInfo->ram_type]); - temp2 = 0; for (i = 0; i < 4; i++) { /* CR6B DQS fine tune delay */ temp = (pVBInfo->ram_type <= 2) ? 0xaa : 0x00; - for (j = 0; j < 4; j++) { - temp1 = ((temp >> (2 * j)) & 0x03) << 2; - temp2 |= temp1; - xgifb_reg_set(P3d4, 0x6B, temp2); - /* Insert read command for delay */ - xgifb_reg_get(P3d4, 0x6B); - temp2 &= 0xF0; - temp2 += 0x10; - } + XGI_SetDRAM_Helper(P3d4, temp, 0, 0x6B, 2, 0xF0, 0x10); } - temp2 = 0; for (i = 0; i < 4; i++) { /* CR6E DQM fine tune delay */ - temp = 0; - for (j = 0; j < 4; j++) { - temp1 = ((temp >> (2 * j)) & 0x03) << 2; - temp2 |= temp1; - xgifb_reg_set(P3d4, 0x6E, temp2); - /* Insert read command for delay */ - xgifb_reg_get(P3d4, 0x6E); - temp2 &= 0xF0; - temp2 += 0x10; - } + XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6E, 2, 0xF0, 0x10); } temp3 = 0; for (k = 0; k < 4; k++) { /* CR6E_D[1:0] select channel */ xgifb_reg_and_or(P3d4, 0x6E, 0xFC, temp3); - temp2 = 0; for (i = 0; i < 8; i++) { /* CR6F DQ fine tune delay */ - temp = 0; - for (j = 0; j < 4; j++) { - temp1 = (temp >> (2 * j)) & 0x03; - temp2 |= temp1; - xgifb_reg_set(P3d4, 0x6F, temp2); - /* Insert read command for delay */ - xgifb_reg_get(P3d4, 0x6F); - temp2 &= 0xF8; - temp2 += 0x08; - } + XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6F, 0, 0xF8, 0x08); } temp3 += 0x01; } @@ -486,15 +470,7 @@ static void XGINew_SetDRAMDefaultRegister340( temp2 = 0x80; /* CR89 terminator type select */ - temp = 0; - for (j = 0; j < 4; j++) { - temp1 = (temp >> (2 * j)) & 0x03; - temp2 |= temp1; - xgifb_reg_set(P3d4, 0x89, temp2); - xgifb_reg_get(P3d4, 0x89); /* Insert read command for delay */ - temp2 &= 0xF0; - temp2 += 0x10; - } + XGI_SetDRAM_Helper(P3d4, 0, temp2, 0x89, 0, 0xF0, 0x10); temp = 0; temp1 = temp & 0x03; -- cgit v0.10.2 From 1504ecbeecfb206179e39d66d7f4d4af542ec45c Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 00:29:45 +0100 Subject: staging/xgifb: Don't write the same values x times With the previous patch 'Move duplicated code for dram to helper function' it becomes evident that the code is performing the same thing 4 or 8 times in a row without changing arguments to the function and thus writing the same values over and over again. It was tested that these repeats are unnecessary. -> we can safely remove them. Tested-by: Aaro Koskinen Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index 25fc7bc..1c6e0f3 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -439,25 +439,18 @@ static void XGINew_SetDRAMDefaultRegister340( xgifb_reg_set(P3d4, 0x69, pVBInfo->CR40[6][pVBInfo->ram_type]); xgifb_reg_set(P3d4, 0x6A, pVBInfo->CR40[7][pVBInfo->ram_type]); - for (i = 0; i < 4; i++) { - /* CR6B DQS fine tune delay */ - temp = (pVBInfo->ram_type <= 2) ? 0xaa : 0x00; - XGI_SetDRAM_Helper(P3d4, temp, 0, 0x6B, 2, 0xF0, 0x10); - } + /* CR6B DQS fine tune delay */ + temp = (pVBInfo->ram_type <= 2) ? 0xaa : 0x00; + XGI_SetDRAM_Helper(P3d4, temp, 0, 0x6B, 2, 0xF0, 0x10); - for (i = 0; i < 4; i++) { - /* CR6E DQM fine tune delay */ - XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6E, 2, 0xF0, 0x10); - } + /* CR6E DQM fine tune delay */ + XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6E, 2, 0xF0, 0x10); temp3 = 0; for (k = 0; k < 4; k++) { /* CR6E_D[1:0] select channel */ xgifb_reg_and_or(P3d4, 0x6E, 0xFC, temp3); - for (i = 0; i < 8; i++) { - /* CR6F DQ fine tune delay */ - XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6F, 0, 0xF8, 0x08); - } + XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6F, 0, 0xF8, 0x08); temp3 += 0x01; } -- cgit v0.10.2 From 826215d98f49bce6ca6bf69f3b54a0d58fc89c99 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 00:29:46 +0100 Subject: staging/xgifb: Consolidate if/else for 'identical' branches Since XGI_LCDDesStruct is fully contained in XGI330_LCDDataDesStruct2 and the offsets for the first members is identical we can consolidate the if/else branches here and use XGI330_LCDDataDesStruct2 for everything. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index f44a254..131a267 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -1470,18 +1470,11 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex, { unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag; unsigned long temp, temp1, temp2, temp3, push3; - struct XGI_LCDDesStruct const *LCDPtr = NULL; struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL; modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; - if (pVBInfo->LCDInfo & EnableScalingLCD) - LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, - ModeIdIndex, RefreshRateTableIndex, - pVBInfo); - else - LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, - ModeIdIndex, RefreshRateTableIndex, - pVBInfo); + LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex, + RefreshRateTableIndex, pVBInfo); XGI_GetLCDSync(&tempax, &tempbx, pVBInfo); push1 = tempbx; @@ -1513,10 +1506,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex, tempax = pVBInfo->HT; - if (pVBInfo->LCDInfo & EnableScalingLCD) - tempbx = LCDPtr1->LCDHDES; - else - tempbx = LCDPtr->LCDHDES; + tempbx = LCDPtr1->LCDHDES; tempcx = pVBInfo->HDE; tempbx = tempbx & 0x0fff; @@ -1537,10 +1527,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex, tempax = pVBInfo->HT; - if (pVBInfo->LCDInfo & EnableScalingLCD) - tempbx = LCDPtr1->LCDHRS; - else - tempbx = LCDPtr->LCDHRS; + tempbx = LCDPtr1->LCDHRS; tempcx = push2; @@ -1565,10 +1552,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex, (unsigned short) (tempbx & 0xff)); tempax = pVBInfo->VT; - if (pVBInfo->LCDInfo & EnableScalingLCD) - tempbx = LCDPtr1->LCDVDES; - else - tempbx = LCDPtr->LCDVDES; + tempbx = LCDPtr1->LCDVDES; tempcx = pVBInfo->VDE; tempbx = tempbx & 0x0fff; @@ -1589,10 +1573,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex, | tempbx)); tempax = pVBInfo->VT; - if (pVBInfo->LCDInfo & EnableScalingLCD) - tempbx = LCDPtr1->LCDVRS; - else - tempbx = LCDPtr->LCDVRS; + tempbx = LCDPtr1->LCDVRS; tempcx = push1; -- cgit v0.10.2 From f951dd05f9549c9b1a16d4eabfe60c20721de292 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 00:29:47 +0100 Subject: staging/xgifb: Consolidate if branches with similar conditions 1) The same condition (pVBInfo->IF_DEF_LVDS == 0) was checked in the if clause directly in front of this one. 2) The same condition pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV | VB_SIS302LV | VB_XGI301C) was checked in the if clause directly in front of this one. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 131a267..bd81656 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2299,9 +2299,7 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo, & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) { tempbx |= SetLCDDualLink; } - } - if (pVBInfo->IF_DEF_LVDS == 0) { if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) && (!(tempbx & EnableScalingLCD))) @@ -5024,12 +5022,8 @@ static void XGI_SetLCDCap(struct vb_device_info *pVBInfo) tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability; - if (pVBInfo->VBType & - (VB_SIS301B | - VB_SIS302B | - VB_SIS301LV | - VB_SIS302LV | - VB_XGI301C)) { /* 301LV/302LV only */ + if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV | + VB_SIS302LV | VB_XGI301C)) { if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) { /* Set 301LV Capability */ @@ -5041,10 +5035,7 @@ static void XGI_SetLCDCap(struct vb_device_info *pVBInfo) ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8), (unsigned short) ((tempcx & (EnableVBCLKDRVLOW | EnablePLLSPLOW)) >> 8)); - } - if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV - | VB_SIS302LV | VB_XGI301C)) { if (pVBInfo->VBInfo & SetCRT2ToLCD) XGI_SetLCDCap_B(tempcx, pVBInfo); else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) -- cgit v0.10.2 From c04edbf2f4194d1f76dd6d0fc5d64600867eae70 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:41:30 -0700 Subject: staging: comedi: quatech_daqp_cs: convert to auto attach Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the static data that held "A list of "instances" of the device" that was used to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. Also, remove the now unused variables in the private data that were used to pass the pcmcia_device. Remove the code that pulled the model number of the card out of the PCMCIA CIS and stashed it in the private data since it is not used in the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 2c35d75..6409236 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -62,10 +62,7 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308 #define MAX_DEV 4 struct local_info_t { - struct pcmcia_device *link; int stop; - int table_index; - char board_name[32]; enum { semaphore, buffer } interrupt_mode; @@ -76,10 +73,6 @@ struct local_info_t { int count; }; -/* A list of "instances" of the device. */ - -static struct local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ }; - /* The DAQP communicates with the system through a 16 byte I/O window. */ #define DAQP_FIFO_SIZE 4096 @@ -725,43 +718,43 @@ static int daqp_do_insn_write(struct comedi_device *dev, return 1; } -/* daqp_attach is called via comedi_config to attach a comedi device - * to a /dev/comedi*. Note that this is different from daqp_cs_attach() - * which is called by the pcmcia subsystem to attach the PCMCIA card - * when it is inserted. - */ +static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) +{ + if (p_dev->config_index == 0) + return -EINVAL; + + return pcmcia_request_io(p_dev); +} -static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int daqp_auto_attach(struct comedi_device *dev, + unsigned long context) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); struct local_info_t *local; struct comedi_subdevice *s; int ret; - if (it->options[0] < 0 || it->options[0] >= MAX_DEV) - return -ENODEV; + dev->board_name = dev->driver->driver_name; - local = dev_table[it->options[0]]; + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(*local), GFP_KERNEL); if (!local) - return -ENODEV; - - /* Typically brittle code that I don't completely understand, - * but "it works on my card". The intent is to pull the model - * number of the card out the PCMCIA CIS and stash it away as - * the COMEDI board_name. Looks like the third field in - * CISTPL_VERS_1 (offset 2) holds what we're looking for. If - * it doesn't work, who cares, just leave it as "DAQP". - */ + return -ENOMEM; - strcpy(local->board_name, "DAQP"); - dev->board_name = local->board_name; - if (local->link->prod_id[2]) { - if (strncmp(local->link->prod_id[2], "DAQP", 4) == 0) { - strncpy(local->board_name, local->link->prod_id[2], - sizeof(local->board_name)); - } - } + link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; + ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL); + if (ret) + return ret; - dev->iobase = local->link->resource[0]->start; + link->priv = local; + ret = pcmcia_request_irq(link, daqp_interrupt); + if (ret) + return ret; + + ret = pcmcia_enable_device(link); + if (ret) + return ret; + dev->iobase = link->resource[0]->start; ret = comedi_alloc_subdevices(dev, 4); if (ret) @@ -811,51 +804,18 @@ static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it) static void daqp_detach(struct comedi_device *dev) { - /* Nothing to cleanup */ + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + + pcmcia_disable_device(link); } static struct comedi_driver driver_daqp = { .driver_name = "quatech_daqp_cs", .module = THIS_MODULE, - .attach = daqp_attach, + .auto_attach = daqp_auto_attach, .detach = daqp_detach, }; -/*==================================================================== - - PCMCIA interface code - - The rest of the code in this file is based on dummy_cs.c v1.24 - from the Linux pcmcia_cs distribution v3.1.8 and is subject - to the following license agreement. - - The remaining contents of this file are subject to the Mozilla Public - License Version 1.1 (the "License"); you may not use this file - except in compliance with the License. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS - IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - implied. See the License for the specific language governing - rights and limitations under the License. - - The initial developer of the original code is David A. Hinds - . Portions created by David A. Hinds - are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - - Alternatively, the contents of this file may be used under the - terms of the GNU Public License version 2 (the "GPL"), in which - case the provisions of the GPL are applicable instead of the - above. If you wish to allow the use of your version of this file - only under the terms of the GPL and not to allow others to use - your version of this file under the MPL, indicate your decision - by deleting the provisions above and replace them with the notice - and other provisions required by the GPL. If you do not delete - the provisions above, a recipient may use your version of this - file under either the MPL or the GPL. - -======================================================================*/ - static int daqp_cs_suspend(struct pcmcia_device *link) { struct local_info_t *local = link->priv; @@ -874,74 +834,11 @@ static int daqp_cs_resume(struct pcmcia_device *link) return 0; } -static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int daqp_cs_attach(struct pcmcia_device *link) { - struct local_info_t *local; - int ret; - int i; - - for (i = 0; i < MAX_DEV; i++) - if (dev_table[i] == NULL) - break; - if (i == MAX_DEV) { - dev_notice(&link->dev, "no devices available\n"); - return -ENODEV; - } - - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(*local), GFP_KERNEL); - if (!local) - return -ENOMEM; - - local->table_index = i; - dev_table[i] = local; - local->link = link; - link->priv = local; - - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL); - if (ret) { - dev_warn(&link->dev, "no configuration found\n"); - goto failed; - } - - ret = pcmcia_request_irq(link, daqp_interrupt); - if (ret) - goto failed; - - ret = pcmcia_enable_device(link); - if (ret) - goto failed; - - return 0; - -failed: - pcmcia_disable_device(link); - return ret; -} - -static void daqp_cs_detach(struct pcmcia_device *link) -{ - struct local_info_t *dev = link->priv; - - dev->stop = 1; - pcmcia_disable_device(link); - - /* Unlink device structure, and free it */ - dev_table[dev->table_index] = NULL; - kfree(dev); + return comedi_pcmcia_auto_config(link, &driver_daqp); } -/*====================================================================*/ static const struct pcmcia_device_id daqp_cs_id_table[] = { PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0027), PCMCIA_DEVICE_NULL @@ -953,7 +850,7 @@ static struct pcmcia_driver daqp_cs_driver = { .owner = THIS_MODULE, .id_table = daqp_cs_id_table, .probe = daqp_cs_attach, - .remove = daqp_cs_detach, + .remove = comedi_pcmcia_auto_unconfig, .suspend = daqp_cs_suspend, .resume = daqp_cs_resume, }; -- cgit v0.10.2 From 87fe1452c6b0154e43fa7c544977279a504ad0e4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:41:49 -0700 Subject: staging: comedi: quatech_daqp_cs: use comedi_pcmcia_{enable, disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 6409236..869a4af 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -718,14 +718,6 @@ static int daqp_do_insn_write(struct comedi_device *dev, return 1; } -static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int daqp_auto_attach(struct comedi_device *dev, unsigned long context) { @@ -742,20 +734,16 @@ static int daqp_auto_attach(struct comedi_device *dev, return -ENOMEM; link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; - ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL); + ret = comedi_pcmcia_enable(dev); if (ret) return ret; + dev->iobase = link->resource[0]->start; link->priv = local; ret = pcmcia_request_irq(link, daqp_interrupt); if (ret) return ret; - ret = pcmcia_enable_device(link); - if (ret) - return ret; - dev->iobase = link->resource[0]->start; - ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; @@ -804,9 +792,7 @@ static int daqp_auto_attach(struct comedi_device *dev, static void daqp_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver driver_daqp = { -- cgit v0.10.2 From 25736670bce6b860910ca789ab628bde46be71e6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:42:09 -0700 Subject: staging: comedi: quatech_daqp_cs: use comedi_pcmcia_disable() for (*detach) The (*detach) function, daqp_detach() is now a simple wrapper around comedi_pcmcia_disable(). Just use comedi_pcmcia_disable() directly for the (*detach). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 869a4af..6eab3bb 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -790,16 +790,11 @@ static int daqp_auto_attach(struct comedi_device *dev, return 0; } -static void daqp_detach(struct comedi_device *dev) -{ - comedi_pcmcia_disable(dev); -} - static struct comedi_driver driver_daqp = { .driver_name = "quatech_daqp_cs", .module = THIS_MODULE, .auto_attach = daqp_auto_attach, - .detach = daqp_detach, + .detach = comedi_pcmcia_disable, }; static int daqp_cs_suspend(struct pcmcia_device *link) -- cgit v0.10.2 From 9c1dcce9c64c2b53042f2cfb730348201d176855 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:42:32 -0700 Subject: staging: comedi: quatech_daqp_cs: ao subdevice does not support commands The analog output subdevice does not support aynchronous commands. Don't set the dev->write_subdev to this subdevice. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 6eab3bb..40d525c 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -763,7 +763,6 @@ static int daqp_auto_attach(struct comedi_device *dev, s->cancel = daqp_ai_cancel; s = &dev->subdevices[1]; - dev->write_subdev = s; s->private = local; s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE; -- cgit v0.10.2 From c12717423e1c61682fada53193813248095cba44 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:42:56 -0700 Subject: staging: comedi: quatech_daqp_cs: store private data in the comedi_device All the comedi_subdevices in this driver use the same 'local' private data. Instead of storing the pointer to the private data in each subdevice, just store it in the comedi_device. Also, instead of passing the private data pointer to pcmcia_request_irq() in link->priv, pass the comedi_device pointer. This allows removing the comedi_device and comedi_subdevice pointers from the private data. We can get them as needed from the void * in the interrupt function. Fix the pcmcia suspend/resume functions so they use the comedi_device pointer stored in link->priv to then get the private data pointer. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 40d525c..8b644f5 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -68,8 +68,6 @@ struct local_info_t { struct completion eos; - struct comedi_device *dev; - struct comedi_subdevice *s; int count; }; @@ -169,7 +167,7 @@ static const struct comedi_lrange range_daqp_ai = { static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { - struct local_info_t *local = s->private; + struct local_info_t *local = dev->private; if (local->stop) return -EIO; @@ -196,13 +194,13 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) */ static enum irqreturn daqp_interrupt(int irq, void *dev_id) { - struct local_info_t *local = dev_id; - struct comedi_device *dev = local ? local->dev : NULL; - struct comedi_subdevice *s = local ? local->s : NULL; + struct comedi_device *dev = dev_id; + struct local_info_t *local = dev->private; + struct comedi_subdevice *s = dev->read_subdev; int loop_limit = 10000; int status; - if (!dev || !dev->attached || !s || s->private != local) + if (!dev->attached) return IRQ_NONE; switch (local->interrupt_mode) { @@ -270,7 +268,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = s->private; + struct local_info_t *local = dev->private; int i; int v; int counter = 10000; @@ -327,8 +325,6 @@ static int daqp_ai_insn_read(struct comedi_device *dev, init_completion(&local->eos); local->interrupt_mode = semaphore; - local->dev = dev; - local->s = s; for (i = 0; i < insn->n; i++) { @@ -463,7 +459,7 @@ static int daqp_ai_cmdtest(struct comedi_device *dev, static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { - struct local_info_t *local = s->private; + struct local_info_t *local = dev->private; struct comedi_cmd *cmd = &s->async->cmd; int counter; int scanlist_start_on_every_entry; @@ -649,8 +645,6 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } local->interrupt_mode = buffer; - local->dev = dev; - local->s = s; /* Start conversion */ outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, @@ -665,7 +659,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = s->private; + struct local_info_t *local = dev->private; int d; unsigned int chan; @@ -692,7 +686,7 @@ static int daqp_di_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = s->private; + struct local_info_t *local = dev->private; if (local->stop) return -EIO; @@ -708,7 +702,7 @@ static int daqp_do_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = s->private; + struct local_info_t *local = dev->private; if (local->stop) return -EIO; @@ -732,6 +726,7 @@ static int daqp_auto_attach(struct comedi_device *dev, local = kzalloc(sizeof(*local), GFP_KERNEL); if (!local) return -ENOMEM; + dev->private = local; link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; ret = comedi_pcmcia_enable(dev); @@ -739,7 +734,7 @@ static int daqp_auto_attach(struct comedi_device *dev, return ret; dev->iobase = link->resource[0]->start; - link->priv = local; + link->priv = dev; ret = pcmcia_request_irq(link, daqp_interrupt); if (ret) return ret; @@ -750,7 +745,6 @@ static int daqp_auto_attach(struct comedi_device *dev, s = &dev->subdevices[0]; dev->read_subdev = s; - s->private = local; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; s->n_chan = 8; @@ -763,7 +757,6 @@ static int daqp_auto_attach(struct comedi_device *dev, s->cancel = daqp_ai_cancel; s = &dev->subdevices[1]; - s->private = local; s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 2; @@ -772,14 +765,12 @@ static int daqp_auto_attach(struct comedi_device *dev, s->insn_write = daqp_ao_insn_write; s = &dev->subdevices[2]; - s->private = local; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 1; s->insn_read = daqp_di_insn_read; s = &dev->subdevices[3]; - s->private = local; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 1; @@ -798,18 +789,23 @@ static struct comedi_driver driver_daqp = { static int daqp_cs_suspend(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; + struct comedi_device *dev = link->priv; + struct local_info_t *local = dev ? dev->private : NULL; /* Mark the device as stopped, to block IO until later */ - local->stop = 1; + if (local) + local->stop = 1; + return 0; } static int daqp_cs_resume(struct pcmcia_device *link) { - struct local_info_t *local = link->priv; + struct comedi_device *dev = link->priv; + struct local_info_t *local = dev ? dev->private : NULL; - local->stop = 0; + if (local) + local->stop = 0; return 0; } -- cgit v0.10.2 From 1801726e87787273d8473bd35a95935629a4e947 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:43:19 -0700 Subject: staging: comedi: quatech_daqp_cs: rename the private data struct The private data in this driver is associated with the comedi_device pointer not the pcmcia_device. For aesthetic reasons, rename the private data struct from local_into_t to daqp_private. Also, rename the local variables used for the private data from local to devpriv as that is more common in the comedi drivers. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 8b644f5..f91e5f5 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -61,7 +61,7 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308 /* Maximum number of separate DAQP devices we'll allow */ #define MAX_DEV 4 -struct local_info_t { +struct daqp_private { int stop; enum { semaphore, buffer } interrupt_mode; @@ -167,26 +167,25 @@ static const struct comedi_lrange range_daqp_ai = { static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; - if (local->stop) + if (devpriv->stop) return -EIO; - outb(DAQP_COMMAND_STOP, dev->iobase + DAQP_COMMAND); /* flush any linguring data in FIFO - superfluous here */ /* outb(DAQP_COMMAND_RSTF, dev->iobase+DAQP_COMMAND); */ - local->interrupt_mode = semaphore; + devpriv->interrupt_mode = semaphore; return 0; } /* Interrupt handler * - * Operates in one of two modes. If local->interrupt_mode is - * 'semaphore', just signal the local->eos completion and return + * Operates in one of two modes. If devpriv->interrupt_mode is + * 'semaphore', just signal the devpriv->eos completion and return * (one-shot mode). Otherwise (continuous mode), read data in from * the card, transfer it to the buffer provided by the higher-level * comedi kernel module, and signal various comedi callback routines, @@ -195,7 +194,7 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) static enum irqreturn daqp_interrupt(int irq, void *dev_id) { struct comedi_device *dev = dev_id; - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; int loop_limit = 10000; int status; @@ -203,15 +202,12 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) if (!dev->attached) return IRQ_NONE; - switch (local->interrupt_mode) { - + switch (devpriv->interrupt_mode) { case semaphore: - - complete(&local->eos); + complete(&devpriv->eos); break; case buffer: - while (!((status = inb(dev->iobase + DAQP_STATUS)) & DAQP_STATUS_FIFO_EMPTY)) { @@ -235,9 +231,9 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) * and stop conversion if zero */ - if (local->count > 0) { - local->count--; - if (local->count == 0) { + if (devpriv->count > 0) { + devpriv->count--; + if (devpriv->count == 0) { daqp_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; break; @@ -268,15 +264,14 @@ static int daqp_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; int i; int v; int counter = 10000; - if (local->stop) + if (devpriv->stop) return -EIO; - /* Stop any running conversion */ daqp_ai_cancel(dev, s); @@ -323,8 +318,8 @@ static int daqp_ai_insn_read(struct comedi_device *dev, return -1; } - init_completion(&local->eos); - local->interrupt_mode = semaphore; + init_completion(&devpriv->eos); + devpriv->interrupt_mode = semaphore; for (i = 0; i < insn->n; i++) { @@ -334,7 +329,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev, /* Wait for interrupt service routine to unblock completion */ /* Maybe could use a timeout here, but it's interruptible */ - if (wait_for_completion_interruptible(&local->eos)) + if (wait_for_completion_interruptible(&devpriv->eos)) return -EINTR; data[i] = inb(dev->iobase + DAQP_FIFO); @@ -459,7 +454,7 @@ static int daqp_ai_cmdtest(struct comedi_device *dev, static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; int counter; int scanlist_start_on_every_entry; @@ -468,10 +463,9 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) int i; int v; - if (local->stop) + if (devpriv->stop) return -EIO; - /* Stop any running conversion */ daqp_ai_cancel(dev, s); @@ -593,16 +587,16 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) /* Save away the number of conversions we should perform, and * compute the FIFO threshold (in bytes, not samples - that's - * why we multiple local->count by 2 = sizeof(sample)) + * why we multiple devpriv->count by 2 = sizeof(sample)) */ if (cmd->stop_src == TRIG_COUNT) { - local->count = cmd->stop_arg * cmd->scan_end_arg; - threshold = 2 * local->count; + devpriv->count = cmd->stop_arg * cmd->scan_end_arg; + threshold = 2 * devpriv->count; while (threshold > DAQP_FIFO_SIZE * 3 / 4) threshold /= 2; } else { - local->count = -1; + devpriv->count = -1; threshold = DAQP_FIFO_SIZE / 2; } @@ -644,7 +638,7 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) return -1; } - local->interrupt_mode = buffer; + devpriv->interrupt_mode = buffer; /* Start conversion */ outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, @@ -659,11 +653,11 @@ static int daqp_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; int d; unsigned int chan; - if (local->stop) + if (devpriv->stop) return -EIO; chan = CR_CHAN(insn->chanspec); @@ -686,9 +680,9 @@ static int daqp_di_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; - if (local->stop) + if (devpriv->stop) return -EIO; data[0] = inb(dev->iobase + DAQP_DIGITAL_IO); @@ -702,9 +696,9 @@ static int daqp_do_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct local_info_t *local = dev->private; + struct daqp_private *devpriv = dev->private; - if (local->stop) + if (devpriv->stop) return -EIO; outw(data[0] & 0xf, dev->iobase + DAQP_DIGITAL_IO); @@ -716,17 +710,16 @@ static int daqp_auto_attach(struct comedi_device *dev, unsigned long context) { struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - struct local_info_t *local; + struct daqp_private *devpriv; struct comedi_subdevice *s; int ret; dev->board_name = dev->driver->driver_name; - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(*local), GFP_KERNEL); - if (!local) + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) return -ENOMEM; - dev->private = local; + dev->private = devpriv; link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; ret = comedi_pcmcia_enable(dev); @@ -790,11 +783,11 @@ static struct comedi_driver driver_daqp = { static int daqp_cs_suspend(struct pcmcia_device *link) { struct comedi_device *dev = link->priv; - struct local_info_t *local = dev ? dev->private : NULL; + struct daqp_private *devpriv = dev ? dev->private : NULL; /* Mark the device as stopped, to block IO until later */ - if (local) - local->stop = 1; + if (devpriv) + devpriv->stop = 1; return 0; } @@ -802,10 +795,10 @@ static int daqp_cs_suspend(struct pcmcia_device *link) static int daqp_cs_resume(struct pcmcia_device *link) { struct comedi_device *dev = link->priv; - struct local_info_t *local = dev ? dev->private : NULL; + struct daqp_private *devpriv = dev ? dev->private : NULL; - if (local) - local->stop = 0; + if (devpriv) + devpriv->stop = 0; return 0; } -- cgit v0.10.2 From 491cc0b042c2c2e7db0b2013e802f1d0124d1611 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:43:37 -0700 Subject: staging: comedi: quatech_daqp_cs: remove unused define The MAX_DEV define is no longer used in this driver. Remove it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index f91e5f5..7046ebd 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -58,9 +58,6 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308 #include "comedi_fc.h" -/* Maximum number of separate DAQP devices we'll allow */ -#define MAX_DEV 4 - struct daqp_private { int stop; -- cgit v0.10.2 From 62100fefbc4f7f45149df1f537de17b4acf01391 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:43:56 -0700 Subject: staging: comedi: quatech_daqp_cs: use (*insn_bits) for digital inputs Change the subdevice operation used to read the digital inputs from a (*insn_read) to a (*insn_bits) function. The (*insn_read) functions are expected to read 'insn->n' number of samples. The (*insn_bits) functions just read a single sample (insn->n = 1). Change the return from '1' to 'insn->n' to clarify what the return is. Also, set the 'maxdata' for the subdevice. For digital io this value should be '1' (digital io can only be 1 or 0). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 7046ebd..dbb8593 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -671,11 +671,10 @@ static int daqp_ao_insn_write(struct comedi_device *dev, return 1; } -/* Digital input routine */ - -static int daqp_di_insn_read(struct comedi_device *dev, +static int daqp_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { struct daqp_private *devpriv = dev->private; @@ -684,7 +683,7 @@ static int daqp_di_insn_read(struct comedi_device *dev, data[0] = inb(dev->iobase + DAQP_DIGITAL_IO); - return 1; + return insn->n; } /* Digital output routine */ @@ -758,7 +757,8 @@ static int daqp_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 1; - s->insn_read = daqp_di_insn_read; + s->maxdata = 1; + s->insn_bits = daqp_di_insn_bits; s = &dev->subdevices[3]; s->type = COMEDI_SUBD_DO; -- cgit v0.10.2 From 6a911d8aa54bc79256e766580a19bbd91e76d48f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:44:17 -0700 Subject: staging: comedi: quatech_daqp_cs: use (*insn_bits) for digital outputs Change the subdevice operation used to write the digital outputs from a (*insn_write) to a (*insn_bits) function. The (*insn_write) functions are expected to write 'insn->n' number of samples. The (*insn_bits) functions just write a single sample (insn->n = 1). Change the return from '1' to 'insn->n' to clarify what the return is. Using an (*insn_bits) function to write the digital outputs also allows the user to read the current state of the output channels. Fix the io operation used to update the digital outputs. The register is only 8-bits and should by updated with an outb() not an outw(). Also, set the 'maxdata' for the subdevice. For digital io this value should be '1' (digital io can only be 1 or 0). Remove the setting of the len_chanlist for the subdevice. This variable only has meaning for subdevices that support asynchronous commands. The comedi core will initialize it appropriately during the postconfig. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index dbb8593..f111042 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -686,20 +686,28 @@ static int daqp_di_insn_bits(struct comedi_device *dev, return insn->n; } -/* Digital output routine */ - -static int daqp_do_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int daqp_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct daqp_private *devpriv = dev->private; + unsigned int mask = data[0]; + unsigned int bits = data[1]; if (devpriv->stop) return -EIO; - outw(data[0] & 0xf, dev->iobase + DAQP_DIGITAL_IO); + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); - return 1; + outb(s->state, dev->iobase + DAQP_DIGITAL_IO); + } + + data[1] = s->state; + + return insn->n; } static int daqp_auto_attach(struct comedi_device *dev, @@ -764,8 +772,8 @@ static int daqp_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 1; - s->len_chanlist = 1; - s->insn_write = daqp_do_insn_write; + s->maxdata = 1; + s->insn_bits = daqp_do_insn_bits; return 0; } -- cgit v0.10.2 From d35dcc89fc93d8f071fc7f88ae87697a77bb99d0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:44:37 -0700 Subject: staging: comedi: quatech_daqp_cs: fix daqp_ao_insn_write() The (*insn_write) functions are expected to write 'insn->n' number of samples to the channel. Fix this function so it works as the comedi core expects. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index f111042..b50ba54 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -644,31 +644,32 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) return 0; } -/* Single-shot analog output routine */ - static int daqp_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { struct daqp_private *devpriv = dev->private; - int d; - unsigned int chan; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val; + int i; if (devpriv->stop) return -EIO; - chan = CR_CHAN(insn->chanspec); - d = data[0]; - d &= 0x0fff; - d ^= 0x0800; /* Flip the sign */ - d |= chan << 12; - /* Make sure D/A update mode is direct update */ outb(0, dev->iobase + DAQP_AUX); - outw(d, dev->iobase + DAQP_DA); + for (i = 0; i > insn->n; i++) { + val = data[0]; + val &= 0x0fff; + val ^= 0x0800; /* Flip the sign */ + val |= (chan << 12); - return 1; + outw(val, dev->iobase + DAQP_DA); + } + + return insn->n; } static int daqp_di_insn_bits(struct comedi_device *dev, -- cgit v0.10.2 From bd7807f96464d1053c6c5fd867461c6e64a766f1 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 16:44:57 -0700 Subject: staging: comedi: quatech_daqp_cs: factor out common ai scanlist code Factor the code that programs the analog input scanlist out of the daqp_ai_insn_read() and daqp_ai_cmd() functions. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index b50ba54..6ab9083 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -255,6 +255,27 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } +static void daqp_ai_set_one_scanlist_entry(struct comedi_device *dev, + unsigned int chanspec, + int start) +{ + unsigned int chan = CR_CHAN(chanspec); + unsigned int range = CR_RANGE(chanspec); + unsigned int aref = CR_AREF(chanspec); + unsigned int val; + + val = DAQP_SCANLIST_CHANNEL(chan) | DAQP_SCANLIST_GAIN(range); + + if (aref == AREF_DIFF) + val |= DAQP_SCANLIST_DIFFERENTIAL; + + if (start) + val |= DAQP_SCANLIST_START; + + outb(val & 0xff, dev->iobase + DAQP_SCANLIST); + outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST); +} + /* One-shot analog data acquisition routine */ static int daqp_ai_insn_read(struct comedi_device *dev, @@ -278,18 +299,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev, outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); /* Program one scan list entry */ - - v = DAQP_SCANLIST_CHANNEL(CR_CHAN(insn->chanspec)) - | DAQP_SCANLIST_GAIN(CR_RANGE(insn->chanspec)); - - if (CR_AREF(insn->chanspec) == AREF_DIFF) - v |= DAQP_SCANLIST_DIFFERENTIAL; - - - v |= DAQP_SCANLIST_START; - - outb(v & 0xff, dev->iobase + DAQP_SCANLIST); - outb(v >> 8, dev->iobase + DAQP_SCANLIST); + daqp_ai_set_one_scanlist_entry(dev, insn->chanspec, 1); /* Reset data FIFO (see page 28 of DAQP User's Manual) */ @@ -501,24 +511,10 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } /* Program scan list */ - for (i = 0; i < cmd->chanlist_len; i++) { + int start = (i == 0 || scanlist_start_on_every_entry); - int chanspec = cmd->chanlist[i]; - - /* Program one scan list entry */ - - v = DAQP_SCANLIST_CHANNEL(CR_CHAN(chanspec)) - | DAQP_SCANLIST_GAIN(CR_RANGE(chanspec)); - - if (CR_AREF(chanspec) == AREF_DIFF) - v |= DAQP_SCANLIST_DIFFERENTIAL; - - if (i == 0 || scanlist_start_on_every_entry) - v |= DAQP_SCANLIST_START; - - outb(v & 0xff, dev->iobase + DAQP_SCANLIST); - outb(v >> 8, dev->iobase + DAQP_SCANLIST); + daqp_ai_set_one_scanlist_entry(dev, cmd->chanlist[i], start); } /* Now it's time to program the FIFO threshold, basically the -- cgit v0.10.2 From 4a79f730179061c54d5c4ce1b59c1babbb05912f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 4 Feb 2013 17:13:01 -0700 Subject: staging: comedi: remove 'comedi_autoconfig' module parameter This module parameter is used to enable the auto config mechanism in the comedi core. Most of the PCI, PCMCIA, and USB drivers have been converted to use the auto config mechanism and will not attach if it is disabled. Since the 'comedi_autoconfig' parameter is defaulted to true, just remove it so that the comedi drivers that use auto config will always be able to attach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index ee127b3..bd89e78 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -58,11 +58,6 @@ MODULE_PARM_DESC(comedi_debug, ); #endif -bool comedi_autoconfig = true; -module_param(comedi_autoconfig, bool, S_IRUGO); -MODULE_PARM_DESC(comedi_autoconfig, - "enable drivers to auto-configure comedi devices (default 1)"); - static int comedi_num_legacy_minors; module_param(comedi_num_legacy_minors, int, S_IRUGO); MODULE_PARM_DESC(comedi_num_legacy_minors, @@ -2437,14 +2432,6 @@ static int __init comedi_init(void) return -EINVAL; } - /* - * comedi is unusable if both comedi_autoconfig and - * comedi_num_legacy_minors are zero, so we might as well adjust the - * defaults in that case - */ - if (!comedi_autoconfig && comedi_num_legacy_minors == 0) - comedi_num_legacy_minors = 16; - memset(comedi_file_info_table, 0, sizeof(struct comedi_file_info *) * COMEDI_NUM_MINORS); diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index df4c676..b374313 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -21,7 +21,6 @@ unsigned int comedi_buf_write_n_allocated(struct comedi_async *async); extern unsigned int comedi_default_buf_size_kb; extern unsigned int comedi_default_buf_maxsize_kb; -extern bool comedi_autoconfig; /* drivers.c */ diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index d91b173..e57e661 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -410,9 +410,6 @@ int comedi_auto_config(struct device *hardware_device, struct comedi_device *comedi_dev; int ret; - if (!comedi_autoconfig) - return 0; - if (!driver->auto_attach) { dev_warn(hardware_device, "BUG! comedi driver '%s' has no auto_attach handler\n", diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c index 539b1d8..f27f48e 100644 --- a/drivers/staging/comedi/drivers/adl_pci7x3x.c +++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c @@ -38,12 +38,6 @@ Author: H Hartley Sweeten Updated: Thu, 02 Aug 2012 14:27:46 -0700 Status: untested -This driver only attaches using the PCI PnP auto config support -in the comedi core. The module parameter 'comedi_autoconfig' -must be 1 (default) to enable this feature. The COMEDI_DEVCONFIG -ioctl, used by the comedi_config utility, is not supported by -this driver. - The PCI-7230, PCI-7432 and PCI-7433 boards also support external interrupt signals on digital input channels 0 and 1. The PCI-7233 has dual-interrupt sources for change-of-state (COS) on any 16 @@ -51,7 +45,7 @@ digital input channels of LSB and for COS on any 16 digital input lines of MSB. Interrupts are not currently supported by this driver. -Configuration Options: not applicable +Configuration Options: not applicable, uses comedi PCI auto config */ #include -- cgit v0.10.2 From cc400e185c07c15a42d2635995f422de5b94b696 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 5 Feb 2013 12:50:40 +0000 Subject: staging: comedi: check s->async for poll(), read() and write() Some low-level comedi drivers (incorrectly) point `dev->read_subdev` or `dev->write_subdev` to a subdevice that does not support asynchronous commands. Comedi's poll(), read() and write() file operation handlers assume these subdevices do support asynchronous commands. In particular, they assume `s->async` is valid (where `s` points to the read or write subdevice), which it won't be if it has been set incorrectly. This can lead to a NULL pointer dereference. Check `s->async` is non-NULL in `comedi_poll()`, `comedi_read()` and `comedi_write()` to avoid the bug. Signed-off-by: Ian Abbott Cc: stable Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index bd89e78..b1e8cdb 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -1839,7 +1839,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) } s = comedi_read_subdevice(info); - if (s) { + if (s && s->async) { poll_wait(file, &s->async->wait_head, wait); if (!s->busy || !comedi_is_subdevice_running(s) || comedi_buf_read_n_available(s->async) > 0) @@ -1847,7 +1847,7 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) } s = comedi_write_subdevice(info); - if (s) { + if (s && s->async) { unsigned int bps = bytes_per_sample(s->async->subdevice); poll_wait(file, &s->async->wait_head, wait); @@ -1882,7 +1882,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, } s = comedi_write_subdevice(info); - if (!s) + if (!s || !s->async) return -EIO; async = s->async; @@ -1977,7 +1977,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, } s = comedi_read_subdevice(info); - if (!s) + if (!s || !s->async) return -EIO; async = s->async; -- cgit v0.10.2 From fc008afff8eb78eedfd9de51b653c7b39fc74995 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 20:38:35 +0100 Subject: staging/xgifb: Remove unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the patch 'staging/xgifb: Don't write the same values x times' the local variable i is unused, which leads to the following warning: driverrs/staging/xgifb/vb_init.c: In function ‘XGINew_SetDRAMDefaultRegister340’: drivers/staging/xgifb/vb_init.c:433:43: warning: unused variable ‘i’ [-Wunused-variable] This patch fixes this Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index 1c6e0f3..7b8f41d 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -430,7 +430,7 @@ static void XGINew_SetDRAMDefaultRegister340( struct xgi_hw_device_info *HwDeviceExtension, unsigned long Port, struct vb_device_info *pVBInfo) { - unsigned char temp, temp1, temp2, temp3, i, j, k; + unsigned char temp, temp1, temp2, temp3, j, k; unsigned long P3d4 = Port, P3c4 = Port - 0x10; -- cgit v0.10.2 From 87be0afafae74ab93303623fb600147968294702 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 22:32:29 +0100 Subject: staging/xgifb: Remove unused values in XGI340_cr41 and XGI27_cr41 In the lookup tables XGI340_cr41 and XGI27_cr41 only the first three values are used of each 'line', thus the remaining fields can be removed. Rationale: - vb_init.c uses pVBInfo->ram_type for the 'column' index for pVBInfo->CR40. - pVBInfo->ram_type is assigned the return value of XGINew_GetXG20DRAMType which can only be 0, 1 or 2 - pVBInfo->CR40 is assigned to either XGI340_cr41 or XGI27_cr41 in vb_setmode.c -> only the first three values are used. This becomes also evident as values 3-7 are all 0. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_struct.h b/drivers/staging/xgifb/vb_struct.h index e570bae..02f3bb5 100644 --- a/drivers/staging/xgifb/vb_struct.h +++ b/drivers/staging/xgifb/vb_struct.h @@ -158,7 +158,7 @@ struct vb_device_info { void __iomem *FBAddr; unsigned char const (*SR15)[8]; - unsigned char const (*CR40)[8]; + unsigned char const (*CR40)[3]; struct SiS_MCLKData const *MCLKData; diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h index 34e1656..a1be751 100644 --- a/drivers/staging/xgifb/vb_table.h +++ b/drivers/staging/xgifb/vb_table.h @@ -47,60 +47,60 @@ static const unsigned char XGI340_SR13[4][8] = { {0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00} /* SR1B */ }; -static const unsigned char XGI340_cr41[24][8] = { - {0x20, 0x50, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0 CR41 */ - {0xc4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1 CR8A */ - {0xc4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2 CR8B */ - {0xb5, 0xa4, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x90, 0x90, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 5 CR68 */ - {0x77, 0x77, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 6 CR69 */ - {0x77, 0x77, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 7 CR6A */ - {0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 8 CR6D */ - {0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 9 CR80 */ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 10 CR81 */ - {0x88, 0xa8, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 11 CR82 */ - {0x44, 0x44, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 12 CR85 */ - {0x48, 0x48, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 13 CR86 */ - {0x54, 0x54, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 14 CR90 */ - {0x54, 0x54, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 15 CR91 */ - {0x0a, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 16 CR92 */ - {0x44, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 17 CR93 */ - {0x10, 0x10, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 18 CR94 */ - {0x11, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 19 CR95 */ - {0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 20 CR96 */ - {0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 21 CRC3 */ - {0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 22 CRC4 */ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 23 CRC5 */ -}; - -static const unsigned char XGI27_cr41[24][8] = { - {0x20, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0 CR41 */ - {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1 CR8A */ - {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2 CR8B */ - {0xB3, 0x13, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 3 CR40[7], - CR99[2:0], - CR45[3:0]*/ - {0xf0, 0xf5, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 4 CR59 */ - {0x90, 0x90, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 5 CR68 */ - {0x77, 0x67, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 6 CR69 */ - {0x77, 0x77, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 7 CR6A */ - {0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 8 CR6D */ - {0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 9 CR80 */ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 10 CR81 */ - {0x88, 0xcc, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 11 CR82 */ - {0x44, 0x88, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 12 CR85 */ - {0x48, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 13 CR86 */ - {0x54, 0x32, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 14 CR90 */ - {0x54, 0x33, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 15 CR91 */ - {0x0a, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 16 CR92 */ - {0x44, 0x63, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 17 CR93 */ - {0x10, 0x14, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 18 CR94 */ - {0x11, 0x0B, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 19 CR95 */ - {0x05, 0x22, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 20 CR96 */ - {0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 21 CRC3 */ - {0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 22 CRC4 */ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 23 CRC5 */ +static const unsigned char XGI340_cr41[24][3] = { + {0x20, 0x50, 0x60}, /* 0 CR41 */ + {0xc4, 0x40, 0x84}, /* 1 CR8A */ + {0xc4, 0x40, 0x84}, /* 2 CR8B */ + {0xb5, 0xa4, 0xa4}, + {0xf0, 0xf0, 0xf0}, + {0x90, 0x90, 0x24}, /* 5 CR68 */ + {0x77, 0x77, 0x44}, /* 6 CR69 */ + {0x77, 0x77, 0x44}, /* 7 CR6A */ + {0xff, 0xff, 0xff}, /* 8 CR6D */ + {0x55, 0x55, 0x55}, /* 9 CR80 */ + {0x00, 0x00, 0x00}, /* 10 CR81 */ + {0x88, 0xa8, 0x48}, /* 11 CR82 */ + {0x44, 0x44, 0x77}, /* 12 CR85 */ + {0x48, 0x48, 0x88}, /* 13 CR86 */ + {0x54, 0x54, 0x44}, /* 14 CR90 */ + {0x54, 0x54, 0x44}, /* 15 CR91 */ + {0x0a, 0x0a, 0x07}, /* 16 CR92 */ + {0x44, 0x44, 0x44}, /* 17 CR93 */ + {0x10, 0x10, 0x0A}, /* 18 CR94 */ + {0x11, 0x11, 0x0a}, /* 19 CR95 */ + {0x05, 0x05, 0x05}, /* 20 CR96 */ + {0xf0, 0xf0, 0xf0}, /* 21 CRC3 */ + {0x05, 0x00, 0x02}, /* 22 CRC4 */ + {0x00, 0x00, 0x00} /* 23 CRC5 */ +}; + +static const unsigned char XGI27_cr41[24][3] = { + {0x20, 0x40, 0x60}, /* 0 CR41 */ + {0xC4, 0x40, 0x84}, /* 1 CR8A */ + {0xC4, 0x40, 0x84}, /* 2 CR8B */ + {0xB3, 0x13, 0xa4}, /* 3 CR40[7], + CR99[2:0], + CR45[3:0]*/ + {0xf0, 0xf5, 0xf0}, /* 4 CR59 */ + {0x90, 0x90, 0x24}, /* 5 CR68 */ + {0x77, 0x67, 0x44}, /* 6 CR69 */ + {0x77, 0x77, 0x44}, /* 7 CR6A */ + {0xff, 0xff, 0xff}, /* 8 CR6D */ + {0x55, 0x55, 0x55}, /* 9 CR80 */ + {0x00, 0x00, 0x00}, /* 10 CR81 */ + {0x88, 0xcc, 0x48}, /* 11 CR82 */ + {0x44, 0x88, 0x77}, /* 12 CR85 */ + {0x48, 0x88, 0x88}, /* 13 CR86 */ + {0x54, 0x32, 0x44}, /* 14 CR90 */ + {0x54, 0x33, 0x44}, /* 15 CR91 */ + {0x0a, 0x07, 0x07}, /* 16 CR92 */ + {0x44, 0x63, 0x44}, /* 17 CR93 */ + {0x10, 0x14, 0x0A}, /* 18 CR94 */ + {0x11, 0x0B, 0x0C}, /* 19 CR95 */ + {0x05, 0x22, 0x05}, /* 20 CR96 */ + {0xf0, 0xf0, 0x00}, /* 21 CRC3 */ + {0x05, 0x00, 0x02}, /* 22 CRC4 */ + {0x00, 0x00, 0x00} /* 23 CRC5 */ }; /* CR47,CR48,CR49,CR4A,CR4B,CR4C,CR70,CR71,CR74,CR75,CR76,CR77 */ -- cgit v0.10.2 From 86c6c948dabff1ff84213e5fb50684ad32895f25 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 22:32:30 +0100 Subject: staging/xgifb: Remove unused values in XG27_SR13 and XGI340_SR13 In the lookup tables XG27_SR13 and XGI340_SR13 only the first three values are used of each 'line', thus the remaining fields can be removed. Rationale: - vb_init.c uses pVBInfo->ram_type for the 'column' index for pVBInfo->SR15. - pVBInfo->ram_type is assigned the return value of XGINew_GetXG20DRAMType which can only be 0, 1 or 2 - pVBInfo->SR15 is assigned to either XG27_SR13 or XGI340_SR13 in vb_setmode.c -> only the first three values are used. This becomes also evident as values 3-7 are all 0. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_struct.h b/drivers/staging/xgifb/vb_struct.h index 02f3bb5..ae0c18b 100644 --- a/drivers/staging/xgifb/vb_struct.h +++ b/drivers/staging/xgifb/vb_struct.h @@ -157,7 +157,7 @@ struct vb_device_info { void __iomem *FBAddr; - unsigned char const (*SR15)[8]; + unsigned char const (*SR15)[3]; unsigned char const (*CR40)[3]; struct SiS_MCLKData const *MCLKData; diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h index a1be751..b7abe25 100644 --- a/drivers/staging/xgifb/vb_table.h +++ b/drivers/staging/xgifb/vb_table.h @@ -33,18 +33,18 @@ const struct XGI_ECLKDataStruct XGI340_ECLKData[] = { {0x5c, 0x23, 0x01, 166} }; -static const unsigned char XG27_SR13[4][8] = { - {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */ - {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */ - {0x32, 0x32, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR18 */ - {0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00} /* SR1B */ -}; - -static const unsigned char XGI340_SR13[4][8] = { - {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */ - {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */ - {0x31, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR18 */ - {0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00} /* SR1B */ +static const unsigned char XG27_SR13[4][3] = { + {0x35, 0x45, 0xb1}, /* SR13 */ + {0x41, 0x51, 0x5c}, /* SR14 */ + {0x32, 0x32, 0x42}, /* SR18 */ + {0x03, 0x03, 0x03} /* SR1B */ +}; + +static const unsigned char XGI340_SR13[4][3] = { + {0x35, 0x45, 0xb1}, /* SR13 */ + {0x41, 0x51, 0x5c}, /* SR14 */ + {0x31, 0x42, 0x42}, /* SR18 */ + {0x03, 0x03, 0x03} /* SR1B */ }; static const unsigned char XGI340_cr41[24][3] = { -- cgit v0.10.2 From 44b8185007d66d61793be08f0c9b2248e6d56ecf Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 22:32:31 +0100 Subject: staging/xgifb: Remove unused entries in XGI340New_MCLKData and XGI27New_MCLKData In the lookup tables XGI340New_MCLKData and XGI27New_MCLKData only the first three 'lines' are used, thus the remaining fields can be removed. Rationale: - vb_init.c uses pVBInfo->ram_type as the index for pVBInfo->MCLKData - pVBInfo->ram_type is assigned the return value of XGINew_GetXG20DRAMType which can only be 0, 1 or 2 - pVBInfo->MCLKData is assigned to either XGI340New_MCLKData or XGI27New_MCLKData in vb_setmode.c -> only the first three values are used, the rest can be removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h index b7abe25..04fd5cf 100644 --- a/drivers/staging/xgifb/vb_table.h +++ b/drivers/staging/xgifb/vb_table.h @@ -4,22 +4,12 @@ static const struct SiS_MCLKData XGI340New_MCLKData[] = { {0x16, 0x01, 0x01, 166}, {0x19, 0x02, 0x01, 124}, {0x7C, 0x08, 0x01, 200}, - {0x79, 0x06, 0x01, 250}, - {0x29, 0x01, 0x81, 301}, - {0x5c, 0x23, 0x01, 166}, - {0x5c, 0x23, 0x01, 166}, - {0x5c, 0x23, 0x01, 166} }; static const struct SiS_MCLKData XGI27New_MCLKData[] = { {0x5c, 0x23, 0x01, 166}, {0x19, 0x02, 0x01, 124}, {0x7C, 0x08, 0x80, 200}, - {0x79, 0x06, 0x80, 250}, - {0x29, 0x01, 0x81, 300}, - {0x5c, 0x23, 0x01, 166}, - {0x5c, 0x23, 0x01, 166}, - {0x5c, 0x23, 0x01, 166} }; const struct XGI_ECLKDataStruct XGI340_ECLKData[] = { -- cgit v0.10.2 From 46a12dfdbea523b5cd89a59f2705bad684e5037c Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 22:32:32 +0100 Subject: staging/xgifb: Remove unused values in XGI340_ECLKData In the lookup table XGI340_ECLKData only the first three 'lines' are used, thus the remaining entries can be removed. Rationale: - vb_init.c uses pVBInfo->ram_type as the index for XGI340_ECLKData. - pVBInfo->ram_type is assigned the return value of XGINew_GetXG20DRAMType which can only be 0, 1 or 2 -> only the first three values are used. -> remove the remeining entries. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h index 04fd5cf..b4c05c8 100644 --- a/drivers/staging/xgifb/vb_table.h +++ b/drivers/staging/xgifb/vb_table.h @@ -16,11 +16,6 @@ const struct XGI_ECLKDataStruct XGI340_ECLKData[] = { {0x5c, 0x23, 0x01, 166}, {0x55, 0x84, 0x01, 123}, {0x7C, 0x08, 0x01, 200}, - {0x79, 0x06, 0x01, 250}, - {0x29, 0x01, 0x81, 301}, - {0x5c, 0x23, 0x01, 166}, - {0x5c, 0x23, 0x01, 166}, - {0x5c, 0x23, 0x01, 166} }; static const unsigned char XG27_SR13[4][3] = { -- cgit v0.10.2 From 6a7fd2db79ab619cecb803619f8077956ec124cc Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 22:32:33 +0100 Subject: staging/xgifb: Remove unneeded conditional assignment pVBInfo->ram_type is assigned the return value of XGINew_GetXG20DRAMType which can only be 0, 1 or 2 -> The conditional assignment is not needed here as it always evaluates to true. -> remove Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index 7b8f41d..e19a714 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -440,7 +440,7 @@ static void XGINew_SetDRAMDefaultRegister340( xgifb_reg_set(P3d4, 0x6A, pVBInfo->CR40[7][pVBInfo->ram_type]); /* CR6B DQS fine tune delay */ - temp = (pVBInfo->ram_type <= 2) ? 0xaa : 0x00; + temp = 0xaa; XGI_SetDRAM_Helper(P3d4, temp, 0, 0x6B, 2, 0xF0, 0x10); /* CR6E DQM fine tune delay */ -- cgit v0.10.2 From 4b488afbc4f0b16dc9507857afb445ae7aa20af2 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 22:32:34 +0100 Subject: staging/xgifb: Remove always false if statement MCLKData does not contain any 0x1C value for its field SR28 nor does XGI340_ECLKData contain any 0x1C or 0x22 value for its field SR2E. -> the statement always evaluates to false. -> remove Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index e19a714..82170d4 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -131,22 +131,6 @@ static void XGINew_SetMemoryClock(struct xgi_hw_device_info *HwDeviceExtension, xgifb_reg_set(pVBInfo->P3c4, 0x30, XGI340_ECLKData[pVBInfo->ram_type].SR30); - - /* When XG42 ECLK = MCLK = 207MHz, Set SR32 D[1:0] = 10b */ - /* Modify SR32 value, when MCLK=207MHZ, ELCK=250MHz, - * Set SR32 D[1:0] = 10b */ - if (HwDeviceExtension->jChipType == XG42) { - if ((pVBInfo->MCLKData[pVBInfo->ram_type].SR28 == 0x1C) && - (pVBInfo->MCLKData[pVBInfo->ram_type].SR29 == 0x01) && - (((XGI340_ECLKData[pVBInfo->ram_type].SR2E == 0x1C) && - (XGI340_ECLKData[pVBInfo->ram_type].SR2F == 0x01)) || - ((XGI340_ECLKData[pVBInfo->ram_type].SR2E == 0x22) && - (XGI340_ECLKData[pVBInfo->ram_type].SR2F == 0x01)))) - xgifb_reg_set(pVBInfo->P3c4, - 0x32, - ((unsigned char) xgifb_reg_get( - pVBInfo->P3c4, 0x32) & 0xFC) | 0x02); - } } static void XGINew_DDRII_Bootup_XG27( -- cgit v0.10.2 From c7b7cad0d8df823ea063c86a54316bbcbfa04a7c Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Tue, 5 Feb 2013 23:31:37 +0100 Subject: staging/vt6656: Fix sparse warning constant 0xffffffff00000000U is so big it is unsigned long Since 7c65fa2a4c176c9bfab1ef954c4cef005dd9fb8b 'staging: vt6656: Remove QWORD from source and replace with u64.' a new sparse warning showed up: 'drivers/staging/vt6656/card.c:798:26: sparse: constant 0xffffffff00000000U is so big it is unsigned long' -> Append L to fix the warning. Reported-by: Fengguang Wu Signed-off-by: Peter Huewe Cc: Forest Bond Cc: Malcolm Priestley Cc: "Justin P. Mattock" Cc: Marcos Paulo de Souza Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 7d725bb..f988f07 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -790,7 +790,7 @@ u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval) if ((~uLowNextTBTT) < uLowRemain) qwTSF = ((qwTSF >> 32) + 1) << 32; - qwTSF = (qwTSF & 0xffffffff00000000U) | + qwTSF = (qwTSF & 0xffffffff00000000UL) | (u64)(uLowNextTBTT + uLowRemain); return (qwTSF); -- cgit v0.10.2 From 152bce6bdd6e6866ff83166ac75177d001c4360d Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 6 Feb 2013 08:45:22 +0900 Subject: zram: fix warning of print format kbuild bot whinges due to print format mistmatch caused by zram: force disksize setting before using zram. This patch fixes it. Reported-by: Wu Fengguang Signed-off-by: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 85055c4..3318b0f 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -519,7 +519,7 @@ int zram_init_device(struct zram *zram) "ratio. Note that zram uses about 0.1%% of the size of " "the disk when not in use so a huge zram is " "wasteful.\n" - "\tMemory Size: %zu kB\n" + "\tMemory Size: %lu kB\n" "\tSize you selected: %llu kB\n" "Continuing anyway ...\n", (totalram_pages << PAGE_SHIFT) >> 10, zram->disksize >> 10 -- cgit v0.10.2 From 8b3cc3edb745cbc131560d19e3f32d81c07454b1 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 6 Feb 2013 08:48:53 +0900 Subject: zram: get rid of lockdep warning Lockdep complains about recursive deadlock of zram->init_lock. [1] made it false positive because we can't request IO to zram before setting disksize. Anyway, we should shut lockdep up to avoid many reporting from user. [1] : zram: force disksize setting before using zram Acked-by: Jerome Marchand Acked-by: Nitin Gupta Signed-off-by: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 3318b0f..9ac140b 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -61,22 +61,22 @@ static void zram_stat64_inc(struct zram *zram, u64 *v) zram_stat64_add(zram, v, 1); } -static int zram_test_flag(struct zram *zram, u32 index, +static int zram_test_flag(struct zram_meta *meta, u32 index, enum zram_pageflags flag) { - return zram->table[index].flags & BIT(flag); + return meta->table[index].flags & BIT(flag); } -static void zram_set_flag(struct zram *zram, u32 index, +static void zram_set_flag(struct zram_meta *meta, u32 index, enum zram_pageflags flag) { - zram->table[index].flags |= BIT(flag); + meta->table[index].flags |= BIT(flag); } -static void zram_clear_flag(struct zram *zram, u32 index, +static void zram_clear_flag(struct zram_meta *meta, u32 index, enum zram_pageflags flag) { - zram->table[index].flags &= ~BIT(flag); + meta->table[index].flags &= ~BIT(flag); } static int page_zero_filled(void *ptr) @@ -96,16 +96,17 @@ static int page_zero_filled(void *ptr) static void zram_free_page(struct zram *zram, size_t index) { - unsigned long handle = zram->table[index].handle; - u16 size = zram->table[index].size; + struct zram_meta *meta = zram->meta; + unsigned long handle = meta->table[index].handle; + u16 size = meta->table[index].size; if (unlikely(!handle)) { /* * No memory is allocated for zero filled pages. * Simply clear zero page flag. */ - if (zram_test_flag(zram, index, ZRAM_ZERO)) { - zram_clear_flag(zram, index, ZRAM_ZERO); + if (zram_test_flag(meta, index, ZRAM_ZERO)) { + zram_clear_flag(meta, index, ZRAM_ZERO); zram->stats.pages_zero--; } return; @@ -114,17 +115,17 @@ static void zram_free_page(struct zram *zram, size_t index) if (unlikely(size > max_zpage_size)) zram->stats.bad_compress--; - zs_free(zram->mem_pool, handle); + zs_free(meta->mem_pool, handle); if (size <= PAGE_SIZE / 2) zram->stats.good_compress--; zram_stat64_sub(zram, &zram->stats.compr_size, - zram->table[index].size); + meta->table[index].size); zram->stats.pages_stored--; - zram->table[index].handle = 0; - zram->table[index].size = 0; + meta->table[index].handle = 0; + meta->table[index].size = 0; } static void handle_zero_page(struct bio_vec *bvec) @@ -149,20 +150,21 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index) int ret = LZO_E_OK; size_t clen = PAGE_SIZE; unsigned char *cmem; - unsigned long handle = zram->table[index].handle; + struct zram_meta *meta = zram->meta; + unsigned long handle = meta->table[index].handle; - if (!handle || zram_test_flag(zram, index, ZRAM_ZERO)) { + if (!handle || zram_test_flag(meta, index, ZRAM_ZERO)) { memset(mem, 0, PAGE_SIZE); return 0; } - cmem = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); - if (zram->table[index].size == PAGE_SIZE) + cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_RO); + if (meta->table[index].size == PAGE_SIZE) memcpy(mem, cmem, PAGE_SIZE); else - ret = lzo1x_decompress_safe(cmem, zram->table[index].size, + ret = lzo1x_decompress_safe(cmem, meta->table[index].size, mem, &clen); - zs_unmap_object(zram->mem_pool, handle); + zs_unmap_object(meta->mem_pool, handle); /* Should NEVER happen. Return bio error if it does. */ if (unlikely(ret != LZO_E_OK)) { @@ -180,11 +182,11 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, int ret; struct page *page; unsigned char *user_mem, *uncmem = NULL; - + struct zram_meta *meta = zram->meta; page = bvec->bv_page; - if (unlikely(!zram->table[index].handle) || - zram_test_flag(zram, index, ZRAM_ZERO)) { + if (unlikely(!meta->table[index].handle) || + zram_test_flag(meta, index, ZRAM_ZERO)) { handle_zero_page(bvec); return 0; } @@ -232,9 +234,10 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, unsigned long handle; struct page *page; unsigned char *user_mem, *cmem, *src, *uncmem = NULL; + struct zram_meta *meta = zram->meta; page = bvec->bv_page; - src = zram->compress_buffer; + src = meta->compress_buffer; if (is_partial_io(bvec)) { /* @@ -256,8 +259,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, * System overwrites unused sectors. Free memory associated * with this sector now. */ - if (zram->table[index].handle || - zram_test_flag(zram, index, ZRAM_ZERO)) + if (meta->table[index].handle || + zram_test_flag(meta, index, ZRAM_ZERO)) zram_free_page(zram, index); user_mem = kmap_atomic(page); @@ -276,13 +279,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, if (is_partial_io(bvec)) kfree(uncmem); zram->stats.pages_zero++; - zram_set_flag(zram, index, ZRAM_ZERO); + zram_set_flag(meta, index, ZRAM_ZERO); ret = 0; goto out; } ret = lzo1x_1_compress(uncmem, PAGE_SIZE, src, &clen, - zram->compress_workmem); + meta->compress_workmem); if (!is_partial_io(bvec)) { kunmap_atomic(user_mem); @@ -303,14 +306,14 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, src = uncmem; } - handle = zs_malloc(zram->mem_pool, clen); + handle = zs_malloc(meta->mem_pool, clen); if (!handle) { pr_info("Error allocating memory for compressed " "page: %u, size=%zu\n", index, clen); ret = -ENOMEM; goto out; } - cmem = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); + cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO); if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) src = kmap_atomic(page); @@ -318,10 +321,10 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) kunmap_atomic(src); - zs_unmap_object(zram->mem_pool, handle); + zs_unmap_object(meta->mem_pool, handle); - zram->table[index].handle = handle; - zram->table[index].size = clen; + meta->table[index].handle = handle; + meta->table[index].size = clen; /* Update stats */ zram_stat64_add(zram, &zram->stats.compr_size, clen); @@ -464,34 +467,25 @@ error: void __zram_reset_device(struct zram *zram) { size_t index; + struct zram_meta *meta; if (!zram->init_done) return; + meta = zram->meta; zram->init_done = 0; - /* Free various per-device buffers */ - kfree(zram->compress_workmem); - free_pages((unsigned long)zram->compress_buffer, 1); - - zram->compress_workmem = NULL; - zram->compress_buffer = NULL; - /* Free all pages that are still in this zram device */ for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) { - unsigned long handle = zram->table[index].handle; + unsigned long handle = meta->table[index].handle; if (!handle) continue; - zs_free(zram->mem_pool, handle); + zs_free(meta->mem_pool, handle); } - vfree(zram->table); - zram->table = NULL; - - zs_destroy_pool(zram->mem_pool); - zram->mem_pool = NULL; - + zram_meta_free(zram->meta); + zram->meta = NULL; /* Reset stats */ memset(&zram->stats, 0, sizeof(zram->stats)); @@ -506,12 +500,65 @@ void zram_reset_device(struct zram *zram) up_write(&zram->init_lock); } -/* zram->init_lock should be held */ -int zram_init_device(struct zram *zram) +void zram_meta_free(struct zram_meta *meta) +{ + zs_destroy_pool(meta->mem_pool); + kfree(meta->compress_workmem); + free_pages((unsigned long)meta->compress_buffer, 1); + vfree(meta->table); + kfree(meta); +} + +struct zram_meta *zram_meta_alloc(u64 disksize) { - int ret; size_t num_pages; + struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL); + if (!meta) + goto out; + + meta->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); + if (!meta->compress_workmem) { + pr_err("Error allocating compressor working memory!\n"); + goto free_meta; + } + + meta->compress_buffer = + (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); + if (!meta->compress_buffer) { + pr_err("Error allocating compressor buffer space\n"); + goto free_workmem; + } + + num_pages = disksize >> PAGE_SHIFT; + meta->table = vzalloc(num_pages * sizeof(*meta->table)); + if (!meta->table) { + pr_err("Error allocating zram address table\n"); + goto free_buffer; + } + + meta->mem_pool = zs_create_pool(GFP_NOIO | __GFP_HIGHMEM); + if (!meta->mem_pool) { + pr_err("Error creating memory pool\n"); + goto free_table; + } + + return meta; + +free_table: + vfree(meta->table); +free_buffer: + free_pages((unsigned long)meta->compress_buffer, 1); +free_workmem: + kfree(meta->compress_workmem); +free_meta: + kfree(meta); + meta = NULL; +out: + return meta; +} +void zram_init_device(struct zram *zram, struct zram_meta *meta) +{ if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) { pr_info( "There is little point creating a zram of greater than " @@ -526,51 +573,13 @@ int zram_init_device(struct zram *zram) ); } - zram->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); - if (!zram->compress_workmem) { - pr_err("Error allocating compressor working memory!\n"); - ret = -ENOMEM; - goto fail_no_table; - } - - zram->compress_buffer = - (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); - if (!zram->compress_buffer) { - pr_err("Error allocating compressor buffer space\n"); - ret = -ENOMEM; - goto fail_no_table; - } - - num_pages = zram->disksize >> PAGE_SHIFT; - zram->table = vzalloc(num_pages * sizeof(*zram->table)); - if (!zram->table) { - pr_err("Error allocating zram address table\n"); - ret = -ENOMEM; - goto fail_no_table; - } - /* zram devices sort of resembles non-rotational disks */ queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); - zram->mem_pool = zs_create_pool(GFP_NOIO | __GFP_HIGHMEM); - if (!zram->mem_pool) { - pr_err("Error creating memory pool\n"); - ret = -ENOMEM; - goto fail; - } - + zram->meta = meta; zram->init_done = 1; pr_debug("Initialization done!\n"); - return 0; - -fail_no_table: - /* To prevent accessing table entries during cleanup */ - zram->disksize = 0; -fail: - __zram_reset_device(zram); - pr_err("Initialization failed: err=%d\n", ret); - return ret; } static void zram_slot_free_notify(struct block_device *bdev, diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h index 5b671d1..2d1a3f1 100644 --- a/drivers/staging/zram/zram_drv.h +++ b/drivers/staging/zram/zram_drv.h @@ -83,11 +83,15 @@ struct zram_stats { u32 bad_compress; /* % of pages with compression ratio>=75% */ }; -struct zram { - struct zs_pool *mem_pool; +struct zram_meta { void *compress_workmem; void *compress_buffer; struct table *table; + struct zs_pool *mem_pool; +}; + +struct zram { + struct zram_meta *meta; spinlock_t stat64_lock; /* protect 64-bit stats */ struct rw_semaphore lock; /* protect compression buffers and table * against concurrent read and writes */ @@ -111,7 +115,9 @@ unsigned int zram_get_num_devices(void); extern struct attribute_group zram_disk_attr_group; #endif -extern int zram_init_device(struct zram *zram); extern void zram_reset_device(struct zram *zram); +extern struct zram_meta *zram_meta_alloc(u64 disksize); +extern void zram_meta_free(struct zram_meta *meta); +extern void zram_init_device(struct zram *zram, struct zram_meta *meta); #endif diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index 369db12..e6a929d 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -56,22 +56,26 @@ static ssize_t disksize_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { u64 disksize; + struct zram_meta *meta; struct zram *zram = dev_to_zram(dev); disksize = memparse(buf, NULL); if (!disksize) return -EINVAL; + disksize = PAGE_ALIGN(disksize); + meta = zram_meta_alloc(disksize); down_write(&zram->init_lock); if (zram->init_done) { up_write(&zram->init_lock); + zram_meta_free(meta); pr_info("Cannot change disksize for initialized device\n"); return -EBUSY; } - zram->disksize = PAGE_ALIGN(disksize); + zram->disksize = disksize; set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); - zram_init_device(zram); + zram_init_device(zram, meta); up_write(&zram->init_lock); return len; @@ -182,9 +186,10 @@ static ssize_t mem_used_total_show(struct device *dev, { u64 val = 0; struct zram *zram = dev_to_zram(dev); + struct zram_meta *meta = zram->meta; if (zram->init_done) - val = zs_get_total_size_bytes(zram->mem_pool); + val = zs_get_total_size_bytes(meta->mem_pool); return sprintf(buf, "%llu\n", val); } -- cgit v0.10.2 From 07b502f50bfc290222fe4032501619a44bbd777e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:17:36 -0700 Subject: staging: comedi: vmk80xx: remove support for manual attaching This comedi USB driver supports attaching with the auto config mechanism. Remove the manual attaching support using the COMEDI_DEVCONFIG ioctl. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 609dc69..f5a999c 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1189,26 +1189,6 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, return 0; } -/* called for COMEDI_DEVCONFIG ioctl for board_name "vmk80xx" */ -static int vmk80xx_attach(struct comedi_device *cdev, - struct comedi_devconfig *it) -{ - int i; - int ret; - - mutex_lock(&glb_mutex); - for (i = 0; i < VMK80XX_MAX_BOARDS; i++) - if (vmb[i].probed && !vmb[i].attached) - break; - if (i == VMK80XX_MAX_BOARDS) - ret = -ENODEV; - else - ret = vmk80xx_attach_common(cdev, &vmb[i]); - mutex_unlock(&glb_mutex); - return ret; -} - -/* called via comedi_usb_auto_config() */ static int vmk80xx_auto_attach(struct comedi_device *cdev, unsigned long context_unused) { @@ -1245,9 +1225,8 @@ static void vmk80xx_detach(struct comedi_device *dev) static struct comedi_driver vmk80xx_driver = { .module = THIS_MODULE, .driver_name = "vmk80xx", - .attach = vmk80xx_attach, - .detach = vmk80xx_detach, .auto_attach = vmk80xx_auto_attach, + .detach = vmk80xx_detach, }; static int vmk80xx_usb_probe(struct usb_interface *intf, -- cgit v0.10.2 From 9377b9234f159773a53c7277559cc24397dd9803 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:18:04 -0700 Subject: staging: comedi: vmk80xx: move usb_driver (*disconnect) code The usb_driver (*disconnect) in this driver calls the comedi core comedi_usb_auto_unconfig() which calls the comedi_driver (*detach). Move the code in the (*disconnect) to the (*detach) to get all the disconnect/detach in one place. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index f5a999c..8cd4971 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1214,12 +1214,26 @@ static void vmk80xx_detach(struct comedi_device *dev) { struct vmk80xx_usb *usb = dev->private; - if (usb) { - down(&usb->limit_sem); - dev->private = NULL; - usb->attached = 0; - up(&usb->limit_sem); - } + if (!usb) + return; + + mutex_lock(&glb_mutex); + down(&usb->limit_sem); + + dev->private = NULL; + + usb->attached = 0; + usb->probed = 0; + usb_set_intfdata(usb->intf, NULL); + + usb_kill_anchored_urbs(&usb->rx_anchor); + usb_kill_anchored_urbs(&usb->tx_anchor); + + kfree(usb->usb_rx_buf); + kfree(usb->usb_tx_buf); + + up(&usb->limit_sem); + mutex_unlock(&glb_mutex); } static struct comedi_driver vmk80xx_driver = { @@ -1382,30 +1396,7 @@ error: static void vmk80xx_usb_disconnect(struct usb_interface *intf) { - struct vmk80xx_usb *dev = usb_get_intfdata(intf); - - if (!dev) - return; - comedi_usb_auto_unconfig(intf); - - mutex_lock(&glb_mutex); - down(&dev->limit_sem); - - dev->probed = 0; - usb_set_intfdata(dev->intf, NULL); - - usb_kill_anchored_urbs(&dev->rx_anchor); - usb_kill_anchored_urbs(&dev->tx_anchor); - - kfree(dev->usb_rx_buf); - kfree(dev->usb_tx_buf); - - dev_info(&intf->dev, "board #%d [%s] now detached\n", - dev->count, dev->board.name); - - up(&dev->limit_sem); - mutex_unlock(&glb_mutex); } static const struct usb_device_id vmk80xx_usb_id_table[] = { -- cgit v0.10.2 From ce87422743608b436da9e0ce34d01519cd75ea3e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:18:26 -0700 Subject: staging: comedi: vmk80xx: use comedi_auto_unconfig() for (*disconnect) The usb_driver (*disconnect) in this driver is simply a wrapper around comedi_auto_unconfig(). Just use comedi_auto_unconfig() directly for the (*disconnect). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 8cd4971..448c11e 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1394,11 +1394,6 @@ error: return -ENODEV; } -static void vmk80xx_usb_disconnect(struct usb_interface *intf) -{ - comedi_usb_auto_unconfig(intf); -} - static const struct usb_device_id vmk80xx_usb_id_table[] = { { USB_DEVICE(0x10cf, 0x5500), .driver_info = DEVICE_VMK8055 }, { USB_DEVICE(0x10cf, 0x5501), .driver_info = DEVICE_VMK8055 }, @@ -1416,13 +1411,11 @@ static const struct usb_device_id vmk80xx_usb_id_table[] = { }; MODULE_DEVICE_TABLE(usb, vmk80xx_usb_id_table); -/* TODO: Add support for suspend, resume, pre_reset, - * post_reset and flush */ static struct usb_driver vmk80xx_usb_driver = { .name = "vmk80xx", - .probe = vmk80xx_usb_probe, - .disconnect = vmk80xx_usb_disconnect, .id_table = vmk80xx_usb_id_table, + .probe = vmk80xx_usb_probe, + .disconnect = comedi_usb_auto_unconfig, }; module_comedi_usb_driver(vmk80xx_driver, vmk80xx_usb_driver); -- cgit v0.10.2 From 20d6007755cb665d75ba34d6b9075b4cc02e816a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:18:52 -0700 Subject: staging: comedi: vmk80xx: move boardinfo into a const array The normal way of presenting the board specific information in comedi drivers is store the data in a static const array. This data is then accessed using a pointer, normally the comedi_device 'board_ptr', Move the boardinfo for the two boards supported by this driver from the vmk80xx_usb_probe() function into a static const array. Change the access of this information so a pointer is used. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 448c11e..dc2efc0 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -173,6 +173,43 @@ struct vmk80xx_board { __le16 pwm_bits; }; +static const struct vmk80xx_board vmk80xx_boardinfo[] = { + [DEVICE_VMK8055] = { + .name = "K8055 (VM110)", + .model = VMK8055_MODEL, + .range = &vmk8055_range, + .ai_chans = 2, + .ai_bits = 8, + .ao_chans = 2, + .ao_bits = 8, + .di_chans = 6, + .di_bits = 1, + .do_chans = 8, + .do_bits = 1, + .cnt_chans = 2, + .cnt_bits = 16, + .pwm_chans = 0, + .pwm_bits = 0, + }, + [DEVICE_VMK8061] = { + .name = "K8061 (VM140)", + .model = VMK8061_MODEL, + .range = &vmk8061_range, + .ai_chans = 8, + .ai_bits = 10, + .ao_chans = 8, + .ao_bits = 8, + .di_chans = 8, + .di_bits = 1, + .do_chans = 8, + .do_bits = 1, + .cnt_chans = 2, + .cnt_bits = 0, + .pwm_chans = 1, + .pwm_bits = 10, + }, +}; + enum { VMK80XX_SUBD_AI, VMK80XX_SUBD_AO, @@ -189,7 +226,7 @@ struct vmk80xx_usb { struct usb_endpoint_descriptor *ep_tx; struct usb_anchor rx_anchor; struct usb_anchor tx_anchor; - struct vmk80xx_board board; + const struct vmk80xx_board *board; struct firmware_version fw; struct semaphore limit_sem; wait_queue_head_t read_wait; @@ -421,7 +458,7 @@ static int vmk80xx_read_packet(struct vmk80xx_usb *dev) &dev->flags))) return -ERESTART; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { vmk80xx_do_bulk_msg(dev); return 0; @@ -466,7 +503,7 @@ static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd) &dev->flags))) return -ERESTART; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { dev->usb_tx_buf[0] = cmd; vmk80xx_do_bulk_msg(dev); @@ -538,7 +575,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board.model) { + switch (dev->board->model) { case VMK8055_MODEL: if (!chan) reg[0] = VMK8055_AI1_REG; @@ -558,7 +595,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, if (vmk80xx_read_packet(dev)) break; - if (dev->board.model == VMK8055_MODEL) { + if (dev->board->model == VMK8055_MODEL) { data[n] = dev->usb_rx_buf[reg[0]]; continue; } @@ -590,7 +627,7 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board.model) { + switch (dev->board->model) { case VMK8055_MODEL: cmd = VMK8055_CMD_WRT_AD; if (!chan) @@ -666,7 +703,7 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, rx_buf = dev->usb_rx_buf; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { @@ -676,7 +713,7 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, retval = vmk80xx_read_packet(dev); if (!retval) { - if (dev->board.model == VMK8055_MODEL) + if (dev->board->model == VMK8055_MODEL) data[1] = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); @@ -711,7 +748,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, rx_buf = dev->usb_rx_buf; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { @@ -721,7 +758,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, if (vmk80xx_read_packet(dev)) break; - if (dev->board.model == VMK8055_MODEL) + if (dev->board->model == VMK8055_MODEL) inp = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); @@ -757,7 +794,7 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, tx_buf = dev->usb_tx_buf; for (n = 0; n < insn->n; n++) { - if (dev->board.model == VMK8055_MODEL) { + if (dev->board->model == VMK8055_MODEL) { reg = VMK8055_DO_REG; cmd = VMK8055_CMD_WRT_AD; if (data[n] == 1) @@ -830,7 +867,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, if (data[0]) dir |= DIR_OUT; - if (dev->board.model == VMK8061_MODEL) + if (dev->board->model == VMK8061_MODEL) dir |= DIR_IN; retval = rudimentary_check(dev, dir); @@ -843,7 +880,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, tx_buf = dev->usb_tx_buf; if (data[0]) { - if (dev->board.model == VMK8055_MODEL) { + if (dev->board->model == VMK8055_MODEL) { reg = VMK8055_DO_REG; cmd = VMK8055_CMD_WRT_AD; } else { /* VMK8061_MODEL */ @@ -860,7 +897,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, goto out; } - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { reg = VMK8061_DO_REG; tx_buf[0] = VMK8061_CMD_RD_DO; @@ -897,7 +934,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board.model) { + switch (dev->board->model) { case VMK8055_MODEL: if (!chan) reg[0] = VMK8055_CNT1_REG; @@ -916,7 +953,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, if (vmk80xx_read_packet(dev)) break; - if (dev->board.model == VMK8055_MODEL) + if (dev->board->model == VMK8055_MODEL) data[n] = dev->usb_rx_buf[reg[0]]; else /* VMK8061_MODEL */ data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] @@ -951,7 +988,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, chan = CR_CHAN(insn->chanspec); - if (dev->board.model == VMK8055_MODEL) { + if (dev->board->model == VMK8055_MODEL) { if (!chan) { cmd = VMK8055_CMD_RST_CNT1; reg = VMK8055_CNT1_REG; @@ -1109,9 +1146,9 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, int ret; down(&dev->limit_sem); - cdev->board_name = dev->board.name; + cdev->board_name = dev->board->name; cdev->private = dev; - if (dev->board.model == VMK8055_MODEL) + if (dev->board->model == VMK8055_MODEL) n_subd = 5; else n_subd = 6; @@ -1124,19 +1161,19 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s = &cdev->subdevices[VMK80XX_SUBD_AI]; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = dev->board.ai_chans; - s->maxdata = (1 << dev->board.ai_bits) - 1; - s->range_table = dev->board.range; + s->n_chan = dev->board->ai_chans; + s->maxdata = (1 << dev->board->ai_bits) - 1; + s->range_table = dev->board->range; s->insn_read = vmk80xx_ai_rinsn; /* Analog output subdevice */ s = &cdev->subdevices[VMK80XX_SUBD_AO]; s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = dev->board.ao_chans; - s->maxdata = (1 << dev->board.ao_bits) - 1; - s->range_table = dev->board.range; + s->n_chan = dev->board->ao_chans; + s->maxdata = (1 << dev->board->ao_bits) - 1; + s->range_table = dev->board->range; s->insn_write = vmk80xx_ao_winsn; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_ao_rinsn; } @@ -1144,7 +1181,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s = &cdev->subdevices[VMK80XX_SUBD_DI]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = dev->board.di_chans; + s->n_chan = dev->board->di_chans; s->maxdata = 1; s->insn_read = vmk80xx_di_rinsn; s->insn_bits = vmk80xx_di_bits; @@ -1152,11 +1189,11 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s = &cdev->subdevices[VMK80XX_SUBD_DO]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = dev->board.do_chans; + s->n_chan = dev->board->do_chans; s->maxdata = 1; s->insn_write = vmk80xx_do_winsn; s->insn_bits = vmk80xx_do_bits; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_do_rinsn; } @@ -1164,27 +1201,27 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s = &cdev->subdevices[VMK80XX_SUBD_CNT]; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_READABLE; - s->n_chan = dev->board.cnt_chans; + s->n_chan = dev->board->cnt_chans; s->insn_read = vmk80xx_cnt_rinsn; s->insn_config = vmk80xx_cnt_cinsn; - if (dev->board.model == VMK8055_MODEL) { + if (dev->board->model == VMK8055_MODEL) { s->subdev_flags |= SDF_WRITEABLE; - s->maxdata = (1 << dev->board.cnt_bits) - 1; + s->maxdata = (1 << dev->board->cnt_bits) - 1; s->insn_write = vmk80xx_cnt_winsn; } /* PWM subdevice */ - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { s = &cdev->subdevices[VMK80XX_SUBD_PWM]; s->type = COMEDI_SUBD_PWM; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; - s->n_chan = dev->board.pwm_chans; - s->maxdata = (1 << dev->board.pwm_bits) - 1; + s->n_chan = dev->board->pwm_chans; + s->maxdata = (1 << dev->board->pwm_bits) - 1; s->insn_read = vmk80xx_pwm_rinsn; s->insn_write = vmk80xx_pwm_winsn; } dev->attached = 1; dev_info(cdev->class_dev, "vmk80xx: board #%d [%s] attached\n", - dev->count, dev->board.name); + dev->count, dev->board->name); up(&dev->limit_sem); return 0; } @@ -1326,44 +1363,9 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, usb_set_intfdata(intf, dev); - switch (id->driver_info) { - case DEVICE_VMK8055: - dev->board.name = "K8055 (VM110)"; - dev->board.model = VMK8055_MODEL; - dev->board.range = &vmk8055_range; - dev->board.ai_chans = 2; - dev->board.ai_bits = 8; - dev->board.ao_chans = 2; - dev->board.ao_bits = 8; - dev->board.di_chans = 5; - dev->board.di_bits = 1; - dev->board.do_chans = 8; - dev->board.do_bits = 1; - dev->board.cnt_chans = 2; - dev->board.cnt_bits = 16; - dev->board.pwm_chans = 0; - dev->board.pwm_bits = 0; - break; - case DEVICE_VMK8061: - dev->board.name = "K8061 (VM140)"; - dev->board.model = VMK8061_MODEL; - dev->board.range = &vmk8061_range; - dev->board.ai_chans = 8; - dev->board.ai_bits = 10; - dev->board.ao_chans = 8; - dev->board.ao_bits = 8; - dev->board.di_chans = 8; - dev->board.di_bits = 1; - dev->board.do_chans = 8; - dev->board.do_bits = 1; - dev->board.cnt_chans = 2; - dev->board.cnt_bits = 0; - dev->board.pwm_chans = 1; - dev->board.pwm_bits = 10; - break; - } + dev->board = &vmk80xx_boardinfo[id->driver_info]; - if (dev->board.model == VMK8061_MODEL) { + if (dev->board->model == VMK8061_MODEL) { vmk80xx_read_eeprom(dev, IC3_VERSION); dev_info(&intf->dev, "%s\n", dev->fw.ic3_vers); @@ -1375,13 +1377,13 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, } } - if (dev->board.model == VMK8055_MODEL) + if (dev->board->model == VMK8055_MODEL) vmk80xx_reset_device(dev); dev->probed = 1; dev_info(&intf->dev, "board #%d [%s] now attached\n", - dev->count, dev->board.name); + dev->count, dev->board->name); mutex_unlock(&glb_mutex); -- cgit v0.10.2 From 0dd772bf76fca8d76a963de5bc378535e4d3cd39 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:19:18 -0700 Subject: staging: comedi: vmk80xx: save the boardinfo in the comedi_device Save a copy of the boardinfo pointer in the comedi_device 'board_ptr'. The subdevice functions can then simply get it using the comedi_board() helper. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index dc2efc0..2ed4ddf 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -445,6 +445,7 @@ static void vmk80xx_do_bulk_msg(struct vmk80xx_usb *dev) static int vmk80xx_read_packet(struct vmk80xx_usb *dev) { + const struct vmk80xx_board *boardinfo = dev->board; struct urb *urb; int retval; @@ -458,7 +459,7 @@ static int vmk80xx_read_packet(struct vmk80xx_usb *dev) &dev->flags))) return -ERESTART; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { vmk80xx_do_bulk_msg(dev); return 0; @@ -491,6 +492,7 @@ exit: static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd) { + const struct vmk80xx_board *boardinfo = dev->board; struct urb *urb; int retval; @@ -503,7 +505,7 @@ static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd) &dev->flags))) return -ERESTART; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { dev->usb_tx_buf[0] = cmd; vmk80xx_do_bulk_msg(dev); @@ -563,6 +565,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; int chan; int reg[2]; @@ -575,7 +578,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board->model) { + switch (boardinfo->model) { case VMK8055_MODEL: if (!chan) reg[0] = VMK8055_AI1_REG; @@ -595,7 +598,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, if (vmk80xx_read_packet(dev)) break; - if (dev->board->model == VMK8055_MODEL) { + if (boardinfo->model == VMK8055_MODEL) { data[n] = dev->usb_rx_buf[reg[0]]; continue; } @@ -614,6 +617,7 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; int chan; int cmd; @@ -627,7 +631,7 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board->model) { + switch (boardinfo->model) { case VMK8055_MODEL: cmd = VMK8055_CMD_WRT_AD; if (!chan) @@ -690,6 +694,7 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; unsigned char *rx_buf; int reg; @@ -703,7 +708,7 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, rx_buf = dev->usb_rx_buf; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { @@ -713,7 +718,7 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, retval = vmk80xx_read_packet(dev); if (!retval) { - if (dev->board->model == VMK8055_MODEL) + if (boardinfo->model == VMK8055_MODEL) data[1] = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); @@ -732,6 +737,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; int chan; unsigned char *rx_buf; @@ -748,7 +754,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, rx_buf = dev->usb_rx_buf; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { @@ -758,7 +764,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, if (vmk80xx_read_packet(dev)) break; - if (dev->board->model == VMK8055_MODEL) + if (boardinfo->model == VMK8055_MODEL) inp = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); @@ -777,6 +783,7 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; int chan; unsigned char *tx_buf; @@ -794,7 +801,7 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, tx_buf = dev->usb_tx_buf; for (n = 0; n < insn->n; n++) { - if (dev->board->model == VMK8055_MODEL) { + if (boardinfo->model == VMK8055_MODEL) { reg = VMK8055_DO_REG; cmd = VMK8055_CMD_WRT_AD; if (data[n] == 1) @@ -857,6 +864,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; unsigned char *rx_buf, *tx_buf; int dir, reg, cmd; @@ -867,7 +875,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, if (data[0]) dir |= DIR_OUT; - if (dev->board->model == VMK8061_MODEL) + if (boardinfo->model == VMK8061_MODEL) dir |= DIR_IN; retval = rudimentary_check(dev, dir); @@ -880,7 +888,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, tx_buf = dev->usb_tx_buf; if (data[0]) { - if (dev->board->model == VMK8055_MODEL) { + if (boardinfo->model == VMK8055_MODEL) { reg = VMK8055_DO_REG; cmd = VMK8055_CMD_WRT_AD; } else { /* VMK8061_MODEL */ @@ -897,7 +905,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, goto out; } - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { reg = VMK8061_DO_REG; tx_buf[0] = VMK8061_CMD_RD_DO; @@ -922,6 +930,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; int chan; int reg[2]; @@ -934,7 +943,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board->model) { + switch (boardinfo->model) { case VMK8055_MODEL: if (!chan) reg[0] = VMK8055_CNT1_REG; @@ -953,7 +962,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, if (vmk80xx_read_packet(dev)) break; - if (dev->board->model == VMK8055_MODEL) + if (boardinfo->model == VMK8055_MODEL) data[n] = dev->usb_rx_buf[reg[0]]; else /* VMK8061_MODEL */ data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] @@ -969,6 +978,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { + const struct vmk80xx_board *boardinfo = comedi_board(cdev); struct vmk80xx_usb *dev = cdev->private; unsigned int insn_cmd; int chan; @@ -988,7 +998,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, chan = CR_CHAN(insn->chanspec); - if (dev->board->model == VMK8055_MODEL) { + if (boardinfo->model == VMK8055_MODEL) { if (!chan) { cmd = VMK8055_CMD_RST_CNT1; reg = VMK8055_CNT1_REG; @@ -1141,14 +1151,19 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, static int vmk80xx_attach_common(struct comedi_device *cdev, struct vmk80xx_usb *dev) { + const struct vmk80xx_board *boardinfo; int n_subd; struct comedi_subdevice *s; int ret; down(&dev->limit_sem); - cdev->board_name = dev->board->name; + + boardinfo = dev->board; + cdev->board_ptr = boardinfo; + cdev->board_name = boardinfo->name; cdev->private = dev; - if (dev->board->model == VMK8055_MODEL) + + if (boardinfo->model == VMK8055_MODEL) n_subd = 5; else n_subd = 6; @@ -1157,72 +1172,81 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, up(&dev->limit_sem); return ret; } + /* Analog input subdevice */ s = &cdev->subdevices[VMK80XX_SUBD_AI]; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = dev->board->ai_chans; - s->maxdata = (1 << dev->board->ai_bits) - 1; - s->range_table = dev->board->range; + s->n_chan = boardinfo->ai_chans; + s->maxdata = (1 << boardinfo->ai_bits) - 1; + s->range_table = boardinfo->range; s->insn_read = vmk80xx_ai_rinsn; + /* Analog output subdevice */ s = &cdev->subdevices[VMK80XX_SUBD_AO]; s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = dev->board->ao_chans; - s->maxdata = (1 << dev->board->ao_bits) - 1; - s->range_table = dev->board->range; + s->n_chan = boardinfo->ao_chans; + s->maxdata = (1 << boardinfo->ao_bits) - 1; + s->range_table = boardinfo->range; s->insn_write = vmk80xx_ao_winsn; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_ao_rinsn; } + /* Digital input subdevice */ s = &cdev->subdevices[VMK80XX_SUBD_DI]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = dev->board->di_chans; + s->n_chan = boardinfo->di_chans; s->maxdata = 1; s->insn_read = vmk80xx_di_rinsn; s->insn_bits = vmk80xx_di_bits; + /* Digital output subdevice */ s = &cdev->subdevices[VMK80XX_SUBD_DO]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = dev->board->do_chans; + s->n_chan = boardinfo->do_chans; s->maxdata = 1; s->insn_write = vmk80xx_do_winsn; s->insn_bits = vmk80xx_do_bits; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_do_rinsn; } + /* Counter subdevice */ s = &cdev->subdevices[VMK80XX_SUBD_CNT]; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_READABLE; - s->n_chan = dev->board->cnt_chans; + s->n_chan = boardinfo->cnt_chans; s->insn_read = vmk80xx_cnt_rinsn; s->insn_config = vmk80xx_cnt_cinsn; - if (dev->board->model == VMK8055_MODEL) { + if (boardinfo->model == VMK8055_MODEL) { s->subdev_flags |= SDF_WRITEABLE; - s->maxdata = (1 << dev->board->cnt_bits) - 1; + s->maxdata = (1 << boardinfo->cnt_bits) - 1; s->insn_write = vmk80xx_cnt_winsn; } + /* PWM subdevice */ - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { s = &cdev->subdevices[VMK80XX_SUBD_PWM]; s->type = COMEDI_SUBD_PWM; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; - s->n_chan = dev->board->pwm_chans; - s->maxdata = (1 << dev->board->pwm_bits) - 1; + s->n_chan = boardinfo->pwm_chans; + s->maxdata = (1 << boardinfo->pwm_bits) - 1; s->insn_read = vmk80xx_pwm_rinsn; s->insn_write = vmk80xx_pwm_winsn; } + dev->attached = 1; dev_info(cdev->class_dev, "vmk80xx: board #%d [%s] attached\n", - dev->count, dev->board->name); + dev->count, boardinfo->name); + up(&dev->limit_sem); + return 0; } @@ -1283,6 +1307,7 @@ static struct comedi_driver vmk80xx_driver = { static int vmk80xx_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { + const struct vmk80xx_board *boardinfo; int i; struct vmk80xx_usb *dev; struct usb_host_interface *iface_desc; @@ -1363,9 +1388,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, usb_set_intfdata(intf, dev); - dev->board = &vmk80xx_boardinfo[id->driver_info]; + boardinfo = &vmk80xx_boardinfo[id->driver_info]; + dev->board = boardinfo; - if (dev->board->model == VMK8061_MODEL) { + if (boardinfo->model == VMK8061_MODEL) { vmk80xx_read_eeprom(dev, IC3_VERSION); dev_info(&intf->dev, "%s\n", dev->fw.ic3_vers); @@ -1377,13 +1403,13 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, } } - if (dev->board->model == VMK8055_MODEL) + if (boardinfo->model == VMK8055_MODEL) vmk80xx_reset_device(dev); dev->probed = 1; dev_info(&intf->dev, "board #%d [%s] now attached\n", - dev->count, dev->board->name); + dev->count, boardinfo->name); mutex_unlock(&glb_mutex); -- cgit v0.10.2 From 70ba1a599333c576e9dea7dfdcd9a4446d958093 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:19:40 -0700 Subject: staging: comedi: vmk80xx: remove common and unused boardinfo Some of the information in the boardinfo is common for both boards supported by this driver. Remove that information from the boardinfo and just initialize the subdevice values directly. Also, remove any information in the boardinfo that is not used in the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 2ed4ddf..947c8d0 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -162,12 +162,7 @@ struct vmk80xx_board { __u8 ai_chans; __le16 ai_bits; __u8 ao_chans; - __le16 ao_bits; __u8 di_chans; - __le16 di_bits; - __u8 do_chans; - __le16 do_bits; - __u8 cnt_chans; __le16 cnt_bits; __u8 pwm_chans; __le16 pwm_bits; @@ -181,12 +176,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ai_chans = 2, .ai_bits = 8, .ao_chans = 2, - .ao_bits = 8, .di_chans = 6, - .di_bits = 1, - .do_chans = 8, - .do_bits = 1, - .cnt_chans = 2, .cnt_bits = 16, .pwm_chans = 0, .pwm_bits = 0, @@ -198,12 +188,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ai_chans = 8, .ai_bits = 10, .ao_chans = 8, - .ao_bits = 8, .di_chans = 8, - .di_bits = 1, - .do_chans = 8, - .do_bits = 1, - .cnt_chans = 2, .cnt_bits = 0, .pwm_chans = 1, .pwm_bits = 10, @@ -1187,7 +1172,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->n_chan = boardinfo->ao_chans; - s->maxdata = (1 << boardinfo->ao_bits) - 1; + s->maxdata = 0x00ff; s->range_table = boardinfo->range; s->insn_write = vmk80xx_ao_winsn; if (boardinfo->model == VMK8061_MODEL) { @@ -1208,7 +1193,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s = &cdev->subdevices[VMK80XX_SUBD_DO]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = boardinfo->do_chans; + s->n_chan = 8; s->maxdata = 1; s->insn_write = vmk80xx_do_winsn; s->insn_bits = vmk80xx_do_bits; @@ -1221,7 +1206,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s = &cdev->subdevices[VMK80XX_SUBD_CNT]; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_READABLE; - s->n_chan = boardinfo->cnt_chans; + s->n_chan = 2; s->insn_read = vmk80xx_cnt_rinsn; s->insn_config = vmk80xx_cnt_cinsn; if (boardinfo->model == VMK8055_MODEL) { -- cgit v0.10.2 From 9f4d4de3080116173256ce86a32b4c4d472ab1e9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:20:01 -0700 Subject: staging: comedi: vmk80xx: remove VMK80XX_SUBD_* enum These enum values are only used in the initialization of the comedi_subdevices. They don't help make the code any clearer so just remove them. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 947c8d0..e0b9a51 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -195,15 +195,6 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { }, }; -enum { - VMK80XX_SUBD_AI, - VMK80XX_SUBD_AO, - VMK80XX_SUBD_DI, - VMK80XX_SUBD_DO, - VMK80XX_SUBD_CNT, - VMK80XX_SUBD_PWM, -}; - struct vmk80xx_usb { struct usb_device *udev; struct usb_interface *intf; @@ -1159,7 +1150,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, } /* Analog input subdevice */ - s = &cdev->subdevices[VMK80XX_SUBD_AI]; + s = &cdev->subdevices[0]; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND; s->n_chan = boardinfo->ai_chans; @@ -1168,7 +1159,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s->insn_read = vmk80xx_ai_rinsn; /* Analog output subdevice */ - s = &cdev->subdevices[VMK80XX_SUBD_AO]; + s = &cdev->subdevices[1]; s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->n_chan = boardinfo->ao_chans; @@ -1181,7 +1172,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, } /* Digital input subdevice */ - s = &cdev->subdevices[VMK80XX_SUBD_DI]; + s = &cdev->subdevices[2]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_GROUND; s->n_chan = boardinfo->di_chans; @@ -1190,7 +1181,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s->insn_bits = vmk80xx_di_bits; /* Digital output subdevice */ - s = &cdev->subdevices[VMK80XX_SUBD_DO]; + s = &cdev->subdevices[3]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->n_chan = 8; @@ -1203,7 +1194,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, } /* Counter subdevice */ - s = &cdev->subdevices[VMK80XX_SUBD_CNT]; + s = &cdev->subdevices[4]; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_READABLE; s->n_chan = 2; @@ -1217,7 +1208,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, /* PWM subdevice */ if (boardinfo->model == VMK8061_MODEL) { - s = &cdev->subdevices[VMK80XX_SUBD_PWM]; + s = &cdev->subdevices[5]; s->type = COMEDI_SUBD_PWM; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; s->n_chan = boardinfo->pwm_chans; -- cgit v0.10.2 From dc49cbfc67f6d85020715901c88d128d02429791 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:20:22 -0700 Subject: staging: comedi: vmk80xx: rename struct vmk80xx_usb The struct vmk80xx_usb is actually the private data for the comedi_device. For aesthetic reasons, rename the struct to vmk80xx_private. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index e0b9a51..a145286 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -195,7 +195,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { }, }; -struct vmk80xx_usb { +struct vmk80xx_private { struct usb_device *udev; struct usb_interface *intf; struct usb_endpoint_descriptor *ep_rx; @@ -215,13 +215,13 @@ struct vmk80xx_usb { int count; }; -static struct vmk80xx_usb vmb[VMK80XX_MAX_BOARDS]; +static struct vmk80xx_private vmb[VMK80XX_MAX_BOARDS]; static DEFINE_MUTEX(glb_mutex); static void vmk80xx_tx_callback(struct urb *urb) { - struct vmk80xx_usb *dev = urb->context; + struct vmk80xx_private *dev = urb->context; int stat = urb->status; if (stat && !(stat == -ENOENT @@ -239,7 +239,7 @@ static void vmk80xx_tx_callback(struct urb *urb) static void vmk80xx_rx_callback(struct urb *urb) { - struct vmk80xx_usb *dev = urb->context; + struct vmk80xx_private *dev = urb->context; int stat = urb->status; switch (stat) { @@ -275,7 +275,7 @@ exit: wake_up_interruptible(&dev->read_wait); } -static int vmk80xx_check_data_link(struct vmk80xx_usb *dev) +static int vmk80xx_check_data_link(struct vmk80xx_private *dev) { unsigned int tx_pipe; unsigned int rx_pipe; @@ -298,7 +298,7 @@ static int vmk80xx_check_data_link(struct vmk80xx_usb *dev) return (int)rx[1]; } -static void vmk80xx_read_eeprom(struct vmk80xx_usb *dev, int flag) +static void vmk80xx_read_eeprom(struct vmk80xx_private *dev, int flag) { unsigned int tx_pipe; unsigned int rx_pipe; @@ -326,7 +326,7 @@ static void vmk80xx_read_eeprom(struct vmk80xx_usb *dev, int flag) strncpy(dev->fw.ic6_vers, rx + 25, 24); } -static int vmk80xx_reset_device(struct vmk80xx_usb *dev) +static int vmk80xx_reset_device(struct vmk80xx_private *dev) { struct urb *urb; unsigned int tx_pipe; @@ -361,7 +361,7 @@ static int vmk80xx_reset_device(struct vmk80xx_usb *dev) static void vmk80xx_build_int_urb(struct urb *urb, int flag) { - struct vmk80xx_usb *dev = urb->context; + struct vmk80xx_private *dev = urb->context; __u8 rx_addr; __u8 tx_addr; unsigned int pipe; @@ -389,7 +389,7 @@ static void vmk80xx_build_int_urb(struct urb *urb, int flag) usb_fill_int_urb(urb, dev->udev, pipe, buf, size, callback, dev, ival); } -static void vmk80xx_do_bulk_msg(struct vmk80xx_usb *dev) +static void vmk80xx_do_bulk_msg(struct vmk80xx_private *dev) { __u8 tx_addr; __u8 rx_addr; @@ -419,7 +419,7 @@ static void vmk80xx_do_bulk_msg(struct vmk80xx_usb *dev) clear_bit(TRANS_IN_BUSY, &dev->flags); } -static int vmk80xx_read_packet(struct vmk80xx_usb *dev) +static int vmk80xx_read_packet(struct vmk80xx_private *dev) { const struct vmk80xx_board *boardinfo = dev->board; struct urb *urb; @@ -466,7 +466,7 @@ exit: return retval; } -static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd) +static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd) { const struct vmk80xx_board *boardinfo = dev->board; struct urb *urb; @@ -517,7 +517,7 @@ exit: #define DIR_IN 1 #define DIR_OUT 2 -static int rudimentary_check(struct vmk80xx_usb *dev, int dir) +static int rudimentary_check(struct vmk80xx_private *dev, int dir) { if (!dev) return -EFAULT; @@ -542,7 +542,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; int reg[2]; int n; @@ -594,7 +594,7 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; int cmd; int reg; @@ -638,7 +638,7 @@ static int vmk80xx_ao_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; int reg; int n; @@ -671,7 +671,7 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; unsigned char *rx_buf; int reg; int retval; @@ -714,7 +714,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; unsigned char *rx_buf; int reg; @@ -760,7 +760,7 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; unsigned char *tx_buf; int reg; @@ -808,7 +808,7 @@ static int vmk80xx_do_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; int reg; int n; @@ -841,7 +841,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; unsigned char *rx_buf, *tx_buf; int dir, reg, cmd; int retval; @@ -907,7 +907,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int chan; int reg[2]; int n; @@ -955,7 +955,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; unsigned int insn_cmd; int chan; int cmd; @@ -1001,7 +1001,7 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; unsigned long debtime; unsigned long val; int chan; @@ -1048,7 +1048,7 @@ static int vmk80xx_pwm_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; int reg[2]; int n; @@ -1079,7 +1079,7 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_usb *dev = cdev->private; + struct vmk80xx_private *dev = cdev->private; unsigned char *tx_buf; int reg[2]; int cmd; @@ -1125,7 +1125,7 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, } static int vmk80xx_attach_common(struct comedi_device *cdev, - struct vmk80xx_usb *dev) + struct vmk80xx_private *dev) { const struct vmk80xx_board *boardinfo; int n_subd; @@ -1249,7 +1249,7 @@ static int vmk80xx_auto_attach(struct comedi_device *cdev, static void vmk80xx_detach(struct comedi_device *dev) { - struct vmk80xx_usb *usb = dev->private; + struct vmk80xx_private *usb = dev->private; if (!usb) return; @@ -1285,7 +1285,7 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, { const struct vmk80xx_board *boardinfo; int i; - struct vmk80xx_usb *dev; + struct vmk80xx_private *dev; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *ep_desc; size_t size; @@ -1303,7 +1303,7 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, dev = &vmb[i]; - memset(dev, 0x00, sizeof(struct vmk80xx_usb)); + memset(dev, 0x00, sizeof(*dev)); dev->count = i; iface_desc = intf->cur_altsetting; -- cgit v0.10.2 From da7b18ee8b552b9b340c44fa8f6de1372a251a78 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:20:58 -0700 Subject: staging: comedi: vmk80xx: consistently use the same local var names Rename some of the local variables used in this driver to make the code easier to maintain and understand. s/udev/usb the usb_device that the comedi_driver is attached to s/dev/devpriv the private data of the comedi_device s/cdev/dev the comedi_device Also, use some local variables in a couple of the functions to tidy up the code a bit. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index a145286..76b99ad 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -196,7 +196,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { }; struct vmk80xx_private { - struct usb_device *udev; + struct usb_device *usb; struct usb_interface *intf; struct usb_endpoint_descriptor *ep_rx; struct usb_endpoint_descriptor *ep_tx; @@ -221,7 +221,8 @@ static DEFINE_MUTEX(glb_mutex); static void vmk80xx_tx_callback(struct urb *urb) { - struct vmk80xx_private *dev = urb->context; + struct vmk80xx_private *devpriv = urb->context; + unsigned long *flags = &devpriv->flags; int stat = urb->status; if (stat && !(stat == -ENOENT @@ -229,17 +230,18 @@ static void vmk80xx_tx_callback(struct urb *urb) dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n", __func__, stat); - if (!test_bit(TRANS_OUT_BUSY, &dev->flags)) + if (!test_bit(TRANS_OUT_BUSY, flags)) return; - clear_bit(TRANS_OUT_BUSY, &dev->flags); + clear_bit(TRANS_OUT_BUSY, flags); - wake_up_interruptible(&dev->write_wait); + wake_up_interruptible(&devpriv->write_wait); } static void vmk80xx_rx_callback(struct urb *urb) { - struct vmk80xx_private *dev = urb->context; + struct vmk80xx_private *devpriv = urb->context; + unsigned long *flags = &devpriv->flags; int stat = urb->status; switch (stat) { @@ -257,8 +259,8 @@ static void vmk80xx_rx_callback(struct urb *urb) goto exit; resubmit: - if (test_bit(TRANS_IN_RUNNING, &dev->flags) && dev->intf) { - usb_anchor_urb(urb, &dev->rx_anchor); + if (test_bit(TRANS_IN_RUNNING, flags) && devpriv->intf) { + usb_anchor_urb(urb, &devpriv->rx_anchor); if (!usb_submit_urb(urb, GFP_KERNEL)) goto exit; @@ -270,20 +272,21 @@ resubmit: usb_unanchor_urb(urb); } exit: - clear_bit(TRANS_IN_BUSY, &dev->flags); + clear_bit(TRANS_IN_BUSY, flags); - wake_up_interruptible(&dev->read_wait); + wake_up_interruptible(&devpriv->read_wait); } -static int vmk80xx_check_data_link(struct vmk80xx_private *dev) +static int vmk80xx_check_data_link(struct vmk80xx_private *devpriv) { + struct usb_device *usb = devpriv->usb; unsigned int tx_pipe; unsigned int rx_pipe; unsigned char tx[1]; unsigned char rx[2]; - tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); - rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); + tx_pipe = usb_sndbulkpipe(usb, 0x01); + rx_pipe = usb_rcvbulkpipe(usb, 0x81); tx[0] = VMK8061_CMD_RD_PWR_STAT; @@ -292,22 +295,23 @@ static int vmk80xx_check_data_link(struct vmk80xx_private *dev) * running and the data link between IC3 and * IC6 is working properly */ - usb_bulk_msg(dev->udev, tx_pipe, tx, 1, NULL, dev->ep_tx->bInterval); - usb_bulk_msg(dev->udev, rx_pipe, rx, 2, NULL, HZ * 10); + usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval); + usb_bulk_msg(usb, rx_pipe, rx, 2, NULL, HZ * 10); return (int)rx[1]; } -static void vmk80xx_read_eeprom(struct vmk80xx_private *dev, int flag) +static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag) { + struct usb_device *usb = devpriv->usb; unsigned int tx_pipe; unsigned int rx_pipe; unsigned char tx[1]; unsigned char rx[64]; int cnt; - tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); - rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); + tx_pipe = usb_sndbulkpipe(usb, 0x01); + rx_pipe = usb_rcvbulkpipe(usb, 0x81); tx[0] = VMK8061_CMD_RD_VERSION; @@ -315,19 +319,21 @@ static void vmk80xx_read_eeprom(struct vmk80xx_private *dev, int flag) * Read the firmware version info of IC3 and * IC6 from the internal EEPROM of the IC */ - usb_bulk_msg(dev->udev, tx_pipe, tx, 1, NULL, dev->ep_tx->bInterval); - usb_bulk_msg(dev->udev, rx_pipe, rx, 64, &cnt, HZ * 10); + usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval); + usb_bulk_msg(usb, rx_pipe, rx, 64, &cnt, HZ * 10); rx[cnt] = '\0'; if (flag & IC3_VERSION) - strncpy(dev->fw.ic3_vers, rx + 1, 24); + strncpy(devpriv->fw.ic3_vers, rx + 1, 24); else /* IC6_VERSION */ - strncpy(dev->fw.ic6_vers, rx + 25, 24); + strncpy(devpriv->fw.ic6_vers, rx + 25, 24); } -static int vmk80xx_reset_device(struct vmk80xx_private *dev) +static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) { + struct usb_device *usb = devpriv->usb; + unsigned char *tx_buf = devpriv->usb_tx_buf; struct urb *urb; unsigned int tx_pipe; int ival; @@ -337,31 +343,32 @@ static int vmk80xx_reset_device(struct vmk80xx_private *dev) if (!urb) return -ENOMEM; - tx_pipe = usb_sndintpipe(dev->udev, 0x01); + tx_pipe = usb_sndintpipe(usb, 0x01); - ival = dev->ep_tx->bInterval; - size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); + ival = devpriv->ep_tx->bInterval; + size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); - dev->usb_tx_buf[0] = VMK8055_CMD_RST; - dev->usb_tx_buf[1] = 0x00; - dev->usb_tx_buf[2] = 0x00; - dev->usb_tx_buf[3] = 0x00; - dev->usb_tx_buf[4] = 0x00; - dev->usb_tx_buf[5] = 0x00; - dev->usb_tx_buf[6] = 0x00; - dev->usb_tx_buf[7] = 0x00; + tx_buf[0] = VMK8055_CMD_RST; + tx_buf[1] = 0x00; + tx_buf[2] = 0x00; + tx_buf[3] = 0x00; + tx_buf[4] = 0x00; + tx_buf[5] = 0x00; + tx_buf[6] = 0x00; + tx_buf[7] = 0x00; - usb_fill_int_urb(urb, dev->udev, tx_pipe, dev->usb_tx_buf, - size, vmk80xx_tx_callback, dev, ival); + usb_fill_int_urb(urb, usb, tx_pipe, tx_buf, size, + vmk80xx_tx_callback, devpriv, ival); - usb_anchor_urb(urb, &dev->tx_anchor); + usb_anchor_urb(urb, &devpriv->tx_anchor); return usb_submit_urb(urb, GFP_KERNEL); } static void vmk80xx_build_int_urb(struct urb *urb, int flag) { - struct vmk80xx_private *dev = urb->context; + struct vmk80xx_private *devpriv = urb->context; + struct usb_device *usb = devpriv->usb; __u8 rx_addr; __u8 tx_addr; unsigned int pipe; @@ -371,72 +378,74 @@ static void vmk80xx_build_int_urb(struct urb *urb, int flag) int ival; if (flag & URB_RCV_FLAG) { - rx_addr = dev->ep_rx->bEndpointAddress; - pipe = usb_rcvintpipe(dev->udev, rx_addr); - buf = dev->usb_rx_buf; - size = le16_to_cpu(dev->ep_rx->wMaxPacketSize); + rx_addr = devpriv->ep_rx->bEndpointAddress; + pipe = usb_rcvintpipe(usb, rx_addr); + buf = devpriv->usb_rx_buf; + size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); callback = vmk80xx_rx_callback; - ival = dev->ep_rx->bInterval; + ival = devpriv->ep_rx->bInterval; } else { /* URB_SND_FLAG */ - tx_addr = dev->ep_tx->bEndpointAddress; - pipe = usb_sndintpipe(dev->udev, tx_addr); - buf = dev->usb_tx_buf; - size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); + tx_addr = devpriv->ep_tx->bEndpointAddress; + pipe = usb_sndintpipe(usb, tx_addr); + buf = devpriv->usb_tx_buf; + size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); callback = vmk80xx_tx_callback; - ival = dev->ep_tx->bInterval; + ival = devpriv->ep_tx->bInterval; } - usb_fill_int_urb(urb, dev->udev, pipe, buf, size, callback, dev, ival); + usb_fill_int_urb(urb, usb, pipe, buf, size, callback, devpriv, ival); } -static void vmk80xx_do_bulk_msg(struct vmk80xx_private *dev) +static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv) { + struct usb_device *usb = devpriv->usb; + unsigned long *flags = &devpriv->flags; __u8 tx_addr; __u8 rx_addr; unsigned int tx_pipe; unsigned int rx_pipe; size_t size; - set_bit(TRANS_IN_BUSY, &dev->flags); - set_bit(TRANS_OUT_BUSY, &dev->flags); + set_bit(TRANS_IN_BUSY, flags); + set_bit(TRANS_OUT_BUSY, flags); - tx_addr = dev->ep_tx->bEndpointAddress; - rx_addr = dev->ep_rx->bEndpointAddress; - tx_pipe = usb_sndbulkpipe(dev->udev, tx_addr); - rx_pipe = usb_rcvbulkpipe(dev->udev, rx_addr); + tx_addr = devpriv->ep_tx->bEndpointAddress; + rx_addr = devpriv->ep_rx->bEndpointAddress; + tx_pipe = usb_sndbulkpipe(usb, tx_addr); + rx_pipe = usb_rcvbulkpipe(usb, rx_addr); /* * The max packet size attributes of the K8061 * input/output endpoints are identical */ - size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); + size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); - usb_bulk_msg(dev->udev, tx_pipe, dev->usb_tx_buf, - size, NULL, dev->ep_tx->bInterval); - usb_bulk_msg(dev->udev, rx_pipe, dev->usb_rx_buf, size, NULL, HZ * 10); + usb_bulk_msg(usb, tx_pipe, devpriv->usb_tx_buf, + size, NULL, devpriv->ep_tx->bInterval); + usb_bulk_msg(usb, rx_pipe, devpriv->usb_rx_buf, size, NULL, HZ * 10); - clear_bit(TRANS_OUT_BUSY, &dev->flags); - clear_bit(TRANS_IN_BUSY, &dev->flags); + clear_bit(TRANS_OUT_BUSY, flags); + clear_bit(TRANS_IN_BUSY, flags); } -static int vmk80xx_read_packet(struct vmk80xx_private *dev) +static int vmk80xx_read_packet(struct vmk80xx_private *devpriv) { - const struct vmk80xx_board *boardinfo = dev->board; + const struct vmk80xx_board *boardinfo = devpriv->board; + unsigned long *flags = &devpriv->flags; struct urb *urb; int retval; - if (!dev->intf) + if (!devpriv->intf) return -ENODEV; /* Only useful for interrupt transfers */ - if (test_bit(TRANS_IN_BUSY, &dev->flags)) - if (wait_event_interruptible(dev->read_wait, - !test_bit(TRANS_IN_BUSY, - &dev->flags))) + if (test_bit(TRANS_IN_BUSY, flags)) + if (wait_event_interruptible(devpriv->read_wait, + !test_bit(TRANS_IN_BUSY, flags))) return -ERESTART; if (boardinfo->model == VMK8061_MODEL) { - vmk80xx_do_bulk_msg(dev); + vmk80xx_do_bulk_msg(devpriv); return 0; } @@ -445,19 +454,19 @@ static int vmk80xx_read_packet(struct vmk80xx_private *dev) if (!urb) return -ENOMEM; - urb->context = dev; + urb->context = devpriv; vmk80xx_build_int_urb(urb, URB_RCV_FLAG); - set_bit(TRANS_IN_RUNNING, &dev->flags); - set_bit(TRANS_IN_BUSY, &dev->flags); + set_bit(TRANS_IN_RUNNING, flags); + set_bit(TRANS_IN_BUSY, flags); - usb_anchor_urb(urb, &dev->rx_anchor); + usb_anchor_urb(urb, &devpriv->rx_anchor); retval = usb_submit_urb(urb, GFP_KERNEL); if (!retval) goto exit; - clear_bit(TRANS_IN_RUNNING, &dev->flags); + clear_bit(TRANS_IN_RUNNING, flags); usb_unanchor_urb(urb); exit: @@ -466,24 +475,24 @@ exit: return retval; } -static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd) +static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd) { - const struct vmk80xx_board *boardinfo = dev->board; + const struct vmk80xx_board *boardinfo = devpriv->board; + unsigned long *flags = &devpriv->flags; struct urb *urb; int retval; - if (!dev->intf) + if (!devpriv->intf) return -ENODEV; - if (test_bit(TRANS_OUT_BUSY, &dev->flags)) - if (wait_event_interruptible(dev->write_wait, - !test_bit(TRANS_OUT_BUSY, - &dev->flags))) + if (test_bit(TRANS_OUT_BUSY, flags)) + if (wait_event_interruptible(devpriv->write_wait, + !test_bit(TRANS_OUT_BUSY, flags))) return -ERESTART; if (boardinfo->model == VMK8061_MODEL) { - dev->usb_tx_buf[0] = cmd; - vmk80xx_do_bulk_msg(dev); + devpriv->usb_tx_buf[0] = cmd; + vmk80xx_do_bulk_msg(devpriv); return 0; } @@ -492,20 +501,20 @@ static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd) if (!urb) return -ENOMEM; - urb->context = dev; + urb->context = devpriv; vmk80xx_build_int_urb(urb, URB_SND_FLAG); - set_bit(TRANS_OUT_BUSY, &dev->flags); + set_bit(TRANS_OUT_BUSY, flags); - usb_anchor_urb(urb, &dev->tx_anchor); + usb_anchor_urb(urb, &devpriv->tx_anchor); - dev->usb_tx_buf[0] = cmd; + devpriv->usb_tx_buf[0] = cmd; retval = usb_submit_urb(urb, GFP_KERNEL); if (!retval) goto exit; - clear_bit(TRANS_OUT_BUSY, &dev->flags); + clear_bit(TRANS_OUT_BUSY, flags); usb_unanchor_urb(urb); exit: @@ -517,41 +526,41 @@ exit: #define DIR_IN 1 #define DIR_OUT 2 -static int rudimentary_check(struct vmk80xx_private *dev, int dir) +static int rudimentary_check(struct vmk80xx_private *devpriv, int dir) { - if (!dev) + if (!devpriv) return -EFAULT; - if (!dev->probed) + if (!devpriv->probed) return -ENODEV; - if (!dev->attached) + if (!devpriv->attached) return -ENODEV; if (dir & DIR_IN) { - if (test_bit(TRANS_IN_BUSY, &dev->flags)) + if (test_bit(TRANS_IN_BUSY, &devpriv->flags)) return -EBUSY; } if (dir & DIR_OUT) { - if (test_bit(TRANS_OUT_BUSY, &dev->flags)) + if (test_bit(TRANS_OUT_BUSY, &devpriv->flags)) return -EBUSY; } return 0; } -static int vmk80xx_ai_rinsn(struct comedi_device *cdev, +static int vmk80xx_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; int chan; int reg[2]; int n; - n = rudimentary_check(dev, DIR_IN); + n = rudimentary_check(devpriv, DIR_IN); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); switch (boardinfo->model) { @@ -565,46 +574,46 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, default: reg[0] = VMK8061_AI_REG1; reg[1] = VMK8061_AI_REG2; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_AI; - dev->usb_tx_buf[VMK8061_CH_REG] = chan; + devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AI; + devpriv->usb_tx_buf[VMK8061_CH_REG] = chan; break; } for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(dev)) + if (vmk80xx_read_packet(devpriv)) break; if (boardinfo->model == VMK8055_MODEL) { - data[n] = dev->usb_rx_buf[reg[0]]; + data[n] = devpriv->usb_rx_buf[reg[0]]; continue; } /* VMK8061_MODEL */ - data[n] = dev->usb_rx_buf[reg[0]] + 256 * - dev->usb_rx_buf[reg[1]]; + data[n] = devpriv->usb_rx_buf[reg[0]] + 256 * + devpriv->usb_rx_buf[reg[1]]; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_ao_winsn(struct comedi_device *cdev, +static int vmk80xx_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; int chan; int cmd; int reg; int n; - n = rudimentary_check(dev, DIR_OUT); + n = rudimentary_check(devpriv, DIR_OUT); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); switch (boardinfo->model) { @@ -618,80 +627,80 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, default: /* NOTE: avoid compiler warnings */ cmd = VMK8061_CMD_SET_AO; reg = VMK8061_AO_REG; - dev->usb_tx_buf[VMK8061_CH_REG] = chan; + devpriv->usb_tx_buf[VMK8061_CH_REG] = chan; break; } for (n = 0; n < insn->n; n++) { - dev->usb_tx_buf[reg] = data[n]; + devpriv->usb_tx_buf[reg] = data[n]; - if (vmk80xx_write_packet(dev, cmd)) + if (vmk80xx_write_packet(devpriv, cmd)) break; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_ao_rinsn(struct comedi_device *cdev, +static int vmk80xx_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_private *dev = cdev->private; + struct vmk80xx_private *devpriv = dev->private; int chan; int reg; int n; - n = rudimentary_check(dev, DIR_IN); + n = rudimentary_check(devpriv, DIR_IN); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); reg = VMK8061_AO_REG - 1; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_AO; + devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AO; for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(dev)) + if (vmk80xx_read_packet(devpriv)) break; - data[n] = dev->usb_rx_buf[reg + chan]; + data[n] = devpriv->usb_rx_buf[reg + chan]; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_di_bits(struct comedi_device *cdev, +static int vmk80xx_di_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf; int reg; int retval; - retval = rudimentary_check(dev, DIR_IN); + retval = rudimentary_check(devpriv, DIR_IN); if (retval) return retval; - down(&dev->limit_sem); + down(&devpriv->limit_sem); - rx_buf = dev->usb_rx_buf; + rx_buf = devpriv->usb_rx_buf; if (boardinfo->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; + devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { reg = VMK8055_DI_REG; } - retval = vmk80xx_read_packet(dev); + retval = vmk80xx_read_packet(devpriv); if (!retval) { if (boardinfo->model == VMK8055_MODEL) @@ -704,40 +713,40 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, retval = 2; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return retval; } -static int vmk80xx_di_rinsn(struct comedi_device *cdev, +static int vmk80xx_di_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; int chan; unsigned char *rx_buf; int reg; int inp; int n; - n = rudimentary_check(dev, DIR_IN); + n = rudimentary_check(devpriv, DIR_IN); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); - rx_buf = dev->usb_rx_buf; + rx_buf = devpriv->usb_rx_buf; if (boardinfo->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; + devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { reg = VMK8055_DI_REG; } for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(dev)) + if (vmk80xx_read_packet(devpriv)) break; if (boardinfo->model == VMK8055_MODEL) @@ -750,31 +759,31 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, data[n] = (inp >> chan) & 1; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_do_winsn(struct comedi_device *cdev, +static int vmk80xx_do_winsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; int chan; unsigned char *tx_buf; int reg; int cmd; int n; - n = rudimentary_check(dev, DIR_OUT); + n = rudimentary_check(devpriv, DIR_OUT); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); - tx_buf = dev->usb_tx_buf; + tx_buf = devpriv->usb_tx_buf; for (n = 0; n < insn->n; n++) { if (boardinfo->model == VMK8055_MODEL) { @@ -795,53 +804,53 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, } } - if (vmk80xx_write_packet(dev, cmd)) + if (vmk80xx_write_packet(devpriv, cmd)) break; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_do_rinsn(struct comedi_device *cdev, +static int vmk80xx_do_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_private *dev = cdev->private; + struct vmk80xx_private *devpriv = dev->private; int chan; int reg; int n; - n = rudimentary_check(dev, DIR_IN); + n = rudimentary_check(devpriv, DIR_IN); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); reg = VMK8061_DO_REG; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_DO; + devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DO; for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(dev)) + if (vmk80xx_read_packet(devpriv)) break; - data[n] = (dev->usb_rx_buf[reg] >> chan) & 1; + data[n] = (devpriv->usb_rx_buf[reg] >> chan) & 1; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_do_bits(struct comedi_device *cdev, +static int vmk80xx_do_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf, *tx_buf; int dir, reg, cmd; int retval; @@ -854,14 +863,14 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, if (boardinfo->model == VMK8061_MODEL) dir |= DIR_IN; - retval = rudimentary_check(dev, dir); + retval = rudimentary_check(devpriv, dir); if (retval) return retval; - down(&dev->limit_sem); + down(&devpriv->limit_sem); - rx_buf = dev->usb_rx_buf; - tx_buf = dev->usb_tx_buf; + rx_buf = devpriv->usb_rx_buf; + tx_buf = devpriv->usb_tx_buf; if (data[0]) { if (boardinfo->model == VMK8055_MODEL) { @@ -875,7 +884,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, tx_buf[reg] &= ~data[0]; tx_buf[reg] |= (data[0] & data[1]); - retval = vmk80xx_write_packet(dev, cmd); + retval = vmk80xx_write_packet(devpriv, cmd); if (retval) goto out; @@ -885,7 +894,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, reg = VMK8061_DO_REG; tx_buf[0] = VMK8061_CMD_RD_DO; - retval = vmk80xx_read_packet(dev); + retval = vmk80xx_read_packet(devpriv); if (!retval) { data[1] = rx_buf[reg]; @@ -897,26 +906,26 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, } out: - up(&dev->limit_sem); + up(&devpriv->limit_sem); return retval; } -static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, +static int vmk80xx_cnt_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; int chan; int reg[2]; int n; - n = rudimentary_check(dev, DIR_IN); + n = rudimentary_check(devpriv, DIR_IN); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); switch (boardinfo->model) { @@ -930,39 +939,39 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, default: reg[0] = VMK8061_CNT_REG; reg[1] = VMK8061_CNT_REG; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_CNT; + devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_CNT; break; } for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(dev)) + if (vmk80xx_read_packet(devpriv)) break; if (boardinfo->model == VMK8055_MODEL) - data[n] = dev->usb_rx_buf[reg[0]]; + data[n] = devpriv->usb_rx_buf[reg[0]]; else /* VMK8061_MODEL */ - data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] - + 256 * dev->usb_rx_buf[reg[1] * 2 + 2]; + data[n] = devpriv->usb_rx_buf[reg[0] * (chan + 1) + 1] + + 256 * devpriv->usb_rx_buf[reg[1] * 2 + 2]; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, +static int vmk80xx_cnt_cinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(cdev); - struct vmk80xx_private *dev = cdev->private; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; unsigned int insn_cmd; int chan; int cmd; int reg; int n; - n = rudimentary_check(dev, DIR_OUT); + n = rudimentary_check(devpriv, DIR_OUT); if (n) return n; @@ -970,7 +979,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET) return -EINVAL; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); @@ -983,36 +992,36 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, reg = VMK8055_CNT2_REG; } - dev->usb_tx_buf[reg] = 0x00; + devpriv->usb_tx_buf[reg] = 0x00; } else { cmd = VMK8061_CMD_RST_CNT; } for (n = 0; n < insn->n; n++) - if (vmk80xx_write_packet(dev, cmd)) + if (vmk80xx_write_packet(devpriv, cmd)) break; - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_cnt_winsn(struct comedi_device *cdev, +static int vmk80xx_cnt_winsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_private *dev = cdev->private; + struct vmk80xx_private *devpriv = dev->private; unsigned long debtime; unsigned long val; int chan; int cmd; int n; - n = rudimentary_check(dev, DIR_OUT); + n = rudimentary_check(devpriv, DIR_OUT); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); if (!chan) @@ -1033,65 +1042,70 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev, if (((val + 1) * val) < debtime * 1000 / 115) val += 1; - dev->usb_tx_buf[6 + chan] = val; + devpriv->usb_tx_buf[6 + chan] = val; - if (vmk80xx_write_packet(dev, cmd)) + if (vmk80xx_write_packet(devpriv, cmd)) break; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_pwm_rinsn(struct comedi_device *cdev, +static int vmk80xx_pwm_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_private *dev = cdev->private; + struct vmk80xx_private *devpriv = dev->private; + unsigned char *tx_buf; + unsigned char *rx_buf; int reg[2]; int n; - n = rudimentary_check(dev, DIR_IN); + n = rudimentary_check(devpriv, DIR_IN); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); + + tx_buf = devpriv->usb_tx_buf; + rx_buf = devpriv->usb_rx_buf; reg[0] = VMK8061_PWM_REG1; reg[1] = VMK8061_PWM_REG2; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_PWM; + tx_buf[0] = VMK8061_CMD_RD_PWM; for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(dev)) + if (vmk80xx_read_packet(devpriv)) break; - data[n] = dev->usb_rx_buf[reg[0]] + 4 * dev->usb_rx_buf[reg[1]]; + data[n] = rx_buf[reg[0]] + 4 * rx_buf[reg[1]]; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_pwm_winsn(struct comedi_device *cdev, +static int vmk80xx_pwm_winsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_private *dev = cdev->private; + struct vmk80xx_private *devpriv = dev->private; unsigned char *tx_buf; int reg[2]; int cmd; int n; - n = rudimentary_check(dev, DIR_OUT); + n = rudimentary_check(devpriv, DIR_OUT); if (n) return n; - down(&dev->limit_sem); + down(&devpriv->limit_sem); - tx_buf = dev->usb_tx_buf; + tx_buf = devpriv->usb_tx_buf; reg[0] = VMK8061_PWM_REG1; reg[1] = VMK8061_PWM_REG2; @@ -1115,42 +1129,42 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03); tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff; - if (vmk80xx_write_packet(dev, cmd)) + if (vmk80xx_write_packet(devpriv, cmd)) break; } - up(&dev->limit_sem); + up(&devpriv->limit_sem); return n; } -static int vmk80xx_attach_common(struct comedi_device *cdev, - struct vmk80xx_private *dev) +static int vmk80xx_attach_common(struct comedi_device *dev, + struct vmk80xx_private *devpriv) { const struct vmk80xx_board *boardinfo; int n_subd; struct comedi_subdevice *s; int ret; - down(&dev->limit_sem); + down(&devpriv->limit_sem); - boardinfo = dev->board; - cdev->board_ptr = boardinfo; - cdev->board_name = boardinfo->name; - cdev->private = dev; + boardinfo = devpriv->board; + dev->board_ptr = boardinfo; + dev->board_name = boardinfo->name; + dev->private = devpriv; if (boardinfo->model == VMK8055_MODEL) n_subd = 5; else n_subd = 6; - ret = comedi_alloc_subdevices(cdev, n_subd); + ret = comedi_alloc_subdevices(dev, n_subd); if (ret) { - up(&dev->limit_sem); + up(&devpriv->limit_sem); return ret; } /* Analog input subdevice */ - s = &cdev->subdevices[0]; + s = &dev->subdevices[0]; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND; s->n_chan = boardinfo->ai_chans; @@ -1159,7 +1173,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s->insn_read = vmk80xx_ai_rinsn; /* Analog output subdevice */ - s = &cdev->subdevices[1]; + s = &dev->subdevices[1]; s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->n_chan = boardinfo->ao_chans; @@ -1172,7 +1186,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, } /* Digital input subdevice */ - s = &cdev->subdevices[2]; + s = &dev->subdevices[2]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_GROUND; s->n_chan = boardinfo->di_chans; @@ -1181,7 +1195,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s->insn_bits = vmk80xx_di_bits; /* Digital output subdevice */ - s = &cdev->subdevices[3]; + s = &dev->subdevices[3]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->n_chan = 8; @@ -1194,7 +1208,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, } /* Counter subdevice */ - s = &cdev->subdevices[4]; + s = &dev->subdevices[4]; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_READABLE; s->n_chan = 2; @@ -1208,7 +1222,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, /* PWM subdevice */ if (boardinfo->model == VMK8061_MODEL) { - s = &cdev->subdevices[5]; + s = &dev->subdevices[5]; s->type = COMEDI_SUBD_PWM; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; s->n_chan = boardinfo->pwm_chans; @@ -1217,19 +1231,19 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, s->insn_write = vmk80xx_pwm_winsn; } - dev->attached = 1; - dev_info(cdev->class_dev, "vmk80xx: board #%d [%s] attached\n", - dev->count, boardinfo->name); + devpriv->attached = 1; + dev_info(dev->class_dev, "vmk80xx: board #%d [%s] attached\n", + devpriv->count, boardinfo->name); - up(&dev->limit_sem); + up(&devpriv->limit_sem); return 0; } -static int vmk80xx_auto_attach(struct comedi_device *cdev, +static int vmk80xx_auto_attach(struct comedi_device *dev, unsigned long context_unused) { - struct usb_interface *intf = comedi_to_usb_interface(cdev); + struct usb_interface *intf = comedi_to_usb_interface(dev); int i; int ret; @@ -1242,34 +1256,34 @@ static int vmk80xx_auto_attach(struct comedi_device *cdev, else if (vmb[i].attached) ret = -EBUSY; else - ret = vmk80xx_attach_common(cdev, &vmb[i]); + ret = vmk80xx_attach_common(dev, &vmb[i]); mutex_unlock(&glb_mutex); return ret; } static void vmk80xx_detach(struct comedi_device *dev) { - struct vmk80xx_private *usb = dev->private; + struct vmk80xx_private *devpriv = dev->private; - if (!usb) + if (!devpriv) return; mutex_lock(&glb_mutex); - down(&usb->limit_sem); + down(&devpriv->limit_sem); dev->private = NULL; - usb->attached = 0; - usb->probed = 0; - usb_set_intfdata(usb->intf, NULL); + devpriv->attached = 0; + devpriv->probed = 0; + usb_set_intfdata(devpriv->intf, NULL); - usb_kill_anchored_urbs(&usb->rx_anchor); - usb_kill_anchored_urbs(&usb->tx_anchor); + usb_kill_anchored_urbs(&devpriv->rx_anchor); + usb_kill_anchored_urbs(&devpriv->tx_anchor); - kfree(usb->usb_rx_buf); - kfree(usb->usb_tx_buf); + kfree(devpriv->usb_rx_buf); + kfree(devpriv->usb_tx_buf); - up(&usb->limit_sem); + up(&devpriv->limit_sem); mutex_unlock(&glb_mutex); } @@ -1284,11 +1298,11 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { const struct vmk80xx_board *boardinfo; - int i; - struct vmk80xx_private *dev; + struct vmk80xx_private *devpriv; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *ep_desc; size_t size; + int i; mutex_lock(&glb_mutex); @@ -1301,10 +1315,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, return -EMFILE; } - dev = &vmb[i]; + devpriv = &vmb[i]; - memset(dev, 0x00, sizeof(*dev)); - dev->count = i; + memset(devpriv, 0x00, sizeof(*devpriv)); + devpriv->count = i; iface_desc = intf->cur_altsetting; if (iface_desc->desc.bNumEndpoints != 2) @@ -1314,78 +1328,78 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, ep_desc = &iface_desc->endpoint[i].desc; if (usb_endpoint_is_int_in(ep_desc)) { - dev->ep_rx = ep_desc; + devpriv->ep_rx = ep_desc; continue; } if (usb_endpoint_is_int_out(ep_desc)) { - dev->ep_tx = ep_desc; + devpriv->ep_tx = ep_desc; continue; } if (usb_endpoint_is_bulk_in(ep_desc)) { - dev->ep_rx = ep_desc; + devpriv->ep_rx = ep_desc; continue; } if (usb_endpoint_is_bulk_out(ep_desc)) { - dev->ep_tx = ep_desc; + devpriv->ep_tx = ep_desc; continue; } } - if (!dev->ep_rx || !dev->ep_tx) + if (!devpriv->ep_rx || !devpriv->ep_tx) goto error; - size = le16_to_cpu(dev->ep_rx->wMaxPacketSize); - dev->usb_rx_buf = kmalloc(size, GFP_KERNEL); - if (!dev->usb_rx_buf) { + size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); + devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL); + if (!devpriv->usb_rx_buf) { mutex_unlock(&glb_mutex); return -ENOMEM; } - size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); - dev->usb_tx_buf = kmalloc(size, GFP_KERNEL); - if (!dev->usb_tx_buf) { - kfree(dev->usb_rx_buf); + size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); + devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL); + if (!devpriv->usb_tx_buf) { + kfree(devpriv->usb_rx_buf); mutex_unlock(&glb_mutex); return -ENOMEM; } - dev->udev = interface_to_usbdev(intf); - dev->intf = intf; + devpriv->usb = interface_to_usbdev(intf); + devpriv->intf = intf; - sema_init(&dev->limit_sem, 8); - init_waitqueue_head(&dev->read_wait); - init_waitqueue_head(&dev->write_wait); + sema_init(&devpriv->limit_sem, 8); + init_waitqueue_head(&devpriv->read_wait); + init_waitqueue_head(&devpriv->write_wait); - init_usb_anchor(&dev->rx_anchor); - init_usb_anchor(&dev->tx_anchor); + init_usb_anchor(&devpriv->rx_anchor); + init_usb_anchor(&devpriv->tx_anchor); - usb_set_intfdata(intf, dev); + usb_set_intfdata(intf, devpriv); boardinfo = &vmk80xx_boardinfo[id->driver_info]; - dev->board = boardinfo; + devpriv->board = boardinfo; if (boardinfo->model == VMK8061_MODEL) { - vmk80xx_read_eeprom(dev, IC3_VERSION); - dev_info(&intf->dev, "%s\n", dev->fw.ic3_vers); + vmk80xx_read_eeprom(devpriv, IC3_VERSION); + dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers); - if (vmk80xx_check_data_link(dev)) { - vmk80xx_read_eeprom(dev, IC6_VERSION); - dev_info(&intf->dev, "%s\n", dev->fw.ic6_vers); + if (vmk80xx_check_data_link(devpriv)) { + vmk80xx_read_eeprom(devpriv, IC6_VERSION); + dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers); } else { dbgcm("comedi#: vmk80xx: no conn. to CPU\n"); } } if (boardinfo->model == VMK8055_MODEL) - vmk80xx_reset_device(dev); + vmk80xx_reset_device(devpriv); - dev->probed = 1; + devpriv->probed = 1; dev_info(&intf->dev, "board #%d [%s] now attached\n", - dev->count, boardinfo->name); + devpriv->count, boardinfo->name); mutex_unlock(&glb_mutex); -- cgit v0.10.2 From 49253d542cc0f5f771dc254d248162a2a666649d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:21:19 -0700 Subject: staging: comedi: vmk80xx: factor out usb endpoint detection Factor the code that detects the usb endpoints out of vmk80xx_usb_probe(). Cleanup the detection code in the new function, Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 76b99ad..26c10a8 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1138,6 +1138,40 @@ static int vmk80xx_pwm_winsn(struct comedi_device *dev, return n; } +static int vmk80xx_find_usb_endpoints(struct vmk80xx_private *devpriv, + struct usb_interface *intf) +{ + struct usb_host_interface *iface_desc = intf->cur_altsetting; + struct usb_endpoint_descriptor *ep_desc; + int i; + + if (iface_desc->desc.bNumEndpoints != 2) + return -ENODEV; + + for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { + ep_desc = &iface_desc->endpoint[i].desc; + + if (usb_endpoint_is_int_in(ep_desc) || + usb_endpoint_is_bulk_in(ep_desc)) { + if (!devpriv->ep_rx) + devpriv->ep_rx = ep_desc; + continue; + } + + if (usb_endpoint_is_int_out(ep_desc) || + usb_endpoint_is_bulk_out(ep_desc)) { + if (!devpriv->ep_tx) + devpriv->ep_tx = ep_desc; + continue; + } + } + + if (!devpriv->ep_rx || !devpriv->ep_tx) + return -ENODEV; + + return 0; +} + static int vmk80xx_attach_common(struct comedi_device *dev, struct vmk80xx_private *devpriv) { @@ -1299,9 +1333,8 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, { const struct vmk80xx_board *boardinfo; struct vmk80xx_private *devpriv; - struct usb_host_interface *iface_desc; - struct usb_endpoint_descriptor *ep_desc; size_t size; + int ret; int i; mutex_lock(&glb_mutex); @@ -1320,37 +1353,12 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, memset(devpriv, 0x00, sizeof(*devpriv)); devpriv->count = i; - iface_desc = intf->cur_altsetting; - if (iface_desc->desc.bNumEndpoints != 2) - goto error; - - for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { - ep_desc = &iface_desc->endpoint[i].desc; - - if (usb_endpoint_is_int_in(ep_desc)) { - devpriv->ep_rx = ep_desc; - continue; - } - - if (usb_endpoint_is_int_out(ep_desc)) { - devpriv->ep_tx = ep_desc; - continue; - } - - if (usb_endpoint_is_bulk_in(ep_desc)) { - devpriv->ep_rx = ep_desc; - continue; - } - - if (usb_endpoint_is_bulk_out(ep_desc)) { - devpriv->ep_tx = ep_desc; - continue; - } + ret = vmk80xx_find_usb_endpoints(devpriv, intf); + if (ret) { + mutex_unlock(&glb_mutex); + return ret; } - if (!devpriv->ep_rx || !devpriv->ep_tx) - goto error; - size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL); if (!devpriv->usb_rx_buf) { @@ -1406,10 +1414,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, comedi_usb_auto_config(intf, &vmk80xx_driver); return 0; -error: - mutex_unlock(&glb_mutex); - - return -ENODEV; } static const struct usb_device_id vmk80xx_usb_id_table[] = { -- cgit v0.10.2 From 78f8fa7f00689f4385c28b1b2be30c83f331c497 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:21:40 -0700 Subject: staging: comedi: vmk80xx: factor out usb buffer allocation Factor the code that allocates the usb buffers out of vmk80xx_usb_probe(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 26c10a8..f52d34d 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1172,6 +1172,25 @@ static int vmk80xx_find_usb_endpoints(struct vmk80xx_private *devpriv, return 0; } +static int vmk80xx_alloc_usb_buffers(struct vmk80xx_private *devpriv) +{ + size_t size; + + size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); + devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL); + if (!devpriv->usb_rx_buf) + return -ENOMEM; + + size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); + devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL); + if (!devpriv->usb_tx_buf) { + kfree(devpriv->usb_rx_buf); + return -ENOMEM; + } + + return 0; +} + static int vmk80xx_attach_common(struct comedi_device *dev, struct vmk80xx_private *devpriv) { @@ -1333,7 +1352,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, { const struct vmk80xx_board *boardinfo; struct vmk80xx_private *devpriv; - size_t size; int ret; int i; @@ -1359,19 +1377,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, return ret; } - size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); - devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL); - if (!devpriv->usb_rx_buf) { - mutex_unlock(&glb_mutex); - return -ENOMEM; - } - - size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); - devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL); - if (!devpriv->usb_tx_buf) { - kfree(devpriv->usb_rx_buf); + ret = vmk80xx_alloc_usb_buffers(devpriv); + if (ret) { mutex_unlock(&glb_mutex); - return -ENOMEM; + return ret; } devpriv->usb = interface_to_usbdev(intf); -- cgit v0.10.2 From 1cc8f8854c86b77637b1300b22e553028c6f2668 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:22:03 -0700 Subject: staging: comedi: vmk80xx: remove private data 'count' The 'count' in the private data is only used in a couple dev_info() kernel messages. These messages are just added noise. Remove the 'count' variable in the private data as well as the dev_info() messages. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index f52d34d..ec9ff0d 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -212,7 +212,6 @@ struct vmk80xx_private { unsigned long flags; int probed; int attached; - int count; }; static struct vmk80xx_private vmb[VMK80XX_MAX_BOARDS]; @@ -1285,8 +1284,6 @@ static int vmk80xx_attach_common(struct comedi_device *dev, } devpriv->attached = 1; - dev_info(dev->class_dev, "vmk80xx: board #%d [%s] attached\n", - devpriv->count, boardinfo->name); up(&devpriv->limit_sem); @@ -1369,7 +1366,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, devpriv = &vmb[i]; memset(devpriv, 0x00, sizeof(*devpriv)); - devpriv->count = i; ret = vmk80xx_find_usb_endpoints(devpriv, intf); if (ret) { @@ -1415,9 +1411,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, devpriv->probed = 1; - dev_info(&intf->dev, "board #%d [%s] now attached\n", - devpriv->count, boardinfo->name); - mutex_unlock(&glb_mutex); comedi_usb_auto_config(intf, &vmk80xx_driver); -- cgit v0.10.2 From db7dabf707f1eb3c4288ca8bedd4b2aa6701ca7b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:22:27 -0700 Subject: staging: comedi: vmk80xx: make sure private data is clean when detached Currently the private data used in this driver is stored in a static array. During the usb (*probe) and empty location is found in this array for use by the usb device. Some initialization of the private data is then done before comedi_usb_auto_config() is called to allow the comedi core to attach its comedi_device to the usb device. The (*probe) can fail for various reasons. If it does, make sure that the private data is clean before returning an error. The usb (*disconnect) simply calls comedi_usb_auto_unconfig() to allow the comedi core to disconnect its comedi_device from the usb device. Since the private data points to the static array it cannot be kfree'ed during the detach. Instead make sure it clean before leaving the detach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index ec9ff0d..e82319b 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1323,8 +1323,6 @@ static void vmk80xx_detach(struct comedi_device *dev) dev->private = NULL; - devpriv->attached = 0; - devpriv->probed = 0; usb_set_intfdata(devpriv->intf, NULL); usb_kill_anchored_urbs(&devpriv->rx_anchor); @@ -1334,6 +1332,14 @@ static void vmk80xx_detach(struct comedi_device *dev) kfree(devpriv->usb_tx_buf); up(&devpriv->limit_sem); + + /* + * Since 'devpriv' points to an element of the static vmb array + * we can't kfree it. Instead memset it to all '0' so subsequent + * usb probes don't find any garbage in it. + */ + memset(devpriv, 0x00, sizeof(*devpriv)); + mutex_unlock(&glb_mutex); } @@ -1359,25 +1365,19 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, break; if (i == VMK80XX_MAX_BOARDS) { - mutex_unlock(&glb_mutex); - return -EMFILE; + ret = -EMFILE; + goto fail; } devpriv = &vmb[i]; - memset(devpriv, 0x00, sizeof(*devpriv)); - ret = vmk80xx_find_usb_endpoints(devpriv, intf); - if (ret) { - mutex_unlock(&glb_mutex); - return ret; - } + if (ret) + goto error; ret = vmk80xx_alloc_usb_buffers(devpriv); - if (ret) { - mutex_unlock(&glb_mutex); - return ret; - } + if (ret) + goto error; devpriv->usb = interface_to_usbdev(intf); devpriv->intf = intf; @@ -1416,6 +1416,17 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, comedi_usb_auto_config(intf, &vmk80xx_driver); return 0; + +error: + /* + * Since 'devpriv' points to an element of the static vmb array + * we can't kfree it. Instead memset it to all '0' so subsequent + * usb probes don't find any garbage in it. + */ + memset(devpriv, 0x00, sizeof(*devpriv)); +fail: + mutex_unlock(&glb_mutex); + return ret; } static const struct usb_device_id vmk80xx_usb_id_table[] = { -- cgit v0.10.2 From b105ad8a78456fbcdb81e98076e9c3813cdb0be0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:22:49 -0700 Subject: staging: comedi: vmk80xx: remove private data 'probed' The 'probed' variable is used in the usb driver (*probe) to detect an unused element in the static private data arry. This variable is then set after the usb driver has completed its (*probe) before calling comedi_usb_auto_config(). When the comedi core does the auto config it will call the (*auto_attach) function, vmk80xx_auto_attach(), which then locates the correct private data in the static array by checking to see if it has been 'probed' and that the 'intf' variable matches the usb_interface pointer for the usb device. Now that the private data is clean after failed usb probes and disconnects we don't have to worry about have a garbage 'intf' value in the private data that might match. Remove the 'probed' flag from the private data and just use the 'intf' pointer to detect the match. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index e82319b..a9aa988 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -210,7 +210,6 @@ struct vmk80xx_private { unsigned char *usb_rx_buf; unsigned char *usb_tx_buf; unsigned long flags; - int probed; int attached; }; @@ -529,8 +528,6 @@ static int rudimentary_check(struct vmk80xx_private *devpriv, int dir) { if (!devpriv) return -EFAULT; - if (!devpriv->probed) - return -ENODEV; if (!devpriv->attached) return -ENODEV; if (dir & DIR_IN) { @@ -1299,7 +1296,7 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, mutex_lock(&glb_mutex); for (i = 0; i < VMK80XX_MAX_BOARDS; i++) - if (vmb[i].probed && vmb[i].intf == intf) + if (vmb[i].intf == intf) break; if (i == VMK80XX_MAX_BOARDS) ret = -ENODEV; @@ -1361,7 +1358,7 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, mutex_lock(&glb_mutex); for (i = 0; i < VMK80XX_MAX_BOARDS; i++) - if (!vmb[i].probed) + if (!vmb[i].intf) break; if (i == VMK80XX_MAX_BOARDS) { @@ -1409,8 +1406,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, if (boardinfo->model == VMK8055_MODEL) vmk80xx_reset_device(devpriv); - devpriv->probed = 1; - mutex_unlock(&glb_mutex); comedi_usb_auto_config(intf, &vmk80xx_driver); -- cgit v0.10.2 From 29d6dd3310641f7dc0dbd9b55f651eb9846f2aa6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:23:16 -0700 Subject: staging: comedi: vmk80xx: remove private data 'attached' The 'attached' flag in the private data is set after the comedi_driver (*auto_attach) function has completed successfully. The only places it's checked are in rudimentary_check(), which does some basic sanity checks before doing any of the subdevice operations, and vmk80xx_auto_attach(), which is the comedi_driver (*auto_attach) function. The (*auto_attach) function can only be called as the result of a successfull usb_driver (*probe). Part of the probe is to locate a free slot in the static private data array. All free slots are initialized to '0' so the 'attached' flag will always be cleared. Remove the unneccessary 'attached' flag in the private data. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index a9aa988..00a115d 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -210,7 +210,6 @@ struct vmk80xx_private { unsigned char *usb_rx_buf; unsigned char *usb_tx_buf; unsigned long flags; - int attached; }; static struct vmk80xx_private vmb[VMK80XX_MAX_BOARDS]; @@ -528,8 +527,6 @@ static int rudimentary_check(struct vmk80xx_private *devpriv, int dir) { if (!devpriv) return -EFAULT; - if (!devpriv->attached) - return -ENODEV; if (dir & DIR_IN) { if (test_bit(TRANS_IN_BUSY, &devpriv->flags)) return -EBUSY; @@ -1280,8 +1277,6 @@ static int vmk80xx_attach_common(struct comedi_device *dev, s->insn_write = vmk80xx_pwm_winsn; } - devpriv->attached = 1; - up(&devpriv->limit_sem); return 0; @@ -1300,8 +1295,6 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, break; if (i == VMK80XX_MAX_BOARDS) ret = -ENODEV; - else if (vmb[i].attached) - ret = -EBUSY; else ret = vmk80xx_attach_common(dev, &vmb[i]); mutex_unlock(&glb_mutex); -- cgit v0.10.2 From 55ab4f641a3bfbdb7c59b80e194c7242234bbb1f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:23:40 -0700 Subject: staging: comedi: comedi_usb: allow comedi usb drivers to pass a 'context' Allow the comedi usb drivers to pass a 'context' from their (*probe) functions to the comedi core's comedi_usb_auto_config(). This 'context' is then passed to comedi_auto_config() and then to the comedi_driver's (*auto_attach). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c index cd6abba..9d9716a 100644 --- a/drivers/staging/comedi/comedi_usb.c +++ b/drivers/staging/comedi/comedi_usb.c @@ -38,13 +38,15 @@ EXPORT_SYMBOL_GPL(comedi_to_usb_interface); * comedi_usb_auto_config() - Configure/probe a comedi USB driver. * @intf: usb_interface struct * @driver: comedi_driver struct + * @context: driver specific data, passed to comedi_auto_config() * * Typically called from the usb_driver (*probe) function. */ int comedi_usb_auto_config(struct usb_interface *intf, - struct comedi_driver *driver) + struct comedi_driver *driver, + unsigned long context) { - return comedi_auto_config(&intf->dev, driver, 0); + return comedi_auto_config(&intf->dev, driver, context); } EXPORT_SYMBOL_GPL(comedi_usb_auto_config); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 4836fe6..d921cd7 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -476,7 +476,8 @@ struct usb_interface; struct usb_interface *comedi_to_usb_interface(struct comedi_device *); -int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *); +int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *, + unsigned long context); void comedi_usb_auto_unconfig(struct usb_interface *); int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c index 17b45eb..7c2f856 100644 --- a/drivers/staging/comedi/drivers/usbdux.c +++ b/drivers/staging/comedi/drivers/usbdux.c @@ -2388,7 +2388,7 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw, "Could not upload firmware (err=%d)\n", ret); goto out; } - comedi_usb_auto_config(uinterf, &usbdux_driver); + comedi_usb_auto_config(uinterf, &usbdux_driver, 0); out: release_firmware(fw); } diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c index 4e19f61..0f6187f 100644 --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -1490,7 +1490,7 @@ static void usbduxfast_firmware_request_complete_handler(const struct firmware goto out; } - comedi_usb_auto_config(uinterf, &usbduxfast_driver); + comedi_usb_auto_config(uinterf, &usbduxfast_driver, 0); out: release_firmware(fw); } diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c index cdd279b..dc6b017 100644 --- a/drivers/staging/comedi/drivers/usbduxsigma.c +++ b/drivers/staging/comedi/drivers/usbduxsigma.c @@ -2374,7 +2374,7 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw, "Could not upload firmware (err=%d)\n", ret); goto out; } - comedi_usb_auto_config(uinterf, &usbduxsigma_driver); + comedi_usb_auto_config(uinterf, &usbduxsigma_driver, 0); out: release_firmware(fw); } diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 00a115d..c20202c 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1401,7 +1401,7 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, mutex_unlock(&glb_mutex); - comedi_usb_auto_config(intf, &vmk80xx_driver); + comedi_usb_auto_config(intf, &vmk80xx_driver, id->driver_info); return 0; -- cgit v0.10.2 From 57cf09aeeeadf35ef7f678a870139894d67a794f Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:24:03 -0700 Subject: staging: comedi: vmk80xx: push usb (*probe) into comedi (*auto_attach) Make the usb_driver (*probe) simply call comedi_usb_auto_config() and move all the (*probe) code into the (*auto_attach) function. This allows getting rid of the static private data array since we no longer do part of the initialization in the (*probe) and then finish it in the (*auto_attach). We can simply kzalloc the private data instead. The comedi core will then handle the kfree of the data when the driver is detached. We can also get rid of the static 'glb_mutex' since this mutex was only used to protect the static private data array. Change the parameters for a couple of the helper functions used during the auto attach. Now that the comedi_device is available we can simply pass that pointer and get the specific pointers needed by the helper functions from it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index c20202c..6ed70ee 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -212,10 +212,6 @@ struct vmk80xx_private { unsigned long flags; }; -static struct vmk80xx_private vmb[VMK80XX_MAX_BOARDS]; - -static DEFINE_MUTEX(glb_mutex); - static void vmk80xx_tx_callback(struct urb *urb) { struct vmk80xx_private *devpriv = urb->context; @@ -1131,9 +1127,10 @@ static int vmk80xx_pwm_winsn(struct comedi_device *dev, return n; } -static int vmk80xx_find_usb_endpoints(struct vmk80xx_private *devpriv, - struct usb_interface *intf) +static int vmk80xx_find_usb_endpoints(struct comedi_device *dev) { + struct vmk80xx_private *devpriv = dev->private; + struct usb_interface *intf = devpriv->intf; struct usb_host_interface *iface_desc = intf->cur_altsetting; struct usb_endpoint_descriptor *ep_desc; int i; @@ -1165,8 +1162,9 @@ static int vmk80xx_find_usb_endpoints(struct vmk80xx_private *devpriv, return 0; } -static int vmk80xx_alloc_usb_buffers(struct vmk80xx_private *devpriv) +static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev) { + struct vmk80xx_private *devpriv = dev->private; size_t size; size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); @@ -1184,21 +1182,16 @@ static int vmk80xx_alloc_usb_buffers(struct vmk80xx_private *devpriv) return 0; } -static int vmk80xx_attach_common(struct comedi_device *dev, - struct vmk80xx_private *devpriv) +static int vmk80xx_attach_common(struct comedi_device *dev) { - const struct vmk80xx_board *boardinfo; - int n_subd; + const struct vmk80xx_board *boardinfo = comedi_board(dev); + struct vmk80xx_private *devpriv = dev->private; struct comedi_subdevice *s; + int n_subd; int ret; down(&devpriv->limit_sem); - boardinfo = devpriv->board; - dev->board_ptr = boardinfo; - dev->board_name = boardinfo->name; - dev->private = devpriv; - if (boardinfo->model == VMK8055_MODEL) n_subd = 5; else @@ -1283,94 +1276,33 @@ static int vmk80xx_attach_common(struct comedi_device *dev, } static int vmk80xx_auto_attach(struct comedi_device *dev, - unsigned long context_unused) + unsigned long context) { struct usb_interface *intf = comedi_to_usb_interface(dev); - int i; - int ret; - - mutex_lock(&glb_mutex); - for (i = 0; i < VMK80XX_MAX_BOARDS; i++) - if (vmb[i].intf == intf) - break; - if (i == VMK80XX_MAX_BOARDS) - ret = -ENODEV; - else - ret = vmk80xx_attach_common(dev, &vmb[i]); - mutex_unlock(&glb_mutex); - return ret; -} - -static void vmk80xx_detach(struct comedi_device *dev) -{ - struct vmk80xx_private *devpriv = dev->private; - - if (!devpriv) - return; - - mutex_lock(&glb_mutex); - down(&devpriv->limit_sem); - - dev->private = NULL; - - usb_set_intfdata(devpriv->intf, NULL); - - usb_kill_anchored_urbs(&devpriv->rx_anchor); - usb_kill_anchored_urbs(&devpriv->tx_anchor); - - kfree(devpriv->usb_rx_buf); - kfree(devpriv->usb_tx_buf); - - up(&devpriv->limit_sem); - - /* - * Since 'devpriv' points to an element of the static vmb array - * we can't kfree it. Instead memset it to all '0' so subsequent - * usb probes don't find any garbage in it. - */ - memset(devpriv, 0x00, sizeof(*devpriv)); - - mutex_unlock(&glb_mutex); -} - -static struct comedi_driver vmk80xx_driver = { - .module = THIS_MODULE, - .driver_name = "vmk80xx", - .auto_attach = vmk80xx_auto_attach, - .detach = vmk80xx_detach, -}; - -static int vmk80xx_usb_probe(struct usb_interface *intf, - const struct usb_device_id *id) -{ const struct vmk80xx_board *boardinfo; struct vmk80xx_private *devpriv; int ret; - int i; - - mutex_lock(&glb_mutex); - for (i = 0; i < VMK80XX_MAX_BOARDS; i++) - if (!vmb[i].intf) - break; + boardinfo = &vmk80xx_boardinfo[context]; + dev->board_ptr = boardinfo; + dev->board_name = boardinfo->name; - if (i == VMK80XX_MAX_BOARDS) { - ret = -EMFILE; - goto fail; - } + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; - devpriv = &vmb[i]; + devpriv->usb = interface_to_usbdev(intf); + devpriv->intf = intf; + devpriv->board = boardinfo; - ret = vmk80xx_find_usb_endpoints(devpriv, intf); + ret = vmk80xx_find_usb_endpoints(dev); if (ret) - goto error; + return ret; - ret = vmk80xx_alloc_usb_buffers(devpriv); + ret = vmk80xx_alloc_usb_buffers(dev); if (ret) - goto error; - - devpriv->usb = interface_to_usbdev(intf); - devpriv->intf = intf; + return ret; sema_init(&devpriv->limit_sem, 8); init_waitqueue_head(&devpriv->read_wait); @@ -1381,9 +1313,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, usb_set_intfdata(intf, devpriv); - boardinfo = &vmk80xx_boardinfo[id->driver_info]; - devpriv->board = boardinfo; - if (boardinfo->model == VMK8061_MODEL) { vmk80xx_read_eeprom(devpriv, IC3_VERSION); dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers); @@ -1399,22 +1328,40 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, if (boardinfo->model == VMK8055_MODEL) vmk80xx_reset_device(devpriv); - mutex_unlock(&glb_mutex); + return vmk80xx_attach_common(dev); +} - comedi_usb_auto_config(intf, &vmk80xx_driver, id->driver_info); +static void vmk80xx_detach(struct comedi_device *dev) +{ + struct vmk80xx_private *devpriv = dev->private; - return 0; + if (!devpriv) + return; -error: - /* - * Since 'devpriv' points to an element of the static vmb array - * we can't kfree it. Instead memset it to all '0' so subsequent - * usb probes don't find any garbage in it. - */ - memset(devpriv, 0x00, sizeof(*devpriv)); -fail: - mutex_unlock(&glb_mutex); - return ret; + down(&devpriv->limit_sem); + + usb_set_intfdata(devpriv->intf, NULL); + + usb_kill_anchored_urbs(&devpriv->rx_anchor); + usb_kill_anchored_urbs(&devpriv->tx_anchor); + + kfree(devpriv->usb_rx_buf); + kfree(devpriv->usb_tx_buf); + + up(&devpriv->limit_sem); +} + +static struct comedi_driver vmk80xx_driver = { + .module = THIS_MODULE, + .driver_name = "vmk80xx", + .auto_attach = vmk80xx_auto_attach, + .detach = vmk80xx_detach, +}; + +static int vmk80xx_usb_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return comedi_usb_auto_config(intf, &vmk80xx_driver, id->driver_info); } static const struct usb_device_id vmk80xx_usb_id_table[] = { -- cgit v0.10.2 From 52d895d3672dd58c0067c2efca4b825e4d733d0c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:24:24 -0700 Subject: staging: comedi: vmk80xx: remove need for boardinfo in private_data The only information in the boardinfo that is used outside of the attach of the driver is the 'model' of the device. Remove the 'board' pointer from the private data and replace it with the 'model' enum and just copy that information over during the attach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 6ed70ee..80864a7 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -202,7 +202,6 @@ struct vmk80xx_private { struct usb_endpoint_descriptor *ep_tx; struct usb_anchor rx_anchor; struct usb_anchor tx_anchor; - const struct vmk80xx_board *board; struct firmware_version fw; struct semaphore limit_sem; wait_queue_head_t read_wait; @@ -210,6 +209,7 @@ struct vmk80xx_private { unsigned char *usb_rx_buf; unsigned char *usb_tx_buf; unsigned long flags; + enum vmk80xx_model model; }; static void vmk80xx_tx_callback(struct urb *urb) @@ -423,7 +423,6 @@ static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv) static int vmk80xx_read_packet(struct vmk80xx_private *devpriv) { - const struct vmk80xx_board *boardinfo = devpriv->board; unsigned long *flags = &devpriv->flags; struct urb *urb; int retval; @@ -437,7 +436,7 @@ static int vmk80xx_read_packet(struct vmk80xx_private *devpriv) !test_bit(TRANS_IN_BUSY, flags))) return -ERESTART; - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { vmk80xx_do_bulk_msg(devpriv); return 0; @@ -470,7 +469,6 @@ exit: static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd) { - const struct vmk80xx_board *boardinfo = devpriv->board; unsigned long *flags = &devpriv->flags; struct urb *urb; int retval; @@ -483,7 +481,7 @@ static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd) !test_bit(TRANS_OUT_BUSY, flags))) return -ERESTART; - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { devpriv->usb_tx_buf[0] = cmd; vmk80xx_do_bulk_msg(devpriv); @@ -539,7 +537,6 @@ static int vmk80xx_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; int chan; int reg[2]; @@ -552,7 +549,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *dev, down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (boardinfo->model) { + switch (devpriv->model) { case VMK8055_MODEL: if (!chan) reg[0] = VMK8055_AI1_REG; @@ -572,7 +569,7 @@ static int vmk80xx_ai_rinsn(struct comedi_device *dev, if (vmk80xx_read_packet(devpriv)) break; - if (boardinfo->model == VMK8055_MODEL) { + if (devpriv->model == VMK8055_MODEL) { data[n] = devpriv->usb_rx_buf[reg[0]]; continue; } @@ -591,7 +588,6 @@ static int vmk80xx_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; int chan; int cmd; @@ -605,7 +601,7 @@ static int vmk80xx_ao_winsn(struct comedi_device *dev, down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (boardinfo->model) { + switch (devpriv->model) { case VMK8055_MODEL: cmd = VMK8055_CMD_WRT_AD; if (!chan) @@ -668,7 +664,6 @@ static int vmk80xx_di_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf; int reg; @@ -682,7 +677,7 @@ static int vmk80xx_di_bits(struct comedi_device *dev, rx_buf = devpriv->usb_rx_buf; - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { @@ -692,7 +687,7 @@ static int vmk80xx_di_bits(struct comedi_device *dev, retval = vmk80xx_read_packet(devpriv); if (!retval) { - if (boardinfo->model == VMK8055_MODEL) + if (devpriv->model == VMK8055_MODEL) data[1] = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); @@ -711,7 +706,6 @@ static int vmk80xx_di_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; int chan; unsigned char *rx_buf; @@ -728,7 +722,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *dev, rx_buf = devpriv->usb_rx_buf; - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { reg = VMK8061_DI_REG; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI; } else { @@ -738,7 +732,7 @@ static int vmk80xx_di_rinsn(struct comedi_device *dev, if (vmk80xx_read_packet(devpriv)) break; - if (boardinfo->model == VMK8055_MODEL) + if (devpriv->model == VMK8055_MODEL) inp = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); @@ -757,7 +751,6 @@ static int vmk80xx_do_winsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; int chan; unsigned char *tx_buf; @@ -775,7 +768,7 @@ static int vmk80xx_do_winsn(struct comedi_device *dev, tx_buf = devpriv->usb_tx_buf; for (n = 0; n < insn->n; n++) { - if (boardinfo->model == VMK8055_MODEL) { + if (devpriv->model == VMK8055_MODEL) { reg = VMK8055_DO_REG; cmd = VMK8055_CMD_WRT_AD; if (data[n] == 1) @@ -838,7 +831,6 @@ static int vmk80xx_do_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf, *tx_buf; int dir, reg, cmd; @@ -849,7 +841,7 @@ static int vmk80xx_do_bits(struct comedi_device *dev, if (data[0]) dir |= DIR_OUT; - if (boardinfo->model == VMK8061_MODEL) + if (devpriv->model == VMK8061_MODEL) dir |= DIR_IN; retval = rudimentary_check(devpriv, dir); @@ -862,7 +854,7 @@ static int vmk80xx_do_bits(struct comedi_device *dev, tx_buf = devpriv->usb_tx_buf; if (data[0]) { - if (boardinfo->model == VMK8055_MODEL) { + if (devpriv->model == VMK8055_MODEL) { reg = VMK8055_DO_REG; cmd = VMK8055_CMD_WRT_AD; } else { /* VMK8061_MODEL */ @@ -879,7 +871,7 @@ static int vmk80xx_do_bits(struct comedi_device *dev, goto out; } - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { reg = VMK8061_DO_REG; tx_buf[0] = VMK8061_CMD_RD_DO; @@ -904,7 +896,6 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; int chan; int reg[2]; @@ -917,7 +908,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *dev, down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (boardinfo->model) { + switch (devpriv->model) { case VMK8055_MODEL: if (!chan) reg[0] = VMK8055_CNT1_REG; @@ -936,7 +927,7 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *dev, if (vmk80xx_read_packet(devpriv)) break; - if (boardinfo->model == VMK8055_MODEL) + if (devpriv->model == VMK8055_MODEL) data[n] = devpriv->usb_rx_buf[reg[0]]; else /* VMK8061_MODEL */ data[n] = devpriv->usb_rx_buf[reg[0] * (chan + 1) + 1] @@ -952,7 +943,6 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; unsigned int insn_cmd; int chan; @@ -972,7 +962,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *dev, chan = CR_CHAN(insn->chanspec); - if (boardinfo->model == VMK8055_MODEL) { + if (devpriv->model == VMK8055_MODEL) { if (!chan) { cmd = VMK8055_CMD_RST_CNT1; reg = VMK8055_CNT1_REG; @@ -1192,7 +1182,7 @@ static int vmk80xx_attach_common(struct comedi_device *dev) down(&devpriv->limit_sem); - if (boardinfo->model == VMK8055_MODEL) + if (devpriv->model == VMK8055_MODEL) n_subd = 5; else n_subd = 6; @@ -1219,7 +1209,7 @@ static int vmk80xx_attach_common(struct comedi_device *dev) s->maxdata = 0x00ff; s->range_table = boardinfo->range; s->insn_write = vmk80xx_ao_winsn; - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_ao_rinsn; } @@ -1241,7 +1231,7 @@ static int vmk80xx_attach_common(struct comedi_device *dev) s->maxdata = 1; s->insn_write = vmk80xx_do_winsn; s->insn_bits = vmk80xx_do_bits; - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_do_rinsn; } @@ -1253,14 +1243,14 @@ static int vmk80xx_attach_common(struct comedi_device *dev) s->n_chan = 2; s->insn_read = vmk80xx_cnt_rinsn; s->insn_config = vmk80xx_cnt_cinsn; - if (boardinfo->model == VMK8055_MODEL) { + if (devpriv->model == VMK8055_MODEL) { s->subdev_flags |= SDF_WRITEABLE; s->maxdata = (1 << boardinfo->cnt_bits) - 1; s->insn_write = vmk80xx_cnt_winsn; } /* PWM subdevice */ - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { s = &dev->subdevices[5]; s->type = COMEDI_SUBD_PWM; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; @@ -1294,7 +1284,7 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, devpriv->usb = interface_to_usbdev(intf); devpriv->intf = intf; - devpriv->board = boardinfo; + devpriv->model = boardinfo->model; ret = vmk80xx_find_usb_endpoints(dev); if (ret) @@ -1313,7 +1303,7 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, usb_set_intfdata(intf, devpriv); - if (boardinfo->model == VMK8061_MODEL) { + if (devpriv->model == VMK8061_MODEL) { vmk80xx_read_eeprom(devpriv, IC3_VERSION); dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers); @@ -1325,7 +1315,7 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, } } - if (boardinfo->model == VMK8055_MODEL) + if (devpriv->model == VMK8055_MODEL) vmk80xx_reset_device(devpriv); return vmk80xx_attach_common(dev); -- cgit v0.10.2 From 658cd3ac2e31d637f50402611976bdaab74c28f8 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:24:45 -0700 Subject: staging: comedi: vmk80xx: cleanup analog input subdevice init Change the 'ai_bits' in the boardinfo to 'ai_maxdata' so that the calculation of s->maxdata can be removed. Change the types for the analog input boardinfo to match the comedi_subdevice types they are set to. Rename the (*insn_read) function for the analog input subdevice from vmk80xx_ai_rinsn to vmk80xx_ai_insn_read to make grepping easier. For aesthetic reasons, add some whitespace to the subdevice init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 80864a7..9eae0a0 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -159,8 +159,8 @@ struct vmk80xx_board { const char *name; enum vmk80xx_model model; const struct comedi_lrange *range; - __u8 ai_chans; - __le16 ai_bits; + int ai_nchans; + unsigned int ai_maxdata; __u8 ao_chans; __u8 di_chans; __le16 cnt_bits; @@ -173,8 +173,8 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .name = "K8055 (VM110)", .model = VMK8055_MODEL, .range = &vmk8055_range, - .ai_chans = 2, - .ai_bits = 8, + .ai_nchans = 2, + .ai_maxdata = 0x00ff, .ao_chans = 2, .di_chans = 6, .cnt_bits = 16, @@ -185,8 +185,8 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .name = "K8061 (VM140)", .model = VMK8061_MODEL, .range = &vmk8061_range, - .ai_chans = 8, - .ai_bits = 10, + .ai_nchans = 8, + .ai_maxdata = 0x03ff, .ao_chans = 8, .di_chans = 8, .cnt_bits = 0, @@ -533,9 +533,10 @@ static int rudimentary_check(struct vmk80xx_private *devpriv, int dir) return 0; } -static int vmk80xx_ai_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -1194,12 +1195,12 @@ static int vmk80xx_attach_common(struct comedi_device *dev) /* Analog input subdevice */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = boardinfo->ai_chans; - s->maxdata = (1 << boardinfo->ai_bits) - 1; - s->range_table = boardinfo->range; - s->insn_read = vmk80xx_ai_rinsn; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = boardinfo->ai_nchans; + s->maxdata = boardinfo->ai_maxdata; + s->range_table = boardinfo->range; + s->insn_read = vmk80xx_ai_insn_read; /* Analog output subdevice */ s = &dev->subdevices[1]; -- cgit v0.10.2 From 8b3ec9f155cf564e0f2320b6a895d8684f2874fe Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:25:07 -0700 Subject: staging: comedi: vmk80xx: cleanup analog output subdevice init Change the type for the analog output 'ao_chans' boardinfo to match the comedi_subdevice type it is set to. For aesthetic reasons, rename the variable also. Rename the (*insn_write) and (*insn_read) functions for the analog output subdevice to make grepping easier. For aesthetic reasons, add some whitespace to the subdevice init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 9eae0a0..be65da1 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -161,7 +161,7 @@ struct vmk80xx_board { const struct comedi_lrange *range; int ai_nchans; unsigned int ai_maxdata; - __u8 ao_chans; + int ao_nchans; __u8 di_chans; __le16 cnt_bits; __u8 pwm_chans; @@ -175,7 +175,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .range = &vmk8055_range, .ai_nchans = 2, .ai_maxdata = 0x00ff, - .ao_chans = 2, + .ao_nchans = 2, .di_chans = 6, .cnt_bits = 16, .pwm_chans = 0, @@ -187,7 +187,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .range = &vmk8061_range, .ai_nchans = 8, .ai_maxdata = 0x03ff, - .ao_chans = 8, + .ao_nchans = 8, .di_chans = 8, .cnt_bits = 0, .pwm_chans = 1, @@ -585,9 +585,10 @@ static int vmk80xx_ai_insn_read(struct comedi_device *dev, return n; } -static int vmk80xx_ao_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -629,9 +630,10 @@ static int vmk80xx_ao_winsn(struct comedi_device *dev, return n; } -static int vmk80xx_ao_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_ao_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -1204,15 +1206,15 @@ static int vmk80xx_attach_common(struct comedi_device *dev) /* Analog output subdevice */ s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = boardinfo->ao_chans; - s->maxdata = 0x00ff; - s->range_table = boardinfo->range; - s->insn_write = vmk80xx_ao_winsn; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; + s->n_chan = boardinfo->ao_nchans; + s->maxdata = 0x00ff; + s->range_table = boardinfo->range; + s->insn_write = vmk80xx_ao_insn_write; if (devpriv->model == VMK8061_MODEL) { - s->subdev_flags |= SDF_READABLE; - s->insn_read = vmk80xx_ao_rinsn; + s->subdev_flags |= SDF_READABLE; + s->insn_read = vmk80xx_ao_insn_read; } /* Digital input subdevice */ -- cgit v0.10.2 From 268e5148aac3108ad1347f9ecf637be3d83e525e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:25:28 -0700 Subject: staging: comedi: vmk80xx: cleanup digital input subdevice init Change the type for the digital input 'di_chans' boardinfo to match the comedi_subdevice type it is set to. For aesthetic reasons, rename the variable also. Remove the SDF_GROUND flag from s->subdev_flags. This flag only has meaning for analog subdevices. Add the missing s->range_table for the subdevice. Rename the (*insn_read) and (*insn_bits) functions for the digital input subdevice to make grepping easier. For aesthetic reasons, add some whitespace to the subdevice init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index be65da1..d34e9ad 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -162,7 +162,7 @@ struct vmk80xx_board { int ai_nchans; unsigned int ai_maxdata; int ao_nchans; - __u8 di_chans; + int di_nchans; __le16 cnt_bits; __u8 pwm_chans; __le16 pwm_bits; @@ -176,7 +176,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ai_nchans = 2, .ai_maxdata = 0x00ff, .ao_nchans = 2, - .di_chans = 6, + .di_nchans = 6, .cnt_bits = 16, .pwm_chans = 0, .pwm_bits = 0, @@ -188,7 +188,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ai_nchans = 8, .ai_maxdata = 0x03ff, .ao_nchans = 8, - .di_chans = 8, + .di_nchans = 8, .cnt_bits = 0, .pwm_chans = 1, .pwm_bits = 10, @@ -663,9 +663,10 @@ static int vmk80xx_ao_insn_read(struct comedi_device *dev, return n; } -static int vmk80xx_di_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf; @@ -705,9 +706,10 @@ static int vmk80xx_di_bits(struct comedi_device *dev, return retval; } -static int vmk80xx_di_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_di_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -1219,12 +1221,13 @@ static int vmk80xx_attach_common(struct comedi_device *dev) /* Digital input subdevice */ s = &dev->subdevices[2]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = boardinfo->di_chans; - s->maxdata = 1; - s->insn_read = vmk80xx_di_rinsn; - s->insn_bits = vmk80xx_di_bits; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = boardinfo->di_nchans; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_read = vmk80xx_di_insn_read; + s->insn_bits = vmk80xx_di_insn_bits; /* Digital output subdevice */ s = &dev->subdevices[3]; -- cgit v0.10.2 From b639e09608f0103761751d707e837a7ca01d82a7 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:25:49 -0700 Subject: staging: comedi: vmk80xx: cleanup digital input subdevice init Remove the SDF_GROUND flag from s->subdev_flags. This flag only has meaning for analog subdevices. Add the missing s->range_table for the subdevice. Rename the (*insn_write), (*insn_bits), and (*insn_read) functions for the digital input subdevice to make grepping easier. For aesthetic reasons, add some whitespace to the subdevice init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index d34e9ad..4d51f6c 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -752,9 +752,10 @@ static int vmk80xx_di_insn_read(struct comedi_device *dev, return n; } -static int vmk80xx_do_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_do_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -800,9 +801,10 @@ static int vmk80xx_do_winsn(struct comedi_device *dev, return n; } -static int vmk80xx_do_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_do_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -832,9 +834,10 @@ static int vmk80xx_do_rinsn(struct comedi_device *dev, return n; } -static int vmk80xx_do_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf, *tx_buf; @@ -1231,15 +1234,16 @@ static int vmk80xx_attach_common(struct comedi_device *dev) /* Digital output subdevice */ s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; - s->n_chan = 8; - s->maxdata = 1; - s->insn_write = vmk80xx_do_winsn; - s->insn_bits = vmk80xx_do_bits; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_write = vmk80xx_do_insn_write; + s->insn_bits = vmk80xx_do_insn_bits; if (devpriv->model == VMK8061_MODEL) { - s->subdev_flags |= SDF_READABLE; - s->insn_read = vmk80xx_do_rinsn; + s->subdev_flags |= SDF_READABLE; + s->insn_read = vmk80xx_do_insn_read; } /* Counter subdevice */ -- cgit v0.10.2 From 75a45d924dd33882caf80d3a78dd96c370a6580b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:27:37 -0700 Subject: staging: comedi: vmk80xx: cleanup counter subdevice init Change the 'cnt_bits' in the boardinfo to 'cnt_maxdata' so that the calculation of s->maxdata can be removed. Also, change the type to match the comedi_subdevice type. Add a comment about the '0' value for DEVICE_VMK8061. The s->maxdata should always be set for the subdevice. Move it out of the conditional. Rename the (*insn_read), (*insn_config_, and (*insn_write) functions for the counter subdevice to make grepping easier. For aesthetic reasons, add some whitespace to the subdevice init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 4d51f6c..26a9a96 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -163,7 +163,7 @@ struct vmk80xx_board { unsigned int ai_maxdata; int ao_nchans; int di_nchans; - __le16 cnt_bits; + unsigned int cnt_maxdata; __u8 pwm_chans; __le16 pwm_bits; }; @@ -177,7 +177,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ai_maxdata = 0x00ff, .ao_nchans = 2, .di_nchans = 6, - .cnt_bits = 16, + .cnt_maxdata = 0xffff, .pwm_chans = 0, .pwm_bits = 0, }, @@ -189,7 +189,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ai_maxdata = 0x03ff, .ao_nchans = 8, .di_nchans = 8, - .cnt_bits = 0, + .cnt_maxdata = 0, /* unknown, device is not writeable */ .pwm_chans = 1, .pwm_bits = 10, }, @@ -900,9 +900,10 @@ out: return retval; } -static int vmk80xx_cnt_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_cnt_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; int chan; @@ -947,9 +948,10 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *dev, return n; } -static int vmk80xx_cnt_cinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_cnt_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; unsigned int insn_cmd; @@ -993,9 +995,10 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *dev, return n; } -static int vmk80xx_cnt_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_cnt_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; unsigned long debtime; @@ -1248,15 +1251,15 @@ static int vmk80xx_attach_common(struct comedi_device *dev) /* Counter subdevice */ s = &dev->subdevices[4]; - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE; - s->n_chan = 2; - s->insn_read = vmk80xx_cnt_rinsn; - s->insn_config = vmk80xx_cnt_cinsn; + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE; + s->n_chan = 2; + s->maxdata = boardinfo->cnt_maxdata; + s->insn_read = vmk80xx_cnt_insn_read; + s->insn_config = vmk80xx_cnt_insn_config; if (devpriv->model == VMK8055_MODEL) { - s->subdev_flags |= SDF_WRITEABLE; - s->maxdata = (1 << boardinfo->cnt_bits) - 1; - s->insn_write = vmk80xx_cnt_winsn; + s->subdev_flags |= SDF_WRITEABLE; + s->insn_write = vmk80xx_cnt_insn_write; } /* PWM subdevice */ -- cgit v0.10.2 From 9a23a7481ea860096acbc032dcb1159b8864fbf5 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:27:56 -0700 Subject: staging: comedi: vmk80xx: cleanup pwm subdevice init Change the 'pwm_bits' in the boardinfo to 'pwm_maxdata' so that the calculation of s->maxdata can be removed. Also, change the type to match the comedi_subdevice type. For aesthetic reasons, rename the 'pwm_chans' boardinfo and change its type also. Remove the '0' values in the boardinfo. Rename the (*insn_read) and (*insn_write) functions for the pwm subdevice to make grepping easier. For aesthetic reasons, add some whitespace to the subdevice init. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 26a9a96..00f5784 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -164,8 +164,8 @@ struct vmk80xx_board { int ao_nchans; int di_nchans; unsigned int cnt_maxdata; - __u8 pwm_chans; - __le16 pwm_bits; + int pwm_nchans; + unsigned int pwm_maxdata; }; static const struct vmk80xx_board vmk80xx_boardinfo[] = { @@ -178,8 +178,6 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ao_nchans = 2, .di_nchans = 6, .cnt_maxdata = 0xffff, - .pwm_chans = 0, - .pwm_bits = 0, }, [DEVICE_VMK8061] = { .name = "K8061 (VM140)", @@ -190,8 +188,8 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { .ao_nchans = 8, .di_nchans = 8, .cnt_maxdata = 0, /* unknown, device is not writeable */ - .pwm_chans = 1, - .pwm_bits = 10, + .pwm_nchans = 1, + .pwm_maxdata = 0x03ff, }, }; @@ -1043,9 +1041,10 @@ static int vmk80xx_cnt_insn_write(struct comedi_device *dev, return n; } -static int vmk80xx_pwm_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_pwm_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; unsigned char *tx_buf; @@ -1079,9 +1078,10 @@ static int vmk80xx_pwm_rinsn(struct comedi_device *dev, return n; } -static int vmk80xx_pwm_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int vmk80xx_pwm_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct vmk80xx_private *devpriv = dev->private; unsigned char *tx_buf; @@ -1265,12 +1265,12 @@ static int vmk80xx_attach_common(struct comedi_device *dev) /* PWM subdevice */ if (devpriv->model == VMK8061_MODEL) { s = &dev->subdevices[5]; - s->type = COMEDI_SUBD_PWM; - s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; - s->n_chan = boardinfo->pwm_chans; - s->maxdata = (1 << boardinfo->pwm_bits) - 1; - s->insn_read = vmk80xx_pwm_rinsn; - s->insn_write = vmk80xx_pwm_winsn; + s->type = COMEDI_SUBD_PWM; + s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; + s->n_chan = boardinfo->pwm_nchans; + s->maxdata = boardinfo->pwm_maxdata; + s->insn_read = vmk80xx_pwm_insn_read; + s->insn_write = vmk80xx_pwm_insn_write; } up(&devpriv->limit_sem); -- cgit v0.10.2 From 03754bdbb10a8045b2c18cfec8f2272d7df004c6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:28:27 -0700 Subject: staging: comedi: vmk80xx: remove digital output (*insn_read) The comedi core can use the (*insn_bits) function to emulate the (*insn_read) function. The digital output (*insn_bits) function properly handles the VMK8061_MODEL to read the digital output states before returning. Remove the unnecessary (*insn_read) function. It's also not necessary to set the SDF_READABLE flag so remove the entire conditional in the attach. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 00f5784..4f32bad 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -799,39 +799,6 @@ static int vmk80xx_do_insn_write(struct comedi_device *dev, return n; } -static int vmk80xx_do_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct vmk80xx_private *devpriv = dev->private; - int chan; - int reg; - int n; - - n = rudimentary_check(devpriv, DIR_IN); - if (n) - return n; - - down(&devpriv->limit_sem); - chan = CR_CHAN(insn->chanspec); - - reg = VMK8061_DO_REG; - - devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DO; - - for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(devpriv)) - break; - - data[n] = (devpriv->usb_rx_buf[reg] >> chan) & 1; - } - - up(&devpriv->limit_sem); - - return n; -} - static int vmk80xx_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -1244,10 +1211,6 @@ static int vmk80xx_attach_common(struct comedi_device *dev) s->range_table = &range_digital; s->insn_write = vmk80xx_do_insn_write; s->insn_bits = vmk80xx_do_insn_bits; - if (devpriv->model == VMK8061_MODEL) { - s->subdev_flags |= SDF_READABLE; - s->insn_read = vmk80xx_do_insn_read; - } /* Counter subdevice */ s = &dev->subdevices[4]; -- cgit v0.10.2 From a348b72eae946dd5d2cc9e00c4344c7814979eb0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:28:51 -0700 Subject: staging: comedi: vmk80xx: remove digital output (*insn_write) The comedi core can use the (*insn_bits) function to emulate the (*insn_write) function. Remove the unnecessary (*insn_read) function. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 4f32bad..ba4fd52 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -750,55 +750,6 @@ static int vmk80xx_di_insn_read(struct comedi_device *dev, return n; } -static int vmk80xx_do_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct vmk80xx_private *devpriv = dev->private; - int chan; - unsigned char *tx_buf; - int reg; - int cmd; - int n; - - n = rudimentary_check(devpriv, DIR_OUT); - if (n) - return n; - - down(&devpriv->limit_sem); - chan = CR_CHAN(insn->chanspec); - - tx_buf = devpriv->usb_tx_buf; - - for (n = 0; n < insn->n; n++) { - if (devpriv->model == VMK8055_MODEL) { - reg = VMK8055_DO_REG; - cmd = VMK8055_CMD_WRT_AD; - if (data[n] == 1) - tx_buf[reg] |= (1 << chan); - else - tx_buf[reg] ^= (1 << chan); - } else { /* VMK8061_MODEL */ - reg = VMK8061_DO_REG; - if (data[n] == 1) { - cmd = VMK8061_CMD_SET_DO; - tx_buf[reg] = 1 << chan; - } else { - cmd = VMK8061_CMD_CLR_DO; - tx_buf[reg] = 0xff - (1 << chan); - } - } - - if (vmk80xx_write_packet(devpriv, cmd)) - break; - } - - up(&devpriv->limit_sem); - - return n; -} - static int vmk80xx_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -1209,7 +1160,6 @@ static int vmk80xx_attach_common(struct comedi_device *dev) s->n_chan = 8; s->maxdata = 1; s->range_table = &range_digital; - s->insn_write = vmk80xx_do_insn_write; s->insn_bits = vmk80xx_do_insn_bits; /* Counter subdevice */ -- cgit v0.10.2 From 0f97889c19bfedf102ec6e1fdd7f99a8342d4f22 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:29:13 -0700 Subject: staging: comedi: vmk80xx: remove digital input (*insn_read) The comedi core can use the (*insn_bits) function to emulate the (*insn_read) function. Remove the unnecessary (*insn_read) function. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index ba4fd52..d728c05 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -704,52 +704,6 @@ static int vmk80xx_di_insn_bits(struct comedi_device *dev, return retval; } -static int vmk80xx_di_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct vmk80xx_private *devpriv = dev->private; - int chan; - unsigned char *rx_buf; - int reg; - int inp; - int n; - - n = rudimentary_check(devpriv, DIR_IN); - if (n) - return n; - - down(&devpriv->limit_sem); - chan = CR_CHAN(insn->chanspec); - - rx_buf = devpriv->usb_rx_buf; - - if (devpriv->model == VMK8061_MODEL) { - reg = VMK8061_DI_REG; - devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI; - } else { - reg = VMK8055_DI_REG; - } - for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(devpriv)) - break; - - if (devpriv->model == VMK8055_MODEL) - inp = (((rx_buf[reg] >> 4) & 0x03) | - ((rx_buf[reg] << 2) & 0x04) | - ((rx_buf[reg] >> 3) & 0x18)); - else - inp = rx_buf[reg]; - - data[n] = (inp >> chan) & 1; - } - - up(&devpriv->limit_sem); - - return n; -} - static int vmk80xx_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -1150,7 +1104,6 @@ static int vmk80xx_attach_common(struct comedi_device *dev) s->n_chan = boardinfo->di_nchans; s->maxdata = 1; s->range_table = &range_digital; - s->insn_read = vmk80xx_di_insn_read; s->insn_bits = vmk80xx_di_insn_bits; /* Digital output subdevice */ -- cgit v0.10.2 From 6f25a527eac10d9ba277a2de7a2a9d3e92c08a52 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:29:35 -0700 Subject: staging: comedi: vmk80xx: remove unused #define This define is no longer used by the driver. Remove it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index d728c05..5ba9632 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -113,8 +113,6 @@ enum { #define VMK8061_CMD_RD_AO 0x0f #define VMK8061_CMD_RD_PWM 0x10 -#define VMK80XX_MAX_BOARDS COMEDI_NUM_BOARD_MINORS - #define TRANS_OUT_BUSY 1 #define TRANS_IN_BUSY 2 #define TRANS_IN_RUNNING 3 -- cgit v0.10.2 From 4c56a2b63979ec1992fddc087c4660fde7d8e6c0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:30:01 -0700 Subject: staging: comedi: vmk80xx: remove CONFIG_COMEDI_DEBUG code If CONFIG_COMEDI_DEBUG is defined a macro is enabled to output some printk(KERN_REBUG ...) messages. These are just added noise. Remove it. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 5ba9632..8ec5985 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -123,18 +123,6 @@ enum { #define URB_RCV_FLAG (1 << 0) #define URB_SND_FLAG (1 << 1) -#ifdef CONFIG_COMEDI_DEBUG -static int dbgcm = 1; -#else -static int dbgcm; -#endif - -#define dbgcm(fmt, arg...) \ -do { \ - if (dbgcm) \ - printk(KERN_DEBUG fmt, ##arg); \ -} while (0) - enum vmk80xx_model { VMK8055_MODEL, VMK8061_MODEL @@ -212,12 +200,6 @@ static void vmk80xx_tx_callback(struct urb *urb) { struct vmk80xx_private *devpriv = urb->context; unsigned long *flags = &devpriv->flags; - int stat = urb->status; - - if (stat && !(stat == -ENOENT - || stat == -ECONNRESET || stat == -ESHUTDOWN)) - dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n", - __func__, stat); if (!test_bit(TRANS_OUT_BUSY, flags)) return; @@ -241,26 +223,16 @@ static void vmk80xx_rx_callback(struct urb *urb) case -ESHUTDOWN: break; default: - dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n", - __func__, stat); - goto resubmit; - } - - goto exit; -resubmit: - if (test_bit(TRANS_IN_RUNNING, flags) && devpriv->intf) { - usb_anchor_urb(urb, &devpriv->rx_anchor); - - if (!usb_submit_urb(urb, GFP_KERNEL)) - goto exit; + /* Try to resubmit the urb */ + if (test_bit(TRANS_IN_RUNNING, flags) && devpriv->intf) { + usb_anchor_urb(urb, &devpriv->rx_anchor); - dev_err(&urb->dev->dev, - "comedi#: vmk80xx: %s - submit urb failed\n", - __func__); - - usb_unanchor_urb(urb); + if (usb_submit_urb(urb, GFP_KERNEL)) + usb_unanchor_urb(urb); + } + break; } -exit: + clear_bit(TRANS_IN_BUSY, flags); wake_up_interruptible(&devpriv->read_wait); @@ -1187,8 +1159,6 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, if (vmk80xx_check_data_link(devpriv)) { vmk80xx_read_eeprom(devpriv, IC6_VERSION); dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers); - } else { - dbgcm("comedi#: vmk80xx: no conn. to CPU\n"); } } -- cgit v0.10.2 From f45787c687adcf3c01599bf8f32667fab5271e0d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:30:21 -0700 Subject: staging: comedi: vmk80xx: cleanup the comedi_lrange tables The vmk8055_range table is a duplicate of the comedi core provided range_unipolar5 table. Use that instead. For aesthetic reasons, clean up the formating of the vmk8061_range table. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 8ec5985..23715f6 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -133,12 +133,11 @@ struct firmware_version { unsigned char ic6_vers[32]; /* CPU */ }; -static const struct comedi_lrange vmk8055_range = { - 1, {UNI_RANGE(5)} -}; - static const struct comedi_lrange vmk8061_range = { - 2, {UNI_RANGE(5), UNI_RANGE(10)} + 2, { + UNI_RANGE(5), + UNI_RANGE(10) + } }; struct vmk80xx_board { @@ -158,7 +157,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { [DEVICE_VMK8055] = { .name = "K8055 (VM110)", .model = VMK8055_MODEL, - .range = &vmk8055_range, + .range = &range_unipolar5, .ai_nchans = 2, .ai_maxdata = 0x00ff, .ao_nchans = 2, -- cgit v0.10.2 From 6dcbe00df71bd0559c32ef7e838eac1458ad24d6 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:30:48 -0700 Subject: staging: comedi: vmk80xx: remove the 'Changelog' comments git history provides a better Changelog for the driver. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 23715f6..d0ff0e7 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -38,19 +38,6 @@ Supports: - counter - pwm */ -/* -Changelog: - -0.8.81 -3- code completely rewritten (adjust driver logic) -0.8.81 -2- full support for K8061 -0.8.81 -1- fix some mistaken among others the number of - supported boards and I/O handling - -0.7.76 -4- renamed to vmk80xx -0.7.76 -3- detect K8061 (only theoretically supported) -0.7.76 -2- code completely rewritten (adjust driver logic) -0.7.76 -1- support for digital and counter subdevice -*/ #include #include -- cgit v0.10.2 From 66dbc7b1b00499285793143b44b979e26141204d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 17:31:10 -0700 Subject: staging: comedi: vmk80xx: rename vmk80xx_attach_common() In comedi drivers typically *_attach_common() is used as the 'common' part of the comedi_driver attach code for drivers that support various bus types (ISA, PCI, etc.). This driver is specific to a USB device. To avoid confusion when grepping, rename this function to something more appropriate. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index d0ff0e7..ebf2d48 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1011,7 +1011,7 @@ static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev) return 0; } -static int vmk80xx_attach_common(struct comedi_device *dev) +static int vmk80xx_init_subdevices(struct comedi_device *dev) { const struct vmk80xx_board *boardinfo = comedi_board(dev); struct vmk80xx_private *devpriv = dev->private; @@ -1151,7 +1151,7 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, if (devpriv->model == VMK8055_MODEL) vmk80xx_reset_device(devpriv); - return vmk80xx_attach_common(dev); + return vmk80xx_init_subdevices(dev); } static void vmk80xx_detach(struct comedi_device *dev) -- cgit v0.10.2 From 573a964882065f9b2cb71db8a225ba067b4b5b7a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 18:15:20 -0700 Subject: staging: comedi: ni_daq_dio24: use comedi_pcmcia_{enable,disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. This driver does not use interrupts and is not an audio device, remove CONF_ENABLE_IRQ and CONF_AUTO_AUDIO from the link->config_flags. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 53fd4d0..edfbfb3 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -45,15 +45,6 @@ the PCMCIA interface. #include "8255.h" -static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int dio24_auto_attach(struct comedi_device *dev, unsigned long context) { @@ -63,15 +54,8 @@ static int dio24_auto_attach(struct comedi_device *dev, dev->board_name = dev->driver->driver_name; - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | - CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL); - if (ret) - return ret; - - ret = pcmcia_enable_device(link); - if (ret) + link->config_flags |= CONF_AUTO_SET_IO; + ret = comedi_pcmcia_enable(dev); return ret; dev->iobase = link->resource[0]->start; @@ -90,12 +74,9 @@ static int dio24_auto_attach(struct comedi_device *dev, static void dio24_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - if (dev->subdevices) subdev_8255_cleanup(dev, &dev->subdevices[0]); - if (dev->iobase) - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver driver_dio24 = { -- cgit v0.10.2 From 4f60f6b69c7741fe97e40f4d5210968162f8b7ad Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 18:15:42 -0700 Subject: staging: comedi: ni_labpc_cs: use comedi_pcmcia_{enable,disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. This driver is not an audio device, remove CONF_AUTO_AUDIO from the link->config_flags. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index d239775..1c55de3 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -87,15 +87,6 @@ static const struct labpc_board_struct labpc_cs_boards[] = { }, }; -static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int labpc_auto_attach(struct comedi_device *dev, unsigned long context) { @@ -106,21 +97,16 @@ static int labpc_auto_attach(struct comedi_device *dev, /* The ni_labpc driver needs the board_ptr */ dev->board_ptr = &labpc_cs_boards[0]; - link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ | - CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, labpc_pcmcia_config_loop, NULL); + link->config_flags |= CONF_AUTO_SET_IO | + CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ; + ret = comedi_pcmcia_enable(dev); if (ret) return ret; + dev->iobase = link->resource[0]->start; if (!link->irq) return -EINVAL; - ret = pcmcia_enable_device(link); - if (ret) - return ret; - dev->iobase = link->resource[0]->start; - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); if (!devpriv) return -ENOMEM; @@ -131,11 +117,8 @@ static int labpc_auto_attach(struct comedi_device *dev, static void labpc_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - labpc_common_detach(dev); - if (dev->iobase) - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver driver_labpc_cs = { -- cgit v0.10.2 From a3ac95195b020a0a8fa2a9b0649145324ba64c83 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 18:16:07 -0700 Subject: staging: comedi: comedi_pcmcia: allow drivers to use a custom conf_check() Allow comedi pcmcia drivers to use a custom conf_check() when calling comedi_pcmcia_enable() to enable the pcmcia device. If a conf_check() is not passed the internal comedi_pcmcia_conf_check() will be used. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c index 925f128..453ff3b 100644 --- a/drivers/staging/comedi/comedi_pcmcia.c +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -49,12 +49,14 @@ static int comedi_pcmcia_conf_check(struct pcmcia_device *link, /** * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device. * @dev: comedi_device struct + * @conf_check: optional callback to check the pcmcia_device configuration * * The comedi PCMCIA driver needs to set the link->config_flags, as * appropriate for that driver, before calling this function in order * to allow pcmcia_loop_config() to do its internal autoconfiguration. */ -int comedi_pcmcia_enable(struct comedi_device *dev) +int comedi_pcmcia_enable(struct comedi_device *dev, + int (*conf_check)(struct pcmcia_device *, void *)) { struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); int ret; @@ -62,7 +64,10 @@ int comedi_pcmcia_enable(struct comedi_device *dev) if (!link) return -ENODEV; - ret = pcmcia_loop_config(link, comedi_pcmcia_conf_check, NULL); + if (!conf_check) + conf_check = comedi_pcmcia_conf_check; + + ret = pcmcia_loop_config(link, conf_check, NULL); if (ret) return ret; diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index d921cd7..f3a990b 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -440,7 +440,8 @@ struct pcmcia_device; struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *); -int comedi_pcmcia_enable(struct comedi_device *); +int comedi_pcmcia_enable(struct comedi_device *, + int (*conf_check)(struct pcmcia_device *, void *)); void comedi_pcmcia_disable(struct comedi_device *); int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *); diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index 5bbffd9..f874fff 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -413,7 +413,7 @@ static int das16cs_auto_attach(struct comedi_device *dev, dev->board_name = board->name; link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; - ret = comedi_pcmcia_enable(dev); + ret = comedi_pcmcia_enable(dev, NULL); if (ret) return ret; dev->iobase = link->resource[0]->start; diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index 818a609..cfeebe4 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -81,7 +81,7 @@ static int das08_cs_auto_attach(struct comedi_device *dev, dev->board_ptr = &das08_cs_boards[0]; link->config_flags |= CONF_AUTO_SET_IO; - ret = comedi_pcmcia_enable(dev); + ret = comedi_pcmcia_enable(dev, NULL); if (ret) return ret; iobase = link->resource[0]->start; diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index c8f4c7d..9cc6092 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -205,7 +205,7 @@ static int daq700_auto_attach(struct comedi_device *dev, dev->board_name = dev->driver->driver_name; link->config_flags |= CONF_AUTO_SET_IO; - ret = comedi_pcmcia_enable(dev); + ret = comedi_pcmcia_enable(dev, NULL); if (ret) return ret; dev->iobase = link->resource[0]->start; diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index edfbfb3..32ee22d 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -55,7 +55,7 @@ static int dio24_auto_attach(struct comedi_device *dev, dev->board_name = dev->driver->driver_name; link->config_flags |= CONF_AUTO_SET_IO; - ret = comedi_pcmcia_enable(dev); + ret = comedi_pcmcia_enable(dev, NULL); return ret; dev->iobase = link->resource[0]->start; diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 1c55de3..be7d141 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -99,7 +99,7 @@ static int labpc_auto_attach(struct comedi_device *dev, link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ; - ret = comedi_pcmcia_enable(dev); + ret = comedi_pcmcia_enable(dev, NULL); if (ret) return ret; dev->iobase = link->resource[0]->start; -- cgit v0.10.2 From 5cd8e852629fc7f1bdaacbdd32fe4139b9944f8b Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 18:16:28 -0700 Subject: staging: comedi: ni_mio_cs: use comedi_pcmcia_{enable, disable} Use the comedi_pcmcia_{enable,disable} helpers to enable/disable the PCMCIA device. This driver uses a local (*conf_check) to check the pcmcia_device configuration. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 4151aba..4da4d09 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -251,20 +251,15 @@ static int mio_cs_auto_attach(struct comedi_device *dev, dev->board_ptr = board; dev->board_name = board->name; - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); + link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; + ret = comedi_pcmcia_enable(dev, mio_pcmcia_config_loop); if (ret) return ret; + dev->iobase = link->resource[0]->start; if (!link->irq) return -EINVAL; - ret = pcmcia_enable_device(link); - if (ret) - return ret; - dev->iobase = link->resource[0]->start; - ret = request_irq(link->irq, ni_E_interrupt, NI_E_IRQ_FLAGS, dev->board_name, dev); if (ret < 0) @@ -286,13 +281,10 @@ static int mio_cs_auto_attach(struct comedi_device *dev, static void mio_cs_detach(struct comedi_device *dev) { - struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); - mio_common_detach(dev); if (dev->irq) free_irq(dev->irq, dev); - if (dev->iobase) - pcmcia_disable_device(link); + comedi_pcmcia_disable(dev); } static struct comedi_driver driver_ni_mio_cs = { -- cgit v0.10.2 From 82e9ee616a89f152f42c7051c5f9f5f0d7663652 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Feb 2013 18:16:53 -0700 Subject: staging: comedi: ni_mio_cs: use pcmcia_request_irq() Use pcmcia_request_irq() instead of request_irq() to request the shared irq for the PCMCIA device. This allows the PCMCIA core to clean up the registration in pcmcia_disable_device(). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 4da4d09..888be7b 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -149,8 +149,6 @@ static const struct ni_board_struct ni_boards[] = { #define IRQ_POLARITY 1 -#define NI_E_IRQ_FLAGS IRQF_SHARED - struct ni_private { struct pcmcia_device *link; @@ -257,12 +255,9 @@ static int mio_cs_auto_attach(struct comedi_device *dev, return ret; dev->iobase = link->resource[0]->start; - if (!link->irq) - return -EINVAL; - - ret = request_irq(link->irq, ni_E_interrupt, NI_E_IRQ_FLAGS, - dev->board_name, dev); - if (ret < 0) + link->priv = dev; + ret = pcmcia_request_irq(link, ni_E_interrupt); + if (ret) return ret; dev->irq = link->irq; @@ -282,8 +277,6 @@ static int mio_cs_auto_attach(struct comedi_device *dev, static void mio_cs_detach(struct comedi_device *dev) { mio_common_detach(dev); - if (dev->irq) - free_irq(dev->irq, dev); comedi_pcmcia_disable(dev); } -- cgit v0.10.2 From 7c3e8675f37503337d901dc254cba253326b572a Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 3 Feb 2013 00:59:00 +0000 Subject: iio: max1363: Use devm_ functions whereever possible to allocate resources Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 08e4feb..c5e46c6 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1410,8 +1410,9 @@ static int max1363_alloc_scan_masks(struct iio_dev *indio_dev) unsigned long *masks; int i; - masks = kzalloc(BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*sizeof(long)* - (st->chip_info->num_modes + 1), GFP_KERNEL); + masks = devm_kzalloc(&indio_dev->dev, + BITS_TO_LONGS(MAX1363_MAX_CHANNELS) * sizeof(long) * + (st->chip_info->num_modes + 1), GFP_KERNEL); if (!masks) return -ENOMEM; @@ -1504,7 +1505,7 @@ static int max1363_probe(struct i2c_client *client, st = iio_priv(indio_dev); - st->reg = regulator_get(&client->dev, "vcc"); + st->reg = devm_regulator_get(&client->dev, "vcc"); if (IS_ERR(st->reg)) { ret = PTR_ERR(st->reg); goto error_unregister_map; @@ -1512,7 +1513,7 @@ static int max1363_probe(struct i2c_client *client, ret = regulator_enable(st->reg); if (ret) - goto error_put_reg; + goto error_unregister_map; /* this is only used for device removal purposes */ i2c_set_clientdata(client, indio_dev); @@ -1533,15 +1534,15 @@ static int max1363_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; ret = max1363_initial_setup(st); if (ret < 0) - goto error_free_available_scan_masks; + goto error_disable_reg; ret = iio_triggered_buffer_setup(indio_dev, NULL, &max1363_trigger_handler, &max1363_buffered_setup_ops); if (ret) - goto error_free_available_scan_masks; + goto error_disable_reg; if (client->irq) { - ret = request_threaded_irq(st->client->irq, + ret = devm_request_threaded_irq(&client->dev, st->client->irq, NULL, &max1363_event_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, @@ -1554,20 +1555,14 @@ static int max1363_probe(struct i2c_client *client, ret = iio_device_register(indio_dev); if (ret < 0) - goto error_free_irq; + goto error_uninit_buffer; return 0; -error_free_irq: - if (client->irq) - free_irq(st->client->irq, indio_dev); + error_uninit_buffer: iio_triggered_buffer_cleanup(indio_dev); -error_free_available_scan_masks: - kfree(indio_dev->available_scan_masks); error_disable_reg: regulator_disable(st->reg); -error_put_reg: - regulator_put(st->reg); error_unregister_map: iio_map_array_unregister(indio_dev); error_free_device: @@ -1582,12 +1577,8 @@ static int max1363_remove(struct i2c_client *client) struct max1363_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - if (client->irq) - free_irq(st->client->irq, indio_dev); iio_triggered_buffer_cleanup(indio_dev); - kfree(indio_dev->available_scan_masks); regulator_disable(st->reg); - regulator_put(st->reg); iio_map_array_unregister(indio_dev); iio_device_free(indio_dev); -- cgit v0.10.2 From a405b00e4470b15ed062de97c4ce552d41a0a60b Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 3 Feb 2013 00:59:00 +0000 Subject: iio/adc: (max1363) Add support for external reference voltage Implement external reference voltage as regulator named "vref". Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index c5e46c6..6c1cfb7 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -163,6 +163,8 @@ struct max1363_chip_info { * @mask_low: bitmask for enabled low thresholds * @thresh_high: high threshold values * @thresh_low: low threshold values + * @vref: Reference voltage regulator + * @vref_uv: Actual (external or internal) reference voltage */ struct max1363_state { struct i2c_client *client; @@ -182,6 +184,8 @@ struct max1363_state { /* 4x unipolar first then the fours bipolar ones */ s16 thresh_high[8]; s16 thresh_low[8]; + struct regulator *vref; + u32 vref_uv; }; #define MAX1363_MODE_SINGLE(_num, _mask) { \ @@ -393,6 +397,8 @@ static int max1363_read_raw(struct iio_dev *indio_dev, { struct max1363_state *st = iio_priv(indio_dev); int ret; + unsigned long scale_uv; + switch (m) { case IIO_CHAN_INFO_RAW: ret = max1363_read_single_chan(indio_dev, chan, val, m); @@ -400,16 +406,10 @@ static int max1363_read_raw(struct iio_dev *indio_dev, return ret; return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - if ((1 << (st->chip_info->bits + 1)) > - st->chip_info->int_vref_mv) { - *val = 0; - *val2 = 500000; - return IIO_VAL_INT_PLUS_MICRO; - } else { - *val = (st->chip_info->int_vref_mv) - >> st->chip_info->bits; - return IIO_VAL_INT; - } + scale_uv = st->vref_uv >> st->chip_info->bits; + *val = scale_uv / 1000; + *val2 = (scale_uv % 1000) * 1000; + return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } @@ -1390,12 +1390,16 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = { static int max1363_initial_setup(struct max1363_state *st) { - st->setupbyte = MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD - | MAX1363_SETUP_POWER_UP_INT_REF - | MAX1363_SETUP_INT_CLOCK + st->setupbyte = MAX1363_SETUP_INT_CLOCK | MAX1363_SETUP_UNIPOLAR | MAX1363_SETUP_NORESET; + if (st->vref) + st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF; + else + st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF + | MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT; + /* Set scan mode writes the config anyway so wait until then */ st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; @@ -1491,6 +1495,7 @@ static int max1363_probe(struct i2c_client *client, int ret; struct max1363_state *st; struct iio_dev *indio_dev; + struct regulator *vref; indio_dev = iio_device_alloc(sizeof(struct max1363_state)); if (indio_dev == NULL) { @@ -1521,6 +1526,23 @@ static int max1363_probe(struct i2c_client *client, st->chip_info = &max1363_chip_info_tbl[id->driver_data]; st->client = client; + st->vref_uv = st->chip_info->int_vref_mv * 1000; + vref = devm_regulator_get(&client->dev, "vref"); + if (!IS_ERR(vref)) { + int vref_uv; + + ret = regulator_enable(vref); + if (ret) + goto error_disable_reg; + st->vref = vref; + vref_uv = regulator_get_voltage(vref); + if (vref_uv <= 0) { + ret = -EINVAL; + goto error_disable_reg; + } + st->vref_uv = vref_uv; + } + ret = max1363_alloc_scan_masks(indio_dev); if (ret) goto error_disable_reg; @@ -1562,6 +1584,8 @@ static int max1363_probe(struct i2c_client *client, error_uninit_buffer: iio_triggered_buffer_cleanup(indio_dev); error_disable_reg: + if (st->vref) + regulator_disable(st->vref); regulator_disable(st->reg); error_unregister_map: iio_map_array_unregister(indio_dev); @@ -1578,6 +1602,8 @@ static int max1363_remove(struct i2c_client *client) iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); + if (st->vref) + regulator_disable(st->vref); regulator_disable(st->reg); iio_map_array_unregister(indio_dev); iio_device_free(indio_dev); -- cgit v0.10.2 From 860c9c54272deaab43b40dbe416becb34abd344f Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Mon, 4 Feb 2013 11:36:00 +0000 Subject: iio: tweak language in industrialio-trigger comments Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 4fe0ead..4d6c7d8 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -160,7 +160,7 @@ void iio_trigger_notify_done(struct iio_trigger *trig) trig->use_count--; if (trig->use_count == 0 && trig->ops && trig->ops->try_reenable) if (trig->ops->try_reenable(trig)) - /* Missed and interrupt so launch new poll now */ + /* Missed an interrupt so launch new poll now */ iio_trigger_poll(trig, 0); } EXPORT_SYMBOL(iio_trigger_notify_done); @@ -193,7 +193,7 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq) * This is not currently handled. Alternative of not enabling trigger unless * the relevant function is in there may be the best option. */ -/* Worth protecting against double additions?*/ +/* Worth protecting against double additions? */ static int iio_trigger_attach_poll_func(struct iio_trigger *trig, struct iio_poll_func *pf) { @@ -201,7 +201,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig, bool notinuse = bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER); - /* Prevent the module being removed whilst attached to a trigger */ + /* Prevent the module from being removed whilst attached to a trigger */ __module_get(pf->indio_dev->info->driver_module); pf->irq = iio_trigger_get_irq(trig); ret = request_threaded_irq(pf->irq, pf->h, pf->thread, @@ -288,7 +288,7 @@ void iio_dealloc_pollfunc(struct iio_poll_func *pf) EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc); /** - * iio_trigger_read_current() - trigger consumer sysfs query which trigger + * iio_trigger_read_current() - trigger consumer sysfs query current trigger * * For trigger consumers the current_trigger interface allows the trigger * used by the device to be queried. @@ -305,7 +305,7 @@ static ssize_t iio_trigger_read_current(struct device *dev, } /** - * iio_trigger_write_current() trigger consumer sysfs set current trigger + * iio_trigger_write_current() - trigger consumer sysfs set current trigger * * For trigger consumers the current_trigger interface allows the trigger * used for this device to be specified at run time based on the triggers @@ -476,7 +476,7 @@ void iio_device_register_trigger_consumer(struct iio_dev *indio_dev) void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) { - /* Clean up and associated but not attached triggers references */ + /* Clean up an associated but not attached trigger reference */ if (indio_dev->trig) iio_trigger_put(indio_dev->trig); } -- cgit v0.10.2 From 5aa57f0a655276f62683c0cc714cd6328d98e08a Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Mon, 4 Feb 2013 20:26:00 +0000 Subject: iio: Update iio_channel_get API to use consumer device pointer as argument For iio_channel_get to work with OF based configurations, it needs the consumer device pointer instead of the consumer device name as argument. Signed-off-by: Guenter Roeck Acked-by: Anton Vorontsov Acked-by: Chanwoo Choi Signed-off-by: Jonathan Cameron diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index eda2a1aa..d0233cd 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c @@ -135,8 +135,7 @@ static int adc_jack_probe(struct platform_device *pdev) ; data->num_conditions = i; - data->chan = iio_channel_get(dev_name(&pdev->dev), - pdata->consumer_channel); + data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel); if (IS_ERR(data->chan)) { err = PTR_ERR(data->chan); goto out; diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index c42aba6..b289915b 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -93,7 +93,8 @@ static const struct iio_chan_spec } -struct iio_channel *iio_channel_get(const char *name, const char *channel_name) +static struct iio_channel *iio_channel_get_sys(const char *name, + const char *channel_name) { struct iio_map_internal *c_i = NULL, *c = NULL; struct iio_channel *channel; @@ -144,6 +145,14 @@ error_no_mem: iio_device_put(c->indio_dev); return ERR_PTR(err); } + +struct iio_channel *iio_channel_get(struct device *dev, + const char *channel_name) +{ + const char *name = dev ? dev_name(dev) : NULL; + + return iio_channel_get_sys(name, channel_name); +} EXPORT_SYMBOL_GPL(iio_channel_get); void iio_channel_release(struct iio_channel *channel) diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c index 32ce17e..42733c4 100644 --- a/drivers/power/generic-adc-battery.c +++ b/drivers/power/generic-adc-battery.c @@ -287,8 +287,8 @@ static int gab_probe(struct platform_device *pdev) * based on the channel supported by consumer device. */ for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { - adc_bat->channel[chan] = iio_channel_get(dev_name(&pdev->dev), - gab_chan_name[chan]); + adc_bat->channel[chan] = iio_channel_get(&pdev->dev, + gab_chan_name[chan]); if (IS_ERR(adc_bat->channel[chan])) { ret = PTR_ERR(adc_bat->channel[chan]); } else { diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c index 22b6407c..2788908 100644 --- a/drivers/power/lp8788-charger.c +++ b/drivers/power/lp8788-charger.c @@ -580,7 +580,7 @@ static void lp8788_irq_unregister(struct platform_device *pdev, } } -static void lp8788_setup_adc_channel(const char *consumer_name, +static void lp8788_setup_adc_channel(struct device *dev, struct lp8788_charger *pchg) { struct lp8788_charger_platform_data *pdata = pchg->pdata; @@ -590,11 +590,11 @@ static void lp8788_setup_adc_channel(const char *consumer_name, return; /* ADC channel for battery voltage */ - chan = iio_channel_get(consumer_name, pdata->adc_vbatt); + chan = iio_channel_get(dev, pdata->adc_vbatt); pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan; /* ADC channel for battery temperature */ - chan = iio_channel_get(consumer_name, pdata->adc_batt_temp); + chan = iio_channel_get(dev, pdata->adc_batt_temp); pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan; } @@ -704,7 +704,7 @@ static int lp8788_charger_probe(struct platform_device *pdev) if (ret) return ret; - lp8788_setup_adc_channel(pdev->name, pchg); + lp8788_setup_adc_channel(&pdev->dev, pchg); ret = lp8788_psy_register(pdev, pchg); if (ret) diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index a85787a..833926c 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -31,14 +31,15 @@ struct iio_channel { /** * iio_channel_get() - get description of all that is needed to access channel. - * @name: Unique name of the device as provided in the iio_map + * @dev: Pointer to consumer device. Device name must match + * the name of the device as provided in the iio_map * with which the desired provider to consumer mapping * was registered. * @consumer_channel: Unique name to identify the channel on the consumer * side. This typically describes the channels use within * the consumer. E.g. 'battery_voltage' */ -struct iio_channel *iio_channel_get(const char *name, +struct iio_channel *iio_channel_get(struct device *dev, const char *consumer_channel); /** -- cgit v0.10.2 From a9d50943b80803bfeca18632d75645062e02f133 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 6 Feb 2013 14:12:07 -0700 Subject: staging: comedi: quatech_daqp_cs: fix build error The kbuild test robot reported a build error in this driver caused by: commit: a3ac95195b020a0a8fa2a9b0649145324ba64c83 staging: comedi: comedi_pcmcia: allow drivers to use a custom conf_check() This commit changed the comedi_pcmcia_enable() function so that it now takes two arguments. The new argument is an optional (*conf_check) function that is passed to pcmcia_loop_config(). This driver uses the default (*conf_check) in comedi_pcmcia.c so just pass a NULL as the second arg. Reported-by: kbuild test robot Signed-off-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 6ab9083..911eb6b 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -723,7 +723,7 @@ static int daqp_auto_attach(struct comedi_device *dev, dev->private = devpriv; link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ; - ret = comedi_pcmcia_enable(dev); + ret = comedi_pcmcia_enable(dev, NULL); if (ret) return ret; dev->iobase = link->resource[0]->start; -- cgit v0.10.2 From d51d45da3e49262f932ca4567bd39b08b94ebf9f Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Thu, 7 Feb 2013 18:45:40 +0200 Subject: staging: xgifb: initialize register 3cc address Commit 56810a92c689c64d586a51a1078c5d307b24e8eb (staging: xgifb: use XGIRegInit()) left 3cc uninitialized, and it may trigger a panic during probe. Fix this. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index 387d1bd..801ac40 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -209,6 +209,7 @@ void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr) XGI_Pr->P3c0 = BaseAddr + 0x10; XGI_Pr->P3ce = BaseAddr + 0x1e; XGI_Pr->P3c2 = BaseAddr + 0x12; + XGI_Pr->P3cc = BaseAddr + 0x1c; XGI_Pr->P3ca = BaseAddr + 0x1a; XGI_Pr->P3c6 = BaseAddr + 0x16; XGI_Pr->P3c7 = BaseAddr + 0x17; -- cgit v0.10.2 From 37fa328f066dc38bf58337b6488232c8cefe37f3 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 7 Feb 2013 13:27:10 -0700 Subject: staging: comedi: ni_daq_dio24: add back missing 'if (ret)' The 'if (ret)' after calling comedi_pcmcia_enable() was accidentally removed in: Commit: 573a964882065f9b2cb71db8a225ba067b4b5b7a staging: comedi: ni_daq_dio24: use comedi_pcmcia_{enable,disable} Put if back so that dio24_auto_attach() can finish attaching to the board after enabling the pcmcia device. Signed-off-by: H Hartley Sweeten Reported-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 32ee22d..e1cc9d0 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -56,6 +56,7 @@ static int dio24_auto_attach(struct comedi_device *dev, link->config_flags |= CONF_AUTO_SET_IO; ret = comedi_pcmcia_enable(dev, NULL); + if (ret) return ret; dev->iobase = link->resource[0]->start; -- cgit v0.10.2 From b4fcf48a740fde8e5acb8e64ad0845fb2500dde4 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Thu, 7 Feb 2013 23:57:07 +0100 Subject: staging/goldfish: Use %zx for printing size_t variables When building the driver, gcc emits the following warnings: .../drivers/staging/goldfish/goldfish_nand.c: In function 'goldfish_nand_read_oob': goldfish_nand.c:159:2: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'size_t' [-Wformat] goldfish_nand.c:159:2: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'size_t' [-Wformat] In function 'goldfish_nand_write_oob': goldfish_nand.c:191:2: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'size_t' [-Wformat] goldfish_nand.c:191:2: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'size_t' [-Wformat] In function 'goldfish_nand_read': goldfish_nand.c:215:2: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'size_t' [-Wformat] In function 'goldfish_nand_write': goldfish_nand.c:239:2: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'size_t' [-Wformat] -> As defined in the printk-formats use %zx for size_t variables Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/goldfish/goldfish_nand.c b/drivers/staging/goldfish/goldfish_nand.c index 1891d89..ab1f019 100644 --- a/drivers/staging/goldfish/goldfish_nand.c +++ b/drivers/staging/goldfish/goldfish_nand.c @@ -156,7 +156,7 @@ static int goldfish_nand_read_oob(struct mtd_info *mtd, loff_t ofs, return 0; invalid_arg: - pr_err("goldfish_nand_read_oob: invalid read, start %llx, len %x, ooblen %x, dev_size %llx, write_size %x\n", + pr_err("goldfish_nand_read_oob: invalid read, start %llx, len %zx, ooblen %zx, dev_size %llx, write_size %x\n", ofs, ops->len, ops->ooblen, mtd->size, mtd->writesize); return -EINVAL; } @@ -188,7 +188,7 @@ static int goldfish_nand_write_oob(struct mtd_info *mtd, loff_t ofs, return 0; invalid_arg: - pr_err("goldfish_nand_write_oob: invalid write, start %llx, len %x, ooblen %x, dev_size %llx, write_size %x\n", + pr_err("goldfish_nand_write_oob: invalid write, start %llx, len %zx, ooblen %zx, dev_size %llx, write_size %x\n", ofs, ops->len, ops->ooblen, mtd->size, mtd->writesize); return -EINVAL; } @@ -212,7 +212,7 @@ static int goldfish_nand_read(struct mtd_info *mtd, loff_t from, size_t len, return 0; invalid_arg: - pr_err("goldfish_nand_read: invalid read, start %llx, len %x, dev_size %llx, write_size %x\n", + pr_err("goldfish_nand_read: invalid read, start %llx, len %zx, dev_size %llx, write_size %x\n", from, len, mtd->size, mtd->writesize); return -EINVAL; } @@ -236,7 +236,7 @@ static int goldfish_nand_write(struct mtd_info *mtd, loff_t to, size_t len, return 0; invalid_arg: - pr_err("goldfish_nand_write: invalid write, start %llx, len %x, dev_size %llx, write_size %x\n", + pr_err("goldfish_nand_write: invalid write, start %llx, len %zx, dev_size %llx, write_size %x\n", to, len, mtd->size, mtd->writesize); return -EINVAL; } -- cgit v0.10.2 From f6fcf7f79b971cad61d9f010e750d74df9309517 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Thu, 7 Feb 2013 23:46:38 +0100 Subject: staging/goldfish: Add MTD dependency to KCONFIG If CONFIG_MTD is not set goldfish_nand fails to compile with the following linker warnings: drivers/built-in.o: In function `goldfish_nand_remove': goldfish_nand.c:(.text+0x6e7d0e): undefined reference to `mtd_device_unregister' drivers/built-in.o: In function `goldfish_nand_erase': goldfish_nand.c:(.text+0x6e8ba2): undefined reference to `mtd_erase_callback' drivers/built-in.o: In function `goldfish_nand_init_device': goldfish_nand.c:(.text+0x6e8eba): undefined reference to `mtd_device_parse_register' Reported-by: Randy Dunlap Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/goldfish/Kconfig b/drivers/staging/goldfish/Kconfig index d6c98d0..4e09460 100644 --- a/drivers/staging/goldfish/Kconfig +++ b/drivers/staging/goldfish/Kconfig @@ -7,6 +7,7 @@ config GOLDFISH_AUDIO config MTD_GOLDFISH_NAND tristate "Goldfish NAND device" depends on GOLDFISH + depends on MTD help Drives the emulated NAND flash device on the Google Goldfish Android virtual device. -- cgit v0.10.2 From da7185462e86b4832342d7e02e52b889126a0fcf Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 7 Feb 2013 16:03:00 +0000 Subject: staging: comedi: don't return minor from comedi_alloc_subdevice_minor() `comedi_alloc_subdevice_minor()` currently returns the allocated minor device number on success. This is not really of any interest to the caller (in fact the return value is not even checked), so just return 0 on success. If the caller really needs to know the allocated minor device number it can look in `s->minor`. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index b1e8cdb..4f587ea 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2383,7 +2383,7 @@ int comedi_alloc_subdevice_minor(struct comedi_subdevice *s) s->class_dev = csdev; dev_set_drvdata(csdev, info); - return i; + return 0; } void comedi_free_subdevice_minor(struct comedi_subdevice *s) -- cgit v0.10.2 From b12da2e4337ce235c4c5951b2217330587f3dda4 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 7 Feb 2013 16:03:01 +0000 Subject: staging: comedi: correct error message in comedi_alloc_subdevice_minor() `comedi_alloc_subdevice_minors()` currently prints a message about running out of minor numbers board device files if it runs out of minor device numbers. Change it to complain about running out of minor device numbers for subdevice files as these are in a different range, not shared with those for board device files. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 4f587ea..195d56d 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2372,7 +2372,7 @@ int comedi_alloc_subdevice_minor(struct comedi_subdevice *s) spin_unlock(&comedi_file_info_table_lock); if (i == COMEDI_NUM_MINORS) { kfree(info); - pr_err("comedi: error: ran out of minor numbers for board device files.\n"); + pr_err("comedi: error: ran out of minor numbers for subdevice files.\n"); return -EBUSY; } s->minor = i; -- cgit v0.10.2 From 69a7c50369ec1529e9cd6ca3989b254d78073379 Mon Sep 17 00:00:00 2001 From: Tommi Rantala Date: Fri, 8 Feb 2013 13:41:25 +0200 Subject: staging: dgrp: use correct release op for /proc/dgrp/info Trinity (the syscall fuzzer) discovered that reading /proc/dgrp/info was leaking some memory. Fix by using the correct release op in info_proc_file_ops. unreferenced object 0xffff88003b6696e0 (size 32): comm "cat", pid 2321, jiffies 4294705179 (age 29.434s) hex dump (first 32 bytes): 40 79 1c 81 ff ff ff ff 60 79 1c 81 ff ff ff ff @y......`y...... 50 79 1c 81 ff ff ff ff b0 62 89 81 ff ff ff ff Py.......b...... backtrace: [] kmemleak_alloc+0x21/0x50 [] kmem_cache_alloc_trace+0x11b/0x190 [] single_open+0x3c/0xc0 [] info_proc_open+0x15/0x20 [] proc_reg_open+0xb7/0x160 [] do_dentry_open+0x1cc/0x280 [] finish_open+0x4a/0x60 [] do_last+0xb07/0xdb0 [] path_openat+0xc2/0x4f0 [] do_filp_open+0x3c/0xa0 [] do_sys_open+0x11c/0x1c0 [] sys_open+0x1c/0x20 [] system_call_fastpath+0x16/0x1b [] 0xffffffffffffffff Signed-off-by: Tommi Rantala Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c index e09fc9c..cc868a2 100644 --- a/drivers/staging/dgrp/dgrp_specproc.c +++ b/drivers/staging/dgrp/dgrp_specproc.c @@ -102,7 +102,7 @@ static struct file_operations info_proc_file_ops = { .open = info_proc_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release, + .release = single_release, }; static struct file_operations nodeinfo_proc_file_ops = { -- cgit v0.10.2 From 900a72a6f20b5949a3afa51c1012a0efefb6c8f3 Mon Sep 17 00:00:00 2001 From: Tommi Rantala Date: Fri, 8 Feb 2013 13:41:26 +0200 Subject: staging: dgrp: prefix function names with dgrp_ in dgrp_specproc.c Prefix the functions in dgrp_specproc.c to avoid ambiguity in backtraces, such as the "info_proc_open" in this one: unreferenced object 0xffff88003b6696e0 (size 32): comm "cat", pid 2321, jiffies 4294705179 (age 29.434s) hex dump (first 32 bytes): 40 79 1c 81 ff ff ff ff 60 79 1c 81 ff ff ff ff @y......`y...... 50 79 1c 81 ff ff ff ff b0 62 89 81 ff ff ff ff Py.......b...... backtrace: [] kmemleak_alloc+0x21/0x50 [] kmem_cache_alloc_trace+0x11b/0x190 [] single_open+0x3c/0xc0 [] info_proc_open+0x15/0x20 [] proc_reg_open+0xb7/0x160 [] do_dentry_open+0x1cc/0x280 [] finish_open+0x4a/0x60 [] do_last+0xb07/0xdb0 [] path_openat+0xc2/0x4f0 [] do_filp_open+0x3c/0xa0 [] do_sys_open+0x11c/0x1c0 [] sys_open+0x1c/0x20 [] system_call_fastpath+0x16/0x1b [] 0xffffffffffffffff Signed-off-by: Tommi Rantala Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c index cc868a2..dfdaede 100644 --- a/drivers/staging/dgrp/dgrp_specproc.c +++ b/drivers/staging/dgrp/dgrp_specproc.c @@ -81,25 +81,26 @@ static struct dgrp_proc_entry dgrp_mon_table[]; static struct dgrp_proc_entry dgrp_ports_table[]; static struct dgrp_proc_entry dgrp_dpa_table[]; -static ssize_t config_proc_write(struct file *file, const char __user *buffer, - size_t count, loff_t *pos); +static ssize_t dgrp_config_proc_write(struct file *file, + const char __user *buffer, + size_t count, loff_t *pos); -static int nodeinfo_proc_open(struct inode *inode, struct file *file); -static int info_proc_open(struct inode *inode, struct file *file); -static int config_proc_open(struct inode *inode, struct file *file); +static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file); +static int dgrp_info_proc_open(struct inode *inode, struct file *file); +static int dgrp_config_proc_open(struct inode *inode, struct file *file); static struct file_operations config_proc_file_ops = { .owner = THIS_MODULE, - .open = config_proc_open, + .open = dgrp_config_proc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, - .write = config_proc_write + .write = dgrp_config_proc_write, }; static struct file_operations info_proc_file_ops = { .owner = THIS_MODULE, - .open = info_proc_open, + .open = dgrp_info_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, @@ -107,7 +108,7 @@ static struct file_operations info_proc_file_ops = { static struct file_operations nodeinfo_proc_file_ops = { .owner = THIS_MODULE, - .open = nodeinfo_proc_open, + .open = dgrp_nodeinfo_proc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, @@ -405,21 +406,21 @@ done: return 0; } -static void *config_proc_start(struct seq_file *m, loff_t *pos) +static void *dgrp_config_proc_start(struct seq_file *m, loff_t *pos) { return seq_list_start_head(&nd_struct_list, *pos); } -static void *config_proc_next(struct seq_file *p, void *v, loff_t *pos) +static void *dgrp_config_proc_next(struct seq_file *p, void *v, loff_t *pos) { return seq_list_next(v, &nd_struct_list, pos); } -static void config_proc_stop(struct seq_file *m, void *v) +static void dgrp_config_proc_stop(struct seq_file *m, void *v) { } -static int config_proc_show(struct seq_file *m, void *v) +static int dgrp_config_proc_show(struct seq_file *m, void *v) { struct nd_struct *nd; char tmp_id[4]; @@ -445,13 +446,13 @@ static int config_proc_show(struct seq_file *m, void *v) } static const struct seq_operations proc_config_ops = { - .start = config_proc_start, - .next = config_proc_next, - .stop = config_proc_stop, - .show = config_proc_show + .start = dgrp_config_proc_start, + .next = dgrp_config_proc_next, + .stop = dgrp_config_proc_stop, + .show = dgrp_config_proc_show, }; -static int config_proc_open(struct inode *inode, struct file *file) +static int dgrp_config_proc_open(struct inode *inode, struct file *file) { return seq_open(file, &proc_config_ops); } @@ -462,8 +463,9 @@ static int config_proc_open(struct inode *inode, struct file *file) * write) is treated as an independent request. See the "parse" * description for more details. */ -static ssize_t config_proc_write(struct file *file, const char __user *buffer, - size_t count, loff_t *pos) +static ssize_t dgrp_config_proc_write(struct file *file, + const char __user *buffer, + size_t count, loff_t *pos) { ssize_t retval; char *inbuf, *sp; @@ -627,7 +629,7 @@ static int parse_write_config(char *buf) return retval; } -static int info_proc_show(struct seq_file *m, void *v) +static int dgrp_info_proc_show(struct seq_file *m, void *v) { seq_printf(m, "version: %s\n", DIGI_VERSION); seq_puts(m, "register_with_sysfs: 1\n"); @@ -637,27 +639,27 @@ static int info_proc_show(struct seq_file *m, void *v) return 0; } -static int info_proc_open(struct inode *inode, struct file *file) +static int dgrp_info_proc_open(struct inode *inode, struct file *file) { - return single_open(file, info_proc_show, NULL); + return single_open(file, dgrp_info_proc_show, NULL); } -static void *nodeinfo_start(struct seq_file *m, loff_t *pos) +static void *dgrp_nodeinfo_start(struct seq_file *m, loff_t *pos) { return seq_list_start_head(&nd_struct_list, *pos); } -static void *nodeinfo_next(struct seq_file *p, void *v, loff_t *pos) +static void *dgrp_nodeinfo_next(struct seq_file *p, void *v, loff_t *pos) { return seq_list_next(v, &nd_struct_list, pos); } -static void nodeinfo_stop(struct seq_file *m, void *v) +static void dgrp_nodeinfo_stop(struct seq_file *m, void *v) { } -static int nodeinfo_show(struct seq_file *m, void *v) +static int dgrp_nodeinfo_show(struct seq_file *m, void *v) { struct nd_struct *nd; char hwver[8]; @@ -699,13 +701,13 @@ static int nodeinfo_show(struct seq_file *m, void *v) static const struct seq_operations nodeinfo_ops = { - .start = nodeinfo_start, - .next = nodeinfo_next, - .stop = nodeinfo_stop, - .show = nodeinfo_show + .start = dgrp_nodeinfo_start, + .next = dgrp_nodeinfo_next, + .stop = dgrp_nodeinfo_stop, + .show = dgrp_nodeinfo_show, }; -static int nodeinfo_proc_open(struct inode *inode, struct file *file) +static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file) { return seq_open(file, &nodeinfo_ops); } -- cgit v0.10.2 From 1e927711c5ecabe76010ed9249f8f3747829f04f Mon Sep 17 00:00:00 2001 From: Fengguang Wu Date: Fri, 8 Feb 2013 10:15:10 +0800 Subject: staging: zram: __zram_reset_device() can be static Signed-off-by: Fengguang Wu Cc: Minchan Kim Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 9ac140b..6094e80 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -464,7 +464,7 @@ error: bio_io_error(bio); } -void __zram_reset_device(struct zram *zram) +static void __zram_reset_device(struct zram *zram) { size_t index; struct zram_meta *meta; -- cgit v0.10.2 From 7ac54d03920b3a100fa2f089a352367c906a867d Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 9 Feb 2013 00:03:43 +0200 Subject: staging: xgifb: XGI_GetVCLK2Ptr(): delete IF_DEF_LVDS check Delete IF_DEF_LVDS check, this function is never called when it's true. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index bd81656..ee73737 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -865,53 +865,42 @@ static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo, /* si+Ext_ResInfo */ modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; - if (pVBInfo->IF_DEF_LVDS == 0) { - if (pVBInfo->VBInfo & - (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/ - if (pVBInfo->LCDResInfo != Panel_1024x768) - /* LCDXlat2VCLK */ - VCLKIndex = VCLK108_2_315 + 5; - else - VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */ - } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) { - if (pVBInfo->SetFlag & RPLLDIV2XO) - VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2; - else - VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK; + if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/ + if (pVBInfo->LCDResInfo != Panel_1024x768) + /* LCDXlat2VCLK */ + VCLKIndex = VCLK108_2_315 + 5; + else + VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */ + } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) { + if (pVBInfo->SetFlag & RPLLDIV2XO) + VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2; + else + VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK; - if (pVBInfo->SetFlag & TVSimuMode) { - if (modeflag & Charx8Dot) { - VCLKIndex = TVCLKBASE_315_25 + - HiTVSimuVCLK; - } else { - VCLKIndex = TVCLKBASE_315_25 + - HiTVTextVCLK; - } + if (pVBInfo->SetFlag & TVSimuMode) { + if (modeflag & Charx8Dot) { + VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK; + } else { + VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK; } + } - /* 301lv */ - if (pVBInfo->VBType & VB_SIS301LV) { - if (pVBInfo->SetFlag & RPLLDIV2XO) - VCLKIndex = YPbPr525iVCLK_2; - else - VCLKIndex = YPbPr525iVCLK; - } - } else if (pVBInfo->VBInfo & SetCRT2ToTV) { + /* 301lv */ + if (pVBInfo->VBType & VB_SIS301LV) { if (pVBInfo->SetFlag & RPLLDIV2XO) - VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2; + VCLKIndex = YPbPr525iVCLK_2; else - VCLKIndex = TVCLKBASE_315_25 + TVVCLK; - } else { /* for CRT2 */ - /* di+Ext_CRTVCLK */ - VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex]. - Ext_CRTVCLK; - VCLKIndex &= IndexMask; + VCLKIndex = YPbPr525iVCLK; } - } else if ((pVBInfo->LCDResInfo == Panel_800x600) || - (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */ - VCLKIndex = VCLK40; /* LVDSXlat1VCLK */ - } else { - VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */ + } else if (pVBInfo->VBInfo & SetCRT2ToTV) { + if (pVBInfo->SetFlag & RPLLDIV2XO) + VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2; + else + VCLKIndex = TVCLKBASE_315_25 + TVVCLK; + } else { /* for CRT2 */ + /* di+Ext_CRTVCLK */ + VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + VCLKIndex &= IndexMask; } return VCLKIndex; -- cgit v0.10.2 From 1b149edfa3496914d6b73a949dc03777ba172c88 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 9 Feb 2013 00:03:44 +0200 Subject: staging: xgifb: XGI_GetVBInfo(): delete IF_DEF_LVDS check Delete IF_DEF_LVDS check, this function is never called when it's true. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index ee73737..9d7ec18 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -1994,40 +1994,28 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex, temp = xgifb_reg_get(pVBInfo->P3d4, 0x38); - if (pVBInfo->IF_DEF_LVDS == 0) { - if (pVBInfo->VBType & - (VB_SIS302B | - VB_SIS301LV | - VB_SIS302LV | - VB_XGI301C)) { - if (temp & EnableDualEdge) { - tempbx |= SetCRT2ToDualEdge; - if (temp & SetToLCDA) - tempbx |= XGI_SetCRT2ToLCDA; - } + if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV | + VB_XGI301C)) { + if (temp & EnableDualEdge) { + tempbx |= SetCRT2ToDualEdge; + if (temp & SetToLCDA) + tempbx |= XGI_SetCRT2ToLCDA; } } if (pVBInfo->IF_DEF_YPbPr == 1) { - if (((pVBInfo->IF_DEF_LVDS == 0) && - ((pVBInfo->VBType & VB_SIS301LV) || - (pVBInfo->VBType & VB_SIS302LV) || - (pVBInfo->VBType & VB_XGI301C)))) { + if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) { if (temp & SetYPbPr) { if (pVBInfo->IF_DEF_HiVision == 1) { - /* shampoo add for new - * scratch */ - temp = xgifb_reg_get( - pVBInfo->P3d4, - 0x35); + /* shampoo add for new scratch */ + temp = xgifb_reg_get(pVBInfo->P3d4, + 0x35); temp &= YPbPrMode; tempbx |= SetCRT2ToHiVision; if (temp != YPbPrMode1080i) { - tempbx &= - (~SetCRT2ToHiVision); - tempbx |= - SetCRT2ToYPbPr525750; + tempbx &= (~SetCRT2ToHiVision); + tempbx |= SetCRT2ToYPbPr525750; } } } @@ -2036,19 +2024,15 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex, tempax = push; /* restore CR31 */ - if (pVBInfo->IF_DEF_LVDS == 0) { - if (pVBInfo->IF_DEF_YPbPr == 1) { - if (pVBInfo->IF_DEF_HiVision == 1) - temp = 0x09FC; - else - temp = 0x097C; - } else if (pVBInfo->IF_DEF_HiVision == 1) { - temp = 0x01FC; - } else { - temp = 0x017C; - } - } else { /* 3rd party chip */ - temp = SetCRT2ToLCD; + if (pVBInfo->IF_DEF_YPbPr == 1) { + if (pVBInfo->IF_DEF_HiVision == 1) + temp = 0x09FC; + else + temp = 0x097C; + } else if (pVBInfo->IF_DEF_HiVision == 1) { + temp = 0x01FC; + } else { + temp = 0x017C; } if (!(tempbx & temp)) { @@ -2059,14 +2043,11 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex, if (!(pVBInfo->VBType & VB_NoLCD)) { if (tempbx & XGI_SetCRT2ToLCDA) { if (tempbx & SetSimuScanMode) - tempbx &= (~(SetCRT2ToLCD | - SetCRT2ToRAMDAC | + tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC | SwitchCRT2)); else - tempbx &= (~(SetCRT2ToLCD | - SetCRT2ToRAMDAC | - SetCRT2ToTV | - SwitchCRT2)); + tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC | + SetCRT2ToTV | SwitchCRT2)); } } @@ -2075,49 +2056,38 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex, if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) { if (pVBInfo->IF_DEF_CRT2Monitor == 1) { if (tempbx & SetCRT2ToRAMDAC) { - tempbx &= (0xFF00 | - SetCRT2ToRAMDAC | - SwitchCRT2 | - SetSimuScanMode); + tempbx &= (0xFF00 | SetCRT2ToRAMDAC | + SwitchCRT2 | SetSimuScanMode); tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750)); } } else { - tempbx &= (~(SetCRT2ToRAMDAC | - SetCRT2ToLCD | + tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV)); } } if (!(pVBInfo->VBType & VB_NoLCD)) { if (tempbx & SetCRT2ToLCD) { - tempbx &= (0xFF00 | - SetCRT2ToLCD | - SwitchCRT2 | + tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 | SetSimuScanMode); tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750)); } } if (tempbx & SetCRT2ToSCART) { - tempbx &= (0xFF00 | - SetCRT2ToSCART | - SwitchCRT2 | + tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 | SetSimuScanMode); tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750)); } if (pVBInfo->IF_DEF_YPbPr == 1) { if (tempbx & SetCRT2ToYPbPr525750) - tempbx &= (0xFF00 | - SwitchCRT2 | - SetSimuScanMode); + tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode); } if (pVBInfo->IF_DEF_HiVision == 1) { if (tempbx & SetCRT2ToHiVision) - tempbx &= (0xFF00 | - SetCRT2ToHiVision | - SwitchCRT2 | + tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); } @@ -2127,19 +2097,15 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex, } if (!(tempbx & DisableCRT2Display)) { - if ((!(tempbx & DriverMode)) || - (!(modeflag & CRT2Mode))) { + if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) { if (!(tempbx & XGI_SetCRT2ToLCDA)) - tempbx |= (SetInSlaveMode | - SetSimuScanMode); + tempbx |= (SetInSlaveMode | SetSimuScanMode); } /* LCD+TV can't support in slave mode * (Force LCDA+TV->LCDB) */ - if ((tempbx & SetInSlaveMode) && - (tempbx & XGI_SetCRT2ToLCDA)) { - tempbx ^= (SetCRT2ToLCD | - XGI_SetCRT2ToLCDA | + if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) { + tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA | SetCRT2ToDualEdge); pVBInfo->SetFlag |= ReserveTVOption; } -- cgit v0.10.2 From a8b35290373c2505c530a06887b1de92b3f43738 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 9 Feb 2013 00:03:45 +0200 Subject: staging: xgifb: XGI_GetTVInfo(): delete IF_DEF_LVDS checks This function is never called when pVBInfo->IF_DEF_LVDS is true, so we can remove checks and reduce complexity. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 9d7ec18..faa25b9 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2137,10 +2137,8 @@ static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex, TVSetNTSCJ | TVSetPAL); - if (pVBInfo->IF_DEF_LVDS == 0) { - if (pVBInfo->VBInfo & SetCRT2ToSCART) - tempbx |= TVSetPAL; - } + if (pVBInfo->VBInfo & SetCRT2ToSCART) + tempbx |= TVSetPAL; if (pVBInfo->IF_DEF_YPbPr == 1) { if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) { @@ -2162,33 +2160,26 @@ static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex, tempbx = tempbx | TVSetHiVision | TVSetPAL; } - if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */ - if ((pVBInfo->VBInfo & SetInSlaveMode) && - (!(pVBInfo->VBInfo & SetNotSimuMode))) - tempbx |= TVSimuMode; + if ((pVBInfo->VBInfo & SetInSlaveMode) && + (!(pVBInfo->VBInfo & SetNotSimuMode))) + tempbx |= TVSimuMode; - if (!(tempbx & TVSetPAL) && - (modeflag > 13) && - (resinfo == 8)) /* NTSC 1024x768, */ - tempbx |= NTSC1024x768; + if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8)) + /* NTSC 1024x768, */ + tempbx |= NTSC1024x768; - tempbx |= RPLLDIV2XO; + tempbx |= RPLLDIV2XO; - if (pVBInfo->VBInfo & SetCRT2ToHiVision) { - if (pVBInfo->VBInfo & SetInSlaveMode) - tempbx &= (~RPLLDIV2XO); - } else if (tempbx & - (TVSetYPbPr525p | TVSetYPbPr750p)) { - tempbx &= (~RPLLDIV2XO); - } else if (!(pVBInfo->VBType & - (VB_SIS301B | - VB_SIS302B | - VB_SIS301LV | - VB_SIS302LV | - VB_XGI301C))) { - if (tempbx & TVSimuMode) - tempbx &= (~RPLLDIV2XO); - } + if (pVBInfo->VBInfo & SetCRT2ToHiVision) { + if (pVBInfo->VBInfo & SetInSlaveMode) + tempbx &= (~RPLLDIV2XO); + } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) { + tempbx &= (~RPLLDIV2XO); + } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | + VB_SIS301LV | VB_SIS302LV | + VB_XGI301C))) { + if (tempbx & TVSimuMode) + tempbx &= (~RPLLDIV2XO); } } pVBInfo->TVInfo = tempbx; -- cgit v0.10.2 From 718e715d1a0182b5f6483bf82fae7c6b337bb16d Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 9 Feb 2013 00:03:46 +0200 Subject: staging: xgifb: XGI_GetLCDInfo(): delete IF_DEF_LVDS check Delete IF_DEF_LVDS check, this function is never called when it's true. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index faa25b9..872eea4 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2240,21 +2240,18 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo, tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability; - if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */ - if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType - & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) { - tempbx |= SetLCDDualLink; - } - - if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo - & SetCRT2ToLCD) && (resinfo == 9) && - (!(tempbx & EnableScalingLCD))) - /* - * set to center in 1280x1024 LCDB - * for Panel_1400x1050 - */ - tempbx |= SetLCDtoNonExpanding; - } + if (((pVBInfo->VBType & VB_SIS302LV) || + (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) + tempbx |= SetLCDDualLink; + + if ((pVBInfo->LCDResInfo == Panel_1400x1050) && + (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) && + (!(tempbx & EnableScalingLCD))) + /* + * set to center in 1280x1024 LCDB + * for Panel_1400x1050 + */ + tempbx |= SetLCDtoNonExpanding; if (pVBInfo->VBInfo & SetInSlaveMode) { if (pVBInfo->VBInfo & SetNotSimuMode) -- cgit v0.10.2 From 22006839a265c69fa56fbe9fadbd5c5e8c9d9736 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 9 Feb 2013 00:03:47 +0200 Subject: staging: xgifb: XGI_GetCRT2ResInfo(): delete IF_DEF_LVDS check Delete IF_DEF_LVDS check, this function is never called when it's true. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 872eea4..2f90464 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2526,36 +2526,34 @@ static void XGI_GetCRT2ResInfo(unsigned short ModeNo, if (!(pVBInfo->VBInfo & SetCRT2ToLCD)) goto exit; - if (pVBInfo->IF_DEF_LVDS == 0) { - if (pVBInfo->LCDResInfo == Panel_1600x1200) { - if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) { - if (yres == 1024) - yres = 1056; - } + if (pVBInfo->LCDResInfo == Panel_1600x1200) { + if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) { + if (yres == 1024) + yres = 1056; } + } - if (pVBInfo->LCDResInfo == Panel_1280x1024) { - if (yres == 400) - yres = 405; - else if (yres == 350) - yres = 360; + if (pVBInfo->LCDResInfo == Panel_1280x1024) { + if (yres == 400) + yres = 405; + else if (yres == 350) + yres = 360; - if (pVBInfo->LCDInfo & XGI_LCDVESATiming) { - if (yres == 360) - yres = 375; - } + if (pVBInfo->LCDInfo & XGI_LCDVESATiming) { + if (yres == 360) + yres = 375; } + } - if (pVBInfo->LCDResInfo == Panel_1024x768) { - if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) { - if (!(pVBInfo->LCDInfo & LCDNonExpanding)) { - if (yres == 350) - yres = 357; - else if (yres == 400) - yres = 420; - else if (yres == 480) - yres = 525; - } + if (pVBInfo->LCDResInfo == Panel_1024x768) { + if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) { + if (!(pVBInfo->LCDInfo & LCDNonExpanding)) { + if (yres == 350) + yres = 357; + else if (yres == 400) + yres = 420; + else if (yres == 480) + yres = 525; } } } -- cgit v0.10.2 From 5305d746054d1c73e7e9263b25189dedefb2dc01 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 9 Feb 2013 00:03:48 +0200 Subject: staging: xgifb: XGI_SetDelayComp(): delete IF_DEF_LVDS check Delete IF_DEF_LVDS check, this function is never called when it's true. Signed-off-by: Aaro Koskinen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 2f90464..3d5c424 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -4863,16 +4863,6 @@ static void XGI_SetDelayComp(struct vb_device_info *pVBInfo) } xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah); } - } else if (pVBInfo->IF_DEF_LVDS == 1) { - tempbl = 0; - tempbh = 0; - if (pVBInfo->VBInfo & SetCRT2ToLCD) { - tempah = XGI301LCDDelay; - tempah &= 0x0f; - tempah = tempah << 4; - xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f, - tempah); - } } } -- cgit v0.10.2 From 91ffbabfd9ae6b9bfef02bb1e0fbba451c7289a7 Mon Sep 17 00:00:00 2001 From: Denis CIOCCA Date: Thu, 7 Feb 2013 09:46:00 +0000 Subject: iio:common: added allocate and deallocate trigger functions when trigger is disabled. This patch resolve a bugfix when driver is compiled without trigger. Signed-off-by: Denis Ciocca Reported-by: Randy Dunlap Signed-off-by: Jonathan Cameron diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index c40fdf5..1f86a97 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -235,6 +235,16 @@ void st_sensors_deallocate_trigger(struct iio_dev *indio_dev); irqreturn_t st_sensors_trigger_handler(int irq, void *p); int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf); +#else +static inline int st_sensors_allocate_trigger(struct iio_dev *indio_dev, + const struct iio_trigger_ops *trigger_ops) +{ + return 0; +} +static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev) +{ + return; +} #endif int st_sensors_init_sensor(struct iio_dev *indio_dev); -- cgit v0.10.2 From ad76fda78318821fe8823b4b7c587a46a268eecf Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 6 Feb 2013 02:54:00 +0000 Subject: iio: mxs-lradc: Fix 'duplicate const' warning The following warning is generated by sparse: drivers/staging/iio/adc/mxs-lradc.c:118:47: warning: duplicate const Remove the duplicate const. Signed-off-by: Fabio Estevam Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index b1b8c42..f5fb0df 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -114,7 +114,7 @@ struct mxs_lradc_of_config { const char * const *irq_name; }; -static const struct mxs_lradc_of_config const mxs_lradc_of_config[] = { +static const struct mxs_lradc_of_config mxs_lradc_of_config[] = { [IMX23_LRADC] = { .irq_count = ARRAY_SIZE(mx23_lradc_irq_names), .irq_name = mx23_lradc_irq_names, -- cgit v0.10.2 From 6d9eecd418afb2c12e5db5be3d72f0f1df43bdd9 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 17:31:00 +0000 Subject: spi: Add helper functions for setting up transfers Quite often the pattern used for setting up and transferring a synchronous SPI transaction looks very much like the following: struct spi_message msg; struct spi_transfer xfers[] = { ... }; spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); ... spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg); ret = spi_sync(&msg); This patch adds two new helper functions for handling this case. The first helper function spi_message_init_with_transfers() takes a spi_message and an array of spi_transfers. It will initialize the message and then call spi_message_add_tail() for each transfer in the array. E.g. the following spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); ... spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg); can be rewritten as spi_message_init_with_transfers(&msg, xfers, ARRAY_SIZE(xfers)); The second function spi_sync_transfer() takes a SPI device and an array of spi_transfers. It will allocate a new spi_message (on the stack) and add all transfers in the array to the message. Finally it will call spi_sync() on the message. E.g. the follwing struct spi_message msg; struct spi_transfer xfers[] = { ... }; spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); ... spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg); ret = spi_sync(spi, &msg); can be rewritten as struct spi_transfer xfers[] = { ... }; ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers)); A coccinelle script to find such instances will follow. Signed-off-by: Lars-Peter Clausen Reviewed-by: Mark Brown Signed-off-by: Jonathan Cameron diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index f629189..7dbe586 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -591,6 +591,26 @@ spi_transfer_del(struct spi_transfer *t) list_del(&t->transfer_list); } +/** + * spi_message_init_with_transfers - Initialize spi_message and append transfers + * @m: spi_message to be initialized + * @xfers: An array of spi transfers + * @num_xfers: Number of items in the xfer array + * + * This function initializes the given spi_message and adds each spi_transfer in + * the given array to the message. + */ +static inline void +spi_message_init_with_transfers(struct spi_message *m, +struct spi_transfer *xfers, unsigned int num_xfers) +{ + unsigned int i; + + spi_message_init(m); + for (i = 0; i < num_xfers; ++i) + spi_message_add_tail(&xfers[i], m); +} + /* It's fine to embed message and transaction structures in other data * structures so long as you don't free them while they're in use. */ @@ -683,6 +703,30 @@ spi_read(struct spi_device *spi, void *buf, size_t len) return spi_sync(spi, &m); } +/** + * spi_sync_transfer - synchronous SPI data transfer + * @spi: device with which data will be exchanged + * @xfers: An array of spi_transfers + * @num_xfers: Number of items in the xfer array + * Context: can sleep + * + * Does a synchronous SPI data transfer of the given spi_transfer array. + * + * For more specific semantics see spi_sync(). + * + * It returns zero on success, else a negative error code. + */ +static inline int +spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers, + unsigned int num_xfers) +{ + struct spi_message msg; + + spi_message_init_with_transfers(&msg, xfers, num_xfers); + + return spi_sync(spi, &msg); +} + /* this copies txbuf and rxbuf data; for small transfers only! */ extern int spi_write_then_read(struct spi_device *spi, const void *txbuf, unsigned n_tx, -- cgit v0.10.2 From 14543a00fc3ce6dac9f297535c502a0085a50467 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 17:31:00 +0000 Subject: iio: Use spi_sync_transfer() Use the new spi_sync_transfer() helper function instead of open-coding it. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c index 4a24c2e..c2229a5 100644 --- a/drivers/iio/accel/kxsd9.c +++ b/drivers/iio/accel/kxsd9.c @@ -94,7 +94,6 @@ error_ret: static int kxsd9_read(struct iio_dev *indio_dev, u8 address) { - struct spi_message msg; int ret; struct kxsd9_state *st = iio_priv(indio_dev); struct spi_transfer xfers[] = { @@ -112,10 +111,7 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address) mutex_lock(&st->buf_lock); st->tx[0] = KXSD9_READ(address); - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) return ret; return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0); diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c index 54b46fd..9277121 100644 --- a/drivers/iio/dac/ad5360.c +++ b/drivers/iio/dac/ad5360.c @@ -213,7 +213,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, unsigned int addr) { struct ad5360_state *st = iio_priv(indio_dev); - struct spi_message m; int ret; struct spi_transfer t[] = { { @@ -226,10 +225,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, }, }; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - mutex_lock(&indio_dev->mlock); st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | @@ -237,7 +232,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, AD5360_READBACK_TYPE(type) | AD5360_READBACK_ADDR(addr)); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret >= 0) ret = be32_to_cpu(st->data[1].d32) & 0xffff; diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c index 43be948..6b86a63 100644 --- a/drivers/iio/dac/ad5421.c +++ b/drivers/iio/dac/ad5421.c @@ -127,7 +127,6 @@ static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg, static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg) { struct ad5421_state *st = iio_priv(indio_dev); - struct spi_message m; int ret; struct spi_transfer t[] = { { @@ -140,15 +139,11 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg) }, }; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - mutex_lock(&indio_dev->mlock); st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret >= 0) ret = be32_to_cpu(st->data[1].d32) & 0xffff; diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c index 0661829..e5e5974 100644 --- a/drivers/iio/dac/ad5504.c +++ b/drivers/iio/dac/ad5504.c @@ -85,11 +85,7 @@ static int ad5504_spi_read(struct spi_device *spi, u8 addr) .rx_buf = &val, .len = 2, }; - struct spi_message m; - - spi_message_init(&m); - spi_message_add_tail(&t, &m); - ret = spi_sync(spi, &m); + ret = spi_sync_transfer(spi, &t, 1); if (ret < 0) return ret; diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index ca9609d..5e554af 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -117,18 +117,13 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr) .len = 3, }, }; - struct spi_message m; int ret; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) | AD5686_ADDR(addr)); st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP)); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret < 0) return ret; diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c index 0869bbd..71faabc 100644 --- a/drivers/iio/dac/ad5755.c +++ b/drivers/iio/dac/ad5755.c @@ -153,7 +153,6 @@ static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel, static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr) { struct ad5755_state *st = iio_priv(indio_dev); - struct spi_message m; int ret; struct spi_transfer t[] = { { @@ -167,16 +166,12 @@ static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr) }, }; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - mutex_lock(&indio_dev->mlock); st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16)); st->data[1].d32 = cpu_to_be32(AD5755_NOOP); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret >= 0) ret = be32_to_cpu(st->data[1].d32) & 0xffff; diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c index 7f9045e..5b7acd3 100644 --- a/drivers/iio/dac/ad5764.c +++ b/drivers/iio/dac/ad5764.c @@ -135,7 +135,6 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg, unsigned int *val) { struct ad5764_state *st = iio_priv(indio_dev); - struct spi_message m; int ret; struct spi_transfer t[] = { { @@ -148,15 +147,11 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg, }, }; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - mutex_lock(&indio_dev->mlock); st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret >= 0) *val = be32_to_cpu(st->data[1].d32) & 0xffff; diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c index 6407b54..8dfd3da 100644 --- a/drivers/iio/dac/ad5791.c +++ b/drivers/iio/dac/ad5791.c @@ -125,7 +125,6 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val) u8 d8[4]; } data[3]; int ret; - struct spi_message msg; struct spi_transfer xfers[] = { { .tx_buf = &data[0].d8[1], @@ -144,10 +143,7 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val) AD5791_ADDR(addr)); data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP)); - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(spi, &msg); + ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers)); *val = be32_to_cpu(data[2].d32); diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c index 8030747..1ea132e 100644 --- a/drivers/iio/frequency/ad9523.c +++ b/drivers/iio/frequency/ad9523.c @@ -287,7 +287,6 @@ struct ad9523_state { static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) { struct ad9523_state *st = iio_priv(indio_dev); - struct spi_message m; int ret; /* We encode the register size 1..3 bytes into the register address. @@ -305,15 +304,11 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) }, }; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - st->data[0].d32 = cpu_to_be32(AD9523_READ | AD9523_CNT(AD9523_TRANSF_LEN(addr)) | AD9523_ADDR(addr)); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret < 0) dev_err(&indio_dev->dev, "read failed (%d)", ret); else @@ -326,7 +321,6 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val) { struct ad9523_state *st = iio_priv(indio_dev); - struct spi_message m; int ret; struct spi_transfer t[] = { { @@ -338,16 +332,12 @@ static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val) }, }; - spi_message_init(&m); - spi_message_add_tail(&t[0], &m); - spi_message_add_tail(&t[1], &m); - st->data[0].d32 = cpu_to_be32(AD9523_WRITE | AD9523_CNT(AD9523_TRANSF_LEN(addr)) | AD9523_ADDR(addr)); st->data[1].d32 = cpu_to_be32(val); - ret = spi_sync(st->spi, &m); + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); if (ret < 0) dev_err(&indio_dev->dev, "write failed (%d)", ret); diff --git a/drivers/iio/gyro/adxrs450.c b/drivers/iio/gyro/adxrs450.c index d9d4383..5b79953 100644 --- a/drivers/iio/gyro/adxrs450.c +++ b/drivers/iio/gyro/adxrs450.c @@ -213,7 +213,6 @@ error_ret: static int adxrs450_spi_initial(struct adxrs450_state *st, u32 *val, char chk) { - struct spi_message msg; int ret; u32 tx; struct spi_transfer xfers = { @@ -228,9 +227,7 @@ static int adxrs450_spi_initial(struct adxrs450_state *st, if (chk) tx |= (ADXRS450_CHK | ADXRS450_P); st->tx = cpu_to_be32(tx); - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, &xfers, 1); if (ret) { dev_err(&st->us->dev, "Problem while reading initializing data\n"); goto error_ret; -- cgit v0.10.2 From ad6c46b0c712e0d8fd8a80ee372b30f14a781888 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 9 Jan 2013 17:31:00 +0000 Subject: staging:iio: Use spi_sync_transfer() Use the new spi_sync_transfer() helper function instead of open-coding it. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c index 37ed1b8..0e01930 100644 --- a/drivers/staging/iio/accel/lis3l02dq_core.c +++ b/drivers/staging/iio/accel/lis3l02dq_core.c @@ -53,7 +53,6 @@ int lis3l02dq_spi_read_reg_8(struct iio_dev *indio_dev, u8 reg_address, u8 *val) { struct lis3l02dq_state *st = iio_priv(indio_dev); - struct spi_message msg; int ret; struct spi_transfer xfer = { .tx_buf = st->tx, @@ -66,9 +65,7 @@ int lis3l02dq_spi_read_reg_8(struct iio_dev *indio_dev, st->tx[0] = LIS3L02DQ_READ_REG(reg_address); st->tx[1] = 0; - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, &xfer, 1); *val = st->rx[1]; mutex_unlock(&st->buf_lock); @@ -109,7 +106,6 @@ static int lis3l02dq_spi_write_reg_s16(struct iio_dev *indio_dev, s16 value) { int ret; - struct spi_message msg; struct lis3l02dq_state *st = iio_priv(indio_dev); struct spi_transfer xfers[] = { { .tx_buf = st->tx, @@ -129,10 +125,7 @@ static int lis3l02dq_spi_write_reg_s16(struct iio_dev *indio_dev, st->tx[2] = LIS3L02DQ_WRITE_REG(lower_reg_address + 1); st->tx[3] = (value >> 8) & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); mutex_unlock(&st->buf_lock); return ret; @@ -143,8 +136,6 @@ static int lis3l02dq_read_reg_s16(struct iio_dev *indio_dev, int *val) { struct lis3l02dq_state *st = iio_priv(indio_dev); - - struct spi_message msg; int ret; s16 tempval; struct spi_transfer xfers[] = { { @@ -167,10 +158,7 @@ static int lis3l02dq_read_reg_s16(struct iio_dev *indio_dev, st->tx[2] = LIS3L02DQ_READ_REG(lower_reg_address + 1); st->tx[3] = 0; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 16 bit register"); goto error_ret; diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c index 414d3ca..14683f5 100644 --- a/drivers/staging/iio/accel/sca3000_core.c +++ b/drivers/staging/iio/accel/sca3000_core.c @@ -90,7 +90,6 @@ int sca3000_read_data_short(struct sca3000_state *st, uint8_t reg_address_high, int len) { - struct spi_message msg; struct spi_transfer xfer[2] = { { .len = 1, @@ -101,11 +100,8 @@ int sca3000_read_data_short(struct sca3000_state *st, } }; st->tx[0] = SCA3000_READ_REG(reg_address_high); - spi_message_init(&msg); - spi_message_add_tail(&xfer[0], &msg); - spi_message_add_tail(&xfer[1], &msg); - return spi_sync(st->us, &msg); + return spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer)); } /** @@ -133,7 +129,6 @@ static int sca3000_reg_lock_on(struct sca3000_state *st) **/ static int __sca3000_unlock_reg_lock(struct sca3000_state *st) { - struct spi_message msg; struct spi_transfer xfer[3] = { { .len = 2, @@ -154,12 +149,8 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st) st->tx[3] = 0x50; st->tx[4] = SCA3000_WRITE_REG(SCA3000_REG_ADDR_UNLOCK); st->tx[5] = 0xA0; - spi_message_init(&msg); - spi_message_add_tail(&xfer[0], &msg); - spi_message_add_tail(&xfer[1], &msg); - spi_message_add_tail(&xfer[2], &msg); - return spi_sync(st->us, &msg); + return spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer)); } /** diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c index cbec2f1..3e5e860 100644 --- a/drivers/staging/iio/accel/sca3000_ring.c +++ b/drivers/staging/iio/accel/sca3000_ring.c @@ -39,7 +39,6 @@ static int sca3000_read_data(struct sca3000_state *st, int len) { int ret; - struct spi_message msg; struct spi_transfer xfer[2] = { { .len = 1, @@ -55,10 +54,7 @@ static int sca3000_read_data(struct sca3000_state *st, } xfer[1].rx_buf = *rx_p; st->tx[0] = SCA3000_READ_REG(reg_address_high); - spi_message_init(&msg); - spi_message_add_tail(&xfer[0], &msg); - spi_message_add_tail(&xfer[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer)); if (ret) { dev_err(get_device(&st->us->dev), "problem reading register"); goto error_free_rx; diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index fa81a49..1f190c1 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -199,12 +199,8 @@ static int __ad7280_read32(struct spi_device *spi, unsigned *val) .rx_buf = &rx_buf, .len = 4, }; - struct spi_message m; - spi_message_init(&m); - spi_message_add_tail(&t, &m); - - ret = spi_sync(spi, &m); + ret = spi_sync_transfer(spi, &t, 1); if (ret) return ret; diff --git a/drivers/staging/iio/frequency/ad5930.c b/drivers/staging/iio/frequency/ad5930.c index 23777be..69e90e9 100644 --- a/drivers/staging/iio/frequency/ad5930.c +++ b/drivers/staging/iio/frequency/ad5930.c @@ -44,7 +44,6 @@ static ssize_t ad5930_set_parameter(struct device *dev, const char *buf, size_t len) { - struct spi_message msg; struct spi_transfer xfer; int ret; struct ad5903_config *config = (struct ad5903_config *)buf; @@ -64,9 +63,7 @@ static ssize_t ad5930_set_parameter(struct device *dev, xfer.tx_buf = config; mutex_lock(&st->lock); - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->sdev, &msg); + ret = spi_sync_transfer(st->sdev, &xfer, 1); if (ret) goto error_ret; error_ret: diff --git a/drivers/staging/iio/frequency/ad9850.c b/drivers/staging/iio/frequency/ad9850.c index 104f7a4..01a8a93 100644 --- a/drivers/staging/iio/frequency/ad9850.c +++ b/drivers/staging/iio/frequency/ad9850.c @@ -39,7 +39,6 @@ static ssize_t ad9850_set_parameter(struct device *dev, const char *buf, size_t len) { - struct spi_message msg; struct spi_transfer xfer; int ret; struct ad9850_config *config = (struct ad9850_config *)buf; @@ -50,9 +49,7 @@ static ssize_t ad9850_set_parameter(struct device *dev, xfer.tx_buf = config; mutex_lock(&st->lock); - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->sdev, &msg); + ret = spi_sync_transfer(st->sdev, &xfer, 1); if (ret) goto error_ret; error_ret: diff --git a/drivers/staging/iio/frequency/ad9852.c b/drivers/staging/iio/frequency/ad9852.c index 17ac825..1344031 100644 --- a/drivers/staging/iio/frequency/ad9852.c +++ b/drivers/staging/iio/frequency/ad9852.c @@ -183,7 +183,6 @@ static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9852_set_parameter, 0); static void ad9852_init(struct ad9852_state *st) { - struct spi_message msg; struct spi_transfer xfer; int ret; u8 config[5]; @@ -199,9 +198,7 @@ static void ad9852_init(struct ad9852_state *st) xfer.len = 5; xfer.tx_buf = &config; - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->sdev, &msg); + ret = spi_sync_transfer(st->sdev, &xfer, 1); if (ret) goto error_ret; diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c index 51c3bde..e5943e2 100644 --- a/drivers/staging/iio/meter/ade7753.c +++ b/drivers/staging/iio/meter/ade7753.c @@ -103,7 +103,6 @@ static int ade7753_spi_read_reg_24(struct device *dev, u8 reg_address, u32 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7753_state *st = iio_priv(indio_dev); int ret; @@ -122,10 +121,7 @@ static int ade7753_spi_read_reg_24(struct device *dev, mutex_lock(&st->buf_lock); st->tx[0] = ADE7753_READ_REG(reg_address); - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X", reg_address); diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c index b50c89e..7b6503b 100644 --- a/drivers/staging/iio/meter/ade7754.c +++ b/drivers/staging/iio/meter/ade7754.c @@ -103,7 +103,6 @@ static int ade7754_spi_read_reg_24(struct device *dev, u8 reg_address, u32 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7754_state *st = iio_priv(indio_dev); int ret; @@ -122,9 +121,7 @@ static int ade7754_spi_read_reg_24(struct device *dev, st->tx[2] = 0; st->tx[3] = 0; - spi_message_init(&msg); - spi_message_add_tail(xfers, &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X", reg_address); diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c index 3454e51..53c68dc 100644 --- a/drivers/staging/iio/meter/ade7758_core.c +++ b/drivers/staging/iio/meter/ade7758_core.c @@ -47,7 +47,6 @@ static int ade7758_spi_write_reg_16(struct device *dev, u16 value) { int ret; - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); struct spi_transfer xfers[] = { @@ -63,9 +62,7 @@ static int ade7758_spi_write_reg_16(struct device *dev, st->tx[1] = (value >> 8) & 0xFF; st->tx[2] = value & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(xfers, &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); mutex_unlock(&st->buf_lock); return ret; @@ -76,7 +73,6 @@ static int ade7758_spi_write_reg_24(struct device *dev, u32 value) { int ret; - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); struct spi_transfer xfers[] = { @@ -93,9 +89,7 @@ static int ade7758_spi_write_reg_24(struct device *dev, st->tx[2] = (value >> 8) & 0xFF; st->tx[3] = value & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(xfers, &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); mutex_unlock(&st->buf_lock); return ret; @@ -105,7 +99,6 @@ int ade7758_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); int ret; @@ -128,10 +121,7 @@ int ade7758_spi_read_reg_8(struct device *dev, st->tx[0] = ADE7758_READ_REG(reg_address); st->tx[1] = 0; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X", reg_address); @@ -148,7 +138,6 @@ static int ade7758_spi_read_reg_16(struct device *dev, u8 reg_address, u16 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); int ret; @@ -173,10 +162,7 @@ static int ade7758_spi_read_reg_16(struct device *dev, st->tx[1] = 0; st->tx[2] = 0; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X", reg_address); @@ -194,7 +180,6 @@ static int ade7758_spi_read_reg_24(struct device *dev, u8 reg_address, u32 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); int ret; @@ -219,10 +204,7 @@ static int ade7758_spi_read_reg_24(struct device *dev, st->tx[2] = 0; st->tx[3] = 0; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X", reg_address); diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c index 10b911b..17dc373 100644 --- a/drivers/staging/iio/meter/ade7759.c +++ b/drivers/staging/iio/meter/ade7759.c @@ -103,7 +103,6 @@ static int ade7759_spi_read_reg_40(struct device *dev, u8 reg_address, u64 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7759_state *st = iio_priv(indio_dev); int ret; @@ -120,9 +119,7 @@ static int ade7759_spi_read_reg_40(struct device *dev, st->tx[0] = ADE7759_READ_REG(reg_address); memset(&st->tx[1], 0 , 5); - spi_message_init(&msg); - spi_message_add_tail(xfers, &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->us->dev, "problem when reading 40 bit register 0x%02X", reg_address); diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c index f0984fa..a802cf2 100644 --- a/drivers/staging/iio/meter/ade7854-spi.c +++ b/drivers/staging/iio/meter/ade7854-spi.c @@ -20,7 +20,6 @@ static int ade7854_spi_write_reg_8(struct device *dev, u8 value) { int ret; - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { @@ -35,9 +34,7 @@ static int ade7854_spi_write_reg_8(struct device *dev, st->tx[2] = reg_address & 0xFF; st->tx[3] = value & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; @@ -48,7 +45,6 @@ static int ade7854_spi_write_reg_16(struct device *dev, u16 value) { int ret; - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { @@ -64,9 +60,7 @@ static int ade7854_spi_write_reg_16(struct device *dev, st->tx[3] = (value >> 8) & 0xFF; st->tx[4] = value & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; @@ -77,7 +71,6 @@ static int ade7854_spi_write_reg_24(struct device *dev, u32 value) { int ret; - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { @@ -94,9 +87,7 @@ static int ade7854_spi_write_reg_24(struct device *dev, st->tx[4] = (value >> 8) & 0xFF; st->tx[5] = value & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; @@ -107,7 +98,6 @@ static int ade7854_spi_write_reg_32(struct device *dev, u32 value) { int ret; - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { @@ -125,9 +115,7 @@ static int ade7854_spi_write_reg_32(struct device *dev, st->tx[5] = (value >> 8) & 0xFF; st->tx[6] = value & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; @@ -137,7 +125,6 @@ static int ade7854_spi_read_reg_8(struct device *dev, u16 reg_address, u8 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); int ret; @@ -159,10 +146,7 @@ static int ade7854_spi_read_reg_8(struct device *dev, st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 8 bit register 0x%02X", reg_address); @@ -179,7 +163,6 @@ static int ade7854_spi_read_reg_16(struct device *dev, u16 reg_address, u16 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); int ret; @@ -200,10 +183,7 @@ static int ade7854_spi_read_reg_16(struct device *dev, st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 16 bit register 0x%02X", reg_address); @@ -220,7 +200,6 @@ static int ade7854_spi_read_reg_24(struct device *dev, u16 reg_address, u32 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); int ret; @@ -242,10 +221,7 @@ static int ade7854_spi_read_reg_24(struct device *dev, st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 24 bit register 0x%02X", reg_address); @@ -262,7 +238,6 @@ static int ade7854_spi_read_reg_32(struct device *dev, u16 reg_address, u32 *val) { - struct spi_message msg; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); int ret; @@ -284,10 +259,7 @@ static int ade7854_spi_read_reg_32(struct device *dev, st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->spi, &msg); + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 32 bit register 0x%02X", reg_address); diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index ed07a34..53110b6 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -130,15 +130,12 @@ static int ad2s1210_config_read(struct ad2s1210_state *st, .rx_buf = st->rx, .tx_buf = st->tx, }; - struct spi_message msg; int ret = 0; ad2s1210_set_mode(MOD_CONFIG, st); - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); st->tx[0] = address | AD2S1210_MSB_IS_HIGH; st->tx[1] = AD2S1210_REG_FAULT; - ret = spi_sync(st->sdev, &msg); + ret = spi_sync_transfer(st->sdev, &xfer, 1); if (ret < 0) return ret; st->old_data = true; -- cgit v0.10.2 From aaa300262c5912bda34c9cf871719209eae01b06 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 9 Feb 2013 10:49:00 +0000 Subject: iio:triggers Protect functions in triggers.h from use when not compiled Also include a couple of forward defs of struct iio_trigger and struct iio_trigger_ops to avoid doing this in each driver. Signed-off-by: Jonathan Cameron Reported-by: Randy Dunlap Acked-by: Denis Ciocca diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h index 20239da..c66e0a9 100644 --- a/include/linux/iio/trigger.h +++ b/include/linux/iio/trigger.h @@ -12,6 +12,7 @@ #ifndef _IIO_TRIGGER_H_ #define _IIO_TRIGGER_H_ +#ifdef CONFIG_IIO_TRIGGER struct iio_subirq { bool enabled; }; @@ -117,4 +118,8 @@ irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private); __printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...); void iio_trigger_free(struct iio_trigger *trig); +#else +struct iio_trigger; +struct iio_trigger_ops; +#endif #endif /* _IIO_TRIGGER_H_ */ -- cgit v0.10.2 From 8ce4a56a52bf566659768a9e46e759e7cd5f33d9 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sat, 9 Feb 2013 10:49:00 +0000 Subject: iio:st_sensors fix build when !CONFIG_IIO_TRIGGER Partly a case of removing unused headers and partly a case of ifdefing out the iio_trigger_ops structures. This has come about because of an 'unusual' separation of code in this driver. Signed-off-by: Jonathan Cameron Reported-by: Randy Dunlap Acked-by: Denis Ciocca diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index a235de2..e0f5a3c 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -419,10 +419,15 @@ static const struct iio_info accel_info = { .write_raw = &st_accel_write_raw, }; +#ifdef CONFIG_IIO_TRIGGER static const struct iio_trigger_ops st_accel_trigger_ops = { .owner = THIS_MODULE, .set_trigger_state = ST_ACCEL_TRIGGER_SET_STATE, }; +#define ST_ACCEL_TRIGGER_OPS (&st_accel_trigger_ops) +#else +#define ST_ACCEL_TRIGGER_OPS NULL +#endif int st_accel_common_probe(struct iio_dev *indio_dev) { @@ -455,7 +460,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) goto st_accel_common_probe_error; err = st_sensors_allocate_trigger(indio_dev, - &st_accel_trigger_ops); + ST_ACCEL_TRIGGER_OPS); if (err < 0) goto st_accel_probe_trigger_error; } diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 90b8ddf..ffc9d09 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c index dbd45c0..22b35bf 100644 --- a/drivers/iio/accel/st_accel_spi.c +++ b/drivers/iio/accel/st_accel_spi.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index 0a09998..fa9b242 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -287,10 +287,15 @@ static const struct iio_info gyro_info = { .write_raw = &st_gyro_write_raw, }; +#ifdef CONFIG_IIO_TRIGGER static const struct iio_trigger_ops st_gyro_trigger_ops = { .owner = THIS_MODULE, .set_trigger_state = ST_GYRO_TRIGGER_SET_STATE, }; +#define ST_GYRO_TRIGGER_OPS (&st_gyro_trigger_ops) +#else +#define ST_GYRO_TRIGGER_OPS NULL +#endif int st_gyro_common_probe(struct iio_dev *indio_dev) { @@ -323,7 +328,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) goto st_gyro_common_probe_error; err = st_sensors_allocate_trigger(indio_dev, - &st_gyro_trigger_ops); + ST_GYRO_TRIGGER_OPS); if (err < 0) goto st_gyro_probe_trigger_error; } diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c index a44b5b4..8a31050 100644 --- a/drivers/iio/gyro/st_gyro_i2c.c +++ b/drivers/iio/gyro/st_gyro_i2c.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c index 8b4dcc5..f354039 100644 --- a/drivers/iio/gyro/st_gyro_spi.c +++ b/drivers/iio/gyro/st_gyro_spi.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index a69fbe1..16f0d6d 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c index 710b256a5..e6adc4a 100644 --- a/drivers/iio/magnetometer/st_magn_i2c.c +++ b/drivers/iio/magnetometer/st_magn_i2c.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c index 94547e7..51adb79 100644 --- a/drivers/iio/magnetometer/st_magn_spi.c +++ b/drivers/iio/magnetometer/st_magn_spi.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include -- cgit v0.10.2 From 09a642b78523e9f4c5970c806ad218aa3de31551 Mon Sep 17 00:00:00 2001 From: Ge Gao Date: Sat, 2 Feb 2013 00:26:00 +0000 Subject: Invensense MPU6050 Device Driver. This the basic functional Invensense MPU6050 Device driver. Signed-off-by: Ge Gao Reviewed-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron diff --git a/Documentation/ABI/testing/sysfs-bus-iio-mpu6050 b/Documentation/ABI/testing/sysfs-bus-iio-mpu6050 new file mode 100644 index 0000000..cb53737 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-mpu6050 @@ -0,0 +1,13 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_gyro_matrix +What: /sys/bus/iio/devices/iio:deviceX/in_accel_matrix +What: /sys/bus/iio/devices/iio:deviceX/in_magn_matrix +KernelVersion: 3.4.0 +Contact: linux-iio@vger.kernel.org +Description: + This is mounting matrix for motion sensors. Mounting matrix + is a 3x3 unitary matrix. A typical mounting matrix would look like + [0, 1, 0; 1, 0, 0; 0, 0, -1]. Using this information, it would be + easy to tell the relative positions among sensors as well as their + positions relative to the board that holds these sensors. Identity matrix + [1, 0, 0; 0, 1, 0; 0, 0, 1] means sensor chip and device are perfectly + aligned with each other. All axes are exactly the same. diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig index 47f66ed..4f40a10 100644 --- a/drivers/iio/imu/Kconfig +++ b/drivers/iio/imu/Kconfig @@ -36,3 +36,5 @@ config IIO_ADIS_LIB_BUFFER help A set of buffer helper functions for the Analog Devices ADIS* device family. + +source "drivers/iio/imu/inv_mpu6050/Kconfig" diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile index 019b717..f2f56ce 100644 --- a/drivers/iio/imu/Makefile +++ b/drivers/iio/imu/Makefile @@ -11,3 +11,5 @@ adis_lib-y += adis.o adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o + +obj-y += inv_mpu6050/ diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig new file mode 100644 index 0000000..b5cfa3a --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/Kconfig @@ -0,0 +1,13 @@ +# +# inv-mpu6050 drivers for Invensense MPU devices and combos +# + +config INV_MPU6050_IIO + tristate "Invensense MPU6050 devices" + depends on I2C && SYSFS + select IIO_TRIGGERED_BUFFER + help + This driver supports the Invensense MPU6050 devices. + It is a gyroscope/accelerometer combo device. + This driver can be built as a module. The module will be called + inv-mpu6050. diff --git a/drivers/iio/imu/inv_mpu6050/Makefile b/drivers/iio/imu/inv_mpu6050/Makefile new file mode 100644 index 0000000..3a677c7 --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/Makefile @@ -0,0 +1,6 @@ +# +# Makefile for Invensense MPU6050 device. +# + +obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o +inv-mpu6050-objs := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c new file mode 100644 index 0000000..37ca05b --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -0,0 +1,795 @@ +/* +* Copyright (C) 2012 Invensense, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "inv_mpu_iio.h" + +/* + * this is the gyro scale translated from dynamic range plus/minus + * {250, 500, 1000, 2000} to rad/s + */ +static const int gyro_scale_6050[] = {133090, 266181, 532362, 1064724}; + +/* + * this is the accel scale translated from dynamic range plus/minus + * {2, 4, 8, 16} to m/s^2 + */ +static const int accel_scale[] = {598, 1196, 2392, 4785}; + +static const struct inv_mpu6050_reg_map reg_set_6050 = { + .sample_rate_div = INV_MPU6050_REG_SAMPLE_RATE_DIV, + .lpf = INV_MPU6050_REG_CONFIG, + .user_ctrl = INV_MPU6050_REG_USER_CTRL, + .fifo_en = INV_MPU6050_REG_FIFO_EN, + .gyro_config = INV_MPU6050_REG_GYRO_CONFIG, + .accl_config = INV_MPU6050_REG_ACCEL_CONFIG, + .fifo_count_h = INV_MPU6050_REG_FIFO_COUNT_H, + .fifo_r_w = INV_MPU6050_REG_FIFO_R_W, + .raw_gyro = INV_MPU6050_REG_RAW_GYRO, + .raw_accl = INV_MPU6050_REG_RAW_ACCEL, + .temperature = INV_MPU6050_REG_TEMPERATURE, + .int_enable = INV_MPU6050_REG_INT_ENABLE, + .pwr_mgmt_1 = INV_MPU6050_REG_PWR_MGMT_1, + .pwr_mgmt_2 = INV_MPU6050_REG_PWR_MGMT_2, +}; + +static const struct inv_mpu6050_chip_config chip_config_6050 = { + .fsr = INV_MPU6050_FSR_2000DPS, + .lpf = INV_MPU6050_FILTER_20HZ, + .fifo_rate = INV_MPU6050_INIT_FIFO_RATE, + .gyro_fifo_enable = false, + .accl_fifo_enable = false, + .accl_fs = INV_MPU6050_FS_02G, +}; + +static const struct inv_mpu6050_hw hw_info[INV_NUM_PARTS] = { + { + .num_reg = 117, + .name = "MPU6050", + .reg = ®_set_6050, + .config = &chip_config_6050, + }, +}; + +int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d) +{ + return i2c_smbus_write_i2c_block_data(st->client, reg, 1, &d); +} + +int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask) +{ + u8 d, mgmt_1; + int result; + + /* switch clock needs to be careful. Only when gyro is on, can + clock source be switched to gyro. Otherwise, it must be set to + internal clock */ + if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { + result = i2c_smbus_read_i2c_block_data(st->client, + st->reg->pwr_mgmt_1, 1, &mgmt_1); + if (result != 1) + return result; + + mgmt_1 &= ~INV_MPU6050_BIT_CLK_MASK; + } + + if ((INV_MPU6050_BIT_PWR_GYRO_STBY == mask) && (!en)) { + /* turning off gyro requires switch to internal clock first. + Then turn off gyro engine */ + mgmt_1 |= INV_CLK_INTERNAL; + result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, mgmt_1); + if (result) + return result; + } + + result = i2c_smbus_read_i2c_block_data(st->client, + st->reg->pwr_mgmt_2, 1, &d); + if (result != 1) + return result; + if (en) + d &= ~mask; + else + d |= mask; + result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_2, d); + if (result) + return result; + + if (en) { + /* Wait for output stablize */ + msleep(INV_MPU6050_TEMP_UP_TIME); + if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { + /* switch internal clock to PLL */ + mgmt_1 |= INV_CLK_PLL; + result = inv_mpu6050_write_reg(st, + st->reg->pwr_mgmt_1, mgmt_1); + if (result) + return result; + } + } + + return 0; +} + +int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on) +{ + int result; + + if (power_on) + result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, 0); + else + result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, + INV_MPU6050_BIT_SLEEP); + if (result) + return result; + + if (power_on) + msleep(INV_MPU6050_REG_UP_TIME); + + return 0; +} + +/** + * inv_mpu6050_init_config() - Initialize hardware, disable FIFO. + * + * Initial configuration: + * FSR: ± 2000DPS + * DLPF: 20Hz + * FIFO rate: 50Hz + * Clock source: Gyro PLL + */ +static int inv_mpu6050_init_config(struct iio_dev *indio_dev) +{ + int result; + u8 d; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + result = inv_mpu6050_set_power_itg(st, true); + if (result) + return result; + d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT); + result = inv_mpu6050_write_reg(st, st->reg->gyro_config, d); + if (result) + return result; + + d = INV_MPU6050_FILTER_20HZ; + result = inv_mpu6050_write_reg(st, st->reg->lpf, d); + if (result) + return result; + + d = INV_MPU6050_ONE_K_HZ / INV_MPU6050_INIT_FIFO_RATE - 1; + result = inv_mpu6050_write_reg(st, st->reg->sample_rate_div, d); + if (result) + return result; + + d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); + result = inv_mpu6050_write_reg(st, st->reg->accl_config, d); + if (result) + return result; + + memcpy(&st->chip_config, hw_info[st->chip_type].config, + sizeof(struct inv_mpu6050_chip_config)); + result = inv_mpu6050_set_power_itg(st, false); + + return result; +} + +static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg, + int axis, int *val) +{ + int ind, result; + __be16 d; + + ind = (axis - IIO_MOD_X) * 2; + result = i2c_smbus_read_i2c_block_data(st->client, reg + ind, 2, + (u8 *)&d); + if (result != 2) + return -EINVAL; + *val = (short)be16_to_cpup(&d); + + return IIO_VAL_INT; +} + +static int inv_mpu6050_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) { + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + { + int ret, result; + + ret = IIO_VAL_INT; + result = 0; + mutex_lock(&indio_dev->mlock); + if (!st->chip_config.enable) { + result = inv_mpu6050_set_power_itg(st, true); + if (result) + goto error_read_raw; + } + /* when enable is on, power is already on */ + switch (chan->type) { + case IIO_ANGL_VEL: + if (!st->chip_config.gyro_fifo_enable || + !st->chip_config.enable) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + goto error_read_raw; + } + ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, + chan->channel2, val); + if (!st->chip_config.gyro_fifo_enable || + !st->chip_config.enable) { + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + goto error_read_raw; + } + break; + case IIO_ACCEL: + if (!st->chip_config.accl_fifo_enable || + !st->chip_config.enable) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + goto error_read_raw; + } + ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, + chan->channel2, val); + if (!st->chip_config.accl_fifo_enable || + !st->chip_config.enable) { + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + goto error_read_raw; + } + break; + case IIO_TEMP: + /* wait for stablization */ + msleep(INV_MPU6050_SENSOR_UP_TIME); + inv_mpu6050_sensor_show(st, st->reg->temperature, + IIO_MOD_X, val); + break; + default: + ret = -EINVAL; + break; + } +error_read_raw: + if (!st->chip_config.enable) + result |= inv_mpu6050_set_power_itg(st, false); + mutex_unlock(&indio_dev->mlock); + if (result) + return result; + + return ret; + } + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = 0; + *val2 = gyro_scale_6050[st->chip_config.fsr]; + + return IIO_VAL_INT_PLUS_NANO; + case IIO_ACCEL: + *val = 0; + *val2 = accel_scale[st->chip_config.accl_fs]; + + return IIO_VAL_INT_PLUS_MICRO; + case IIO_TEMP: + *val = 0; + *val2 = INV_MPU6050_TEMP_SCALE; + + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_TEMP: + *val = INV_MPU6050_TEMP_OFFSET; + + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static int inv_mpu6050_write_fsr(struct inv_mpu6050_state *st, int fsr) +{ + int result; + u8 d; + + if (fsr < 0 || fsr > INV_MPU6050_MAX_GYRO_FS_PARAM) + return -EINVAL; + if (fsr == st->chip_config.fsr) + return 0; + + d = (fsr << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT); + result = inv_mpu6050_write_reg(st, st->reg->gyro_config, d); + if (result) + return result; + st->chip_config.fsr = fsr; + + return 0; +} + +static int inv_mpu6050_write_accel_fs(struct inv_mpu6050_state *st, int fs) +{ + int result; + u8 d; + + if (fs < 0 || fs > INV_MPU6050_MAX_ACCL_FS_PARAM) + return -EINVAL; + if (fs == st->chip_config.accl_fs) + return 0; + + d = (fs << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); + result = inv_mpu6050_write_reg(st, st->reg->accl_config, d); + if (result) + return result; + st->chip_config.accl_fs = fs; + + return 0; +} + +static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long mask) { + struct inv_mpu6050_state *st = iio_priv(indio_dev); + int result; + + mutex_lock(&indio_dev->mlock); + /* we should only update scale when the chip is disabled, i.e., + not running */ + if (st->chip_config.enable) { + result = -EBUSY; + goto error_write_raw; + } + result = inv_mpu6050_set_power_itg(st, true); + if (result) + goto error_write_raw; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + result = inv_mpu6050_write_fsr(st, val); + break; + case IIO_ACCEL: + result = inv_mpu6050_write_accel_fs(st, val); + break; + default: + result = -EINVAL; + break; + } + break; + default: + result = -EINVAL; + break; + } + +error_write_raw: + result |= inv_mpu6050_set_power_itg(st, false); + mutex_unlock(&indio_dev->mlock); + + return result; +} + +/** + * inv_mpu6050_set_lpf() - set low pass filer based on fifo rate. + * + * Based on the Nyquist principle, the sampling rate must + * exceed twice of the bandwidth of the signal, or there + * would be alising. This function basically search for the + * correct low pass parameters based on the fifo rate, e.g, + * sampling frequency. + */ +static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate) +{ + const int hz[] = {188, 98, 42, 20, 10, 5}; + const int d[] = {INV_MPU6050_FILTER_188HZ, INV_MPU6050_FILTER_98HZ, + INV_MPU6050_FILTER_42HZ, INV_MPU6050_FILTER_20HZ, + INV_MPU6050_FILTER_10HZ, INV_MPU6050_FILTER_5HZ}; + int i, h, result; + u8 data; + + h = (rate >> 1); + i = 0; + while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1)) + i++; + data = d[i]; + result = inv_mpu6050_write_reg(st, st->reg->lpf, data); + if (result) + return result; + st->chip_config.lpf = data; + + return 0; +} + +/** + * inv_mpu6050_fifo_rate_store() - Set fifo rate. + */ +static ssize_t inv_mpu6050_fifo_rate_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + s32 fifo_rate; + u8 d; + int result; + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + if (kstrtoint(buf, 10, &fifo_rate)) + return -EINVAL; + if (fifo_rate < INV_MPU6050_MIN_FIFO_RATE || + fifo_rate > INV_MPU6050_MAX_FIFO_RATE) + return -EINVAL; + if (fifo_rate == st->chip_config.fifo_rate) + return count; + + mutex_lock(&indio_dev->mlock); + if (st->chip_config.enable) { + result = -EBUSY; + goto fifo_rate_fail; + } + result = inv_mpu6050_set_power_itg(st, true); + if (result) + goto fifo_rate_fail; + + d = INV_MPU6050_ONE_K_HZ / fifo_rate - 1; + result = inv_mpu6050_write_reg(st, st->reg->sample_rate_div, d); + if (result) + goto fifo_rate_fail; + st->chip_config.fifo_rate = fifo_rate; + + result = inv_mpu6050_set_lpf(st, fifo_rate); + if (result) + goto fifo_rate_fail; + +fifo_rate_fail: + result |= inv_mpu6050_set_power_itg(st, false); + mutex_unlock(&indio_dev->mlock); + if (result) + return result; + + return count; +} + +/** + * inv_fifo_rate_show() - Get the current sampling rate. + */ +static ssize_t inv_fifo_rate_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct inv_mpu6050_state *st = iio_priv(dev_to_iio_dev(dev)); + + return sprintf(buf, "%d\n", st->chip_config.fifo_rate); +} + +/** + * inv_attr_show() - calling this function will show current + * parameters. + */ +static ssize_t inv_attr_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct inv_mpu6050_state *st = iio_priv(dev_to_iio_dev(dev)); + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + s8 *m; + + switch (this_attr->address) { + /* In MPU6050, the two matrix are the same because gyro and accel + are integrated in one chip */ + case ATTR_GYRO_MATRIX: + case ATTR_ACCL_MATRIX: + m = st->plat_data.orientation; + + return sprintf(buf, "%d, %d, %d; %d, %d, %d; %d, %d, %d\n", + m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]); + default: + return -EINVAL; + } +} + +/** + * inv_mpu6050_validate_trigger() - validate_trigger callback for invensense + * MPU6050 device. + * @indio_dev: The IIO device + * @trig: The new trigger + * + * Returns: 0 if the 'trig' matches the trigger registered by the MPU6050 + * device, -EINVAL otherwise. + */ +static int inv_mpu6050_validate_trigger(struct iio_dev *indio_dev, + struct iio_trigger *trig) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + if (st->trig != trig) + return -EINVAL; + + return 0; +} + +#define INV_MPU6050_CHAN(_type, _channel2, _index) \ + { \ + .type = _type, \ + .modified = 1, \ + .channel2 = _channel2, \ + .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT \ + | IIO_CHAN_INFO_RAW_SEPARATE_BIT, \ + .scan_index = _index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .shift = 0 , \ + .endianness = IIO_BE, \ + }, \ + } + +static const struct iio_chan_spec inv_mpu_channels[] = { + IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP), + /* + * Note that temperature should only be via polled reading only, + * not the final scan elements output. + */ + { + .type = IIO_TEMP, + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT + | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT + | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, + .scan_index = -1, + }, + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z), + + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z), +}; + +/* constant IIO attribute */ +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 20 50 100 200 500"); +static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show, + inv_mpu6050_fifo_rate_store); +static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL, + ATTR_GYRO_MATRIX); +static IIO_DEVICE_ATTR(in_accel_matrix, S_IRUGO, inv_attr_show, NULL, + ATTR_ACCL_MATRIX); + +static struct attribute *inv_attributes[] = { + &iio_dev_attr_in_gyro_matrix.dev_attr.attr, + &iio_dev_attr_in_accel_matrix.dev_attr.attr, + &iio_dev_attr_sampling_frequency.dev_attr.attr, + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group inv_attribute_group = { + .attrs = inv_attributes +}; + +static const struct iio_info mpu_info = { + .driver_module = THIS_MODULE, + .read_raw = &inv_mpu6050_read_raw, + .write_raw = &inv_mpu6050_write_raw, + .attrs = &inv_attribute_group, + .validate_trigger = inv_mpu6050_validate_trigger, +}; + +/** + * inv_check_and_setup_chip() - check and setup chip. + */ +static int inv_check_and_setup_chip(struct inv_mpu6050_state *st, + const struct i2c_device_id *id) +{ + int result; + + st->chip_type = INV_MPU6050; + st->hw = &hw_info[st->chip_type]; + st->reg = hw_info[st->chip_type].reg; + + /* reset to make sure previous state are not there */ + result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, + INV_MPU6050_BIT_H_RESET); + if (result) + return result; + msleep(INV_MPU6050_POWER_UP_TIME); + /* toggle power state. After reset, the sleep bit could be on + or off depending on the OTP settings. Toggling power would + make it in a definite state as well as making the hardware + state align with the software state */ + result = inv_mpu6050_set_power_itg(st, false); + if (result) + return result; + result = inv_mpu6050_set_power_itg(st, true); + if (result) + return result; + + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + return result; + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + return result; + + return 0; +} + +/** + * inv_mpu_probe() - probe function. + * @client: i2c client. + * @id: i2c device id. + * + * Returns 0 on success, a negative error code otherwise. + */ +static int inv_mpu_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct inv_mpu6050_state *st; + struct iio_dev *indio_dev; + int result; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_I2C_BLOCK | + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { + result = -ENOSYS; + goto out_no_free; + } + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) { + result = -ENOMEM; + goto out_no_free; + } + st = iio_priv(indio_dev); + st->client = client; + st->plat_data = *(struct inv_mpu6050_platform_data + *)dev_get_platdata(&client->dev); + /* power is turned on inside check chip type*/ + result = inv_check_and_setup_chip(st, id); + if (result) + goto out_free; + + result = inv_mpu6050_init_config(indio_dev); + if (result) { + dev_err(&client->dev, + "Could not initialize device.\n"); + goto out_free; + } + + i2c_set_clientdata(client, indio_dev); + indio_dev->dev.parent = &client->dev; + indio_dev->name = id->name; + indio_dev->channels = inv_mpu_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); + + indio_dev->info = &mpu_info; + indio_dev->modes = INDIO_BUFFER_TRIGGERED; + + result = iio_triggered_buffer_setup(indio_dev, + inv_mpu6050_irq_handler, + inv_mpu6050_read_fifo, + NULL); + if (result) { + dev_err(&st->client->dev, "configure buffer fail %d\n", + result); + goto out_free; + } + result = inv_mpu6050_probe_trigger(indio_dev); + if (result) { + dev_err(&st->client->dev, "trigger probe fail %d\n", result); + goto out_unreg_ring; + } + + INIT_KFIFO(st->timestamps); + spin_lock_init(&st->time_stamp_lock); + result = iio_device_register(indio_dev); + if (result) { + dev_err(&st->client->dev, "IIO register fail %d\n", result); + goto out_remove_trigger; + } + + return 0; + +out_remove_trigger: + inv_mpu6050_remove_trigger(st); +out_unreg_ring: + iio_triggered_buffer_cleanup(indio_dev); +out_free: + iio_device_free(indio_dev); +out_no_free: + + return result; +} + +static int inv_mpu_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + inv_mpu6050_remove_trigger(st); + iio_triggered_buffer_cleanup(indio_dev); + iio_device_free(indio_dev); + + return 0; +} +#ifdef CONFIG_PM_SLEEP + +static int inv_mpu_resume(struct device *dev) +{ + return inv_mpu6050_set_power_itg( + iio_priv(i2c_get_clientdata(to_i2c_client(dev))), true); +} + +static int inv_mpu_suspend(struct device *dev) +{ + return inv_mpu6050_set_power_itg( + iio_priv(i2c_get_clientdata(to_i2c_client(dev))), false); +} +static SIMPLE_DEV_PM_OPS(inv_mpu_pmops, inv_mpu_suspend, inv_mpu_resume); + +#define INV_MPU6050_PMOPS (&inv_mpu_pmops) +#else +#define INV_MPU6050_PMOPS NULL +#endif /* CONFIG_PM_SLEEP */ + +/* + * device id table is used to identify what device can be + * supported by this driver + */ +static const struct i2c_device_id inv_mpu_id[] = { + {"mpu6050", INV_MPU6050}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, inv_mpu_id); + +static struct i2c_driver inv_mpu_driver = { + .probe = inv_mpu_probe, + .remove = inv_mpu_remove, + .id_table = inv_mpu_id, + .driver = { + .owner = THIS_MODULE, + .name = "inv-mpu6050", + .pm = INV_MPU6050_PMOPS, + }, +}; + +module_i2c_driver(inv_mpu_driver); + +MODULE_AUTHOR("Invensense Corporation"); +MODULE_DESCRIPTION("Invensense device MPU6050 driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h new file mode 100644 index 0000000..f383955 --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -0,0 +1,246 @@ +/* +* Copyright (C) 2012 Invensense, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* 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. +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * struct inv_mpu6050_reg_map - Notable registers. + * @sample_rate_div: Divider applied to gyro output rate. + * @lpf: Configures internal low pass filter. + * @user_ctrl: Enables/resets the FIFO. + * @fifo_en: Determines which data will appear in FIFO. + * @gyro_config: gyro config register. + * @accl_config: accel config register + * @fifo_count_h: Upper byte of FIFO count. + * @fifo_r_w: FIFO register. + * @raw_gyro: Address of first gyro register. + * @raw_accl: Address of first accel register. + * @temperature: temperature register + * @int_enable: Interrupt enable register. + * @pwr_mgmt_1: Controls chip's power state and clock source. + * @pwr_mgmt_2: Controls power state of individual sensors. + */ +struct inv_mpu6050_reg_map { + u8 sample_rate_div; + u8 lpf; + u8 user_ctrl; + u8 fifo_en; + u8 gyro_config; + u8 accl_config; + u8 fifo_count_h; + u8 fifo_r_w; + u8 raw_gyro; + u8 raw_accl; + u8 temperature; + u8 int_enable; + u8 pwr_mgmt_1; + u8 pwr_mgmt_2; +}; + +/*device enum */ +enum inv_devices { + INV_MPU6050, + INV_NUM_PARTS +}; + +/** + * struct inv_mpu6050_chip_config - Cached chip configuration data. + * @fsr: Full scale range. + * @lpf: Digital low pass filter frequency. + * @accl_fs: accel full scale range. + * @enable: master enable state. + * @accl_fifo_enable: enable accel data output + * @gyro_fifo_enable: enable gyro data output + * @fifo_rate: FIFO update rate. + */ +struct inv_mpu6050_chip_config { + unsigned int fsr:2; + unsigned int lpf:3; + unsigned int accl_fs:2; + unsigned int enable:1; + unsigned int accl_fifo_enable:1; + unsigned int gyro_fifo_enable:1; + u16 fifo_rate; +}; + +/** + * struct inv_mpu6050_hw - Other important hardware information. + * @num_reg: Number of registers on device. + * @name: name of the chip. + * @reg: register map of the chip. + * @config: configuration of the chip. + */ +struct inv_mpu6050_hw { + u8 num_reg; + u8 *name; + const struct inv_mpu6050_reg_map *reg; + const struct inv_mpu6050_chip_config *config; +}; + +/* + * struct inv_mpu6050_state - Driver state variables. + * @TIMESTAMP_FIFO_SIZE: fifo size for timestamp. + * @trig: IIO trigger. + * @chip_config: Cached attribute information. + * @reg: Map of important registers. + * @hw: Other hardware-specific information. + * @chip_type: chip type. + * @time_stamp_lock: spin lock to time stamp. + * @client: i2c client handle. + * @plat_data: platform data. + * @timestamps: kfifo queue to store time stamp. + */ +struct inv_mpu6050_state { +#define TIMESTAMP_FIFO_SIZE 16 + struct iio_trigger *trig; + struct inv_mpu6050_chip_config chip_config; + const struct inv_mpu6050_reg_map *reg; + const struct inv_mpu6050_hw *hw; + enum inv_devices chip_type; + spinlock_t time_stamp_lock; + struct i2c_client *client; + struct inv_mpu6050_platform_data plat_data; + DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE); +}; + +/*register and associated bit definition*/ +#define INV_MPU6050_REG_SAMPLE_RATE_DIV 0x19 +#define INV_MPU6050_REG_CONFIG 0x1A +#define INV_MPU6050_REG_GYRO_CONFIG 0x1B +#define INV_MPU6050_REG_ACCEL_CONFIG 0x1C + +#define INV_MPU6050_REG_FIFO_EN 0x23 +#define INV_MPU6050_BIT_ACCEL_OUT 0x08 +#define INV_MPU6050_BITS_GYRO_OUT 0x70 + +#define INV_MPU6050_REG_INT_ENABLE 0x38 +#define INV_MPU6050_BIT_DATA_RDY_EN 0x01 +#define INV_MPU6050_BIT_DMP_INT_EN 0x02 + +#define INV_MPU6050_REG_RAW_ACCEL 0x3B +#define INV_MPU6050_REG_TEMPERATURE 0x41 +#define INV_MPU6050_REG_RAW_GYRO 0x43 + +#define INV_MPU6050_REG_USER_CTRL 0x6A +#define INV_MPU6050_BIT_FIFO_RST 0x04 +#define INV_MPU6050_BIT_DMP_RST 0x08 +#define INV_MPU6050_BIT_I2C_MST_EN 0x20 +#define INV_MPU6050_BIT_FIFO_EN 0x40 +#define INV_MPU6050_BIT_DMP_EN 0x80 + +#define INV_MPU6050_REG_PWR_MGMT_1 0x6B +#define INV_MPU6050_BIT_H_RESET 0x80 +#define INV_MPU6050_BIT_SLEEP 0x40 +#define INV_MPU6050_BIT_CLK_MASK 0x7 + +#define INV_MPU6050_REG_PWR_MGMT_2 0x6C +#define INV_MPU6050_BIT_PWR_ACCL_STBY 0x38 +#define INV_MPU6050_BIT_PWR_GYRO_STBY 0x07 + +#define INV_MPU6050_REG_FIFO_COUNT_H 0x72 +#define INV_MPU6050_REG_FIFO_R_W 0x74 + +#define INV_MPU6050_BYTES_PER_3AXIS_SENSOR 6 +#define INV_MPU6050_FIFO_COUNT_BYTE 2 +#define INV_MPU6050_FIFO_THRESHOLD 500 +#define INV_MPU6050_POWER_UP_TIME 100 +#define INV_MPU6050_TEMP_UP_TIME 100 +#define INV_MPU6050_SENSOR_UP_TIME 30 +#define INV_MPU6050_REG_UP_TIME 5 + +#define INV_MPU6050_TEMP_OFFSET 12421 +#define INV_MPU6050_TEMP_SCALE 2941 +#define INV_MPU6050_MAX_GYRO_FS_PARAM 3 +#define INV_MPU6050_MAX_ACCL_FS_PARAM 3 +#define INV_MPU6050_THREE_AXIS 3 +#define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT 3 +#define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT 3 + +/* 6 + 6 round up and plus 8 */ +#define INV_MPU6050_OUTPUT_DATA_SIZE 24 + +/* init parameters */ +#define INV_MPU6050_INIT_FIFO_RATE 50 +#define INV_MPU6050_TIME_STAMP_TOR 5 +#define INV_MPU6050_MAX_FIFO_RATE 1000 +#define INV_MPU6050_MIN_FIFO_RATE 4 +#define INV_MPU6050_ONE_K_HZ 1000 + +/* scan element definition */ +enum inv_mpu6050_scan { + INV_MPU6050_SCAN_ACCL_X, + INV_MPU6050_SCAN_ACCL_Y, + INV_MPU6050_SCAN_ACCL_Z, + INV_MPU6050_SCAN_GYRO_X, + INV_MPU6050_SCAN_GYRO_Y, + INV_MPU6050_SCAN_GYRO_Z, + INV_MPU6050_SCAN_TIMESTAMP, +}; + +enum inv_mpu6050_filter_e { + INV_MPU6050_FILTER_256HZ_NOLPF2 = 0, + INV_MPU6050_FILTER_188HZ, + INV_MPU6050_FILTER_98HZ, + INV_MPU6050_FILTER_42HZ, + INV_MPU6050_FILTER_20HZ, + INV_MPU6050_FILTER_10HZ, + INV_MPU6050_FILTER_5HZ, + INV_MPU6050_FILTER_2100HZ_NOLPF, + NUM_MPU6050_FILTER +}; + +/* IIO attribute address */ +enum INV_MPU6050_IIO_ATTR_ADDR { + ATTR_GYRO_MATRIX, + ATTR_ACCL_MATRIX, +}; + +enum inv_mpu6050_accl_fs_e { + INV_MPU6050_FS_02G = 0, + INV_MPU6050_FS_04G, + INV_MPU6050_FS_08G, + INV_MPU6050_FS_16G, + NUM_ACCL_FSR +}; + +enum inv_mpu6050_fsr_e { + INV_MPU6050_FSR_250DPS = 0, + INV_MPU6050_FSR_500DPS, + INV_MPU6050_FSR_1000DPS, + INV_MPU6050_FSR_2000DPS, + NUM_MPU6050_FSR +}; + +enum inv_mpu6050_clock_sel_e { + INV_CLK_INTERNAL = 0, + INV_CLK_PLL, + NUM_CLK +}; + +irqreturn_t inv_mpu6050_irq_handler(int irq, void *p); +irqreturn_t inv_mpu6050_read_fifo(int irq, void *p); +int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev); +void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st); +int inv_reset_fifo(struct iio_dev *indio_dev); +int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask); +int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val); +int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c new file mode 100644 index 0000000..331781f --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -0,0 +1,196 @@ +/* +* Copyright (C) 2012 Invensense, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "inv_mpu_iio.h" + +int inv_reset_fifo(struct iio_dev *indio_dev) +{ + int result; + u8 d; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + /* disable interrupt */ + result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0); + if (result) { + dev_err(&st->client->dev, "int_enable failed %d\n", result); + return result; + } + /* disable the sensor output to FIFO */ + result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0); + if (result) + goto reset_fifo_fail; + /* disable fifo reading */ + result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0); + if (result) + goto reset_fifo_fail; + + /* reset FIFO*/ + result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, + INV_MPU6050_BIT_FIFO_RST); + if (result) + goto reset_fifo_fail; + /* enable interrupt */ + if (st->chip_config.accl_fifo_enable || + st->chip_config.gyro_fifo_enable) { + result = inv_mpu6050_write_reg(st, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN); + if (result) + return result; + } + /* enable FIFO reading and I2C master interface*/ + result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, + INV_MPU6050_BIT_FIFO_EN); + if (result) + goto reset_fifo_fail; + /* enable sensor output to FIFO */ + d = 0; + if (st->chip_config.gyro_fifo_enable) + d |= INV_MPU6050_BITS_GYRO_OUT; + if (st->chip_config.accl_fifo_enable) + d |= INV_MPU6050_BIT_ACCEL_OUT; + result = inv_mpu6050_write_reg(st, st->reg->fifo_en, d); + if (result) + goto reset_fifo_fail; + + return 0; + +reset_fifo_fail: + dev_err(&st->client->dev, "reset fifo failed %d\n", result); + result = inv_mpu6050_write_reg(st, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN); + + return result; +} + +static void inv_clear_kfifo(struct inv_mpu6050_state *st) +{ + unsigned long flags; + + /* take the spin lock sem to avoid interrupt kick in */ + spin_lock_irqsave(&st->time_stamp_lock, flags); + kfifo_reset(&st->timestamps); + spin_unlock_irqrestore(&st->time_stamp_lock, flags); +} + +/** + * inv_mpu6050_irq_handler() - Cache a timestamp at each data ready interrupt. + */ +irqreturn_t inv_mpu6050_irq_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + s64 timestamp; + + timestamp = iio_get_time_ns(); + spin_lock(&st->time_stamp_lock); + kfifo_in(&st->timestamps, ×tamp, 1); + spin_unlock(&st->time_stamp_lock); + + return IRQ_WAKE_THREAD; +} + +/** + * inv_mpu6050_read_fifo() - Transfer data from hardware FIFO to KFIFO. + */ +irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + size_t bytes_per_datum; + int result; + u8 data[INV_MPU6050_OUTPUT_DATA_SIZE]; + u16 fifo_count; + s64 timestamp; + u64 *tmp; + + mutex_lock(&indio_dev->mlock); + if (!(st->chip_config.accl_fifo_enable | + st->chip_config.gyro_fifo_enable)) + goto end_session; + bytes_per_datum = 0; + if (st->chip_config.accl_fifo_enable) + bytes_per_datum += INV_MPU6050_BYTES_PER_3AXIS_SENSOR; + + if (st->chip_config.gyro_fifo_enable) + bytes_per_datum += INV_MPU6050_BYTES_PER_3AXIS_SENSOR; + + /* + * read fifo_count register to know how many bytes inside FIFO + * right now + */ + result = i2c_smbus_read_i2c_block_data(st->client, + st->reg->fifo_count_h, + INV_MPU6050_FIFO_COUNT_BYTE, data); + if (result != INV_MPU6050_FIFO_COUNT_BYTE) + goto end_session; + fifo_count = be16_to_cpup((__be16 *)(&data[0])); + if (fifo_count < bytes_per_datum) + goto end_session; + /* fifo count can't be odd number, if it is odd, reset fifo*/ + if (fifo_count & 1) + goto flush_fifo; + if (fifo_count > INV_MPU6050_FIFO_THRESHOLD) + goto flush_fifo; + /* Timestamp mismatch. */ + if (kfifo_len(&st->timestamps) > + fifo_count / bytes_per_datum + INV_MPU6050_TIME_STAMP_TOR) + goto flush_fifo; + while (fifo_count >= bytes_per_datum) { + result = i2c_smbus_read_i2c_block_data(st->client, + st->reg->fifo_r_w, + bytes_per_datum, data); + if (result != bytes_per_datum) + goto flush_fifo; + + result = kfifo_out(&st->timestamps, ×tamp, 1); + /* when there is no timestamp, put timestamp as 0 */ + if (0 == result) + timestamp = 0; + + tmp = (u64 *)data; + tmp[DIV_ROUND_UP(bytes_per_datum, 8)] = timestamp; + result = iio_push_to_buffers(indio_dev, data); + if (result) + goto flush_fifo; + fifo_count -= bytes_per_datum; + } + +end_session: + mutex_unlock(&indio_dev->mlock); + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; + +flush_fifo: + /* Flush HW and SW FIFOs. */ + inv_reset_fifo(indio_dev); + inv_clear_kfifo(st); + mutex_unlock(&indio_dev->mlock); + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c new file mode 100644 index 0000000..e1d0869 --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -0,0 +1,155 @@ +/* +* Copyright (C) 2012 Invensense, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* 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. +*/ + +#include "inv_mpu_iio.h" + +static void inv_scan_query(struct iio_dev *indio_dev) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + st->chip_config.gyro_fifo_enable = + test_bit(INV_MPU6050_SCAN_GYRO_X, + indio_dev->active_scan_mask) || + test_bit(INV_MPU6050_SCAN_GYRO_Y, + indio_dev->active_scan_mask) || + test_bit(INV_MPU6050_SCAN_GYRO_Z, + indio_dev->active_scan_mask); + + st->chip_config.accl_fifo_enable = + test_bit(INV_MPU6050_SCAN_ACCL_X, + indio_dev->active_scan_mask) || + test_bit(INV_MPU6050_SCAN_ACCL_Y, + indio_dev->active_scan_mask) || + test_bit(INV_MPU6050_SCAN_ACCL_Z, + indio_dev->active_scan_mask); +} + +/** + * inv_mpu6050_set_enable() - enable chip functions. + * @indio_dev: Device driver instance. + * @enable: enable/disable + */ +static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + int result; + + if (enable) { + result = inv_mpu6050_set_power_itg(st, true); + if (result) + return result; + inv_scan_query(indio_dev); + if (st->chip_config.gyro_fifo_enable) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + return result; + } + if (st->chip_config.accl_fifo_enable) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + return result; + } + result = inv_reset_fifo(indio_dev); + if (result) + return result; + } else { + result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0); + if (result) + return result; + + result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0); + if (result) + return result; + + result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0); + if (result) + return result; + + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + return result; + + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + return result; + result = inv_mpu6050_set_power_itg(st, false); + if (result) + return result; + } + st->chip_config.enable = enable; + + return 0; +} + +/** + * inv_mpu_data_rdy_trigger_set_state() - set data ready interrupt state + * @trig: Trigger instance + * @state: Desired trigger state + */ +static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + return inv_mpu6050_set_enable(trig->private_data, state); +} + +static const struct iio_trigger_ops inv_mpu_trigger_ops = { + .owner = THIS_MODULE, + .set_trigger_state = &inv_mpu_data_rdy_trigger_set_state, +}; + +int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev) +{ + int ret; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + st->trig = iio_trigger_alloc("%s-dev%d", + indio_dev->name, + indio_dev->id); + if (st->trig == NULL) { + ret = -ENOMEM; + goto error_ret; + } + ret = request_irq(st->client->irq, &iio_trigger_generic_data_rdy_poll, + IRQF_TRIGGER_RISING, + "inv_mpu", + st->trig); + if (ret) + goto error_free_trig; + st->trig->dev.parent = &st->client->dev; + st->trig->private_data = indio_dev; + st->trig->ops = &inv_mpu_trigger_ops; + ret = iio_trigger_register(st->trig); + if (ret) + goto error_free_irq; + indio_dev->trig = st->trig; + + return 0; + +error_free_irq: + free_irq(st->client->irq, st->trig); +error_free_trig: + iio_trigger_free(st->trig); +error_ret: + return ret; +} + +void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st) +{ + iio_trigger_unregister(st->trig); + free_irq(st->client->irq, st->trig); + iio_trigger_free(st->trig); +} diff --git a/include/linux/platform_data/invensense_mpu6050.h b/include/linux/platform_data/invensense_mpu6050.h new file mode 100644 index 0000000..ad3aa7b --- /dev/null +++ b/include/linux/platform_data/invensense_mpu6050.h @@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 Invensense, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* 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. +*/ + +#ifndef __INV_MPU6050_PLATFORM_H_ +#define __INV_MPU6050_PLATFORM_H_ + +/** + * struct inv_mpu6050_platform_data - Platform data for the mpu driver + * @orientation: Orientation matrix of the chip + * + * Contains platform specific information on how to configure the MPU6050 to + * work on this platform. The orientation matricies are 3x3 rotation matricies + * that are applied to the data to rotate from the mounting orientation to the + * platform orientation. The values must be one of 0, 1, or -1 and each row and + * column should have exactly 1 non-zero value. + */ +struct inv_mpu6050_platform_data { + __s8 orientation[9]; +}; + +#endif -- cgit v0.10.2 From 78110bb8dc4a7ff331bfa3cfe7d4e287cfb3f22b Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 11 Feb 2013 09:41:29 -0800 Subject: staging: Remove unnecessary OOM messages alloc failures already get standardized OOM messages and a dump_stack. For the affected mallocs around these OOM messages: Converted kzallocs with multiplies to kcalloc. Converted kmallocs with multiplies to kmalloc_array. Converted a kmalloc/strlen/strncpy to kstrdup. Moved a spin_lock below a removed OOM message and removed a now unnecessary spin_unlock. Neatened alignment and whitespace. Signed-off-by: Joe Perches Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/asus_oled/asus_oled.c b/drivers/staging/asus_oled/asus_oled.c index 0018547..d0a5a28 100644 --- a/drivers/staging/asus_oled/asus_oled.c +++ b/drivers/staging/asus_oled/asus_oled.c @@ -164,11 +164,8 @@ static void enable_oled(struct asus_oled_dev *odev, uint8_t enabl) struct asus_oled_packet *packet; packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); - - if (!packet) { - dev_err(&odev->udev->dev, "out of memory\n"); + if (!packet) return; - } setup_packet_header(packet, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00); @@ -323,11 +320,8 @@ static void send_data(struct asus_oled_dev *odev) struct asus_oled_packet *packet; packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); - - if (!packet) { - dev_err(&odev->udev->dev, "out of memory\n"); + if (!packet) return; - } if (odev->pack_mode == PACK_MODE_G1) { /* When sending roll-mode data the display updated only @@ -665,11 +659,8 @@ static int asus_oled_probe(struct usb_interface *interface, } odev = kzalloc(sizeof(struct asus_oled_dev), GFP_KERNEL); - - if (odev == NULL) { - dev_err(&interface->dev, "Out of memory\n"); + if (odev == NULL) return -ENOMEM; - } odev->udev = usb_get_dev(udev); odev->pic_mode = ASUS_OLED_STATIC; diff --git a/drivers/staging/bcm/InterfaceInit.c b/drivers/staging/bcm/InterfaceInit.c index eb24643..79058ce 100644 --- a/drivers/staging/bcm/InterfaceInit.c +++ b/drivers/staging/bcm/InterfaceInit.c @@ -190,9 +190,9 @@ static int usbbcm_device_probe(struct usb_interface *intf, const struct usb_devi } /* Allocate interface adapter structure */ - psIntfAdapter = kzalloc(sizeof(struct bcm_interface_adapter), GFP_KERNEL); + psIntfAdapter = kzalloc(sizeof(struct bcm_interface_adapter), + GFP_KERNEL); if (psIntfAdapter == NULL) { - dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n"); AdapterFree(psAdapter); return -ENOMEM; } @@ -564,11 +564,8 @@ static int InterfaceAdapterInit(struct bcm_interface_adapter *psIntfAdapter) psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval; psIntfAdapter->sIntrIn.int_in_buffer = kmalloc(buffer_size, GFP_KERNEL); - if (!psIntfAdapter->sIntrIn.int_in_buffer) { - dev_err(&psIntfAdapter->udev->dev, - "could not allocate interrupt_in_buffer\n"); + if (!psIntfAdapter->sIntrIn.int_in_buffer) return -EINVAL; - } } if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) { @@ -587,11 +584,8 @@ static int InterfaceAdapterInit(struct bcm_interface_adapter *psIntfAdapter) psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress; psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval; psIntfAdapter->sIntrOut.int_out_buffer = kmalloc(buffer_size, GFP_KERNEL); - if (!psIntfAdapter->sIntrOut.int_out_buffer) { - dev_err(&psIntfAdapter->udev->dev, - "could not allocate interrupt_out_buffer\n"); + if (!psIntfAdapter->sIntrOut.int_out_buffer) return -EINVAL; - } } } } diff --git a/drivers/staging/ced1401/usb1401.c b/drivers/staging/ced1401/usb1401.c index 60bed3e..254131d 100644 --- a/drivers/staging/ced1401/usb1401.c +++ b/drivers/staging/ced1401/usb1401.c @@ -1391,10 +1391,8 @@ static int ced_probe(struct usb_interface *interface, // allocate memory for our device extension and initialize it pdx = kzalloc(sizeof(*pdx), GFP_KERNEL); - if (!pdx) { - dev_err(&interface->dev, "Out of memory\n"); + if (!pdx) goto error; - } for (i = 0; i < MAX_TRANSAREAS; ++i) // Initialise the wait queues { diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index e57e661..64be7c5 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -203,10 +203,9 @@ static int __comedi_device_postconfig_async(struct comedi_device *dev, } async = kzalloc(sizeof(*async), GFP_KERNEL); - if (!async) { - dev_warn(dev->class_dev, "failed to allocate async struct\n"); + if (!async) return -ENOMEM; - } + init_waitqueue_head(&async->wait_head); async->subdevice = s; s->async = async; diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c index b30d1a0..7c53dea 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.c +++ b/drivers/staging/comedi/drivers/amplc_dio200.c @@ -1105,10 +1105,9 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s, struct dio200_subdev_intr *subpriv; subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); - if (!subpriv) { - dev_err(dev->class_dev, "error! out of memory!\n"); + if (!subpriv) return -ENOMEM; - } + subpriv->ofs = offset; subpriv->valid_isns = valid_isns; spin_lock_init(&subpriv->spinlock); @@ -1444,10 +1443,8 @@ dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int chan; subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); - if (!subpriv) { - dev_err(dev->class_dev, "error! out of memory!\n"); + if (!subpriv) return -ENOMEM; - } s->private = subpriv; s->type = COMEDI_SUBD_COUNTER; diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c index 3151599..1bb5381 100644 --- a/drivers/staging/comedi/drivers/comedi_bond.c +++ b/drivers/staging/comedi/drivers/comedi_bond.c @@ -245,10 +245,9 @@ static int doDevConfig(struct comedi_device *dev, struct comedi_devconfig *it) return 0; } bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); - if (!bdev) { - dev_err(dev->class_dev, "Out of memory\n"); + if (!bdev) return 0; - } + bdev->dev = d; bdev->minor = minor; bdev->subdev = sdev; diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index fc5b30c..192cf08 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -702,10 +702,9 @@ static int dt9812_probe(struct usb_interface *interface, /* allocate memory for our device state and initialize it */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) { - dev_err(&interface->dev, "Out of memory\n"); + if (dev == NULL) goto error; - } + kref_init(&dev->kref); dev->udev = usb_get_dev(interface_to_usbdev(interface)); diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index f851c54..f957b88 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -570,13 +570,11 @@ int labpc_common_attach(struct comedi_device *dev, unsigned long iobase, return -EINVAL; } else if (dma_chan) { /* allocate dma buffer */ - devpriv->dma_buffer = - kmalloc(dma_buffer_size, GFP_KERNEL | GFP_DMA); - if (devpriv->dma_buffer == NULL) { - dev_err(dev->class_dev, - "failed to allocate dma buffer\n"); + devpriv->dma_buffer = kmalloc(dma_buffer_size, + GFP_KERNEL | GFP_DMA); + if (devpriv->dma_buffer == NULL) return -ENOMEM; - } + if (request_dma(dma_chan, DRV_NAME)) { dev_err(dev->class_dev, "failed to allocate dma channel %u\n", diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index 71ef3f9..433270c 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c @@ -838,14 +838,11 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) chans_left = CHANS_PER_ASIC * board->num_asics; n_subdevs = CALC_N_SUBDEVS(chans_left); - devpriv->sprivs = - kcalloc(n_subdevs, sizeof(struct pcmuio_subdev_private), - GFP_KERNEL); - if (!devpriv->sprivs) { - dev_warn(dev->class_dev, - "cannot allocate subdevice private data structures\n"); + devpriv->sprivs = kcalloc(n_subdevs, + sizeof(struct pcmuio_subdev_private), + GFP_KERNEL); + if (!devpriv->sprivs) return -ENOMEM; - } ret = comedi_alloc_subdevices(dev, n_subdevs); if (ret) diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c index c9ded93..74b974b 100644 --- a/drivers/staging/comedi/drivers/unioxx5.c +++ b/drivers/staging/comedi/drivers/unioxx5.c @@ -380,12 +380,8 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev, } usp = kzalloc(sizeof(*usp), GFP_KERNEL); - - if (usp == NULL) { - dev_err(subdev->class_dev, - "comedi%d: error! --> out of memory!\n", minor); + if (usp == NULL) return -1; - } usp->usp_iobase = subdev_iobase; dev_info(subdev->class_dev, "comedi%d: |", minor); diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c index 7c2f856..1a0062a 100644 --- a/drivers/staging/comedi/drivers/usbdux.c +++ b/drivers/staging/comedi/drivers/usbdux.c @@ -2445,8 +2445,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, /* create space for the commands of the DA converter */ usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); if (!usbduxsub[index].dac_commands) { - dev_err(dev, "comedi_: usbdux: " - "error alloc space for dac commands\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2454,8 +2452,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, /* create space for the commands going to the usb device */ usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); if (!usbduxsub[index].dux_commands) { - dev_err(dev, "comedi_: usbdux: " - "error alloc space for dux commands\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2463,8 +2459,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, /* create space for the in buffer and set it to zero */ usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxsub[index].inBuffer)) { - dev_err(dev, "comedi_: usbdux: " - "could not alloc space for inBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2472,8 +2466,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, /* create space of the instruction buffer */ usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); if (!(usbduxsub[index].insnBuffer)) { - dev_err(dev, "comedi_: usbdux: " - "could not alloc space for insnBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2481,8 +2473,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, /* create space for the outbuffer */ usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); if (!(usbduxsub[index].outBuffer)) { - dev_err(dev, "comedi_: usbdux: " - "could not alloc space for outBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2504,10 +2494,9 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; usbduxsub[index].urbIn = - kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfInBuffers, - GFP_KERNEL); + kcalloc(usbduxsub[index].numOfInBuffers, sizeof(struct urb *), + GFP_KERNEL); if (!(usbduxsub[index].urbIn)) { - dev_err(dev, "comedi_: usbdux: Could not alloc. urbIn array\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2532,8 +2521,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, usbduxsub[index].urbIn[i]->transfer_buffer = kzalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) { - dev_err(dev, "comedi_: usbdux%d: " - "could not alloc. transb.\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2552,11 +2539,9 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; usbduxsub[index].urbOut = - kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfOutBuffers, - GFP_KERNEL); + kcalloc(usbduxsub[index].numOfOutBuffers, sizeof(struct urb *), + GFP_KERNEL); if (!(usbduxsub[index].urbOut)) { - dev_err(dev, "comedi_: usbdux: " - "Could not alloc. urbOut array\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2581,8 +2566,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, usbduxsub[index].urbOut[i]->transfer_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) { - dev_err(dev, "comedi_: usbdux%d: " - "could not alloc. transb.\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2617,8 +2600,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, usbduxsub[index].urbPwm->transfer_buffer = kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL); if (!(usbduxsub[index].urbPwm->transfer_buffer)) { - dev_err(dev, "comedi_: usbdux%d: " - "could not alloc. transb. for pwm\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c index 0f6187f..4bf5dd0 100644 --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -1556,8 +1556,6 @@ static int usbduxfast_usb_probe(struct usb_interface *uinterf, usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER, GFP_KERNEL); if (!usbduxfastsub[index].dux_commands) { - dev_err(&uinterf->dev, - "error alloc space for dac commands\n"); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -1565,8 +1563,6 @@ static int usbduxfast_usb_probe(struct usb_interface *uinterf, /* create space of the instruction buffer */ usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); if (!usbduxfastsub[index].insnBuffer) { - dev_err(&uinterf->dev, - "could not alloc space for insnBuffer\n"); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -1592,8 +1588,6 @@ static int usbduxfast_usb_probe(struct usb_interface *uinterf, } usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL); if (!usbduxfastsub[index].transfer_buffer) { - dev_err(&uinterf->dev, - "usbduxfast%d: could not alloc. transb.\n", index); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); return -ENOMEM; diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c index dc6b017..d066351 100644 --- a/drivers/staging/comedi/drivers/usbduxsigma.c +++ b/drivers/staging/comedi/drivers/usbduxsigma.c @@ -2431,8 +2431,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, /* create space for the commands of the DA converter */ usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); if (!usbduxsub[index].dac_commands) { - dev_err(dev, "comedi_: usbduxsigma: " - "error alloc space for dac commands\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2440,8 +2438,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, /* create space for the commands going to the usb device */ usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); if (!usbduxsub[index].dux_commands) { - dev_err(dev, "comedi_: usbduxsigma: " - "error alloc space for dux commands\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2449,8 +2445,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, /* create space for the in buffer and set it to zero */ usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxsub[index].inBuffer)) { - dev_err(dev, "comedi_: usbduxsigma: " - "could not alloc space for inBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2458,8 +2452,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, /* create space of the instruction buffer */ usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); if (!(usbduxsub[index].insnBuffer)) { - dev_err(dev, "comedi_: usbduxsigma: " - "could not alloc space for insnBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2467,8 +2459,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, /* create space for the outbuffer */ usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); if (!(usbduxsub[index].outBuffer)) { - dev_err(dev, "comedi_: usbduxsigma: " - "could not alloc space for outBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2489,12 +2479,10 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, else usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; - usbduxsub[index].urbIn = - kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfInBuffers, - GFP_KERNEL); + usbduxsub[index].urbIn = kcalloc(usbduxsub[index].numOfInBuffers, + sizeof(struct urb *), + GFP_KERNEL); if (!(usbduxsub[index].urbIn)) { - dev_err(dev, "comedi_: usbduxsigma: " - "Could not alloc. urbIn array\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2519,8 +2507,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, usbduxsub[index].urbIn[i]->transfer_buffer = kzalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "could not alloc. transb.\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2539,12 +2525,9 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, else usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; - usbduxsub[index].urbOut = - kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfOutBuffers, - GFP_KERNEL); + usbduxsub[index].urbOut = kcalloc(usbduxsub[index].numOfOutBuffers, + sizeof(struct urb *), GFP_KERNEL); if (!(usbduxsub[index].urbOut)) { - dev_err(dev, "comedi_: usbduxsigma: " - "Could not alloc. urbOut array\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2569,8 +2552,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, usbduxsub[index].urbOut[i]->transfer_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "could not alloc. transb.\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; @@ -2606,8 +2587,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf, usbduxsub[index].urbPwm->transfer_buffer = kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL); if (!(usbduxsub[index].urbPwm->transfer_buffer)) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "could not alloc. transb. for pwm\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); return -ENOMEM; diff --git a/drivers/staging/cptm1217/clearpad_tm1217.c b/drivers/staging/cptm1217/clearpad_tm1217.c index a49b0da..31fb5d3 100644 --- a/drivers/staging/cptm1217/clearpad_tm1217.c +++ b/drivers/staging/cptm1217/clearpad_tm1217.c @@ -421,11 +421,8 @@ static int cp_tm1217_probe(struct i2c_client *client, pdata = client->dev.platform_data; ts = kzalloc(sizeof(struct cp_tm1217_device), GFP_KERNEL); - if (!ts) { - dev_err(&client->dev, - "cp_tm1217: Private Device Struct alloc failed\n"); + if (!ts) return -ENOMEM; - } ts->client = client; ts->dev = &client->dev; diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index 4a7c302..ebf5e49 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -2462,11 +2462,8 @@ static int et131x_init_recv(struct et131x_adapter *adapter) /* Setup each RFD */ for (rfdct = 0; rfdct < rx_ring->num_rfd; rfdct++) { rfd = kzalloc(sizeof(struct rfd), GFP_ATOMIC | GFP_DMA); - - if (!rfd) { - dev_err(&adapter->pdev->dev, "Couldn't alloc RFD\n"); + if (!rfd) return -ENOMEM; - } rfd->skb = NULL; @@ -2814,12 +2811,10 @@ static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter) struct tx_ring *tx_ring = &adapter->tx_ring; /* Allocate memory for the TCB's (Transmit Control Block) */ - adapter->tx_ring.tcb_ring = - kcalloc(NUM_TCB, sizeof(struct tcb), GFP_ATOMIC | GFP_DMA); - if (!adapter->tx_ring.tcb_ring) { - dev_err(&adapter->pdev->dev, "Cannot alloc memory for TCBs\n"); + adapter->tx_ring.tcb_ring = kcalloc(NUM_TCB, sizeof(struct tcb), + GFP_ATOMIC | GFP_DMA); + if (!adapter->tx_ring.tcb_ring) return -ENOMEM; - } desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX); tx_ring->tx_desc_ring = @@ -4895,11 +4890,10 @@ static int et131x_pci_setup(struct pci_dev *pdev, adapter->mii_bus->read = et131x_mdio_read; adapter->mii_bus->write = et131x_mdio_write; adapter->mii_bus->reset = et131x_mdio_reset; - adapter->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); - if (!adapter->mii_bus->irq) { - dev_err(&pdev->dev, "mii_bus irq allocation failed\n"); + adapter->mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), + GFP_KERNEL); + if (!adapter->mii_bus->irq) goto err_mdio_free; - } for (ii = 0; ii < PHY_MAX_ADDR; ii++) adapter->mii_bus->irq[ii] = PHY_POLL; diff --git a/drivers/staging/frontier/alphatrack.c b/drivers/staging/frontier/alphatrack.c index 33085782..ea9362d 100644 --- a/drivers/staging/frontier/alphatrack.c +++ b/drivers/staging/frontier/alphatrack.c @@ -678,10 +678,9 @@ static int usb_alphatrack_probe(struct usb_interface *intf, /* allocate memory for our device state and initialize it */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) { - dev_err(&intf->dev, "Out of memory\n"); + if (dev == NULL) goto exit; - } + mutex_init(&dev->mtx); dev->intf = intf; init_waitqueue_head(&dev->read_wait); @@ -721,28 +720,21 @@ static int usb_alphatrack_probe(struct usb_interface *intf, /* FIXME - there are more usb_alloc routines for dma correctness. Needed? */ - dev->ring_buffer = - kmalloc((true_size * sizeof(struct alphatrack_icmd)), GFP_KERNEL); - - if (!dev->ring_buffer) { - dev_err(&intf->dev, - "Couldn't allocate input ring_buffer of size %d\n", - true_size); + dev->ring_buffer = kmalloc_array(true_size, + sizeof(struct alphatrack_icmd), + GFP_KERNEL); + if (!dev->ring_buffer) goto error; - } - dev->interrupt_in_buffer = - kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); - - if (!dev->interrupt_in_buffer) { - dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n"); + dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, + GFP_KERNEL); + if (!dev->interrupt_in_buffer) goto error; - } + dev->oldi_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); - if (!dev->oldi_buffer) { - dev_err(&intf->dev, "Couldn't allocate old buffer\n"); + if (!dev->oldi_buffer) goto error; - } + dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_in_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); @@ -764,20 +756,17 @@ static int usb_alphatrack_probe(struct usb_interface *intf, true_size = min(write_buffer_size, WRITE_BUFFER_SIZE); dev->interrupt_out_buffer = - kmalloc(true_size * dev->interrupt_out_endpoint_size, GFP_KERNEL); - - if (!dev->interrupt_out_buffer) { - dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n"); + kmalloc_array(true_size, + dev->interrupt_out_endpoint_size, + GFP_KERNEL); + if (!dev->interrupt_out_buffer) goto error; - } - - dev->write_buffer = - kmalloc(true_size * sizeof(struct alphatrack_ocmd), GFP_KERNEL); - if (!dev->write_buffer) { - dev_err(&intf->dev, "Couldn't allocate write_buffer\n"); + dev->write_buffer = kmalloc_array(true_size, + sizeof(struct alphatrack_ocmd), + GFP_KERNEL); + if (!dev->write_buffer) goto error; - } dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_out_urb) { diff --git a/drivers/staging/frontier/tranzport.c b/drivers/staging/frontier/tranzport.c index 5196a4e..04b5e66 100644 --- a/drivers/staging/frontier/tranzport.c +++ b/drivers/staging/frontier/tranzport.c @@ -803,10 +803,9 @@ static int usb_tranzport_probe(struct usb_interface *intf, /* allocate memory for our device state and initialize it */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) { - dev_err(&intf->dev, "Out of memory\n"); + if (dev == NULL) goto exit; - } + mutex_init(&dev->mtx); dev->intf = intf; init_waitqueue_head(&dev->read_wait); @@ -848,18 +847,14 @@ static int usb_tranzport_probe(struct usb_interface *intf, dev->ring_buffer = kmalloc((true_size * sizeof(struct tranzport_cmd)) + 8, GFP_KERNEL); - - if (!dev->ring_buffer) { - dev_err(&intf->dev, - "Couldn't allocate ring_buffer size %d\n", true_size); + if (!dev->ring_buffer) goto error; - } + dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); - if (!dev->interrupt_in_buffer) { - dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n"); + if (!dev->interrupt_in_buffer) goto error; - } + dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_in_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); @@ -875,12 +870,11 @@ static int usb_tranzport_probe(struct usb_interface *intf, "Interrupt out endpoint size is not 8!)\n"); dev->interrupt_out_buffer = - kmalloc(write_buffer_size * dev->interrupt_out_endpoint_size, - GFP_KERNEL); - if (!dev->interrupt_out_buffer) { - dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n"); + kmalloc_array(write_buffer_size, + dev->interrupt_out_endpoint_size, GFP_KERNEL); + if (!dev->interrupt_out_buffer) goto error; - } + dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_out_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n"); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c index 1bf3792..614db55 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c @@ -68,11 +68,8 @@ static int ft1000_probe(struct usb_interface *interface, const struct firmware *dsp_fw; ft1000dev = kzalloc(sizeof(struct ft1000_usb), GFP_KERNEL); - - if (!ft1000dev) { - pr_err("out of memory allocating device structure\n"); + if (!ft1000dev) return -ENOMEM; - } dev = interface_to_usbdev(interface); DEBUG("ft1000_probe: usb device descriptor info:\n"); diff --git a/drivers/staging/gdm72xx/gdm_sdio.c b/drivers/staging/gdm72xx/gdm_sdio.c index 8b8ed98..695762b 100644 --- a/drivers/staging/gdm72xx/gdm_sdio.c +++ b/drivers/staging/gdm72xx/gdm_sdio.c @@ -156,10 +156,8 @@ static int init_sdio(struct sdiowm_dev *sdev) spin_lock_init(&tx->lock); tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL); - if (tx->sdu_buf == NULL) { - dev_err(&sdev->func->dev, "Failed to allocate SDU tx buffer.\n"); + if (tx->sdu_buf == NULL) goto fail; - } for (i = 0; i < MAX_NR_SDU_BUF; i++) { t = alloc_tx_struct(tx); @@ -185,10 +183,8 @@ static int init_sdio(struct sdiowm_dev *sdev) } rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL); - if (rx->rx_buf == NULL) { - dev_err(&sdev->func->dev, "Failed to allocate rx buffer.\n"); + if (rx->rx_buf == NULL) goto fail; - } return 0; diff --git a/drivers/staging/gdm72xx/sdio_boot.c b/drivers/staging/gdm72xx/sdio_boot.c index 6291829..93046dd 100644 --- a/drivers/staging/gdm72xx/sdio_boot.c +++ b/drivers/staging/gdm72xx/sdio_boot.c @@ -72,10 +72,8 @@ static int download_image(struct sdio_func *func, const char *img_name) } buf = kmalloc(DOWNLOAD_SIZE + TYPE_A_HEADER_SIZE, GFP_KERNEL); - if (buf == NULL) { - dev_err(&func->dev, "Error: kmalloc\n"); + if (buf == NULL) return -ENOMEM; - } img_len = firm->size; @@ -141,11 +139,8 @@ int sdio_boot(struct sdio_func *func) const char *rfs_name = FW_DIR FW_RFS; tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL); - if (tx_buf == NULL) { - dev_err(&func->dev, "Error: kmalloc: %s %d\n", - __func__, __LINE__); + if (tx_buf == NULL) return -ENOMEM; - } ret = download_image(func, krn_name); if (ret) diff --git a/drivers/staging/gdm72xx/usb_boot.c b/drivers/staging/gdm72xx/usb_boot.c index 3e2103a..0d45eb6 100644 --- a/drivers/staging/gdm72xx/usb_boot.c +++ b/drivers/staging/gdm72xx/usb_boot.c @@ -158,10 +158,8 @@ int usb_boot(struct usb_device *usbdev, u16 pid) } tx_buf = kmalloc(DOWNLOAD_SIZE, GFP_KERNEL); - if (tx_buf == NULL) { - dev_err(&usbdev->dev, "Error: kmalloc\n"); + if (tx_buf == NULL) return -ENOMEM; - } if (firm->size < sizeof(hdr)) { dev_err(&usbdev->dev, "Cannot read the image info.\n"); @@ -301,10 +299,8 @@ static int em_download_image(struct usb_device *usbdev, const char *img_name, } buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL); - if (buf == NULL) { - dev_err(&usbdev->dev, "Error: kmalloc\n"); + if (buf == NULL) return -ENOMEM; - } strcpy(buf+pad_size, type_string); ret = gdm_wibro_send(usbdev, buf, strlen(type_string)+pad_size); diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c index 6861877..e676403 100644 --- a/drivers/staging/iio/accel/lis3l02dq_ring.c +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c @@ -140,11 +140,8 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p) char *data; data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(indio_dev->dev.parent, - "memory alloc failed in buffer bh"); + if (data == NULL) goto done; - } if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) len = lis3l02dq_get_buffer_element(indio_dev, data); diff --git a/drivers/staging/keucr/usb.c b/drivers/staging/keucr/usb.c index 4dec93d..f656f8a 100644 --- a/drivers/staging/keucr/usb.c +++ b/drivers/staging/keucr/usb.c @@ -266,10 +266,9 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf) } us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); - if (!us->sensebuf) { - pr_info("Sense buffer allocation failed\n"); + if (!us->sensebuf) return -ENOMEM; - } + return 0; } diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c index 9f9a21a..6252aca 100644 --- a/drivers/staging/line6/driver.c +++ b/drivers/staging/line6/driver.c @@ -233,11 +233,8 @@ int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer, /* create message: */ msg = kmalloc(sizeof(struct message), GFP_ATOMIC); - - if (msg == NULL) { - dev_err(line6->ifcdev, "Out of memory\n"); + if (msg == NULL) return -ENOMEM; - } /* create URB: */ urb = usb_alloc_urb(0, GFP_ATOMIC); @@ -300,10 +297,8 @@ char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2, { char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC); - if (!buffer) { - dev_err(line6->ifcdev, "out of memory\n"); + if (!buffer) return NULL; - } buffer[0] = LINE6_SYSEX_BEGIN; memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id)); @@ -403,11 +398,8 @@ int line6_send_program(struct usb_line6 *line6, u8 value) int partial; buffer = kmalloc(2, GFP_KERNEL); - - if (!buffer) { - dev_err(line6->ifcdev, "out of memory\n"); + if (!buffer) return -ENOMEM; - } buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST; buffer[1] = value; @@ -435,11 +427,8 @@ int line6_transmit_parameter(struct usb_line6 *line6, int param, u8 value) int partial; buffer = kmalloc(3, GFP_KERNEL); - - if (!buffer) { - dev_err(line6->ifcdev, "out of memory\n"); + if (!buffer) return -ENOMEM; - } buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST; buffer[1] = param; @@ -834,9 +823,7 @@ static int line6_probe(struct usb_interface *interface, } line6 = kzalloc(size, GFP_KERNEL); - if (line6 == NULL) { - dev_err(&interface->dev, "Out of memory\n"); ret = -ENODEV; goto err_put; } @@ -875,18 +862,14 @@ static int line6_probe(struct usb_interface *interface, /* initialize USB buffers: */ line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL); - if (line6->buffer_listen == NULL) { - dev_err(&interface->dev, "Out of memory\n"); ret = -ENOMEM; goto err_destruct; } line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL); - if (line6->buffer_message == NULL) { - dev_err(&interface->dev, "Out of memory\n"); ret = -ENOMEM; goto err_destruct; } diff --git a/drivers/staging/line6/pcm.c b/drivers/staging/line6/pcm.c index 17969c6..02f77d7 100644 --- a/drivers/staging/line6/pcm.c +++ b/drivers/staging/line6/pcm.c @@ -121,10 +121,7 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels) line6pcm->buffer_in = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * line6pcm->max_packet_size, GFP_KERNEL); - if (!line6pcm->buffer_in) { - dev_err(line6pcm->line6->ifcdev, - "cannot malloc capture buffer\n"); err = -ENOMEM; goto pcm_acquire_error; } @@ -160,10 +157,7 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels) line6pcm->buffer_out = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * line6pcm->max_packet_size, GFP_KERNEL); - if (!line6pcm->buffer_out) { - dev_err(line6pcm->line6->ifcdev, - "cannot malloc playback buffer\n"); err = -ENOMEM; goto pcm_acquire_error; } diff --git a/drivers/staging/omapdrm/omap_connector.c b/drivers/staging/omapdrm/omap_connector.c index 4cc9ee7..8979c80 100644 --- a/drivers/staging/omapdrm/omap_connector.c +++ b/drivers/staging/omapdrm/omap_connector.c @@ -261,10 +261,8 @@ struct drm_connector *omap_connector_init(struct drm_device *dev, omap_dss_get_device(dssdev); omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL); - if (!omap_connector) { - dev_err(dev->dev, "could not allocate connector\n"); + if (!omap_connector) goto fail; - } omap_connector->dssdev = dssdev; omap_connector->encoder = encoder; diff --git a/drivers/staging/omapdrm/omap_crtc.c b/drivers/staging/omapdrm/omap_crtc.c index 5c6ed60..32109c0 100644 --- a/drivers/staging/omapdrm/omap_crtc.c +++ b/drivers/staging/omapdrm/omap_crtc.c @@ -601,11 +601,8 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev, DBG("%s", channel_names[channel]); omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL); - - if (!omap_crtc) { - dev_err(dev->dev, "could not allocate CRTC\n"); + if (!omap_crtc) goto fail; - } crtc = &omap_crtc->base; diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.c b/drivers/staging/omapdrm/omap_dmm_tiler.c index 3910215..9b794c9 100644 --- a/drivers/staging/omapdrm/omap_dmm_tiler.c +++ b/drivers/staging/omapdrm/omap_dmm_tiler.c @@ -581,10 +581,8 @@ static int omap_dmm_probe(struct platform_device *dev) struct resource *mem; omap_dmm = kzalloc(sizeof(*omap_dmm), GFP_KERNEL); - if (!omap_dmm) { - dev_err(&dev->dev, "failed to allocate driver data section\n"); + if (!omap_dmm) goto fail; - } /* initialize lists */ INIT_LIST_HEAD(&omap_dmm->alloc_head); @@ -681,11 +679,9 @@ static int omap_dmm_probe(struct platform_device *dev) } /* alloc engines */ - omap_dmm->engines = kzalloc( - omap_dmm->num_engines * sizeof(struct refill_engine), - GFP_KERNEL); + omap_dmm->engines = kcalloc(omap_dmm->num_engines, + sizeof(struct refill_engine), GFP_KERNEL); if (!omap_dmm->engines) { - dev_err(&dev->dev, "could not allocate engines\n"); ret = -ENOMEM; goto fail; } @@ -702,10 +698,9 @@ static int omap_dmm_probe(struct platform_device *dev) list_add(&omap_dmm->engines[i].idle_node, &omap_dmm->idle_head); } - omap_dmm->tcm = kzalloc(omap_dmm->num_lut * sizeof(*omap_dmm->tcm), + omap_dmm->tcm = kcalloc(omap_dmm->num_lut, sizeof(*omap_dmm->tcm), GFP_KERNEL); if (!omap_dmm->tcm) { - dev_err(&dev->dev, "failed to allocate lut ptrs\n"); ret = -ENOMEM; goto fail; } diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c index d246f85..480dc34 100644 --- a/drivers/staging/omapdrm/omap_drv.c +++ b/drivers/staging/omapdrm/omap_drv.c @@ -335,10 +335,8 @@ static int dev_load(struct drm_device *dev, unsigned long flags) DBG("load: dev=%p", dev); priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - dev_err(dev->dev, "could not allocate priv\n"); + if (!priv) return -ENOMEM; - } priv->omaprev = pdata->omaprev; diff --git a/drivers/staging/omapdrm/omap_encoder.c b/drivers/staging/omapdrm/omap_encoder.c index e053160..25fc0c7 100644 --- a/drivers/staging/omapdrm/omap_encoder.c +++ b/drivers/staging/omapdrm/omap_encoder.c @@ -147,10 +147,8 @@ struct drm_encoder *omap_encoder_init(struct drm_device *dev, struct omap_encoder *omap_encoder; omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL); - if (!omap_encoder) { - dev_err(dev->dev, "could not allocate encoder\n"); + if (!omap_encoder) goto fail; - } omap_encoder->dssdev = dssdev; diff --git a/drivers/staging/omapdrm/omap_fb.c b/drivers/staging/omapdrm/omap_fb.c index 09028e9..bb49699 100644 --- a/drivers/staging/omapdrm/omap_fb.c +++ b/drivers/staging/omapdrm/omap_fb.c @@ -418,7 +418,6 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, omap_fb = kzalloc(sizeof(*omap_fb), GFP_KERNEL); if (!omap_fb) { - dev_err(dev->dev, "could not allocate fb\n"); ret = -ENOMEM; goto fail; } diff --git a/drivers/staging/omapdrm/omap_fbdev.c b/drivers/staging/omapdrm/omap_fbdev.c index 8a027bb..70f2d6e 100644 --- a/drivers/staging/omapdrm/omap_fbdev.c +++ b/drivers/staging/omapdrm/omap_fbdev.c @@ -348,10 +348,8 @@ struct drm_fb_helper *omap_fbdev_init(struct drm_device *dev) int ret = 0; fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); - if (!fbdev) { - dev_err(dev->dev, "could not allocate fbdev\n"); + if (!fbdev) goto fail; - } INIT_WORK(&fbdev->work, pan_worker); diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c index f9297eb..518d03d 100644 --- a/drivers/staging/omapdrm/omap_gem.c +++ b/drivers/staging/omapdrm/omap_gem.c @@ -1402,10 +1402,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, } omap_obj = kzalloc(sizeof(*omap_obj), GFP_KERNEL); - if (!omap_obj) { - dev_err(dev->dev, "could not allocate GEM object\n"); + if (!omap_obj) goto fail; - } list_add(&omap_obj->mm_list, &priv->obj_list); @@ -1461,11 +1459,9 @@ void omap_gem_init(struct drm_device *dev) return; } - usergart = kzalloc(3 * sizeof(*usergart), GFP_KERNEL); - if (!usergart) { - dev_warn(dev->dev, "could not allocate usergart\n"); + usergart = kcalloc(3, sizeof(*usergart), GFP_KERNEL); + if (!usergart) return; - } /* reserve 4k aligned/wide regions for userspace mappings: */ for (i = 0; i < ARRAY_SIZE(fmts); i++) { diff --git a/drivers/staging/omapdrm/omap_plane.c b/drivers/staging/omapdrm/omap_plane.c index bb989d7..c063476 100644 --- a/drivers/staging/omapdrm/omap_plane.c +++ b/drivers/staging/omapdrm/omap_plane.c @@ -390,10 +390,8 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, DBG("%s: priv=%d", plane_names[id], private_plane); omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL); - if (!omap_plane) { - dev_err(dev->dev, "could not allocate plane\n"); + if (!omap_plane) goto fail; - } ret = kfifo_alloc(&omap_plane->unpin_fifo, 16, GFP_KERNEL); if (ret) { diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c index 4358c4b..07a1fbb 100644 --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c @@ -68,10 +68,8 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee) ieee->networks = kcalloc( MAX_NETWORK_COUNT, sizeof(struct ieee80211_network), GFP_KERNEL); - if (!ieee->networks) { - netdev_warn(ieee->dev, "Out of memory allocating beacons\n"); + if (!ieee->networks) return -ENOMEM; - } return 0; } diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c index 446f15e..e303159 100644 --- a/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c +++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c @@ -408,11 +408,9 @@ static int is_duplicate_packet(struct ieee80211_device *ieee, // if (memcmp(entry->mac, mac, ETH_ALEN)){ if (p == &ieee->ibss_mac_hash[index]) { entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC); - if (!entry) { - netdev_warn(ieee->dev, - "Cannot malloc new mac entry\n"); + if (!entry) return 0; - } + memcpy(entry->mac, mac, ETH_ALEN); entry->seq_num[tid] = seq; entry->frag_num[tid] = frag; diff --git a/drivers/staging/sbe-2t3e3/dc.c b/drivers/staging/sbe-2t3e3/dc.c index daadd6e..f207b9e 100644 --- a/drivers/staging/sbe-2t3e3/dc.c +++ b/drivers/staging/sbe-2t3e3/dc.c @@ -315,20 +315,17 @@ static int dc_init_descriptor_list(struct channel *sc) struct sk_buff *m; if (sc->ether.rx_ring == NULL) - sc->ether.rx_ring = kzalloc(SBE_2T3E3_RX_DESC_RING_SIZE * + sc->ether.rx_ring = kcalloc(SBE_2T3E3_RX_DESC_RING_SIZE, sizeof(t3e3_rx_desc_t), GFP_KERNEL); - if (sc->ether.rx_ring == NULL) { - dev_err(&sc->pdev->dev, "SBE 2T3E3: no buffer space for RX ring\n"); + if (sc->ether.rx_ring == NULL) return -ENOMEM; - } if (sc->ether.tx_ring == NULL) - sc->ether.tx_ring = kzalloc(SBE_2T3E3_TX_DESC_RING_SIZE * + sc->ether.tx_ring = kcalloc(SBE_2T3E3_TX_DESC_RING_SIZE, sizeof(t3e3_tx_desc_t), GFP_KERNEL); if (sc->ether.tx_ring == NULL) { kfree(sc->ether.rx_ring); sc->ether.rx_ring = NULL; - dev_err(&sc->pdev->dev, "SBE 2T3E3: no buffer space for RX ring\n"); return -ENOMEM; } diff --git a/drivers/staging/sbe-2t3e3/module.c b/drivers/staging/sbe-2t3e3/module.c index ae7af39..0e32be5 100644 --- a/drivers/staging/sbe-2t3e3/module.c +++ b/drivers/staging/sbe-2t3e3/module.c @@ -154,11 +154,10 @@ static int t3e3_init_card(struct pci_dev *pdev, const struct pci_device_id *ent) /* holds the reference for pdev1 */ } - card = kzalloc(sizeof(struct card) + channels * sizeof(struct channel), GFP_KERNEL); - if (!card) { - dev_err(&pdev->dev, "Out of memory\n"); + card = kzalloc(sizeof(struct card) + channels * sizeof(struct channel), + GFP_KERNEL); + if (!card) return -ENOBUFS; - } spin_lock_init(&card->bootrom_lock); card->bootrom_addr = pci_resource_start(pdev, 0); diff --git a/drivers/staging/sep/sep_crypto.c b/drivers/staging/sep/sep_crypto.c index 861588f..cd3bb39 100644 --- a/drivers/staging/sep/sep_crypto.c +++ b/drivers/staging/sep/sep_crypto.c @@ -178,11 +178,9 @@ static struct scatterlist *sep_alloc_sg_buf( nbr_pages += 1; } - sg = kmalloc((sizeof(struct scatterlist) * nbr_pages), GFP_ATOMIC); - if (!sg) { - dev_warn(&sep->pdev->dev, "Cannot allocate page for new sg\n"); + sg = kmalloc_array(nbr_pages, sizeof(struct scatterlist), GFP_ATOMIC); + if (!sg) return NULL; - } sg_init_table(sg, nbr_pages); diff --git a/drivers/staging/sep/sep_main.c b/drivers/staging/sep/sep_main.c index 15c6e3d..30e8d25 100644 --- a/drivers/staging/sep/sep_main.c +++ b/drivers/staging/sep/sep_main.c @@ -219,12 +219,8 @@ static int sep_allocate_dmatables_region(struct sep_device *sep, dev_dbg(&sep->pdev->dev, "[PID%d] oldlen = 0x%08X\n", current->pid, dma_ctx->dmatables_len); tmp_region = kzalloc(new_len + dma_ctx->dmatables_len, GFP_KERNEL); - if (!tmp_region) { - dev_warn(&sep->pdev->dev, - "[PID%d] no mem for dma tables region\n", - current->pid); + if (!tmp_region) return -ENOMEM; - } /* Were there any previous tables that need to be preserved ? */ if (*dmatables_region) { @@ -1245,27 +1241,23 @@ static int sep_lock_user_pages(struct sep_device *sep, current->pid, num_pages); /* Allocate array of pages structure pointers */ - page_array = kmalloc(sizeof(struct page *) * num_pages, GFP_ATOMIC); + page_array = kmalloc_array(num_pages, sizeof(struct page *), + GFP_ATOMIC); if (!page_array) { error = -ENOMEM; goto end_function; } - map_array = kmalloc(sizeof(struct sep_dma_map) * num_pages, GFP_ATOMIC); + + map_array = kmalloc_array(num_pages, sizeof(struct sep_dma_map), + GFP_ATOMIC); if (!map_array) { - dev_warn(&sep->pdev->dev, - "[PID%d] kmalloc for map_array failed\n", - current->pid); error = -ENOMEM; goto end_function_with_error1; } - lli_array = kmalloc(sizeof(struct sep_lli_entry) * num_pages, - GFP_ATOMIC); - + lli_array = kmalloc_array(num_pages, sizeof(struct sep_lli_entry), + GFP_ATOMIC); if (!lli_array) { - dev_warn(&sep->pdev->dev, - "[PID%d] kmalloc for lli_array failed\n", - current->pid); error = -ENOMEM; goto end_function_with_error2; } @@ -1448,15 +1440,10 @@ static int sep_lli_table_secure_dma(struct sep_device *sep, dev_dbg(&sep->pdev->dev, "[PID%d] num_pages is (hex) %x\n", current->pid, num_pages); - lli_array = kmalloc(sizeof(struct sep_lli_entry) * num_pages, - GFP_ATOMIC); - - if (!lli_array) { - dev_warn(&sep->pdev->dev, - "[PID%d] kmalloc for lli_array failed\n", - current->pid); + lli_array = kmalloc_array(num_pages, sizeof(struct sep_lli_entry), + GFP_ATOMIC); + if (!lli_array) return -ENOMEM; - } /* * Fill the lli_array @@ -3419,11 +3406,9 @@ static ssize_t sep_create_dcb_dmatables_context(struct sep_device *sep, goto end_function; } - dcb_args = kzalloc(num_dcbs * sizeof(struct build_dcb_struct), + dcb_args = kcalloc(num_dcbs, sizeof(struct build_dcb_struct), GFP_KERNEL); if (!dcb_args) { - dev_warn(&sep->pdev->dev, "[PID%d] no memory for dcb args\n", - current->pid); error = -ENOMEM; goto end_function; } @@ -3610,9 +3595,6 @@ static ssize_t sep_create_msgarea_context(struct sep_device *sep, /* Allocate thread-specific memory for message buffer */ *msg_region = kzalloc(msg_len, GFP_KERNEL); if (!(*msg_region)) { - dev_warn(&sep->pdev->dev, - "[PID%d] no mem for msgarea context\n", - current->pid); error = -ENOMEM; goto end_function; } @@ -4133,8 +4115,6 @@ static int sep_probe(struct pci_dev *pdev, /* Allocate the sep_device structure for this device */ sep_dev = kzalloc(sizeof(struct sep_device), GFP_ATOMIC); if (sep_dev == NULL) { - dev_warn(&pdev->dev, - "can't kmalloc the sep_device structure\n"); error = -ENOMEM; goto end_function_disable_device; } diff --git a/drivers/staging/speakup/selection.c b/drivers/staging/speakup/selection.c index d6558fa..822ac3d 100644 --- a/drivers/staging/speakup/selection.c +++ b/drivers/staging/speakup/selection.c @@ -95,7 +95,6 @@ int speakup_set_selection(struct tty_struct *tty) /* Allocate a new buffer before freeing the old one ... */ bp = kmalloc((sel_end-sel_start)/2+1, GFP_ATOMIC); if (!bp) { - dev_warn(tty->dev, "selection: kmalloc() failed\n"); speakup_clear_selection(); return -ENOMEM; } diff --git a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c index 299f518..6a21f67 100644 --- a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c +++ b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c @@ -742,13 +742,9 @@ static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata) case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM: if (rmi_fd.intr_src_count) { rfi = kmalloc(sizeof(*rfi), - GFP_KERNEL); - if (!rfi) { - dev_err(&client->dev, - "%s:kmalloc failed\n", - __func__); - return -ENOMEM; - } + GFP_KERNEL); + if (!rfi) + return -ENOMEM; retval = synpatics_rmi4_touchpad_detect (pdata, rfi, &rmi_fd, @@ -900,12 +896,10 @@ static int synaptics_rmi4_probe } /* Allocate and initialize the instance data for this client */ - rmi4_data = kzalloc(sizeof(struct synaptics_rmi4_data) * 2, - GFP_KERNEL); - if (!rmi4_data) { - dev_err(&client->dev, "%s: no memory allocated\n", __func__); + rmi4_data = kcalloc(2, sizeof(struct synaptics_rmi4_data), + GFP_KERNEL); + if (!rmi4_data) return -ENOMEM; - } rmi4_data->input_dev = input_allocate_device(); if (rmi4_data->input_dev == NULL) { diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c index 5a18a94..70db4ff 100644 --- a/drivers/staging/tidspbridge/pmgr/dspapi.c +++ b/drivers/staging/tidspbridge/pmgr/dspapi.c @@ -1543,7 +1543,7 @@ u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt) if (num_bufs > MAX_BUFS) return -EINVAL; - ap_buffer = kmalloc((num_bufs * sizeof(u8 *)), GFP_KERNEL); + ap_buffer = kmalloc_array(num_bufs, sizeof(u8 *), GFP_KERNEL); if (ap_buffer == NULL) return -ENOMEM; diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c index e1bdf6e..0df55bd 100644 --- a/drivers/staging/tidspbridge/rmgr/proc.c +++ b/drivers/staging/tidspbridge/rmgr/proc.c @@ -119,16 +119,14 @@ static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt, dsp_addr, size); map_obj = kzalloc(sizeof(struct dmm_map_object), GFP_KERNEL); - if (!map_obj) { - pr_err("%s: kzalloc failed\n", __func__); + if (!map_obj) return NULL; - } + INIT_LIST_HEAD(&map_obj->link); map_obj->pages = kcalloc(num_usr_pgs, sizeof(struct page *), - GFP_KERNEL); + GFP_KERNEL); if (!map_obj->pages) { - pr_err("%s: kzalloc failed\n", __func__); kfree(map_obj); return NULL; } @@ -693,7 +691,6 @@ static int memory_give_ownership(struct dmm_map_object *map_obj, sg = kcalloc(num_pages, sizeof(*sg), GFP_KERNEL); if (!sg) { - pr_err("%s: kcalloc failed\n", __func__); ret = -ENOMEM; goto out; } @@ -1227,12 +1224,8 @@ int proc_load(void *hprocessor, const s32 argc_index, (p_proc_object->bridge_context, &brd_state))) { pr_info("%s: Processor Loaded %s\n", __func__, pargv0); kfree(drv_datap->base_img); - drv_datap->base_img = kmalloc(strlen(pargv0) + 1, - GFP_KERNEL); - if (drv_datap->base_img) - strncpy(drv_datap->base_img, pargv0, - strlen(pargv0) + 1); - else + drv_datap->base_img = kstrdup(pargv0, GFP_KERNEL); + if (!drv_datap->base_img) status = -ENOMEM; } } diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c index d36c69e..ca5de9d 100644 --- a/drivers/staging/usbip/stub_dev.c +++ b/drivers/staging/usbip/stub_dev.c @@ -286,10 +286,8 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev, /* yes, it's a new device */ sdev = kzalloc(sizeof(struct stub_device), GFP_KERNEL); - if (!sdev) { - dev_err(&interface->dev, "no memory for stub_device\n"); + if (!sdev) return NULL; - } sdev->interface = usb_get_intf(interface); sdev->udev = usb_get_dev(udev); diff --git a/drivers/staging/usbip/stub_rx.c b/drivers/staging/usbip/stub_rx.c index e7458e1..715e8a7 100644 --- a/drivers/staging/usbip/stub_rx.c +++ b/drivers/staging/usbip/stub_rx.c @@ -485,7 +485,6 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, kzalloc(pdu->u.cmd_submit.transfer_buffer_length, GFP_KERNEL); if (!priv->urb->transfer_buffer) { - dev_err(&sdev->interface->dev, "malloc x_buff\n"); usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); return; } diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c index 513961f..cd5326a 100644 --- a/drivers/staging/usbip/stub_tx.c +++ b/drivers/staging/usbip/stub_tx.c @@ -42,7 +42,6 @@ void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum, unlink = kzalloc(sizeof(struct stub_unlink), GFP_ATOMIC); if (!unlink) { - dev_err(&sdev->interface->dev, "alloc stub_unlink\n"); usbip_event_add(&sdev->ud, VDEV_EVENT_ERROR_MALLOC); return; } diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c index 216648d..f1ca084 100644 --- a/drivers/staging/usbip/vhci_hcd.c +++ b/drivers/staging/usbip/vhci_hcd.c @@ -434,16 +434,13 @@ static void vhci_tx_urb(struct urb *urb) } priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC); - - spin_lock(&vdev->priv_lock); - if (!priv) { - dev_err(&urb->dev->dev, "malloc vhci_priv\n"); - spin_unlock(&vdev->priv_lock); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); return; } + spin_lock(&vdev->priv_lock); + priv->seqnum = atomic_inc_return(&the_controller->seqnum); if (priv->seqnum == 0xffff) dev_info(&urb->dev->dev, "seqnum max\n"); @@ -684,7 +681,6 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) /* setup CMD_UNLINK pdu */ unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC); if (!unlink) { - pr_err("malloc vhci_unlink\n"); spin_unlock(&vdev->priv_lock); spin_unlock(&the_controller->lock); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); diff --git a/drivers/staging/vme/devices/vme_pio2_core.c b/drivers/staging/vme/devices/vme_pio2_core.c index bf73ba2..fd19c25 100644 --- a/drivers/staging/vme/devices/vme_pio2_core.c +++ b/drivers/staging/vme/devices/vme_pio2_core.c @@ -222,7 +222,6 @@ static int pio2_probe(struct vme_dev *vdev) card = kzalloc(sizeof(struct pio2_card), GFP_KERNEL); if (card == NULL) { - dev_err(&vdev->dev, "Unable to allocate card structure\n"); retval = -ENOMEM; goto err_struct; } diff --git a/drivers/staging/vme/devices/vme_pio2_gpio.c b/drivers/staging/vme/devices/vme_pio2_gpio.c index 69d8805..2a2d920 100644 --- a/drivers/staging/vme/devices/vme_pio2_gpio.c +++ b/drivers/staging/vme/devices/vme_pio2_gpio.c @@ -192,10 +192,8 @@ int pio2_gpio_init(struct pio2_card *card) char *label; label = kmalloc(PIO2_NUM_CHANNELS, GFP_KERNEL); - if (label == NULL) { - dev_err(&card->vdev->dev, "Unable to allocate GPIO label\n"); + if (label == NULL) return -ENOMEM; - } sprintf(label, "%s@%s", driver_name, dev_name(&card->vdev->dev)); card->gc.label = label; diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c index 4ef852c..57474cf 100644 --- a/drivers/staging/vme/devices/vme_user.c +++ b/drivers/staging/vme/devices/vme_user.c @@ -761,8 +761,6 @@ static int vme_user_probe(struct vme_dev *vdev) image[i].size_buf = PCI_BUF_SIZE; image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL); if (image[i].kern_buf == NULL) { - dev_warn(&vdev->dev, - "Unable to allocate memory for master window buffers\n"); err = -ENOMEM; goto err_master_buf; } diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index c1ac905..f3204ac 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -1304,10 +1304,8 @@ int zcache_new_pool(uint16_t cli_id, uint32_t flags) goto out; atomic_inc(&cli->refcount); pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC); - if (pool == NULL) { - pr_info("%s: pool creation failed: out of memory\n", namestr); + if (pool == NULL) goto out; - } for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++) if (cli->tmem_pools[poolid] == NULL) @@ -1380,10 +1378,9 @@ int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph) goto out; } pool = kmalloc(sizeof(struct tmem_pool), GFP_KERNEL); - if (pool == NULL) { - pr_info("%s: pool creation failed: out of memory\n", namestr); + if (pool == NULL) goto out; - } + atomic_set(&pool->refcount, 0); pool->client = cli; pool->pool_id = pool_id; diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 6094e80..5918fd7 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -246,7 +246,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, */ uncmem = kmalloc(PAGE_SIZE, GFP_NOIO); if (!uncmem) { - pr_info("Error allocating temp memory!\n"); ret = -ENOMEM; goto out; } @@ -517,10 +516,8 @@ struct zram_meta *zram_meta_alloc(u64 disksize) goto out; meta->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); - if (!meta->compress_workmem) { - pr_err("Error allocating compressor working memory!\n"); + if (!meta->compress_workmem) goto free_meta; - } meta->compress_buffer = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); -- cgit v0.10.2 From 76426daf50d5df38893cc189e9ccd026093debc8 Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Mon, 11 Feb 2013 14:07:22 -0800 Subject: staging/zcache: Fix/improve zcache writeback code, tie to a config option It was observed by Andrea Arcangeli in 2011 that zcache can get "full" and there must be some way for compressed swap pages to be (uncompressed and then) sent through to the backing swap disk. A prototype of this functionality, called "unuse", was added in 2012 as part of a major update to zcache (aka "zcache2"), but was left unfinished due to the unfortunate temporary fork of zcache. This earlier version of the code had an unresolved memory leak and was anyway dependent on not-yet-upstream frontswap and mm changes. The code was meanwhile adapted by Seth Jennings for similar functionality in zswap (which he calls "flush"). Seth also made some clever simplifications which are herein ported back to zcache. As a result of those simplifications, the frontswap changes are no longer necessary, but a slightly different (and simpler) set of mm changes are still required [1]. The memory leak is also fixed. Due to feedback from akpm in a zswap thread, this functionality in zcache has now been renamed from "unuse" to "writeback". Although this zcache writeback code now works, there are open questions as how best to handle the policy that drives it. As a result, this patch also ties writeback to a new config option. And, since the code still depends on not-yet-upstreamed mm patches, to avoid build problems, the config option added by this patch temporarily depends on "BROKEN"; this config dependency can be removed in trees that contain the necessary mm patches. [1] https://lkml.org/lkml/2013/1/29/540/ https://lkml.org/lkml/2013/1/29/539/ Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig index c1dbd04..7358270 100644 --- a/drivers/staging/zcache/Kconfig +++ b/drivers/staging/zcache/Kconfig @@ -24,3 +24,20 @@ config RAMSTER while minimizing total RAM across the cluster. RAMster, like zcache2, compresses swap pages into local RAM, but then remotifies the compressed pages to another node in the RAMster cluster. + +# Depends on not-yet-upstreamed mm patches to export end_swap_bio_write and +# __add_to_swap_cache, and implement __swap_writepage (which is swap_writepage +# without the frontswap call. When these are in-tree, the dependency on +# BROKEN can be removed +config ZCACHE_WRITEBACK + bool "Allow compressed swap pages to be writtenback to swap disk" + depends on ZCACHE=y && BROKEN + default n + help + Zcache caches compressed swap pages (and other data) in RAM which + often improves performance by avoiding I/O's due to swapping. + In some workloads with very long-lived large processes, it can + instead reduce performance. Writeback decompresses zcache-compressed + pages (in LRU order) when under memory pressure and writes them to + the backing swap disk to ameliorate this problem. Policy driving + writeback is still under development. diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index f3204ac..4456ab4 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -22,6 +22,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -55,6 +59,9 @@ static inline void frontswap_tmem_exclusive_gets(bool b) } #endif +/* enable (or fix code) when Seth's patches are accepted upstream */ +#define zcache_writeback_enabled 0 + static int zcache_enabled __read_mostly; static int disable_cleancache __read_mostly; static int disable_frontswap __read_mostly; @@ -181,6 +188,8 @@ static unsigned long zcache_last_active_anon_pageframes; static unsigned long zcache_last_inactive_anon_pageframes; static unsigned long zcache_eph_nonactive_puts_ignored; static unsigned long zcache_pers_nonactive_puts_ignored; +static unsigned long zcache_writtenback_pages; +static long zcache_outstanding_writeback_pages; #ifdef CONFIG_DEBUG_FS #include @@ -239,6 +248,9 @@ static int zcache_debugfs_init(void) zdfs64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max); zdfs64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes); zdfs64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max); + zdfs("outstanding_writeback_pages", S_IRUGO, root, + &zcache_outstanding_writeback_pages); + zdfs("writtenback_pages", S_IRUGO, root, &zcache_writtenback_pages); return 0; } #undef zdebugfs @@ -285,6 +297,18 @@ void zcache_dump(void) pr_info("zcache: eph_zpages_max=%lu\n", zcache_eph_zpages_max); pr_info("zcache: pers_zpages=%lu\n", zcache_pers_zpages); pr_info("zcache: pers_zpages_max=%lu\n", zcache_pers_zpages_max); + pr_info("zcache: last_active_file_pageframes=%lu\n", + zcache_last_active_file_pageframes); + pr_info("zcache: last_inactive_file_pageframes=%lu\n", + zcache_last_inactive_file_pageframes); + pr_info("zcache: last_active_anon_pageframes=%lu\n", + zcache_last_active_anon_pageframes); + pr_info("zcache: last_inactive_anon_pageframes=%lu\n", + zcache_last_inactive_anon_pageframes); + pr_info("zcache: eph_nonactive_puts_ignored=%lu\n", + zcache_eph_nonactive_puts_ignored); + pr_info("zcache: pers_nonactive_puts_ignored=%lu\n", + zcache_pers_nonactive_puts_ignored); pr_info("zcache: eph_zbytes=%llu\n", (unsigned long long)zcache_eph_zbytes); pr_info("zcache: eph_zbytes_max=%llu\n", @@ -292,7 +316,10 @@ void zcache_dump(void) pr_info("zcache: pers_zbytes=%llu\n", (unsigned long long)zcache_pers_zbytes); pr_info("zcache: pers_zbytes_max=%llu\n", - (unsigned long long)zcache_pers_zbytes_max); + (unsigned long long)zcache_pers_zbytes_max); + pr_info("zcache: outstanding_writeback_pages=%lu\n", + zcache_outstanding_writeback_pages); + pr_info("zcache: writtenback_pages=%lu\n", zcache_writtenback_pages); } #endif @@ -449,14 +476,6 @@ static struct page *zcache_alloc_page(void) return page; } -#ifdef FRONTSWAP_HAS_UNUSE -static void zcache_unacct_page(void) -{ - zcache_pageframes_freed = - atomic_inc_return(&zcache_pageframes_freed_atomic); -} -#endif - static void zcache_free_page(struct page *page) { long curr_pageframes; @@ -959,7 +978,7 @@ static struct page *zcache_evict_eph_pageframe(void) &zcache_eph_zbytes_atomic); zcache_eph_zpages = atomic_sub_return(zpages, &zcache_eph_zpages_atomic); - zcache_evicted_eph_zpages++; + zcache_evicted_eph_zpages += zpages; zcache_eph_pageframes = atomic_dec_return(&zcache_eph_pageframes_atomic); zcache_evicted_eph_pageframes++; @@ -967,77 +986,253 @@ out: return page; } -#ifdef FRONTSWAP_HAS_UNUSE +#ifdef CONFIG_ZCACHE_WRITEBACK + +static atomic_t zcache_outstanding_writeback_pages_atomic = ATOMIC_INIT(0); + static void unswiz(struct tmem_oid oid, u32 index, unsigned *type, pgoff_t *offset); /* - * Choose an LRU persistent pageframe and attempt to "unuse" it by - * calling frontswap_unuse on both zpages. + * Choose an LRU persistent pageframe and attempt to write it back to + * the backing swap disk by calling frontswap_writeback on both zpages. * * This is work-in-progress. */ -static int zcache_frontswap_unuse(void) +static void zcache_end_swap_write(struct bio *bio, int err) +{ + end_swap_bio_write(bio, err); + zcache_outstanding_writeback_pages = + atomic_dec_return(&zcache_outstanding_writeback_pages_atomic); + zcache_writtenback_pages++; +} + +/* + * zcache_get_swap_cache_page + * + * This is an adaption of read_swap_cache_async() + * + * If success, page is returned in retpage + * Returns 0 if page was already in the swap cache, page is not locked + * Returns 1 if the new page needs to be populated, page is locked + */ +static int zcache_get_swap_cache_page(int type, pgoff_t offset, + struct page *new_page) +{ + struct page *found_page; + swp_entry_t entry = swp_entry(type, offset); + int err; + + BUG_ON(new_page == NULL); + do { + /* + * First check the swap cache. Since this is normally + * called after lookup_swap_cache() failed, re-calling + * that would confuse statistics. + */ + found_page = find_get_page(&swapper_space, entry.val); + if (found_page) + return 0; + + /* + * call radix_tree_preload() while we can wait. + */ + err = radix_tree_preload(GFP_KERNEL); + if (err) + break; + + /* + * Swap entry may have been freed since our caller observed it. + */ + err = swapcache_prepare(entry); + if (err == -EEXIST) { /* seems racy */ + radix_tree_preload_end(); + continue; + } + if (err) { /* swp entry is obsolete ? */ + radix_tree_preload_end(); + break; + } + + /* May fail (-ENOMEM) if radix-tree node allocation failed. */ + __set_page_locked(new_page); + SetPageSwapBacked(new_page); + err = __add_to_swap_cache(new_page, entry); + if (likely(!err)) { + radix_tree_preload_end(); + lru_cache_add_anon(new_page); + return 1; + } + radix_tree_preload_end(); + ClearPageSwapBacked(new_page); + __clear_page_locked(new_page); + /* + * add_to_swap_cache() doesn't return -EEXIST, so we can safely + * clear SWAP_HAS_CACHE flag. + */ + swapcache_free(entry, NULL); + /* FIXME: is it possible to get here without err==-ENOMEM? + * If not, we can dispense with the do loop, use goto retry */ + } while (err != -ENOMEM); + + return -ENOMEM; +} + +/* + * Given a frontswap zpage in zcache (identified by type/offset) and + * an empty page, put the page into the swap cache, use frontswap + * to get the page from zcache into the empty page, then give it + * to the swap subsystem to send to disk (carefully avoiding the + * possibility that frontswap might snatch it back). + * Returns < 0 if error, 0 if successful, and 1 if successful but + * the newpage passed in not needed and should be freed. + */ +static int zcache_frontswap_writeback_zpage(int type, pgoff_t offset, + struct page *newpage) +{ + struct page *page = newpage; + int ret; + struct writeback_control wbc = { + .sync_mode = WB_SYNC_NONE, + }; + + ret = zcache_get_swap_cache_page(type, offset, page); + if (ret < 0) + return ret; + else if (ret == 0) { + /* more uptodate page is already in swapcache */ + __frontswap_invalidate_page(type, offset); + return 1; + } + + BUG_ON(!frontswap_has_exclusive_gets); /* load must also invalidate */ + /* FIXME: how is it possible to get here when page is unlocked? */ + __frontswap_load(page); + SetPageUptodate(page); /* above does SetPageDirty, is that enough? */ + + /* start writeback */ + SetPageReclaim(page); + /* + * Return value is ignored here because it doesn't change anything + * for us. Page is returned unlocked. + */ + (void)__swap_writepage(page, &wbc, zcache_end_swap_write); + page_cache_release(page); + zcache_outstanding_writeback_pages = + atomic_inc_return(&zcache_outstanding_writeback_pages_atomic); + + return 0; +} + +/* + * The following is still a magic number... we want to allow forward progress + * for writeback because it clears out needed RAM when under pressure, but + * we don't want to allow writeback to absorb and queue too many GFP_KERNEL + * pages if the swap device is very slow. + */ +#define ZCACHE_MAX_OUTSTANDING_WRITEBACK_PAGES 6400 + +/* + * Try to allocate two free pages, first using a non-aggressive alloc, + * then by evicting zcache ephemeral (clean pagecache) pages, and last + * by aggressive GFP_KERNEL alloc. We allow zbud to choose a pageframe + * consisting of 1-2 zbuds/zpages, then call the writeback_zpage helper + * function above for each. + */ +static int zcache_frontswap_writeback(void) { struct tmem_handle th[2]; - int ret = -ENOMEM; - int nzbuds, unuse_ret; + int ret = 0; + int nzbuds, writeback_ret; unsigned type; - struct page *newpage1 = NULL, *newpage2 = NULL; + struct page *znewpage1 = NULL, *znewpage2 = NULL; struct page *evictpage1 = NULL, *evictpage2 = NULL; + struct page *newpage1 = NULL, *newpage2 = NULL; + struct page *page1 = NULL, *page2 = NULL; pgoff_t offset; - newpage1 = alloc_page(ZCACHE_GFP_MASK); - newpage2 = alloc_page(ZCACHE_GFP_MASK); - if (newpage1 == NULL) + znewpage1 = alloc_page(ZCACHE_GFP_MASK); + znewpage2 = alloc_page(ZCACHE_GFP_MASK); + if (znewpage1 == NULL) evictpage1 = zcache_evict_eph_pageframe(); - if (newpage2 == NULL) + if (znewpage2 == NULL) evictpage2 = zcache_evict_eph_pageframe(); - if (evictpage1 == NULL || evictpage2 == NULL) + + if ((evictpage1 == NULL || evictpage2 == NULL) && + atomic_read(&zcache_outstanding_writeback_pages_atomic) > + ZCACHE_MAX_OUTSTANDING_WRITEBACK_PAGES) { goto free_and_out; - /* ok, we have two pages pre-allocated */ + } + if (znewpage1 == NULL && evictpage1 == NULL) + newpage1 = alloc_page(GFP_KERNEL); + if (znewpage2 == NULL && evictpage2 == NULL) + newpage2 = alloc_page(GFP_KERNEL); + if (newpage1 == NULL || newpage2 == NULL) + goto free_and_out; + + /* ok, we have two pageframes pre-allocated, get a pair of zbuds */ nzbuds = zbud_make_zombie_lru(&th[0], NULL, NULL, false); if (nzbuds == 0) { ret = -ENOENT; goto free_and_out; } + + /* process the first zbud */ unswiz(th[0].oid, th[0].index, &type, &offset); - unuse_ret = frontswap_unuse(type, offset, - newpage1 != NULL ? newpage1 : evictpage1, - ZCACHE_GFP_MASK); - if (unuse_ret != 0) + page1 = (znewpage1 != NULL) ? znewpage1 : + ((newpage1 != NULL) ? newpage1 : evictpage1); + writeback_ret = zcache_frontswap_writeback_zpage(type, offset, page1); + if (writeback_ret < 0) { + ret = -ENOMEM; goto free_and_out; - else if (evictpage1 != NULL) - zcache_unacct_page(); - newpage1 = NULL; - evictpage1 = NULL; - if (nzbuds == 2) { - unswiz(th[1].oid, th[1].index, &type, &offset); - unuse_ret = frontswap_unuse(type, offset, - newpage2 != NULL ? newpage2 : evictpage2, - ZCACHE_GFP_MASK); - if (unuse_ret != 0) - goto free_and_out; - else if (evictpage2 != NULL) - zcache_unacct_page(); } - ret = 0; - goto out; + if (evictpage1 != NULL) + zcache_pageframes_freed = + atomic_inc_return(&zcache_pageframes_freed_atomic); + if (writeback_ret == 0) { + /* zcache_get_swap_cache_page will free, don't double free */ + znewpage1 = NULL; + newpage1 = NULL; + evictpage1 = NULL; + } + if (nzbuds < 2) + goto free_and_out; + + /* if there is a second zbud, process it */ + unswiz(th[1].oid, th[1].index, &type, &offset); + page2 = (znewpage2 != NULL) ? znewpage2 : + ((newpage2 != NULL) ? newpage2 : evictpage2); + writeback_ret = zcache_frontswap_writeback_zpage(type, offset, page2); + if (writeback_ret < 0) { + ret = -ENOMEM; + goto free_and_out; + } + if (evictpage2 != NULL) + zcache_pageframes_freed = + atomic_inc_return(&zcache_pageframes_freed_atomic); + if (writeback_ret == 0) { + znewpage2 = NULL; + newpage2 = NULL; + evictpage2 = NULL; + } free_and_out: + if (znewpage1 != NULL) + page_cache_release(znewpage1); + if (znewpage2 != NULL) + page_cache_release(znewpage2); if (newpage1 != NULL) - __free_page(newpage1); + page_cache_release(newpage1); if (newpage2 != NULL) - __free_page(newpage2); + page_cache_release(newpage2); if (evictpage1 != NULL) zcache_free_page(evictpage1); if (evictpage2 != NULL) zcache_free_page(evictpage2); -out: return ret; } -#endif +#endif /* CONFIG_ZCACHE_WRITEBACK */ /* * When zcache is disabled ("frozen"), pools can be created and destroyed, @@ -1051,7 +1246,10 @@ static bool zcache_freeze; /* * This zcache shrinker interface reduces the number of ephemeral pageframes * used by zcache to approximately the same as the total number of LRU_FILE - * pageframes in use. + * pageframes in use, and now also reduces the number of persistent pageframes + * used by zcache to approximately the same as the total number of LRU_ANON + * pageframes in use. FIXME POLICY: Probably the writeback should only occur + * if the eviction doesn't free enough pages. */ static int shrink_zcache_memory(struct shrinker *shrink, struct shrink_control *sc) @@ -1060,11 +1258,9 @@ static int shrink_zcache_memory(struct shrinker *shrink, int ret = -1; int nr = sc->nr_to_scan; int nr_evict = 0; - int nr_unuse = 0; + int nr_writeback = 0; struct page *page; -#ifdef FRONTSWAP_HAS_UNUSE - int unuse_ret; -#endif + int file_pageframes_inuse, anon_pageframes_inuse; if (nr <= 0) goto skip_evict; @@ -1080,8 +1276,12 @@ static int shrink_zcache_memory(struct shrinker *shrink, global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); zcache_last_inactive_file_pageframes = global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); - nr_evict = zcache_eph_pageframes - zcache_last_active_file_pageframes + - zcache_last_inactive_file_pageframes; + file_pageframes_inuse = zcache_last_active_file_pageframes + + zcache_last_inactive_file_pageframes; + if (zcache_eph_pageframes > file_pageframes_inuse) + nr_evict = zcache_eph_pageframes - file_pageframes_inuse; + else + nr_evict = 0; while (nr_evict-- > 0) { page = zcache_evict_eph_pageframe(); if (page == NULL) @@ -1093,18 +1293,20 @@ static int shrink_zcache_memory(struct shrinker *shrink, global_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON); zcache_last_inactive_anon_pageframes = global_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON); - nr_unuse = zcache_pers_pageframes - zcache_last_active_anon_pageframes + - zcache_last_inactive_anon_pageframes; -#ifdef FRONTSWAP_HAS_UNUSE - /* rate limit for testing */ - if (nr_unuse > 32) - nr_unuse = 32; - while (nr_unuse-- > 0) { - unuse_ret = zcache_frontswap_unuse(); - if (unuse_ret == -ENOMEM) + anon_pageframes_inuse = zcache_last_active_anon_pageframes + + zcache_last_inactive_anon_pageframes; + if (zcache_pers_pageframes > anon_pageframes_inuse) + nr_writeback = zcache_pers_pageframes - anon_pageframes_inuse; + else + nr_writeback = 0; + while (nr_writeback-- > 0) { +#ifdef CONFIG_ZCACHE_WRITEBACK + int writeback_ret; + writeback_ret = zcache_frontswap_writeback(); + if (writeback_ret == -ENOMEM) +#endif break; } -#endif in_progress = false; skip_evict: @@ -1343,7 +1545,7 @@ static int zcache_local_new_pool(uint32_t flags) int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph) { struct tmem_pool *pool; - struct zcache_client *cli = NULL; + struct zcache_client *cli; uint32_t flags = eph ? 0 : TMEM_POOL_PERSIST; int ret = -1; @@ -1520,7 +1722,7 @@ static inline struct tmem_oid oswiz(unsigned type, u32 ind) return oid; } -#ifdef FRONTSWAP_HAS_UNUSE +#ifdef CONFIG_ZCACHE_WRITEBACK static void unswiz(struct tmem_oid oid, u32 index, unsigned *type, pgoff_t *offset) { -- cgit v0.10.2 From ae87d63664721c9022ad709077de82b02b8227ca Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 12 Feb 2013 05:01:51 +0100 Subject: staging: dgrp: remove redundant NULL check before unregister_dgrp_device(). unregister_dgrp_device on a NULL pointer is a no-op, so the NULL checks in dgrp_remove_nd() can be removed. Signed-off-by: Cyril Roelandt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c index dfdaede..13c7ccf 100644 --- a/drivers/staging/dgrp/dgrp_specproc.c +++ b/drivers/staging/dgrp/dgrp_specproc.c @@ -777,14 +777,11 @@ static int dgrp_remove_nd(struct nd_struct *nd) dgrp_remove_node_class_sysfs_files(nd); } - if (nd->nd_mon_de) - unregister_dgrp_device(nd->nd_mon_de); + unregister_dgrp_device(nd->nd_mon_de); - if (nd->nd_ports_de) - unregister_dgrp_device(nd->nd_ports_de); + unregister_dgrp_device(nd->nd_ports_de); - if (nd->nd_dpa_de) - unregister_dgrp_device(nd->nd_dpa_de); + unregister_dgrp_device(nd->nd_dpa_de); dgrp_tty_uninit(nd); -- cgit v0.10.2 From b7e6724238409d0985dcf7219dd9eb0a1f58e7e5 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 12 Feb 2013 05:01:52 +0100 Subject: staging: tidspbridge: remove redundant NULL check before delete_msg_mgr(). delete_msg_mgr on a NULL pointer is a no-op, so the NULL check in bridge_msg_delete can be removed. Signed-off-by: Cyril Roelandt Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/tidspbridge/core/msg_sm.c b/drivers/staging/tidspbridge/core/msg_sm.c index ce9557e..7b517eb 100644 --- a/drivers/staging/tidspbridge/core/msg_sm.c +++ b/drivers/staging/tidspbridge/core/msg_sm.c @@ -198,8 +198,7 @@ out_err: */ void bridge_msg_delete(struct msg_mgr *hmsg_mgr) { - if (hmsg_mgr) - delete_msg_mgr(hmsg_mgr); + delete_msg_mgr(hmsg_mgr); } /* -- cgit v0.10.2 From fc9ca48eb60f4a516f59bbde1dc7685744ceb310 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 15:28:14 +0100 Subject: staging/comedi: Fix undefined array subscript In vmk80xx_do_insn_bits the local variable reg, which is used as an index to the tx_buf array, can be used uninitialized if - data[0] == 0 and - devpriv->model != VMK8061_MODEL -> we get into the else branch without having reg initialized. Since the driver usually differentiates between VMK8061_MODEL and VMK8055_MODEL it's safe to assume that VMK8055_DO_REG was meant as an initial value. And to avoid duplication we can move the assignments to the top. Acked-by: Ian Abbott Acked-by: Dan Carpenter Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index ebf2d48..eed46ee 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -675,8 +675,14 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, if (data[0]) dir |= DIR_OUT; - if (devpriv->model == VMK8061_MODEL) + if (devpriv->model == VMK8061_MODEL) { dir |= DIR_IN; + reg = VMK8061_DO_REG; + cmd = VMK8061_CMD_DO; + } else { /* VMK8055_MODEL */ + reg = VMK8055_DO_REG; + cmd = VMK8055_CMD_WRT_AD; + } retval = rudimentary_check(devpriv, dir); if (retval) @@ -688,14 +694,6 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, tx_buf = devpriv->usb_tx_buf; if (data[0]) { - if (devpriv->model == VMK8055_MODEL) { - reg = VMK8055_DO_REG; - cmd = VMK8055_CMD_WRT_AD; - } else { /* VMK8061_MODEL */ - reg = VMK8061_DO_REG; - cmd = VMK8061_CMD_DO; - } - tx_buf[reg] &= ~data[0]; tx_buf[reg] |= (data[0] & data[1]); @@ -706,7 +704,6 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, } if (devpriv->model == VMK8061_MODEL) { - reg = VMK8061_DO_REG; tx_buf[0] = VMK8061_CMD_RD_DO; retval = vmk80xx_read_packet(devpriv); -- cgit v0.10.2 From 0bcc0429bdb9f7cca3b7ab1f905b0d47031c03e0 Mon Sep 17 00:00:00 2001 From: Dan Magenheimer Date: Wed, 13 Feb 2013 10:13:06 -0800 Subject: staging: zcache: add TODO file Add zcache TODO file Signed-off-by: Dan Magenheimer Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/TODO b/drivers/staging/zcache/TODO new file mode 100644 index 0000000..c1e26d4 --- /dev/null +++ b/drivers/staging/zcache/TODO @@ -0,0 +1,69 @@ + +** ZCACHE PLAN FOR PROMOTION FROM STAGING ** + +Last updated: Feb 13, 2013 + +PLAN STEPS + +1. merge zcache and ramster to eliminate horrible code duplication +2. converge on a predictable, writeback-capable allocator +3. use debugfs instead of sysfs (per akpm feedback in 2011) +4. zcache side of cleancache/mm WasActive patch +5. zcache side of frontswap exclusive gets +6. zcache must be able to writeback to physical swap disk + (per Andrea Arcangeli feedback in 2011) +7. implement adequate policy for writeback +8. frontswap/cleancache work to allow zcache to be loaded + as a module +9. get core mm developer to review +10. incorporate feedback from review +11. get review/acks from 1-2 additional mm developers +12. incorporate any feedback from additional mm reviews +13. propose location/file-naming in mm tree +14. repeat 9-13 as necessary until akpm is happy and merges + +STATUS/OWNERSHIP + +1. DONE as part of "new" zcache; in staging/zcache for 3.9 +2. DONE as part of "new" zcache (cf zbud.[ch]); in staging/zcache for 3.9 + (this was the core of the zcache1 vs zcache2 flail) +3. DONE as part of "new" zcache; in staging/zcache for 3.9 +4. DONE (w/caveats) as part of "new" zcache; per cleancache performance + feedback see https://lkml.org/lkml/2011/8/17/351, in + staging/zcache for 3.9; dependent on proposed mm patch, see + https://lkml.org/lkml/2012/1/25/300 +5. DONE as part of "new" zcache; performance tuning only, + in staging/zcache for 3.9; dependent on frontswap patch + merged in 3.7 (33c2a174) +6. DONE (w/caveats), prototyped as part of "new" zcache, had + bad memory leak; reimplemented to use sjennings clever tricks + and proposed mm patches with new version in staging/zcache + for 3.9, see https://lkml.org/lkml/2013/2/6/437; +7. PROTOTYPED as part of "new" zcache; in staging/zcache for 3.9; + needs more review (plan to discuss at LSF/MM 2013) +8. IN PROGRESS; owned by Konrad Wilk; v2 recently posted + http://lkml.org/lkml/2013/2/1/542 +9. IN PROGRESS; owned by Konrad Wilk; Mel Gorman provided + great feedback in August 2012 (unfortunately of "old" + zcache) +10. Konrad posted series of fixes (that now need rebasing) + https://lkml.org/lkml/2013/2/1/566 +11. NOT DONE; owned by Konrad Wilk +12. TBD (depends on quantity of feedback) +13. PROPOSED; one suggestion proposed by Dan; needs more ideas/feedback +14. TBD (depends on feedback) + +WHO NEEDS TO AGREE + +Not sure. Seth Jennings is now pursuing a separate but semi-parallel +track. Akpm clearly has to approve for any mm merge to happen. Minchan +Kim has interest but may be happy if/when zram is merged into mm. Konrad +Wilk may be maintainer if akpm decides compression is maintainable +separately from the rest of mm. (More LSF/MM 2013 discussion.) + +ZCACHE FUTURE NEW FUNCTIONALITY + +A. Support zsmalloc as an alternative high-density allocator + (See https://lkml.org/lkml/2013/1/23/511) +B. Support zero-filled pages more efficiently +C. Possibly support three zbuds per pageframe when space allows -- cgit v0.10.2 From fae7e4d39373305cf505d1f0871a4491897d56f9 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Thu, 14 Feb 2013 03:37:10 +0100 Subject: staging/wlan-ng: Fix 'Branch condition evaluates to a garbage value' in p80211netdev.c clang/scan-build complains that: p80211netdev.c:451:6: warning: Branch condition evaluates to a garbage value if ((p80211_wep.data) && (p80211_wep.data != skb->data)) ^~~~~~~~~~~~~~~~~ This can happen in p80211knetdev_hard_start_xmit if - if (wlandev->state != WLAN_DEVICE_OPEN) evaluates to true. the execution flow then continues at the 'failed' label where p80211_wep.data is used without being initialized first. -> Initialize the data field to NULL to fix this issue. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c index 750330f..0039e08 100644 --- a/drivers/staging/wlan-ng/p80211netdev.c +++ b/drivers/staging/wlan-ng/p80211netdev.c @@ -351,6 +351,8 @@ static int p80211knetdev_hard_start_xmit(struct sk_buff *skb, union p80211_hdr p80211_hdr; struct p80211_metawep p80211_wep; + p80211_wep.data = NULL; + if (skb == NULL) return NETDEV_TX_OK; -- cgit v0.10.2 From 67a88e6390e52e42b72342a88fab458ada00ba28 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Thu, 14 Feb 2013 04:08:55 +0100 Subject: staging/rtl8192u/ieee80211: Fix buffer overflow in ieee80211_softmac_wx.c Clang/scan-build complains about a possible buffer overflow in ieee80211_wx_get_name: .../staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c:499:3: warning: String copy function overflows destination buffer strcat(wrqu->name," link.."); .../staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c:497:3: warning: String copy function overflows destination buffer strcat(wrqu->name," linked"); The buffer wrqu->name is only IFNAMSIZ bytes big (currently 16), so if we have a "802.11b/g/n linked" device we overrun the buffer by 3 bytes. -> Use strlcopy / strlcat to populate the name. This is done in a similar fashion in staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c While at it cleaned some whitespace issues. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c index 45422db..60746b8 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c @@ -482,22 +482,23 @@ int ieee80211_wx_get_name(struct ieee80211_device *ieee, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { - strcpy(wrqu->name, "802.11"); - if(ieee->modulation & IEEE80211_CCK_MODULATION){ - strcat(wrqu->name, "b"); - if(ieee->modulation & IEEE80211_OFDM_MODULATION) - strcat(wrqu->name, "/g"); - }else if(ieee->modulation & IEEE80211_OFDM_MODULATION) - strcat(wrqu->name, "g"); - if (ieee->mode & (IEEE_N_24G | IEEE_N_5G)) - strcat(wrqu->name, "/n"); + strlcpy(wrqu->name, "802.11", IFNAMSIZ); + if (ieee->modulation & IEEE80211_CCK_MODULATION) { + strlcat(wrqu->name, "b", IFNAMSIZ); + if (ieee->modulation & IEEE80211_OFDM_MODULATION) + strlcat(wrqu->name, "/g", IFNAMSIZ); + } else if (ieee->modulation & IEEE80211_OFDM_MODULATION) { + strlcat(wrqu->name, "g", IFNAMSIZ); + } - if((ieee->state == IEEE80211_LINKED) || - (ieee->state == IEEE80211_LINKED_SCANNING)) - strcat(wrqu->name," linked"); - else if(ieee->state != IEEE80211_NOLINK) - strcat(wrqu->name," link.."); + if (ieee->mode & (IEEE_N_24G | IEEE_N_5G)) + strlcat(wrqu->name, "/n", IFNAMSIZ); + if ((ieee->state == IEEE80211_LINKED) || + (ieee->state == IEEE80211_LINKED_SCANNING)) + strlcat(wrqu->name, " linked", IFNAMSIZ); + else if (ieee->state != IEEE80211_NOLINK) + strlcat(wrqu->name, " link..", IFNAMSIZ); return 0; } -- cgit v0.10.2 From 291131cba157d411d80bf86a105885c3dc48a817 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Fri, 15 Feb 2013 12:53:41 -0500 Subject: zcache: Fix compile warnings due to usage of debugfs_create_size_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we compile we get tons of: include/linux/debugfs.h:80:16: note: expected ‘size_t *’ but argument is of type ‘long int *’ drivers/staging/zcache/zcache-main.c:279:2: warning: passing argument 4 of ‘debugfs_create_size_t’ from incompatible pointer type [enabled by d efault] which is b/c we end up using 'unsigned' or 'unsigned long' instead of 'ssize_t'. So lets fix this up and use the proper type. [v2: Rebased directly on staging] Acked-by: Dan Magenheimer Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 4456ab4..328898e 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -135,61 +135,62 @@ static struct kmem_cache *zcache_obj_cache; static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, }; /* we try to keep these statistics SMP-consistent */ -static long zcache_obj_count; +static ssize_t zcache_obj_count; static atomic_t zcache_obj_atomic = ATOMIC_INIT(0); -static long zcache_obj_count_max; -static long zcache_objnode_count; +static ssize_t zcache_obj_count_max; +static ssize_t zcache_objnode_count; static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0); -static long zcache_objnode_count_max; +static ssize_t zcache_objnode_count_max; static u64 zcache_eph_zbytes; static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0); static u64 zcache_eph_zbytes_max; static u64 zcache_pers_zbytes; static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0); static u64 zcache_pers_zbytes_max; -static long zcache_eph_pageframes; +static ssize_t zcache_eph_pageframes; static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0); -static long zcache_eph_pageframes_max; -static long zcache_pers_pageframes; +static ssize_t zcache_eph_pageframes_max; +static ssize_t zcache_pers_pageframes; static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0); -static long zcache_pers_pageframes_max; -static long zcache_pageframes_alloced; +static ssize_t zcache_pers_pageframes_max; +static ssize_t zcache_pageframes_alloced; static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0); -static long zcache_pageframes_freed; +static ssize_t zcache_pageframes_freed; static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0); -static long zcache_eph_zpages; +static ssize_t zcache_eph_zpages; +static ssize_t zcache_eph_zpages; static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0); -static long zcache_eph_zpages_max; -static long zcache_pers_zpages; +static ssize_t zcache_eph_zpages_max; +static ssize_t zcache_pers_zpages; static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0); -static long zcache_pers_zpages_max; +static ssize_t zcache_pers_zpages_max; /* but for the rest of these, counting races are ok */ -static unsigned long zcache_flush_total; -static unsigned long zcache_flush_found; -static unsigned long zcache_flobj_total; -static unsigned long zcache_flobj_found; -static unsigned long zcache_failed_eph_puts; -static unsigned long zcache_failed_pers_puts; -static unsigned long zcache_failed_getfreepages; -static unsigned long zcache_failed_alloc; -static unsigned long zcache_put_to_flush; -static unsigned long zcache_compress_poor; -static unsigned long zcache_mean_compress_poor; -static unsigned long zcache_eph_ate_tail; -static unsigned long zcache_eph_ate_tail_failed; -static unsigned long zcache_pers_ate_eph; -static unsigned long zcache_pers_ate_eph_failed; -static unsigned long zcache_evicted_eph_zpages; -static unsigned long zcache_evicted_eph_pageframes; -static unsigned long zcache_last_active_file_pageframes; -static unsigned long zcache_last_inactive_file_pageframes; -static unsigned long zcache_last_active_anon_pageframes; -static unsigned long zcache_last_inactive_anon_pageframes; -static unsigned long zcache_eph_nonactive_puts_ignored; -static unsigned long zcache_pers_nonactive_puts_ignored; -static unsigned long zcache_writtenback_pages; -static long zcache_outstanding_writeback_pages; +static ssize_t zcache_flush_total; +static ssize_t zcache_flush_found; +static ssize_t zcache_flobj_total; +static ssize_t zcache_flobj_found; +static ssize_t zcache_failed_eph_puts; +static ssize_t zcache_failed_pers_puts; +static ssize_t zcache_failed_getfreepages; +static ssize_t zcache_failed_alloc; +static ssize_t zcache_put_to_flush; +static ssize_t zcache_compress_poor; +static ssize_t zcache_mean_compress_poor; +static ssize_t zcache_eph_ate_tail; +static ssize_t zcache_eph_ate_tail_failed; +static ssize_t zcache_pers_ate_eph; +static ssize_t zcache_pers_ate_eph_failed; +static ssize_t zcache_evicted_eph_zpages; +static ssize_t zcache_evicted_eph_pageframes; +static ssize_t zcache_last_active_file_pageframes; +static ssize_t zcache_last_inactive_file_pageframes; +static ssize_t zcache_last_active_anon_pageframes; +static ssize_t zcache_last_inactive_anon_pageframes; +static ssize_t zcache_eph_nonactive_puts_ignored; +static ssize_t zcache_pers_nonactive_puts_ignored; +static ssize_t zcache_writtenback_pages; +static ssize_t zcache_outstanding_writeback_pages; #ifdef CONFIG_DEBUG_FS #include @@ -262,64 +263,64 @@ static int zcache_debugfs_init(void) /* developers can call this in case of ooms, e.g. to find memory leaks */ void zcache_dump(void) { - pr_info("zcache: obj_count=%lu\n", zcache_obj_count); - pr_info("zcache: obj_count_max=%lu\n", zcache_obj_count_max); - pr_info("zcache: objnode_count=%lu\n", zcache_objnode_count); - pr_info("zcache: objnode_count_max=%lu\n", zcache_objnode_count_max); - pr_info("zcache: flush_total=%lu\n", zcache_flush_total); - pr_info("zcache: flush_found=%lu\n", zcache_flush_found); - pr_info("zcache: flobj_total=%lu\n", zcache_flobj_total); - pr_info("zcache: flobj_found=%lu\n", zcache_flobj_found); - pr_info("zcache: failed_eph_puts=%lu\n", zcache_failed_eph_puts); - pr_info("zcache: failed_pers_puts=%lu\n", zcache_failed_pers_puts); - pr_info("zcache: failed_get_free_pages=%lu\n", + pr_info("zcache: obj_count=%zd\n", zcache_obj_count); + pr_info("zcache: obj_count_max=%zd\n", zcache_obj_count_max); + pr_info("zcache: objnode_count=%zd\n", zcache_objnode_count); + pr_info("zcache: objnode_count_max=%zd\n", zcache_objnode_count_max); + pr_info("zcache: flush_total=%zd\n", zcache_flush_total); + pr_info("zcache: flush_found=%zd\n", zcache_flush_found); + pr_info("zcache: flobj_total=%zd\n", zcache_flobj_total); + pr_info("zcache: flobj_found=%zd\n", zcache_flobj_found); + pr_info("zcache: failed_eph_puts=%zd\n", zcache_failed_eph_puts); + pr_info("zcache: failed_pers_puts=%zd\n", zcache_failed_pers_puts); + pr_info("zcache: failed_get_free_pages=%zd\n", zcache_failed_getfreepages); - pr_info("zcache: failed_alloc=%lu\n", zcache_failed_alloc); - pr_info("zcache: put_to_flush=%lu\n", zcache_put_to_flush); - pr_info("zcache: compress_poor=%lu\n", zcache_compress_poor); - pr_info("zcache: mean_compress_poor=%lu\n", + pr_info("zcache: failed_alloc=%zd\n", zcache_failed_alloc); + pr_info("zcache: put_to_flush=%zd\n", zcache_put_to_flush); + pr_info("zcache: compress_poor=%zd\n", zcache_compress_poor); + pr_info("zcache: mean_compress_poor=%zd\n", zcache_mean_compress_poor); - pr_info("zcache: eph_ate_tail=%lu\n", zcache_eph_ate_tail); - pr_info("zcache: eph_ate_tail_failed=%lu\n", + pr_info("zcache: eph_ate_tail=%zd\n", zcache_eph_ate_tail); + pr_info("zcache: eph_ate_tail_failed=%zd\n", zcache_eph_ate_tail_failed); - pr_info("zcache: pers_ate_eph=%lu\n", zcache_pers_ate_eph); - pr_info("zcache: pers_ate_eph_failed=%lu\n", + pr_info("zcache: pers_ate_eph=%zd\n", zcache_pers_ate_eph); + pr_info("zcache: pers_ate_eph_failed=%zd\n", zcache_pers_ate_eph_failed); - pr_info("zcache: evicted_eph_zpages=%lu\n", zcache_evicted_eph_zpages); - pr_info("zcache: evicted_eph_pageframes=%lu\n", + pr_info("zcache: evicted_eph_zpages=%zd\n", zcache_evicted_eph_zpages); + pr_info("zcache: evicted_eph_pageframes=%zd\n", zcache_evicted_eph_pageframes); - pr_info("zcache: eph_pageframes=%lu\n", zcache_eph_pageframes); - pr_info("zcache: eph_pageframes_max=%lu\n", zcache_eph_pageframes_max); - pr_info("zcache: pers_pageframes=%lu\n", zcache_pers_pageframes); - pr_info("zcache: pers_pageframes_max=%lu\n", + pr_info("zcache: eph_pageframes=%zd\n", zcache_eph_pageframes); + pr_info("zcache: eph_pageframes_max=%zd\n", zcache_eph_pageframes_max); + pr_info("zcache: pers_pageframes=%zd\n", zcache_pers_pageframes); + pr_info("zcache: pers_pageframes_max=%zd\n", zcache_pers_pageframes_max); - pr_info("zcache: eph_zpages=%lu\n", zcache_eph_zpages); - pr_info("zcache: eph_zpages_max=%lu\n", zcache_eph_zpages_max); - pr_info("zcache: pers_zpages=%lu\n", zcache_pers_zpages); - pr_info("zcache: pers_zpages_max=%lu\n", zcache_pers_zpages_max); - pr_info("zcache: last_active_file_pageframes=%lu\n", + pr_info("zcache: eph_zpages=%zd\n", zcache_eph_zpages); + pr_info("zcache: eph_zpages_max=%zd\n", zcache_eph_zpages_max); + pr_info("zcache: pers_zpages=%zd\n", zcache_pers_zpages); + pr_info("zcache: pers_zpages_max=%zd\n", zcache_pers_zpages_max); + pr_info("zcache: last_active_file_pageframes=%zd\n", zcache_last_active_file_pageframes); - pr_info("zcache: last_inactive_file_pageframes=%lu\n", + pr_info("zcache: last_inactive_file_pageframes=%zd\n", zcache_last_inactive_file_pageframes); - pr_info("zcache: last_active_anon_pageframes=%lu\n", + pr_info("zcache: last_active_anon_pageframes=%zd\n", zcache_last_active_anon_pageframes); - pr_info("zcache: last_inactive_anon_pageframes=%lu\n", + pr_info("zcache: last_inactive_anon_pageframes=%zd\n", zcache_last_inactive_anon_pageframes); - pr_info("zcache: eph_nonactive_puts_ignored=%lu\n", + pr_info("zcache: eph_nonactive_puts_ignored=%zd\n", zcache_eph_nonactive_puts_ignored); - pr_info("zcache: pers_nonactive_puts_ignored=%lu\n", + pr_info("zcache: pers_nonactive_puts_ignored=%zd\n", zcache_pers_nonactive_puts_ignored); pr_info("zcache: eph_zbytes=%llu\n", - (unsigned long long)zcache_eph_zbytes); + zcache_eph_zbytes); pr_info("zcache: eph_zbytes_max=%llu\n", - (unsigned long long)zcache_eph_zbytes_max); + zcache_eph_zbytes_max); pr_info("zcache: pers_zbytes=%llu\n", - (unsigned long long)zcache_pers_zbytes); + zcache_pers_zbytes); pr_info("zcache: pers_zbytes_max=%llu\n", - (unsigned long long)zcache_pers_zbytes_max); - pr_info("zcache: outstanding_writeback_pages=%lu\n", + zcache_pers_zbytes_max); + pr_info("zcache: outstanding_writeback_pages=%zd\n", zcache_outstanding_writeback_pages); - pr_info("zcache: writtenback_pages=%lu\n", zcache_writtenback_pages); + pr_info("zcache: writtenback_pages=%zd\n", zcache_writtenback_pages); } #endif -- cgit v0.10.2 From 80e9fc9af4cbab97508f5853a5c5ab6ca9ef14bd Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Fri, 15 Feb 2013 12:53:42 -0500 Subject: ramster: Fix compile warnings due to usage of debugfs_create_size_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We get tons of "note: expected ‘size_t *’ but argument is of type ‘long int *’" warnings. This fixes it. Acked-by: Dan Magenheimer Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/ramster/ramster.c b/drivers/staging/zcache/ramster/ramster.c index c06709f..bf96a1c 100644 --- a/drivers/staging/zcache/ramster/ramster.c +++ b/drivers/staging/zcache/ramster/ramster.c @@ -67,25 +67,25 @@ static int ramster_remote_target_nodenum __read_mostly = -1; static long ramster_flnodes; static atomic_t ramster_flnodes_atomic = ATOMIC_INIT(0); static unsigned long ramster_flnodes_max; -static long ramster_foreign_eph_pages; +static ssize_t ramster_foreign_eph_pages; static atomic_t ramster_foreign_eph_pages_atomic = ATOMIC_INIT(0); -static unsigned long ramster_foreign_eph_pages_max; -static long ramster_foreign_pers_pages; +static ssize_t ramster_foreign_eph_pages_max; +static ssize_t ramster_foreign_pers_pages; static atomic_t ramster_foreign_pers_pages_atomic = ATOMIC_INIT(0); -static unsigned long ramster_foreign_pers_pages_max; -static unsigned long ramster_eph_pages_remoted; -static unsigned long ramster_pers_pages_remoted; -static unsigned long ramster_eph_pages_remote_failed; -static unsigned long ramster_pers_pages_remote_failed; -static unsigned long ramster_remote_eph_pages_succ_get; -static unsigned long ramster_remote_pers_pages_succ_get; -static unsigned long ramster_remote_eph_pages_unsucc_get; -static unsigned long ramster_remote_pers_pages_unsucc_get; -static unsigned long ramster_pers_pages_remote_nomem; -static unsigned long ramster_remote_objects_flushed; -static unsigned long ramster_remote_object_flushes_failed; -static unsigned long ramster_remote_pages_flushed; -static unsigned long ramster_remote_page_flushes_failed; +static ssize_t ramster_foreign_pers_pages_max; +static ssize_t ramster_eph_pages_remoted; +static ssize_t ramster_pers_pages_remoted; +static ssize_t ramster_eph_pages_remote_failed; +static ssize_t ramster_pers_pages_remote_failed; +static ssize_t ramster_remote_eph_pages_succ_get; +static ssize_t ramster_remote_pers_pages_succ_get; +static ssize_t ramster_remote_eph_pages_unsucc_get; +static ssize_t ramster_remote_pers_pages_unsucc_get; +static ssize_t ramster_pers_pages_remote_nomem; +static ssize_t ramster_remote_objects_flushed; +static ssize_t ramster_remote_object_flushes_failed; +static ssize_t ramster_remote_pages_flushed; +static ssize_t ramster_remote_page_flushes_failed; /* FIXME frontswap selfshrinking knobs in debugfs? */ #ifdef CONFIG_DEBUG_FS -- cgit v0.10.2 From feb897e1f48918bf5cd60a075a6641ed41ace988 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Fri, 15 Feb 2013 12:53:43 -0500 Subject: zbud: Fix compile warnings due to usage of debugfs_create_size_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit . drivers/staging/zcache/zbud.c:336: warning: passing argument 4 of ‘debugfs_create_size_t’ from incompatible pointer type include/linux/debugfs.h:80: note: expected ‘size_t *’ but argument is of type ‘long unsigned int *’ .. which is b/c we end up using 'unsigned' or 'unsigned long' instead of 'ssize_t'. So lets fix this up and use the proper type. Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zbud.c b/drivers/staging/zcache/zbud.c index 6835fab..4654978 100644 --- a/drivers/staging/zcache/zbud.c +++ b/drivers/staging/zcache/zbud.c @@ -281,26 +281,26 @@ static inline char *zbud_data(void *zbpg, * debugfs viewers, some of these should also be atomic_long_t, but * I don't know how to expose atomics via debugfs either... */ -static unsigned long zbud_eph_pageframes; -static unsigned long zbud_pers_pageframes; -static unsigned long zbud_eph_zpages; -static unsigned long zbud_pers_zpages; +static ssize_t zbud_eph_pageframes; +static ssize_t zbud_pers_pageframes; +static ssize_t zbud_eph_zpages; +static ssize_t zbud_pers_zpages; static u64 zbud_eph_zbytes; static u64 zbud_pers_zbytes; -static unsigned long zbud_eph_evicted_pageframes; -static unsigned long zbud_pers_evicted_pageframes; -static unsigned long zbud_eph_cumul_zpages; -static unsigned long zbud_pers_cumul_zpages; +static ssize_t zbud_eph_evicted_pageframes; +static ssize_t zbud_pers_evicted_pageframes; +static ssize_t zbud_eph_cumul_zpages; +static ssize_t zbud_pers_cumul_zpages; static u64 zbud_eph_cumul_zbytes; static u64 zbud_pers_cumul_zbytes; -static unsigned long zbud_eph_cumul_chunk_counts[NCHUNKS]; -static unsigned long zbud_pers_cumul_chunk_counts[NCHUNKS]; -static unsigned long zbud_eph_buddied_count; -static unsigned long zbud_pers_buddied_count; -static unsigned long zbud_eph_unbuddied_count; -static unsigned long zbud_pers_unbuddied_count; -static unsigned long zbud_eph_zombie_count; -static unsigned long zbud_pers_zombie_count; +static ssize_t zbud_eph_cumul_chunk_counts[NCHUNKS]; +static ssize_t zbud_pers_cumul_chunk_counts[NCHUNKS]; +static ssize_t zbud_eph_buddied_count; +static ssize_t zbud_pers_buddied_count; +static ssize_t zbud_eph_unbuddied_count; +static ssize_t zbud_pers_unbuddied_count; +static ssize_t zbud_eph_zombie_count; +static ssize_t zbud_pers_zombie_count; static atomic_t zbud_eph_zombie_atomic; static atomic_t zbud_pers_zombie_atomic; -- cgit v0.10.2 From d489082ac690f7cf784e66cfd74f076a361740ba Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Fri, 15 Feb 2013 12:53:44 -0500 Subject: zcache/zbud: Fix __init mismatch We get: WARNING: drivers/staging/zcache/zcache.o(.text+0x13a1): Section mismatch in reference from the function zcache_init() to the function .init.text:zbud_init() The function zcache_init() references the function __init zbud_init(). This is often because zcache_init lacks a __init annotation or the annotation of zbud_init is wrong. And this fixes it. Acked-by: Dan Magenheimer Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zbud.c b/drivers/staging/zcache/zbud.c index 4654978..ee927e8 100644 --- a/drivers/staging/zcache/zbud.c +++ b/drivers/staging/zcache/zbud.c @@ -1047,7 +1047,7 @@ out: return ret; } -void __init zbud_init(void) +void zbud_init(void) { int i; -- cgit v0.10.2 From 0cbfc8269b980adafa7b529bb529a2fc316c5405 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 14 Feb 2013 16:42:13 +0000 Subject: staging: comedi: vmk80xx: zero buffers on allocation Zero out `devpriv->usb_tx_buf` and `devpriv->usb_rx_buf` on allocation. When sending data to the USB device, this ensures any unused part of the buffer will not contain random crap. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index eed46ee..78228f6 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -994,12 +994,12 @@ static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev) size_t size; size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); - devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL); + devpriv->usb_rx_buf = kzalloc(size, GFP_KERNEL); if (!devpriv->usb_rx_buf) return -ENOMEM; size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); - devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL); + devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL); if (!devpriv->usb_tx_buf) { kfree(devpriv->usb_rx_buf); return -ENOMEM; -- cgit v0.10.2 From e8f311a5b6b9163f6aeba2524eaab92dc3b0fb6f Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 14 Feb 2013 16:42:14 +0000 Subject: staging: comedi: vmk80xx: simplify vmk80xx_reset_device() vmk80xx_reset_device() is called during initialization of a Velleman K8055 (aka VM110) to send a reset command to the hardware. The current function is a bit long-winded and doesn't set the TRANS_OUT_BUSY flag to prevent re-use of the transmit buffer while the URB is in progress. Rewrite the function to use vmk80xx_write_packet() to send the command. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 78228f6..057d840 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -277,41 +277,6 @@ static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag) strncpy(devpriv->fw.ic6_vers, rx + 25, 24); } -static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) -{ - struct usb_device *usb = devpriv->usb; - unsigned char *tx_buf = devpriv->usb_tx_buf; - struct urb *urb; - unsigned int tx_pipe; - int ival; - size_t size; - - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) - return -ENOMEM; - - tx_pipe = usb_sndintpipe(usb, 0x01); - - ival = devpriv->ep_tx->bInterval; - size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); - - tx_buf[0] = VMK8055_CMD_RST; - tx_buf[1] = 0x00; - tx_buf[2] = 0x00; - tx_buf[3] = 0x00; - tx_buf[4] = 0x00; - tx_buf[5] = 0x00; - tx_buf[6] = 0x00; - tx_buf[7] = 0x00; - - usb_fill_int_urb(urb, usb, tx_pipe, tx_buf, size, - vmk80xx_tx_callback, devpriv, ival); - - usb_anchor_urb(urb, &devpriv->tx_anchor); - - return usb_submit_urb(urb, GFP_KERNEL); -} - static void vmk80xx_build_int_urb(struct urb *urb, int flag) { struct vmk80xx_private *devpriv = urb->context; @@ -468,6 +433,15 @@ exit: return retval; } +static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) +{ + size_t size; + + size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); + memset(devpriv->usb_tx_buf, 0, size); + return vmk80xx_write_packet(devpriv, VMK8055_CMD_RST); +} + #define DIR_IN 1 #define DIR_OUT 2 -- cgit v0.10.2 From f06a23c93b900c37ef14858868c00dc8f061fa22 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 14 Feb 2013 16:42:15 +0000 Subject: staging: comedi: vmk80xx: initialize K8055 outputs to known state vmk8055_reset_device() is called during initialization of a Velleman K8055 (aka VM110) to send a reset command to the hardware. I don't know what this does, but I know that it doesn't reset the digital outputs as I've tried it. Since the hardware does not have any way to query the current output values and there is only the one command to update all the analog and digital outputs simultaneously (VMK8055_CMD_WRT_AD), send this command during initialization to set all the analog and digital outputs to a known state. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 057d840..7984e03 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -436,10 +436,15 @@ exit: static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) { size_t size; + int retval; size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); memset(devpriv->usb_tx_buf, 0, size); - return vmk80xx_write_packet(devpriv, VMK8055_CMD_RST); + retval = vmk80xx_write_packet(devpriv, VMK8055_CMD_RST); + if (retval) + return retval; + /* set outputs to known state as we cannot read them */ + return vmk80xx_write_packet(devpriv, VMK8055_CMD_WRT_AD); } #define DIR_IN 1 -- cgit v0.10.2 From 8289ad0578ad7e66b2052754746b4deb1a88cc4a Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Thu, 14 Feb 2013 22:27:06 +0100 Subject: staging/comedi: Use && instead of & for logical comparision sparse complains that: drivers/staging/comedi/drivers/adl_pci9118.c:813 pci9118_calc_divisors() warn: maybe use && instead of & usessh is used as a boolean flag (0 and 1) and is compared to a boolean value so we should use && here. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index ef4dbe5..4dbac74 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -810,7 +810,7 @@ static void pci9118_calc_divisors(char mode, struct comedi_device *dev, *tim2 = *div1 * devpriv->i8254_osc_base; /* real convert timer */ - if (usessh & (chnsshfront == 0)) /* use BSSH signal */ + if (usessh && (chnsshfront == 0)) /* use BSSH signal */ if (*div2 < (chans + 2)) *div2 = chans + 2; -- cgit v0.10.2 From a81875dd7a6e31e69ea1f6ed22209acb8f82bf36 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 13:14:26 +0100 Subject: staging/comedi: Remove if(); statement without effect Smatch warns about: staging/comedi/drivers/cb_pcidas64.c:3304 prep_ao_dma() warn: if(); So the check currently does nothing and can be removed, as indicated by Ian. Signed-off-by: Peter Huewe Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c index d33fc32..9f3112c 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas64.c +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c @@ -3301,7 +3301,6 @@ static int prep_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd) num_bytes = load_ao_dma_buffer(dev, cmd); if (num_bytes == 0) return -1; - if (num_bytes >= DMA_BUFFER_SIZE) ; load_ao_dma(dev, cmd); dma_start_sync(dev, 0); -- cgit v0.10.2 From 36d2041a3d57b9542bb93c94df4f9ebf3a1aee32 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 13:47:05 +0100 Subject: staging/panel: Mark local functions/structs static and add const if applicable (fix sparse warnings) sparse complains about the following functions: panel.c:188:1: warning: symbol 'logical_inputs' was not declared. Should it be static? panel.c:569:6: warning: symbol 'old_keypad_profile' was not declared. Should it be static? panel.c:580:6: warning: symbol 'new_keypad_profile' was not declared. Should it be static? panel.c:593:6: warning: symbol 'nexcom_keypad_profile' was not declared. Should it be static? panel.c:672:6: warning: symbol 'pin_to_bits' was not declared. Should it be static? panel.c:1375:6: warning: symbol 'panel_lcd_print' was not declared. Should it be static? panel.c:1382:6: warning: symbol 'lcd_init' was not declared. Should it be static? panel.c:2181:5: warning: symbol 'panel_init' was not declared. Should it be static? Add the static keyword to silence these warnings and make sparse happy. If structs or function parameters are used readonly they are also marked as const. CC: David Howells Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c index e3113ec..c54df39 100644 --- a/drivers/staging/panel/panel.c +++ b/drivers/staging/panel/panel.c @@ -185,7 +185,7 @@ struct logical_input { } u; }; -LIST_HEAD(logical_inputs); /* list of all defined logical inputs */ +static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */ /* physical contacts history * Physical contacts are a 45 bits string of 9 groups of 5 bits each. @@ -527,10 +527,10 @@ MODULE_PARM_DESC(lcd_cl_pin, "# of the // port pin connected to serial LCD 'SCL' " "signal, with polarity (-17..17)"); -static unsigned char *lcd_char_conv; +static const unsigned char *lcd_char_conv; /* for some LCD drivers (ks0074) we need a charset conversion table. */ -static unsigned char lcd_char_conv_ks0074[256] = { +static const unsigned char lcd_char_conv_ks0074[256] = { /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */ /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, @@ -566,7 +566,7 @@ static unsigned char lcd_char_conv_ks0074[256] = { /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79, }; -char old_keypad_profile[][4][9] = { +static const char old_keypad_profile[][4][9] = { {"S0", "Left\n", "Left\n", ""}, {"S1", "Down\n", "Down\n", ""}, {"S2", "Up\n", "Up\n", ""}, @@ -577,7 +577,7 @@ char old_keypad_profile[][4][9] = { }; /* signals, press, repeat, release */ -char new_keypad_profile[][4][9] = { +static const char new_keypad_profile[][4][9] = { {"S0", "Left\n", "Left\n", ""}, {"S1", "Down\n", "Down\n", ""}, {"S2", "Up\n", "Up\n", ""}, @@ -590,7 +590,7 @@ char new_keypad_profile[][4][9] = { }; /* signals, press, repeat, release */ -char nexcom_keypad_profile[][4][9] = { +static const char nexcom_keypad_profile[][4][9] = { {"a-p-e-", "Down\n", "Down\n", ""}, {"a-p-E-", "Ret\n", "Ret\n", ""}, {"a-P-E-", "Esc\n", "Esc\n", ""}, @@ -599,7 +599,7 @@ char nexcom_keypad_profile[][4][9] = { {"", "", "", ""} }; -static char (*keypad_profile)[4][9] = old_keypad_profile; +static const char (*keypad_profile)[4][9] = old_keypad_profile; /* FIXME: this should be converted to a bit array containing signals states */ static struct { @@ -669,7 +669,7 @@ static void panel_set_bits(void) * out(dport, in(dport) & d_val[2] | d_val[signal_state]) * out(cport, in(cport) & c_val[2] | c_val[signal_state]) */ -void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val) +static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val) { int d_bit, c_bit, inv; @@ -1372,14 +1372,14 @@ static struct miscdevice lcd_dev = { }; /* public function usable from the kernel for any purpose */ -void panel_lcd_print(char *s) +static void panel_lcd_print(const char *s) { if (lcd_enabled && lcd_initialized) lcd_write(NULL, s, strlen(s), NULL); } /* initialize the LCD driver */ -void lcd_init(void) +static void lcd_init(void) { switch (lcd_type) { case LCD_TYPE_OLD: @@ -1638,7 +1638,7 @@ static struct miscdevice keypad_dev = { &keypad_fops }; -static void keypad_send_key(char *string, int max_len) +static void keypad_send_key(const char *string, int max_len) { if (init_in_progress) return; @@ -1929,7 +1929,7 @@ static void init_scan_timer(void) * corresponding to out and in bits respectively. * returns 1 if ok, 0 if error (in which case, nothing is written). */ -static int input_name2mask(char *name, pmask_t *mask, pmask_t *value, +static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value, char *imask, char *omask) { static char sigtab[10] = "EeSsPpAaBb"; @@ -1977,8 +1977,9 @@ static int input_name2mask(char *name, pmask_t *mask, pmask_t *value, * strings , , for these respective events. * Returns the pointer to the new key if ok, NULL if the key could not be bound. */ -static struct logical_input *panel_bind_key(char *name, char *press, - char *repeat, char *release) +static struct logical_input *panel_bind_key(const char *name, const char *press, + const char *repeat, + const char *release) { struct logical_input *key; @@ -2178,7 +2179,7 @@ static struct parport_driver panel_driver = { }; /* init function */ -int panel_init(void) +static int panel_init(void) { /* for backwards compatibility */ if (keypad_type < 0) -- cgit v0.10.2 From 86b02be043c42e1d7450be025177e3e248a2e8c1 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:22 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozpd.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Reviewed-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c index 118a4db..d969ed7 100644 --- a/drivers/staging/ozwpan/ozpd.c +++ b/drivers/staging/ozwpan/ozpd.c @@ -61,8 +61,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = { oz_def_app_start, oz_def_app_stop, oz_def_app_rx, - 0, - 0, + NULL, + NULL, OZ_APPID_UNUSED1}, {oz_def_app_init, @@ -70,8 +70,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = { oz_def_app_start, oz_def_app_stop, oz_def_app_rx, - 0, - 0, + NULL, + NULL, OZ_APPID_UNUSED2}, {oz_cdev_init, @@ -79,8 +79,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = { oz_cdev_start, oz_cdev_stop, oz_cdev_rx, - 0, - 0, + NULL, + NULL, OZ_APPID_SERIAL}, }; /*------------------------------------------------------------------------------ @@ -121,7 +121,7 @@ static void oz_def_app_rx(struct oz_pd *pd, struct oz_elt *elt) void oz_pd_set_state(struct oz_pd *pd, unsigned state) { pd->state = state; - oz_event_log(OZ_EVT_PD_STATE, 0, 0, 0, state); + oz_event_log(OZ_EVT_PD_STATE, 0, 0, NULL, state); #ifdef WANT_TRACE switch (state) { case OZ_PD_S_IDLE: @@ -171,7 +171,7 @@ struct oz_pd *oz_pd_alloc(u8 *mac_addr) memcpy(pd->mac_addr, mac_addr, ETH_ALEN); if (0 != oz_elt_buf_init(&pd->elt_buff)) { kfree(pd); - pd = 0; + pd = NULL; } spin_lock_init(&pd->tx_frame_lock); INIT_LIST_HEAD(&pd->tx_queue); @@ -355,7 +355,7 @@ int oz_pd_sleep(struct oz_pd *pd) */ static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd) { - struct oz_tx_frame *f = 0; + struct oz_tx_frame *f = NULL; spin_lock_bh(&pd->tx_frame_lock); if (pd->tx_pool) { f = container_of(pd->tx_pool, struct oz_tx_frame, link); @@ -363,7 +363,7 @@ static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd) pd->tx_pool_count--; } spin_unlock_bh(&pd->tx_frame_lock); - if (f == 0) + if (f == NULL) f = kmalloc(sizeof(struct oz_tx_frame), GFP_ATOMIC); if (f) { f->total_size = sizeof(struct oz_hdr); @@ -399,7 +399,7 @@ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f) f->link.next = pd->tx_pool; pd->tx_pool = &f->link; pd->tx_pool_count++; - f = 0; + f = NULL; } spin_unlock_bh(&pd->tx_frame_lock); kfree(f); @@ -433,7 +433,7 @@ int oz_prepare_frame(struct oz_pd *pd, int empty) if (!empty && !oz_are_elts_available(&pd->elt_buff)) return -1; f = oz_tx_frame_alloc(pd); - if (f == 0) + if (f == NULL) return -1; f->skb = NULL; f->hdr.control = @@ -455,7 +455,7 @@ int oz_prepare_frame(struct oz_pd *pd, int empty) */ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f) { - struct sk_buff *skb = 0; + struct sk_buff *skb; struct net_device *dev = pd->net_dev; struct oz_hdr *oz_hdr; struct oz_elt *elt; @@ -464,8 +464,8 @@ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f) * as the space we need. */ skb = alloc_skb(f->total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) - return 0; + if (skb == NULL) + return NULL; /* Reserve the head room for lower layers. */ skb_reserve(skb, LL_RESERVED_SPACE(dev)); @@ -492,7 +492,7 @@ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f) return skb; fail: kfree_skb(skb); - return 0; + return NULL; } /*------------------------------------------------------------------------------ * Context: softirq or process @@ -544,7 +544,7 @@ static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data) if (dev_queue_xmit(skb) < 0) { oz_trace2(OZ_TRACE_TX_FRAMES, "Dropping ISOC Frame\n"); - oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); + oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0); return -1; } atomic_inc(&g_submitted_isoc); @@ -555,7 +555,7 @@ static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data) } else { kfree_skb(skb); oz_trace2(OZ_TRACE_TX_FRAMES, "Dropping ISOC Frame>\n"); - oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); + oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0); return -1; } } @@ -570,7 +570,7 @@ static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data) oz_event_log(OZ_EVT_TX_FRAME, 0, (((u16)f->hdr.control)<<8)|f->hdr.last_pkt_num, - 0, f->hdr.pkt_num); + NULL, f->hdr.pkt_num); if (dev_queue_xmit(skb) < 0) return -1; @@ -620,7 +620,7 @@ out: oz_prepare_frame(pd, 1); */ static int oz_send_isoc_frame(struct oz_pd *pd) { - struct sk_buff *skb = 0; + struct sk_buff *skb; struct net_device *dev = pd->net_dev; struct oz_hdr *oz_hdr; struct oz_elt *elt; @@ -634,7 +634,7 @@ static int oz_send_isoc_frame(struct oz_pd *pd) if (list.next == &list) return 0; skb = alloc_skb(total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) { + if (skb == NULL) { oz_trace("Cannot alloc skb\n"); oz_elt_info_free_chain(&pd->elt_buff, &list); return -1; @@ -659,7 +659,7 @@ static int oz_send_isoc_frame(struct oz_pd *pd) memcpy(elt, ei->data, ei->length); elt = oz_next_elt(elt); } - oz_event_log(OZ_EVT_TX_ISOC, 0, 0, 0, 0); + oz_event_log(OZ_EVT_TX_ISOC, 0, 0, NULL, 0); dev_queue_xmit(skb); oz_elt_info_free_chain(&pd->elt_buff, &list); return 0; @@ -671,8 +671,8 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) { struct list_head *e; struct oz_tx_frame *f; - struct list_head *first = 0; - struct list_head *last = 0; + struct list_head *first = NULL; + struct list_head *last = NULL; u8 diff; u32 pkt_num; @@ -686,7 +686,7 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) break; oz_trace2(OZ_TRACE_TX_FRAMES, "Releasing pkt_num= %u, nb= %d\n", pkt_num, pd->nb_queued_frames); - if (first == 0) + if (first == NULL) first = e; last = e; e = e->next; @@ -695,7 +695,7 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) if (first) { last->next->prev = &pd->tx_queue; pd->tx_queue.next = last->next; - last->next = 0; + last->next = NULL; } pd->last_sent_frame = &pd->tx_queue; spin_unlock(&pd->tx_frame_lock); @@ -718,7 +718,7 @@ static struct oz_isoc_stream *pd_stream_find(struct oz_pd *pd, u8 ep_num) if (st->ep_num == ep_num) return st; } - return 0; + return NULL; } /*------------------------------------------------------------------------------ * Context: softirq @@ -733,7 +733,7 @@ int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num) spin_lock_bh(&pd->stream_lock); if (!pd_stream_find(pd, ep_num)) { list_add(&st->link, &pd->stream_list); - st = 0; + st = NULL; } spin_unlock_bh(&pd->stream_lock); kfree(st); @@ -779,14 +779,14 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) struct net_device *dev = pd->net_dev; struct oz_isoc_stream *st; u8 nb_units = 0; - struct sk_buff *skb = 0; - struct oz_hdr *oz_hdr = 0; + struct sk_buff *skb = NULL; + struct oz_hdr *oz_hdr = NULL; int size = 0; spin_lock_bh(&pd->stream_lock); st = pd_stream_find(pd, ep_num); if (st) { skb = st->skb; - st->skb = 0; + st->skb = NULL; nb_units = st->nb_units; st->nb_units = 0; oz_hdr = st->oz_hdr; @@ -799,7 +799,7 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) /* Allocate enough space for max size frame. */ skb = alloc_skb(pd->max_tx_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) + if (skb == NULL) return 0; /* Reserve the head room for lower layers. */ skb_reserve(skb, LL_RESERVED_SPACE(dev)); @@ -874,13 +874,13 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) oz_event_log(OZ_EVT_TX_ISOC, nb_units, iso.frame_number, skb, atomic_read(&g_submitted_isoc)); if (dev_queue_xmit(skb) < 0) { - oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); + oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0); return -1; } else return 0; } -out: oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); +out: oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0); kfree_skb(skb); return -1; -- cgit v0.10.2 From 4d1b2fbbaf6420f64fae8b3f3a7801fc97d07260 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:23 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozusbsvc1.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c index 66bd576..ea4a238b 100644 --- a/drivers/staging/ozwpan/ozusbsvc1.c +++ b/drivers/staging/ozwpan/ozusbsvc1.c @@ -71,7 +71,7 @@ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, oz_trace(" len = 0x%x\n", len); if (len > 200) len = 200; - if (ei == 0) + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_get_desc_req); @@ -97,7 +97,7 @@ static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index) struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_set_config_req *body; - if (ei == 0) + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_set_config_req); @@ -118,7 +118,7 @@ static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt) struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_set_interface_req *body; - if (ei == 0) + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_set_interface_req); @@ -141,7 +141,7 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type, struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_feature_req *body; - if (ei == 0) + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_feature_req); @@ -165,7 +165,7 @@ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_vendor_class_req *body; - if (ei == 0) + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_vendor_class_req) - 1 + data_len; @@ -264,7 +264,7 @@ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb) int unit_count; int unit_size; int rem; - if (ei == 0) + if (ei == NULL) return -1; rem = MAX_ISOC_FIXED_DATA; elt = (struct oz_elt *)ei->data; @@ -359,7 +359,7 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt) if (usb_ctx) oz_usb_get(usb_ctx); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); - if (usb_ctx == 0) + if (usb_ctx == NULL) return; /* Context has gone so nothing to do. */ if (usb_ctx->stopped) goto done; @@ -391,14 +391,14 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt) struct oz_set_config_rsp *body = (struct oz_set_config_rsp *)usb_hdr; oz_hcd_control_cnf(usb_ctx->hport, body->req_id, - body->rcode, 0, 0); + body->rcode, NULL, 0); } break; case OZ_SET_INTERFACE_RSP: { struct oz_set_interface_rsp *body = (struct oz_set_interface_rsp *)usb_hdr; oz_hcd_control_cnf(usb_ctx->hport, - body->req_id, body->rcode, 0, 0); + body->req_id, body->rcode, NULL, 0); } break; case OZ_VENDOR_CLASS_RSP: { @@ -427,7 +427,7 @@ void oz_usb_farewell(struct oz_pd *pd, u8 ep_num, u8 *data, u8 len) if (usb_ctx) oz_usb_get(usb_ctx); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); - if (usb_ctx == 0) + if (usb_ctx == NULL) return; /* Context has gone so nothing to do. */ if (!usb_ctx->stopped) { oz_trace("Farewell indicated ep = 0x%x\n", ep_num); -- cgit v0.10.2 From 953b19013a0dd313490db9bc625609a6936c5c98 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:24 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozeltbuf.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozeltbuf.c b/drivers/staging/ozwpan/ozeltbuf.c index 988f522..ac90fc7 100644 --- a/drivers/staging/ozwpan/ozeltbuf.c +++ b/drivers/staging/ozwpan/ozeltbuf.c @@ -64,7 +64,7 @@ void oz_elt_buf_term(struct oz_elt_buf *buf) */ struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf) { - struct oz_elt_info *ei = 0; + struct oz_elt_info *ei = NULL; spin_lock_bh(&buf->lock); if (buf->free_elts && buf->elt_pool) { ei = container_of(buf->elt_pool, struct oz_elt_info, link); @@ -82,9 +82,9 @@ struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf) if (ei) { ei->flags = 0; ei->app_id = 0; - ei->callback = 0; + ei->callback = NULL; ei->context = 0; - ei->stream = 0; + ei->stream = NULL; ei->magic = OZ_ELT_INFO_MAGIC_USED; INIT_LIST_HEAD(&ei->link); INIT_LIST_HEAD(&ei->link_order); @@ -135,7 +135,7 @@ int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count) oz_trace("oz_elt_stream_create(0x%x)\n", id); st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO); - if (st == 0) + if (st == NULL) return -ENOMEM; atomic_set(&st->ref_count, 1); st->id = id; @@ -151,7 +151,7 @@ int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count) int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) { struct list_head *e; - struct oz_elt_stream *st; + struct oz_elt_stream *st = NULL; oz_trace("oz_elt_stream_delete(0x%x)\n", id); spin_lock_bh(&buf->lock); e = buf->stream_list.next; @@ -161,7 +161,7 @@ int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) list_del(e); break; } - st = 0; + st = NULL; } if (!st) { spin_unlock_bh(&buf->lock); @@ -208,7 +208,7 @@ void oz_elt_stream_put(struct oz_elt_stream *st) int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id, struct oz_elt_info *ei) { - struct oz_elt_stream *st = 0; + struct oz_elt_stream *st = NULL; struct list_head *e; if (id) { list_for_each(e, &buf->stream_list) { @@ -297,7 +297,7 @@ int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len, "Stream down: %d %d\n", ei->stream->buf_count, ei->length); oz_elt_stream_put(ei->stream); - ei->stream = 0; + ei->stream = NULL; } INIT_LIST_HEAD(&ei->link_order); list_add_tail(&ei->link, list); @@ -319,7 +319,7 @@ int oz_are_elts_available(struct oz_elt_buf *buf) */ void oz_trim_elt_pool(struct oz_elt_buf *buf) { - struct list_head *free = 0; + struct list_head *free = NULL; struct list_head *e; spin_lock_bh(&buf->lock); while (buf->free_elts > buf->max_free_elts) { -- cgit v0.10.2 From 41ebb8a1c5f1f567b9c30c9b50aace91387537f8 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:25 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozproto.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c index e00a539..40c283c 100644 --- a/drivers/staging/ozwpan/ozproto.c +++ b/drivers/staging/ozwpan/ozproto.c @@ -98,7 +98,7 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) + sizeof(struct oz_elt_connect_rsp); skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) + if (skb == NULL) return; skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reset_network_header(skb); @@ -116,7 +116,7 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) oz_hdr->control = (OZ_PROTOCOL_VERSION<last_pkt_num = 0; put_unaligned(0, &oz_hdr->pkt_num); - oz_event_log(OZ_EVT_CONNECT_RSP, 0, 0, 0, 0); + oz_event_log(OZ_EVT_CONNECT_RSP, 0, 0, NULL, 0); elt->type = OZ_ELT_CONNECT_RSP; elt->length = sizeof(struct oz_elt_connect_rsp); memset(body, 0, sizeof(struct oz_elt_connect_rsp)); @@ -179,17 +179,17 @@ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, u8 rsp_status = OZ_STATUS_SUCCESS; u8 stop_needed = 0; u16 new_apps = g_apps; - struct net_device *old_net_dev = 0; - struct oz_pd *free_pd = 0; + struct net_device *old_net_dev = NULL; + struct oz_pd *free_pd = NULL; if (cur_pd) { pd = cur_pd; spin_lock_bh(&g_polling_lock); } else { - struct oz_pd *pd2 = 0; + struct oz_pd *pd2 = NULL; struct list_head *e; pd = oz_pd_alloc(pd_addr); - if (pd == 0) - return 0; + if (pd == NULL) + return NULL; pd->last_rx_time_j = jiffies; spin_lock_bh(&g_polling_lock); list_for_each(e, &g_pd_list) { @@ -203,9 +203,9 @@ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, if (pd != pd2) list_add_tail(&pd->link, &g_pd_list); } - if (pd == 0) { + if (pd == NULL) { spin_unlock_bh(&g_polling_lock); - return 0; + return NULL; } if (pd->net_dev != net_dev) { old_net_dev = pd->net_dev; @@ -294,7 +294,7 @@ done: if (stop_needed) oz_pd_stop(pd); oz_pd_put(pd); - pd = 0; + pd = NULL; } if (old_net_dev) dev_put(old_net_dev); @@ -340,14 +340,14 @@ static void oz_rx_frame(struct sk_buff *skb) u8 *src_addr; struct oz_elt *elt; int length; - struct oz_pd *pd = 0; + struct oz_pd *pd = NULL; struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); int dup = 0; u32 pkt_num; oz_event_log(OZ_EVT_RX_PROCESS, 0, (((u16)oz_hdr->control)<<8)|oz_hdr->last_pkt_num, - 0, oz_hdr->pkt_num); + NULL, oz_hdr->pkt_num); oz_trace2(OZ_TRACE_RX_FRAMES, "RX frame PN=0x%x LPN=0x%x control=0x%x\n", oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control); @@ -402,7 +402,7 @@ static void oz_rx_frame(struct sk_buff *skb) break; switch (elt->type) { case OZ_ELT_CONNECT_REQ: - oz_event_log(OZ_EVT_CONNECT_REQ, 0, 0, 0, 0); + oz_event_log(OZ_EVT_CONNECT_REQ, 0, 0, NULL, 0); oz_trace("RX: OZ_ELT_CONNECT_REQ\n"); pd = oz_connect_req(pd, elt, src_addr, skb->dev); break; @@ -456,7 +456,7 @@ done: */ void oz_protocol_term(void) { - struct list_head *chain = 0; + struct list_head *chain; del_timer_sync(&g_timer); /* Walk the list of bindings and remove each one. */ @@ -487,7 +487,7 @@ void oz_protocol_term(void) spin_lock_bh(&g_polling_lock); } chain = g_timer_pool; - g_timer_pool = 0; + g_timer_pool = NULL; spin_unlock_bh(&g_polling_lock); while (chain) { struct oz_timer *t = container_of(chain, struct oz_timer, link); @@ -534,25 +534,25 @@ static void oz_protocol_timer(unsigned long arg) /* This happens if we remove the current timer but can't stop * the timer from firing. In this case just get out. */ - oz_event_log(OZ_EVT_TIMER, 0, 0, 0, 0); + oz_event_log(OZ_EVT_TIMER, 0, 0, NULL, 0); spin_unlock_bh(&g_polling_lock); return; } g_timer_state = OZ_TIMER_IN_HANDLER; t = g_cur_timer; - g_cur_timer = 0; + g_cur_timer = NULL; list_del(&t->link); spin_unlock_bh(&g_polling_lock); do { pd = t->pd; - oz_event_log(OZ_EVT_TIMER, 0, t->type, 0, 0); + oz_event_log(OZ_EVT_TIMER, 0, t->type, NULL, 0); oz_pd_handle_timer(pd, t->type); spin_lock_bh(&g_polling_lock); if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) { t->link.next = g_timer_pool; g_timer_pool = &t->link; g_timer_pool_count++; - t = 0; + t = NULL; } if (!list_empty(&g_timer_list)) { t2 = container_of(g_timer_list.next, @@ -560,9 +560,9 @@ static void oz_protocol_timer(unsigned long arg) if (time_before_eq(t2->due_time, jiffies)) list_del(&t2->link); else - t2 = 0; + t2 = NULL; } else { - t2 = 0; + t2 = NULL; } spin_unlock_bh(&g_polling_lock); oz_pd_put(pd); @@ -583,12 +583,12 @@ static void oz_protocol_timer_start(void) container_of(g_timer_list.next, struct oz_timer, link); if (g_timer_state == OZ_TIMER_SET) { oz_event_log(OZ_EVT_TIMER_CTRL, 3, - (u16)g_cur_timer->type, 0, + (u16)g_cur_timer->type, NULL, (unsigned)g_cur_timer->due_time); mod_timer(&g_timer, g_cur_timer->due_time); } else { oz_event_log(OZ_EVT_TIMER_CTRL, 4, - (u16)g_cur_timer->type, 0, + (u16)g_cur_timer->type, NULL, (unsigned)g_cur_timer->due_time); g_timer.expires = g_cur_timer->due_time; g_timer.function = oz_protocol_timer; @@ -608,9 +608,9 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, int remove) { struct list_head *e; - struct oz_timer *t = 0; + struct oz_timer *t = NULL; int restart_needed = 0; - oz_event_log(OZ_EVT_TIMER_CTRL, 1, (u16)type, 0, (unsigned)due_time); + oz_event_log(OZ_EVT_TIMER_CTRL, 1, (u16)type, NULL, (unsigned)due_time); spin_lock(&g_polling_lock); if (remove) { list_for_each(e, &g_timer_list) { @@ -618,12 +618,12 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, if ((t->pd == pd) && (t->type == type)) { if (g_cur_timer == t) { restart_needed = 1; - g_cur_timer = 0; + g_cur_timer = NULL; } list_del(e); break; } - t = 0; + t = NULL; } } if (!t) { @@ -647,7 +647,7 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, t2 = container_of(e, struct oz_timer, link); if (time_before(due_time, t2->due_time)) { if (t2 == g_cur_timer) { - g_cur_timer = 0; + g_cur_timer = NULL; restart_needed = 1; } break; @@ -668,18 +668,18 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, */ void oz_timer_delete(struct oz_pd *pd, int type) { - struct list_head *chain = 0; + struct list_head *chain = NULL; struct oz_timer *t; struct oz_timer *n; int restart_needed = 0; int release = 0; - oz_event_log(OZ_EVT_TIMER_CTRL, 2, (u16)type, 0, 0); + oz_event_log(OZ_EVT_TIMER_CTRL, 2, (u16)type, NULL, 0); spin_lock(&g_polling_lock); list_for_each_entry_safe(t, n, &g_timer_list, link) { if ((t->pd == pd) && ((type == 0) || (t->type == type))) { if (g_cur_timer == t) { restart_needed = 1; - g_cur_timer = 0; + g_cur_timer = NULL; del_timer(&g_timer); } list_del(&t->link); @@ -748,7 +748,7 @@ struct oz_pd *oz_pd_find(u8 *mac_addr) } } spin_unlock_bh(&g_polling_lock); - return 0; + return NULL; } /*------------------------------------------------------------------------------ * Context: process @@ -770,9 +770,9 @@ void oz_app_enable(int app_id, int enable) static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { - oz_event_log(OZ_EVT_RX_FRAME, 0, 0, 0, 0); + oz_event_log(OZ_EVT_RX_FRAME, 0, 0, NULL, 0); skb = skb_share_check(skb, GFP_ATOMIC); - if (skb == 0) + if (skb == NULL) return 0; spin_lock_bh(&g_rx_queue.lock); if (g_processing_rx) { @@ -815,14 +815,14 @@ void oz_binding_add(char *net_dev) oz_trace("Adding binding: %s\n", net_dev); binding->ptype.dev = dev_get_by_name(&init_net, net_dev); - if (binding->ptype.dev == 0) { + if (binding->ptype.dev == NULL) { oz_trace("Netdev %s not found\n", net_dev); kfree(binding); - binding = 0; + binding = NULL; } } else { oz_trace("Binding to all netcards\n"); - binding->ptype.dev = 0; + binding->ptype.dev = NULL; } if (binding) { dev_add_pack(&binding->ptype); @@ -876,7 +876,7 @@ static void pd_stop_all_for_device(struct net_device *net_dev) */ void oz_binding_remove(char *net_dev) { - struct oz_binding *binding = 0; + struct oz_binding *binding; struct oz_binding **link; oz_trace("Removing binding: %s\n", net_dev); spin_lock_bh(&g_binding_lock); @@ -923,7 +923,7 @@ int oz_protocol_init(char *devs) { skb_queue_head_init(&g_rx_queue); if (devs && (devs[0] == '*')) { - oz_binding_add(0); + oz_binding_add(NULL); } else { char d[32]; while (*devs) { -- cgit v0.10.2 From bc501c551ca28dcac01627b6c390e2ee6bbb1179 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:26 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozcdev.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c index 64913ae..a38716f 100644 --- a/drivers/staging/ozwpan/ozcdev.c +++ b/drivers/staging/ozwpan/ozcdev.c @@ -97,7 +97,7 @@ ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count, int ix; struct oz_pd *pd; - struct oz_serial_ctx *ctx = 0; + struct oz_serial_ctx *ctx; spin_lock_bh(&g_cdev.lock); pd = g_cdev.active_pd; @@ -147,7 +147,7 @@ ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count, { struct oz_pd *pd; struct oz_elt_buf *eb; - struct oz_elt_info *ei = 0; + struct oz_elt_info *ei; struct oz_elt *elt; struct oz_app_hdr *app_hdr; struct oz_serial_ctx *ctx; @@ -182,7 +182,7 @@ ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count, ctx->tx_seq_num = 1; spin_lock(&eb->lock); if (oz_queue_elt_info(eb, 0, 0, ei) == 0) - ei = 0; + ei = NULL; spin_unlock(&eb->lock); } spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); @@ -217,7 +217,7 @@ static int oz_set_active_pd(u8 *addr) if (is_zero_ether_addr(addr)) { spin_lock_bh(&g_cdev.lock); pd = g_cdev.active_pd; - g_cdev.active_pd = 0; + g_cdev.active_pd = NULL; memset(g_cdev.active_addr, 0, sizeof(g_cdev.active_addr)); spin_unlock_bh(&g_cdev.lock); @@ -385,7 +385,7 @@ int oz_cdev_deregister(void) */ int oz_cdev_init(void) { - oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_SERIAL, 0, 0); + oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_SERIAL, NULL, 0); oz_app_enable(OZ_APPID_SERIAL, 1); return 0; } @@ -394,7 +394,7 @@ int oz_cdev_init(void) */ void oz_cdev_term(void) { - oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_SERIAL, 0, 0); + oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_SERIAL, NULL, 0); oz_app_enable(OZ_APPID_SERIAL, 0); } /*------------------------------------------------------------------------------ @@ -403,8 +403,8 @@ void oz_cdev_term(void) int oz_cdev_start(struct oz_pd *pd, int resume) { struct oz_serial_ctx *ctx; - struct oz_serial_ctx *old_ctx = 0; - oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_SERIAL, 0, resume); + struct oz_serial_ctx *old_ctx; + oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_SERIAL, NULL, resume); if (resume) { oz_trace("Serial service resumed.\n"); return 0; @@ -440,22 +440,22 @@ int oz_cdev_start(struct oz_pd *pd, int resume) void oz_cdev_stop(struct oz_pd *pd, int pause) { struct oz_serial_ctx *ctx; - oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_SERIAL, 0, pause); + oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_SERIAL, NULL, pause); if (pause) { oz_trace("Serial service paused.\n"); return; } spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); ctx = (struct oz_serial_ctx *)pd->app_ctx[OZ_APPID_SERIAL-1]; - pd->app_ctx[OZ_APPID_SERIAL-1] = 0; + pd->app_ctx[OZ_APPID_SERIAL-1] = NULL; spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); if (ctx) oz_cdev_release_ctx(ctx); spin_lock(&g_cdev.lock); if (pd == g_cdev.active_pd) - g_cdev.active_pd = 0; + g_cdev.active_pd = NULL; else - pd = 0; + pd = NULL; spin_unlock(&g_cdev.lock); if (pd) { oz_pd_put(pd); -- cgit v0.10.2 From ba346a4367a824a2c6337d4031fc9a82397a2abd Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:27 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozusbsvc.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozusbsvc.c b/drivers/staging/ozwpan/ozusbsvc.c index 8fa7f25..543a941 100644 --- a/drivers/staging/ozwpan/ozusbsvc.c +++ b/drivers/staging/ozwpan/ozusbsvc.c @@ -34,7 +34,7 @@ */ int oz_usb_init(void) { - oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_USB, 0, 0); + oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_USB, NULL, 0); return oz_hcd_init(); } /*------------------------------------------------------------------------------ @@ -43,7 +43,7 @@ int oz_usb_init(void) */ void oz_usb_term(void) { - oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_USB, 0, 0); + oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_USB, NULL, 0); oz_hcd_term(); } /*------------------------------------------------------------------------------ @@ -54,8 +54,8 @@ int oz_usb_start(struct oz_pd *pd, int resume) { int rc = 0; struct oz_usb_ctx *usb_ctx; - struct oz_usb_ctx *old_ctx = 0; - oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_USB, 0, resume); + struct oz_usb_ctx *old_ctx; + oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_USB, NULL, resume); if (resume) { oz_trace("USB service resumed.\n"); return 0; @@ -65,7 +65,7 @@ int oz_usb_start(struct oz_pd *pd, int resume) * has a USB context then we will destroy it. */ usb_ctx = kzalloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC); - if (usb_ctx == 0) + if (usb_ctx == NULL) return -ENOMEM; atomic_set(&usb_ctx->ref_count, 1); usb_ctx->pd = pd; @@ -76,7 +76,7 @@ int oz_usb_start(struct oz_pd *pd, int resume) */ spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); old_ctx = pd->app_ctx[OZ_APPID_USB-1]; - if (old_ctx == 0) + if (old_ctx == NULL) pd->app_ctx[OZ_APPID_USB-1] = usb_ctx; oz_usb_get(pd->app_ctx[OZ_APPID_USB-1]); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); @@ -98,10 +98,10 @@ int oz_usb_start(struct oz_pd *pd, int resume) oz_hcd_pd_reset(usb_ctx, usb_ctx->hport); } else { usb_ctx->hport = oz_hcd_pd_arrived(usb_ctx); - if (usb_ctx->hport == 0) { + if (usb_ctx->hport == NULL) { oz_trace("USB hub returned null port.\n"); spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); - pd->app_ctx[OZ_APPID_USB-1] = 0; + pd->app_ctx[OZ_APPID_USB-1] = NULL; spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); oz_usb_put(usb_ctx); rc = -1; @@ -117,14 +117,14 @@ int oz_usb_start(struct oz_pd *pd, int resume) void oz_usb_stop(struct oz_pd *pd, int pause) { struct oz_usb_ctx *usb_ctx; - oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_USB, 0, pause); + oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_USB, NULL, pause); if (pause) { oz_trace("USB service paused.\n"); return; } spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB-1]; - pd->app_ctx[OZ_APPID_USB-1] = 0; + pd->app_ctx[OZ_APPID_USB-1] = NULL; spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); if (usb_ctx) { unsigned long tout = jiffies + HZ; @@ -182,7 +182,7 @@ int oz_usb_heartbeat(struct oz_pd *pd) if (usb_ctx) oz_usb_get(usb_ctx); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); - if (usb_ctx == 0) + if (usb_ctx == NULL) return rc; if (usb_ctx->stopped) goto done; -- cgit v0.10.2 From 7be7d6def3358736d479fa99c424e07e60d4de72 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 15:22:28 +0100 Subject: staging/ozwpan: Fix NULL vs zero in ozhcd.c (sparse warning) This patch fixes the warning "Using plain integer as NULL pointer", generated by sparse, by replacing the offending 0s with NULL. If the initialization with NULL was unnecessary (due to unconditional assignment before first use) it was removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index 9154f33..b48663e 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -248,7 +248,7 @@ static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr) */ static struct oz_urb_link *oz_alloc_urb_link(void) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; unsigned long irq_state; spin_lock_irqsave(&g_link_lock, irq_state); if (g_link_pool) { @@ -257,7 +257,7 @@ static struct oz_urb_link *oz_alloc_urb_link(void) --g_link_pool_size; } spin_unlock_irqrestore(&g_link_lock, irq_state); - if (urbl == 0) + if (urbl == NULL) urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC); return urbl; } @@ -274,7 +274,7 @@ static void oz_free_urb_link(struct oz_urb_link *urbl) if (g_link_pool_size < OZ_MAX_LINK_POOL_SIZE) { urbl->link.next = g_link_pool; g_link_pool = &urbl->link; - urbl = 0; + urbl = NULL; g_link_pool_size++; } spin_unlock_irqrestore(&g_link_lock, irq_state); @@ -291,7 +291,7 @@ static void oz_empty_link_pool(void) unsigned long irq_state; spin_lock_irqsave(&g_link_lock, irq_state); e = g_link_pool; - g_link_pool = 0; + g_link_pool = NULL; g_link_pool_size = 0; spin_unlock_irqrestore(&g_link_lock, irq_state); while (e) { @@ -337,7 +337,7 @@ struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb) return urbl; } } - return 0; + return NULL; } /*------------------------------------------------------------------------------ * This is called when we have finished processing an urb. It unlinks it from @@ -349,13 +349,13 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, { struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned long irq_state; - struct oz_urb_link *cancel_urbl = 0; + struct oz_urb_link *cancel_urbl = NULL; spin_lock_irqsave(&g_tasklet_lock, irq_state); usb_hcd_unlink_urb_from_ep(hcd, urb); /* Clear hcpriv which will prevent it being put in the cancel list * in the event that an attempt is made to cancel it. */ - urb->hcpriv = 0; + urb->hcpriv = NULL; /* Walk the cancel list in case the urb is already sitting there. * Since we process the cancel list in a tasklet rather than in * the dequeue function this could happen. @@ -507,7 +507,7 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, ep->last_jiffies = jiffies; ep->credit = 0; oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, - 0, 0, ep->credit); + 0, NULL, ep->credit); } } else { err = -EPIPE; @@ -525,7 +525,7 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, struct urb *urb) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; struct oz_endpoint *ep; spin_lock_bh(&port->ozhcd->hcd_lock); if (in_dir) @@ -540,7 +540,7 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, list_del_init(e); break; } - urbl = 0; + urbl = NULL; } } spin_unlock_bh(&port->ozhcd->hcd_lock); @@ -556,8 +556,8 @@ static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix, u8 req_id) { struct oz_hcd *ozhcd = port->ozhcd; - struct urb *urb = 0; - struct oz_urb_link *urbl = 0; + struct urb *urb = NULL; + struct oz_urb_link *urbl = NULL; struct oz_endpoint *ep; spin_lock_bh(&ozhcd->hcd_lock); @@ -630,13 +630,13 @@ static inline void oz_hcd_put(struct oz_hcd *ozhcd) void *oz_hcd_pd_arrived(void *hpd) { int i; - void *hport = 0; - struct oz_hcd *ozhcd = 0; + void *hport = NULL; + struct oz_hcd *ozhcd = NULL; struct oz_endpoint *ep; oz_trace("oz_hcd_pd_arrived()\n"); ozhcd = oz_hcd_claim(); - if (ozhcd == 0) - return 0; + if (ozhcd == NULL) + return NULL; /* Allocate an endpoint object in advance (before holding hcd lock) to * use for out endpoint 0. */ @@ -663,7 +663,7 @@ void *oz_hcd_pd_arrived(void *hpd) /* Attach out endpoint 0. */ ozhcd->ports[i].out_ep[0] = ep; - ep = 0; + ep = NULL; hport = &ozhcd->ports[i]; spin_unlock_bh(&ozhcd->hcd_lock); if (ozhcd->flags & OZ_HDC_F_SUSPENDED) { @@ -676,7 +676,7 @@ void *oz_hcd_pd_arrived(void *hpd) } out: if (ep) /* ep is non-null if not used. */ - oz_ep_free(0, ep); + oz_ep_free(NULL, ep); oz_hcd_put(ozhcd); return hport; } @@ -691,15 +691,15 @@ void oz_hcd_pd_departed(void *hport) struct oz_port *port = (struct oz_port *)hport; struct oz_hcd *ozhcd; void *hpd; - struct oz_endpoint *ep = 0; + struct oz_endpoint *ep = NULL; oz_trace("oz_hcd_pd_departed()\n"); - if (port == 0) { + if (port == NULL) { oz_trace("oz_hcd_pd_departed() port = 0\n"); return; } ozhcd = port->ozhcd; - if (ozhcd == 0) + if (ozhcd == NULL) return; /* Check if this is the connection port - if so clear it. */ @@ -717,7 +717,7 @@ void oz_hcd_pd_departed(void *hport) oz_clean_endpoints_for_config(ozhcd->hcd, port); spin_lock_bh(&port->port_lock); hpd = port->hpd; - port->hpd = 0; + port->hpd = NULL; port->bus_addr = 0xff; port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING); port->flags |= OZ_PORT_F_CHANGED; @@ -728,7 +728,7 @@ void oz_hcd_pd_departed(void *hport) */ if (port->out_ep[0]) { ep = port->out_ep[0]; - port->out_ep[0] = 0; + port->out_ep[0] = NULL; } spin_unlock_bh(&port->port_lock); if (ep) @@ -764,7 +764,7 @@ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, u8 *desc, struct urb *urb; int err = 0; - oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, 0, status); + oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, NULL, status); oz_trace("oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", length, offset, total_size); urb = oz_find_urb_by_id(port, 0, req_id); @@ -903,7 +903,7 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, unsigned windex; unsigned wvalue; - oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, 0, rcode); + oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, NULL, rcode); oz_trace("oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); urb = oz_find_urb_by_id(port, 0, req_id); if (!urb) { @@ -988,7 +988,7 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) struct oz_hcd *ozhcd = port->ozhcd; spin_lock_bh(&ozhcd->hcd_lock); ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK]; - if (ep == 0) + if (ep == NULL) goto done; switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) { case USB_ENDPOINT_XFER_INT: @@ -1056,7 +1056,8 @@ int oz_hcd_heartbeat(void *hport) ep->credit += jiffies_to_msecs(now - ep->last_jiffies); if (ep->credit > ep->credit_ceiling) ep->credit = ep->credit_ceiling; - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, 0, ep->credit); + oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, NULL, + ep->credit); ep->last_jiffies = now; while (ep->credit && !list_empty(&ep->urb_list)) { urbl = list_first_entry(&ep->urb_list, @@ -1065,8 +1066,8 @@ int oz_hcd_heartbeat(void *hport) if ((ep->credit + 1) < urb->number_of_packets) break; ep->credit -= urb->number_of_packets; - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, 0, - ep->credit); + oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, NULL, + ep->credit); list_move_tail(&urbl->link, &xfr_list); } } @@ -1096,17 +1097,17 @@ int oz_hcd_heartbeat(void *hport) ep->credit = 0; oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, - 0, 0, ep->credit); + 0, NULL, ep->credit); ep->last_jiffies = now; ep->start_frame = 0; oz_event_log(OZ_EVT_EP_BUFFERING, - ep->ep_num | USB_DIR_IN, 0, 0, 0); + ep->ep_num | USB_DIR_IN, 0, NULL, 0); } continue; } ep->credit += jiffies_to_msecs(now - ep->last_jiffies); oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, - 0, 0, ep->credit); + 0, NULL, ep->credit); ep->last_jiffies = now; while (!list_empty(&ep->urb_list)) { struct oz_urb_link *urbl = @@ -1151,7 +1152,7 @@ int oz_hcd_heartbeat(void *hport) list_move_tail(&urbl->link, &xfr_list); ep->credit -= urb->number_of_packets; oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, - 0, 0, ep->credit); + 0, NULL, ep->credit); } } if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep)) @@ -1244,7 +1245,7 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, if (ep_addr & USB_ENDPOINT_DIR_MASK) { ep->flags |= OZ_F_EP_BUFFERING; oz_event_log(OZ_EVT_EP_BUFFERING, - ep->ep_num | USB_DIR_IN, 1, 0, 0); + ep->ep_num | USB_DIR_IN, 1, NULL, 0); } else { ep->flags |= OZ_F_EP_HAVE_STREAM; if (oz_usb_stream_create(port->hpd, ep_num)) @@ -1300,7 +1301,7 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, */ if ((mask & (1<out_ep[i]) { e = &port->out_ep[i]->link; - port->out_ep[i] = 0; + port->out_ep[i] = NULL; /* Remove from isoc list if present. */ list_move_tail(e, &ep_list); @@ -1309,7 +1310,7 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, */ if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) { e = &port->in_ep[i]->link; - port->in_ep[i] = 0; + port->in_ep[i] = NULL; list_move_tail(e, &ep_list); } } @@ -1370,7 +1371,7 @@ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, if (port->iface) { oz_trace("Freeing interfaces object.\n"); kfree(port->iface); - port->iface = 0; + port->iface = NULL; } port->num_iface = 0; spin_unlock_bh(&ozhcd->hcd_lock); @@ -1380,7 +1381,7 @@ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, */ static void *oz_claim_hpd(struct oz_port *port) { - void *hpd = 0; + void *hpd = NULL; struct oz_hcd *ozhcd = port->ozhcd; spin_lock_bh(&ozhcd->hcd_lock); hpd = port->hpd; @@ -1399,13 +1400,13 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, unsigned windex; unsigned wvalue; unsigned wlength; - void *hpd = 0; + void *hpd = NULL; u8 req_id; int rc = 0; unsigned complete = 0; int port_ix = -1; - struct oz_port *port = 0; + struct oz_port *port = NULL; oz_trace2(OZ_TRACE_URB, "%lu: oz_process_ep0_urb(%p)\n", jiffies, urb); port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); @@ -1437,7 +1438,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, req_id = port->next_req_id++; hpd = oz_claim_hpd(port); - if (hpd == 0) { + if (hpd == NULL) { oz_trace("Cannot claim port\n"); rc = -EPIPE; goto out; @@ -1452,7 +1453,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, break; case USB_REQ_SET_ADDRESS: oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, - 0, 0, setup->bRequestType); + 0, NULL, setup->bRequestType); oz_trace("USB_REQ_SET_ADDRESS - req\n"); oz_trace("Port %d address is 0x%x\n", ozhcd->conn_port, (u8)le16_to_cpu(setup->wValue)); @@ -1473,8 +1474,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, /* We short circuit this case and reply directly since * we have the selected configuration number cached. */ - oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, - setup->bRequestType); + oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, + NULL, setup->bRequestType); oz_trace("USB_REQ_GET_CONFIGURATION - reply now\n"); if (urb->transfer_buffer_length >= 1) { urb->actual_length = 1; @@ -1489,8 +1490,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, /* We short circuit this case and reply directly since * we have the selected interface alternative cached. */ - oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, - setup->bRequestType); + oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, + NULL, setup->bRequestType); oz_trace("USB_REQ_GET_INTERFACE - reply now\n"); if (urb->transfer_buffer_length >= 1) { urb->actual_length = 1; @@ -1583,7 +1584,7 @@ static void oz_urb_process_tasklet(unsigned long unused) struct urb *urb; struct oz_hcd *ozhcd = oz_hcd_claim(); int rc = 0; - if (ozhcd == 0) + if (ozhcd == NULL) return; /* This is called from a tasklet so is in softirq context but the urb * list is filled from any context so we need to lock @@ -1617,17 +1618,17 @@ static void oz_urb_process_tasklet(unsigned long unused) */ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; struct list_head *e; struct oz_hcd *ozhcd; unsigned long irq_state; u8 ix; - if (port == 0) { + if (port == NULL) { oz_trace("ERRORERROR: oz_urb_cancel(%p) port is null\n", urb); return; } ozhcd = port->ozhcd; - if (ozhcd == 0) { + if (ozhcd == NULL) { oz_trace("ERRORERROR: oz_urb_cancel(%p) ozhcd is null\n", urb); return; } @@ -1644,7 +1645,7 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) } } spin_unlock_irqrestore(&g_tasklet_lock, irq_state); - urbl = 0; + urbl = NULL; /* Look in the orphanage. */ @@ -1658,7 +1659,7 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) } } ix = (ep_num & 0xf); - urbl = 0; + urbl = NULL; if ((ep_num & USB_DIR_IN) && ix) urbl = oz_remove_urb(port->in_ep[ix], urb); else @@ -1680,7 +1681,7 @@ static void oz_urb_cancel_tasklet(unsigned long unused) unsigned long irq_state; struct urb *urb; struct oz_hcd *ozhcd = oz_hcd_claim(); - if (ozhcd == 0) + if (ozhcd == NULL) return; spin_lock_irqsave(&g_tasklet_lock, irq_state); while (!list_empty(&ozhcd->urb_cancel_list)) { @@ -1772,7 +1773,7 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, jiffies, urb); oz_event_log(OZ_EVT_URB_SUBMIT, oz_get_irq_ctx(), (u16)urb->number_of_packets, urb, urb->pipe); - if (unlikely(ozhcd == 0)) { + if (unlikely(ozhcd == NULL)) { oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not ozhcd.\n", jiffies, urb); return -EPIPE; @@ -1786,7 +1787,7 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, if (port_ix < 0) return -EPIPE; port = &ozhcd->ports[port_ix]; - if (port == 0) + if (port == NULL) return -EPIPE; if ((port->flags & OZ_PORT_F_PRESENT) == 0) { oz_trace("Refusing URB port_ix = %d devnum = %d\n", @@ -1797,7 +1798,7 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, /* Put request in queue for processing by tasklet. */ urbl = oz_alloc_urb_link(); - if (unlikely(urbl == 0)) + if (unlikely(urbl == NULL)) return -ENOMEM; urbl->urb = urb; spin_lock_irqsave(&g_tasklet_lock, irq_state); @@ -1819,10 +1820,10 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, struct urb *urb) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; struct list_head *e; - if (unlikely(ep == 0)) - return 0; + if (unlikely(ep == NULL)) + return NULL; list_for_each(e, &ep->urb_list) { urbl = container_of(e, struct oz_urb_link, link); if (urbl->urb == urb) { @@ -1834,12 +1835,12 @@ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, oz_event_log(OZ_EVT_EP_CREDIT, usb_pipein(urb->pipe) ? (ep->ep_num | USB_DIR_IN) : ep->ep_num, - 0, 0, ep->credit); + 0, NULL, ep->credit); } return urbl; } } - return 0; + return NULL; } /*------------------------------------------------------------------------------ * Called to dequeue a previously submitted urb for the device. @@ -1848,12 +1849,12 @@ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; int rc; unsigned long irq_state; oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_dequeue(%p)\n", jiffies, urb); urbl = oz_alloc_urb_link(); - if (unlikely(urbl == 0)) + if (unlikely(urbl == NULL)) return -ENOMEM; spin_lock_irqsave(&g_tasklet_lock, irq_state); /* The following function checks the urb is still in the queue @@ -2193,7 +2194,7 @@ static int oz_plat_probe(struct platform_device *dev) struct oz_hcd *ozhcd; oz_trace("oz_plat_probe()\n"); hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev)); - if (hcd == 0) { + if (hcd == NULL) { oz_trace("Failed to created hcd object OK\n"); return -ENOMEM; } @@ -2232,12 +2233,12 @@ static int oz_plat_remove(struct platform_device *dev) struct usb_hcd *hcd = platform_get_drvdata(dev); struct oz_hcd *ozhcd; oz_trace("oz_plat_remove()\n"); - if (hcd == 0) + if (hcd == NULL) return -1; ozhcd = oz_hcd_private(hcd); spin_lock_bh(&g_hcdlock); if (ozhcd == g_ozhcd) - g_ozhcd = 0; + g_ozhcd = NULL; spin_unlock_bh(&g_hcdlock); oz_trace("Clearing orphanage\n"); oz_hcd_clear_orphanage(ozhcd, -EPIPE); @@ -2278,7 +2279,7 @@ int oz_hcd_init(void) if (err) goto error; g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1); - if (g_plat_dev == 0) { + if (g_plat_dev == NULL) { err = -ENOMEM; goto error1; } -- cgit v0.10.2 From e9d077bd2aafd11b4b12c76d34e9414157fb7665 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 03:58:14 +0100 Subject: staging/rtl8187se: Remove code without effect Local variable AcmCtrl is never read/used after assignment so we can remove all assignments to it and the related code around the assignments. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index f1db9e4..41419f0 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -964,54 +964,7 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, break; } - /* Cehck ACM bit. */ - /* If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13. */ - { - PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn); - AC_CODING eACI = pAciAifsn->f.ACI; - - /*for 8187B AsynIORead issue */ - u8 AcmCtrl = 0; - if (pAciAifsn->f.ACM) { - /* ACM bit is 1. */ - switch (eACI) { - case AC0_BE: - AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); /* or 0x21 */ - break; - - case AC2_VI: - AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); /* or 0x42 */ - break; - - case AC3_VO: - AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); /* or 0x84 */ - break; - - default: - DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI); - break; - } - } else { - /* ACM bit is 0. */ - switch (eACI) { - case AC0_BE: - AcmCtrl &= ((~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xDE */ - break; - - case AC2_VI: - AcmCtrl &= ((~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xBD */ - break; - - case AC3_VO: - AcmCtrl &= ((~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0x7B */ - break; - - default: - break; - } - } - write_nic_byte(dev, ACM_CONTROL, 0); - } + write_nic_byte(dev, ACM_CONTROL, 0); } } } -- cgit v0.10.2 From 2578180858e80261f8ba133dc998d5fb5b54d547 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 03:58:15 +0100 Subject: staging/rtl8187se: Remove code without effect The local variable u4bAcParam is never read/used after assignment, thus we can remove the declaration, assignment and any related code. -> the local variables u1bAIFS, eACI and pAcParam can also be removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 41419f0..5495d1e 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -928,44 +928,7 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, for (eACI = 0; eACI < AC_MAX; eACI++) { AcParam.f.AciAifsn.f.ACI = (u8)eACI; - { - PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam); - AC_CODING eACI; - u8 u1bAIFS; - u32 u4bAcParam; - - /* Retrieve parameters to update. */ - eACI = pAcParam->f.AciAifsn.f.ACI; - u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime; - u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) | - (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) | - (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) | - (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET)); - - switch (eACI) { - case AC1_BK: - /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */ - break; - - case AC0_BE: - /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */ - break; - - case AC2_VI: - /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */ - break; - - case AC3_VO: - /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */ - break; - - default: - DMESGW("SetHwReg8185(): invalid ACI: %d !\n", eACI); - break; - } - - write_nic_byte(dev, ACM_CONTROL, 0); - } + write_nic_byte(dev, ACM_CONTROL, 0); } } } -- cgit v0.10.2 From b926050cb1bfa64e575fab5e4eb3d2a15d349464 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 03:58:16 +0100 Subject: staging/rtl8187se: Remove code without effect The local variable AcParam is only assigned to but not read/used afterwards, thus it and all related code can be removed. The bFollowLegacySetting variable and check can also be removed as it is always true. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 5495d1e..4aca954 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -869,8 +869,6 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, struct r8180_priv *priv = ieee80211_priv(dev); struct ieee80211_device *ieee = priv->ieee80211; AC_CODING eACI; - AC_PARAM AcParam; - u8 bFollowLegacySetting = 0; u8 u1bAIFS; /* @@ -899,37 +897,8 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, write_nic_byte(dev, AckTimeOutReg, 0x5B); /* Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */ - { /* Legacy 802.11. */ - bFollowLegacySetting = 1; - - } - - /* this setting is copied from rtl8187B. xiong-2006-11-13 */ - if (bFollowLegacySetting) { - - /* - * Follow 802.11 seeting to AC parameter, all AC shall use the same parameter. - * 2005.12.01, by rcnjko. - */ - AcParam.longData = 0; - AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */ - AcParam.f.AciAifsn.f.ACM = 0; - AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; /* Follow 802.11 CWmin. */ - AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; /* Follow 802.11 CWmax. */ - AcParam.f.TXOPLimit = 0; - - /* lzm reserved 080826 */ - /* For turbo mode setting. port from 87B by Isaiah 2008-08-01 */ - if (ieee->current_network.Turbo_Enable == 1) - AcParam.f.TXOPLimit = 0x01FF; - /* For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB) */ - if (ieee->iw_mode == IW_MODE_ADHOC) - AcParam.f.TXOPLimit = 0x0020; - - for (eACI = 0; eACI < AC_MAX; eACI++) { - AcParam.f.AciAifsn.f.ACI = (u8)eACI; - write_nic_byte(dev, ACM_CONTROL, 0); - } + for (eACI = 0; eACI < AC_MAX; eACI++) { + write_nic_byte(dev, ACM_CONTROL, 0); } } -- cgit v0.10.2 From 8a26aefda17d7fdf0bdfb505b6366a7051e7fb1a Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 03:58:17 +0100 Subject: staging/rtl8187se: Remove unused/unnecessary variables The local variables priv and ieee are not used and thus can be removed. The local variable u1bAIFS is not used/read after assignment and thus can be removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 4aca954..1e54ead 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -866,10 +866,7 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, WIRELESS_MODE WirelessMode, PCHANNEL_ACCESS_SETTING ChnlAccessSetting) { - struct r8180_priv *priv = ieee80211_priv(dev); - struct ieee80211_device *ieee = priv->ieee80211; AC_CODING eACI; - u8 u1bAIFS; /* * @@ -891,8 +888,6 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer); write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); /* Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29. */ - u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer); - write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer); write_nic_byte(dev, AckTimeOutReg, 0x5B); /* Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */ -- cgit v0.10.2 From 2c370d9512c4ea0929e87cb18a2308d9422a350a Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 04:05:22 +0100 Subject: staging/rtl8187se: Reuse ReadBBPortUchar to avoid duplicated code WriteBBPortUchar reimplements ReadBBPortUchar in its body, so we can remove the duplicated code by calling ReadBBPortUchar directly. Unfortunately we have to move ReadBBPortUchar around; while at it we can also get rid of the temporary variable for the return value. Also we can remove the local variables UCharData and RegisterContent in WriteBBPortUchar as they are not used / without effect. Both functions are only 'local' so we can mark them as static. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 1e54ead..a3b836c 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -287,35 +287,19 @@ u16 RF_ReadReg(struct net_device *dev, u8 offset) return reg; } +static u8 ReadBBPortUchar(struct net_device *dev, u32 addr) +{ + PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f); + return PlatformIORead1Byte(dev, PhyDataR); +} /* by Owen on 04/07/14 for writing BB register successfully */ -void WriteBBPortUchar(struct net_device *dev, u32 Data) +static void WriteBBPortUchar(struct net_device *dev, u32 Data) { - /* u8 TimeoutCounter; */ - u8 RegisterContent; - u8 UCharData; - - UCharData = (u8)((Data & 0x0000ff00) >> 8); PlatformIOWrite4Byte(dev, PhyAddr, Data); - /* for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--) */ - { - PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f); - RegisterContent = PlatformIORead1Byte(dev, PhyDataR); - /*if(UCharData == RegisterContent) */ - /* break; */ - } + ReadBBPortUchar(dev, Data); } -u8 ReadBBPortUchar(struct net_device *dev, u32 addr) -{ - /*u8 TimeoutCounter; */ - u8 RegisterContent; - - PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f); - RegisterContent = PlatformIORead1Byte(dev, PhyDataR); - - return RegisterContent; -} /* * Description: * Perform Antenna settings with antenna diversity on 87SE. -- cgit v0.10.2 From aa341b6afab172b626f37b4ce6eff6d7485e400f Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 04:05:23 +0100 Subject: staging/rtl8187se: Remove temporary variable for return value The simple PlatformIORead1Byte function doesn't need to store its return value in a temporary variable; rather simply return the value directly. By moving the function to the top we can also get rid of the forward declaration. The wrapper functions could be easily replaced by direct calls to read_nic_byte but is kept for readability. Since this functions is local only we can mark it as static. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index a3b836c..1dfa78e 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -115,6 +115,11 @@ static u8 OFDM_CONFIG[] = { *--------------------------------------------------------------- */ +static u8 PlatformIORead1Byte(struct net_device *dev, u32 offset) +{ + return read_nic_byte(dev, offset); +} + void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data) { write_nic_byte(dev, offset, data); @@ -127,8 +132,6 @@ void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data) read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ } -u8 PlatformIORead1Byte(struct net_device *dev, u32 offset); - void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) { if (offset == PhyAddr) { @@ -172,16 +175,6 @@ void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) } } -u8 PlatformIORead1Byte(struct net_device *dev, u32 offset) -{ - u8 data = 0; - - data = read_nic_byte(dev, offset); - - - return data; -} - u16 PlatformIORead2Byte(struct net_device *dev, u32 offset) { u16 data = 0; -- cgit v0.10.2 From a638d6afbcf05cdd6d3a221544dbd8d1cd1eb3b6 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 04:05:24 +0100 Subject: staging/rtl8187se: Remove unused functions PlatformIORead2Byte / PlatformIORead4Byte These two functions PlatformIORead2Byte and PlatformIORead4Byte are unused and thus can be removed. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 1dfa78e..005fb0b 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -175,26 +175,6 @@ void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) } } -u16 PlatformIORead2Byte(struct net_device *dev, u32 offset) -{ - u16 data = 0; - - data = read_nic_word(dev, offset); - - - return data; -} - -u32 PlatformIORead4Byte(struct net_device *dev, u32 offset) -{ - u32 data = 0; - - data = read_nic_dword(dev, offset); - - - return data; -} - void SetOutputEnableOfRfPins(struct net_device *dev) { write_nic_word(dev, RFPinsEnable, 0x1bff); -- cgit v0.10.2 From 7f0cb0a05df262c51084f8b079188395ea1ad3da Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 04:05:25 +0100 Subject: staging/rtl8187se: Remove duplicated code by using an offset In SetAntennaConfig87SE both branches of if (bAntDiversity) do exactly the same, except that there is an offset of 0x80 for the register values if bAntDiversity is true. -> Consolidate both branches and assign the offset if necessary. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 005fb0b..2ca857d 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -284,62 +284,38 @@ bool SetAntennaConfig87SE(struct net_device *dev, { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); bool bAntennaSwitched = true; + u8 ant_diversity_offset = 0x00; /* 0x00 = disabled, 0x80 = enabled */ /* printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity); */ /* Threshold for antenna diversity. */ write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */ - if (bAntDiversity) { /* Enable Antenna Diversity. */ - if (DefaultAnt == 1) { /* aux antenna */ - - /* Mac register, aux antenna */ - write_nic_byte(dev, ANTSEL, 0x00); - - /* Config CCK RX antenna. */ - write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ - write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */ - - /* Config OFDM RX antenna. */ - write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ - write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */ - } else { /* use main antenna */ - /* Mac register, main antenna */ - write_nic_byte(dev, ANTSEL, 0x03); - /* base band */ - /* Config CCK RX antenna. */ - write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ - write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */ - - /* Config OFDM RX antenna. */ - write_phy_ofdm(dev, 0x0d, 0x5c); /* Reg0d : 5c */ - write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */ - } - } else { - /* Disable Antenna Diversity. */ - if (DefaultAnt == 1) { /* aux Antenna */ - /* Mac register, aux antenna */ - write_nic_byte(dev, ANTSEL, 0x00); - - /* Config CCK RX antenna. */ - write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ - write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */ - - /* Config OFDM RX antenna. */ - write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ - write_phy_ofdm(dev, 0x18, 0x32); /* Reg18 : 32 */ - } else { /* main Antenna */ - /* Mac register, main antenna */ - write_nic_byte(dev, ANTSEL, 0x03); - - /* Config CCK RX antenna. */ - write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ - write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */ - - /* Config OFDM RX antenna. */ - write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */ - write_phy_ofdm(dev, 0x18, 0x32); /*Reg18 : 32 */ - } + if (bAntDiversity) /* Enable Antenna Diversity. */ + ant_diversity_offset = 0x80; + + if (DefaultAnt == 1) { /* aux Antenna */ + /* Mac register, aux antenna */ + write_nic_byte(dev, ANTSEL, 0x00); + + /* Config CCK RX antenna. */ + write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ + write_phy_cck(dev, 0x01, 0x47|ant_diversity_offset); /* Reg01 : 47 | ant_diversity_offset */ + + /* Config OFDM RX antenna. */ + write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ + write_phy_ofdm(dev, 0x18, 0x32|ant_diversity_offset); /* Reg18 : 32 */ + } else { /* main Antenna */ + /* Mac register, main antenna */ + write_nic_byte(dev, ANTSEL, 0x03); + + /* Config CCK RX antenna. */ + write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ + write_phy_cck(dev, 0x01, 0x47|ant_diversity_offset); /* Reg01 : 47 */ + + /* Config OFDM RX antenna. */ + write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */ + write_phy_ofdm(dev, 0x18, 0x32|ant_diversity_offset); /*Reg18 : 32 */ } priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */ return bAntennaSwitched; -- cgit v0.10.2 From b6592810e4d9493781c187e482ab0fd5cc97893f Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Wed, 13 Feb 2013 04:05:26 +0100 Subject: staging/rtl8187se: Mark functions as static to silence sparse Sparse complains that some functions can be declared as static: 123:6: warning: symbol 'PlatformIOWrite1Byte' was not declared. Should it be static? 129:6: warning: symbol 'PlatformIOWrite2Byte' was not declared. Should it be static? 135:6: warning: symbol 'PlatformIOWrite4Byte' was not declared. Should it be static? 178:6: warning: symbol 'SetOutputEnableOfRfPins' was not declared. Should it be static? 354:6: warning: symbol 'ZEBRA_Config_85BASIC_HardCode' was not declared. Should it be static? 655:6: warning: symbol 'InitTxPwrTracking87SE' was not declared. Should it be static? 665:6: warning: symbol 'PhyConfig8185' was not declared. Should it be static? 692:6: warning: symbol 'HwConfigureRTL8185' was not declared. Should it be static? 817:4: warning: symbol 'GetSupportedWirelessMode8185' was not declared. Should it be static? 822:6: warning: symbol 'ActUpdateChannelAccessSetting' was not declared. Should it be static? 857:6: warning: symbol 'ActSetWirelessMode8185' was not declared. Should it be static? 914:6: warning: symbol 'MgntDisconnectIBSS' was not declared. Should it be static? 940:6: warning: symbol 'MlmeDisassociateRequest' was not declared. Should it be static? 957:6: warning: symbol 'MgntDisconnectAP' was not declared. Should it be static? 975:6: warning: symbol 'MgntDisconnect' was not declared. Should it be static? 1011:6: warning: symbol 'SetRFPowerState' was not declared. Should it be static? 1115:6: warning: symbol 'InactivePowerSave' was not declared. Should it be static? -> Add the static keyword. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c index 2ca857d..978dc5f 100644 --- a/drivers/staging/rtl8187se/r8185b_init.c +++ b/drivers/staging/rtl8187se/r8185b_init.c @@ -120,19 +120,19 @@ static u8 PlatformIORead1Byte(struct net_device *dev, u32 offset) return read_nic_byte(dev, offset); } -void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data) +static void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data) { write_nic_byte(dev, offset, data); read_nic_byte(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ } -void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data) +static void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data) { write_nic_word(dev, offset, data); read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ } -void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) +static void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) { if (offset == PhyAddr) { /* For Base Band configuration. */ @@ -175,7 +175,7 @@ void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) } } -void SetOutputEnableOfRfPins(struct net_device *dev) +static void SetOutputEnableOfRfPins(struct net_device *dev) { write_nic_word(dev, RFPinsEnable, 0x1bff); } @@ -327,7 +327,7 @@ bool SetAntennaConfig87SE(struct net_device *dev, *-------------------------------------------------------------- */ -void ZEBRA_Config_85BASIC_HardCode(struct net_device *dev) +static void ZEBRA_Config_85BASIC_HardCode(struct net_device *dev) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); @@ -628,7 +628,7 @@ void UpdateInitialGain(struct net_device *dev) * Tx Power tracking mechanism routine on 87SE. * Created by Roger, 2007.12.11. */ -void InitTxPwrTracking87SE(struct net_device *dev) +static void InitTxPwrTracking87SE(struct net_device *dev) { u32 u4bRfReg; @@ -638,7 +638,7 @@ void InitTxPwrTracking87SE(struct net_device *dev) RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1); } -void PhyConfig8185(struct net_device *dev) +static void PhyConfig8185(struct net_device *dev) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); write_nic_dword(dev, RCR, priv->ReceiveConfig); @@ -665,7 +665,7 @@ void PhyConfig8185(struct net_device *dev) return; } -void HwConfigureRTL8185(struct net_device *dev) +static void HwConfigureRTL8185(struct net_device *dev) { /* RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control. */ u8 bUNIVERSAL_CONTROL_RL = 0; @@ -790,12 +790,12 @@ static void MacConfig_85BASIC(struct net_device *dev) write_nic_byte(dev, 0x24E, 0x01); } -u8 GetSupportedWirelessMode8185(struct net_device *dev) +static u8 GetSupportedWirelessMode8185(struct net_device *dev) { return WIRELESS_MODE_B | WIRELESS_MODE_G; } -void ActUpdateChannelAccessSetting(struct net_device *dev, +static void ActUpdateChannelAccessSetting(struct net_device *dev, WIRELESS_MODE WirelessMode, PCHANNEL_ACCESS_SETTING ChnlAccessSetting) { @@ -830,7 +830,7 @@ void ActUpdateChannelAccessSetting(struct net_device *dev, } } -void ActSetWirelessMode8185(struct net_device *dev, u8 btWirelessMode) +static void ActSetWirelessMode8185(struct net_device *dev, u8 btWirelessMode) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); struct ieee80211_device *ieee = priv->ieee80211; @@ -887,7 +887,7 @@ void rtl8185b_irq_enable(struct net_device *dev) write_nic_dword(dev, IMR, priv->IntrMask); } -void MgntDisconnectIBSS(struct net_device *dev) +static void MgntDisconnectIBSS(struct net_device *dev) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); u8 i; @@ -913,7 +913,7 @@ void MgntDisconnectIBSS(struct net_device *dev) notify_wx_assoc_event(priv->ieee80211); } -void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn) +static void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); u8 i; @@ -930,7 +930,7 @@ void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn) } } -void MgntDisconnectAP(struct net_device *dev, u8 asRsn) +static void MgntDisconnectAP(struct net_device *dev, u8 asRsn) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); @@ -948,7 +948,7 @@ void MgntDisconnectAP(struct net_device *dev, u8 asRsn) priv->ieee80211->state = IEEE80211_NOLINK; } -bool MgntDisconnect(struct net_device *dev, u8 asRsn) +static bool MgntDisconnect(struct net_device *dev, u8 asRsn) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); /* @@ -984,7 +984,7 @@ bool MgntDisconnect(struct net_device *dev, u8 asRsn) * Assumption: * PASSIVE LEVEL. */ -bool SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerState) +static bool SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerState) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); bool bResult = false; @@ -1088,7 +1088,7 @@ bool MgntActSet_RF_State(struct net_device *dev, RT_RF_POWER_STATE StateToSet, u return bActionAllowed; } -void InactivePowerSave(struct net_device *dev) +static void InactivePowerSave(struct net_device *dev) { struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); /* -- cgit v0.10.2 From dfdcc425975d06cbfcc9b5c0fad2f3af5476cd05 Mon Sep 17 00:00:00 2001 From: Andres More Date: Tue, 12 Feb 2013 20:36:28 -0500 Subject: staging: vt6656: replace custom BOOL definition with bool Checkpatch findings were not resolved, just make direct replacement plus a couple of conflicting types in declarations. sed -i 's/\bBOOL\b/bool/g' drivers/staging/vt6656/*.[ch] Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/aes_ccmp.c b/drivers/staging/vt6656/aes_ccmp.c index f7a3b8f..62fedc1 100644 --- a/drivers/staging/vt6656/aes_ccmp.c +++ b/drivers/staging/vt6656/aes_ccmp.c @@ -231,7 +231,7 @@ void AESv128(BYTE *key, BYTE *data, BYTE *ciphertext) * */ -BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) +bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) { BYTE abyNonce[13]; BYTE MIC_IV[16]; @@ -249,7 +249,7 @@ BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) WORD wHLen = 22; /* 8 is IV, 8 is MIC, 4 is CRC */ WORD wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN; - BOOL bA4 = FALSE; + bool bA4 = FALSE; BYTE byTmp; WORD wCnt; int ii, jj, kk; diff --git a/drivers/staging/vt6656/aes_ccmp.h b/drivers/staging/vt6656/aes_ccmp.h index 353bd21..a2e2c4e 100644 --- a/drivers/staging/vt6656/aes_ccmp.h +++ b/drivers/staging/vt6656/aes_ccmp.h @@ -41,6 +41,6 @@ /*--------------------- Export Variables --------------------------*/ /*--------------------- Export Functions --------------------------*/ -BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize); +bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize); #endif /* __AES_CCMP_H__ */ diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index 79339fd..edebc9a 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -355,7 +355,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, (struct vnt_rx_mgmt *)pRxPacketContext; PKnownBSS pBSSList = NULL; unsigned int ii; - BOOL bParsingQuiet = FALSE; + bool bParsingQuiet = FALSE; pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]); @@ -453,7 +453,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) { PSKeyItem pTransmitKey = NULL; - BOOL bIs802_1x = FALSE; + bool bIs802_1x = FALSE; for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) { if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) { @@ -534,7 +534,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice, (struct vnt_rx_mgmt *)pRxPacketContext; int ii, jj; signed long ldBm, ldBmSum; - BOOL bParsingQuiet = FALSE; + bool bParsingQuiet = FALSE; if (pBSSList == NULL) return FALSE; diff --git a/drivers/staging/vt6656/bssdb.h b/drivers/staging/vt6656/bssdb.h index 9ee37b9..08091a0 100644 --- a/drivers/staging/vt6656/bssdb.h +++ b/drivers/staging/vt6656/bssdb.h @@ -79,20 +79,20 @@ // typedef struct tagSERPObject { - BOOL bERPExist; + bool bERPExist; BYTE byERP; } ERPObject, *PERPObject; typedef struct tagSRSNCapObject { - BOOL bRSNCapExist; + bool bRSNCapExist; WORD wRSNCap; } SRSNCapObject, *PSRSNCapObject; // BSS info(AP) typedef struct tagKnownBSS { // BSS info - BOOL bActive; + bool bActive; BYTE abyBSSID[WLAN_BSSID_LEN]; unsigned int uChannel; BYTE abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; @@ -110,10 +110,10 @@ typedef struct tagKnownBSS { signed long ldBmAverage[RSSI_STAT_COUNT]; signed long ldBmAverRange; //For any BSSID selection improvment - BOOL bSelected; + bool bSelected; //++ WPA informations - BOOL bWPAValid; + bool bWPAValid; BYTE byGKType; BYTE abyPKType[4]; WORD wPKCount; @@ -124,7 +124,7 @@ typedef struct tagKnownBSS { //-- //++ WPA2 informations - BOOL bWPA2Valid; + bool bWPA2Valid; BYTE byCSSGK; WORD wCSSPKCount; BYTE abyCSSPK[4]; @@ -167,14 +167,14 @@ typedef enum tagNODE_STATE { // STA node info typedef struct tagKnownNodeDB { // STA info - BOOL bActive; + bool bActive; BYTE abyMACAddr[WLAN_ADDR_LEN]; BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN]; BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN]; WORD wTxDataRate; - BOOL bShortPreamble; - BOOL bERPExist; - BOOL bShortSlotTime; + bool bShortPreamble; + bool bERPExist; + bool bShortSlotTime; unsigned int uInActiveCount; WORD wMaxBasicRate; //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp. WORD wMaxSuppRate; //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon. @@ -188,15 +188,15 @@ typedef struct tagKnownNodeDB { WORD wListenInterval; WORD wAID; NODE_STATE eNodeState; - BOOL bPSEnable; - BOOL bRxPSPoll; + bool bPSEnable; + bool bRxPSPoll; BYTE byAuthSequence; unsigned long ulLastRxJiffer; BYTE bySuppRate; DWORD dwFlags; WORD wEnQueueCnt; - BOOL bOnFly; + bool bOnFly; unsigned long long KeyRSC; BYTE byKeyIndex; DWORD dwKeyIndex; @@ -207,7 +207,7 @@ typedef struct tagKnownNodeDB { BYTE abyWepKey[WLAN_WEPMAX_KEYLEN]; // // Auto rate fallback vars - BOOL bIsInFallback; + bool bIsInFallback; unsigned int uAverageRSSI; unsigned int uRateRecoveryTimeout; unsigned int uRatePollTimeout; diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index f988f07..9b8daed 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -501,7 +501,7 @@ void vUpdateIFS(struct vnt_private *pDevice) } else {// PK_TYPE_11GA & PK_TYPE_11GB BYTE byRate = 0; - BOOL bOFDMRate = FALSE; + bool bOFDMRate = FALSE; unsigned int ii = 0; PWLAN_IE_SUPP_RATES pItemRates = NULL; @@ -726,7 +726,7 @@ void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate, * Return Value: TRUE if success; otherwise FALSE * */ -int CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF) +bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF) { *pqwCurrTSF = pDevice->qwCurrTSF; @@ -746,7 +746,7 @@ int CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF) * Return Value: TRUE if success; otherwise FALSE * */ -int CARDbClearCurrentTSF(struct vnt_private *pDevice) +bool CARDbClearCurrentTSF(struct vnt_private *pDevice) { MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h index 720643f..5123bc7 100644 --- a/drivers/staging/vt6656/card.h +++ b/drivers/staging/vt6656/card.h @@ -68,8 +68,8 @@ void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx); int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice); void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate, u64 qwBSSTimestamp, u64 qwLocalTSF); -BOOL CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF); -BOOL CARDbClearCurrentTSF(struct vnt_private *pDevice); +bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF); +bool CARDbClearCurrentTSF(struct vnt_private *pDevice); void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval); void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF, WORD wBeaconInterval); diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c index 95f00ba..b969ade 100644 --- a/drivers/staging/vt6656/channel.c +++ b/drivers/staging/vt6656/channel.c @@ -387,10 +387,10 @@ static struct // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) ************************************************************************/ -BOOL +bool ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex) { - BOOL bValid; + bool bValid; bValid = FALSE; /* @@ -422,7 +422,7 @@ exit: * 0x0000000000000003 means channel 1,2 are supported * 0x000000000000000F means channel 1,2,..15 are supported ************************************************************************/ -BOOL +bool CHvChannelGetList ( unsigned int uCountryCodeIdx, PBYTE pbyChannelTable diff --git a/drivers/staging/vt6656/channel.h b/drivers/staging/vt6656/channel.h index 8031491..9914dba 100644 --- a/drivers/staging/vt6656/channel.h +++ b/drivers/staging/vt6656/channel.h @@ -40,17 +40,17 @@ typedef struct tagSChannelTblElement { BYTE byChannelNumber; unsigned int uFrequency; - BOOL bValid; + bool bValid; } SChannelTblElement, *PSChannelTblElement; /*--------------------- Export Variables --------------------------*/ /*--------------------- Export Functions --------------------------*/ -BOOL ChannelValid(unsigned int CountryCode, unsigned int ChannelNum); +bool ChannelValid(unsigned int CountryCode, unsigned int ChannelNum); void CHvInitChannelTable(struct vnt_private *pDevice); BYTE CHbyGetChannelMapping(BYTE byChannelNumber); -BOOL CHvChannelGetList(unsigned int uCountryCodeIdx, PBYTE pbyChannelTable); +bool CHvChannelGetList(unsigned int uCountryCodeIdx, PBYTE pbyChannelTable); #endif /* _CHANNEL_H_ */ diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index 82af871..6bba2e0 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -193,7 +193,7 @@ typedef struct _USB_SEND_CONTEXT { CONTEXT_TYPE Type; SEthernetHeader sEthHeader; void *Next; - BOOL bBoolInUse; + bool bBoolInUse; unsigned char Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS]; } USB_SEND_CONTEXT, *PUSB_SEND_CONTEXT; @@ -214,7 +214,7 @@ typedef struct { unsigned int uDataLen; PBYTE pDataBuf; /* struct urb *pUrb; */ - BOOL bInUse; + bool bInUse; } INT_BUFFER, *PINT_BUFFER; /* 0:11A 1:11B 2:11G */ @@ -308,7 +308,7 @@ typedef struct tagSPMKIDCandidateEvent { #define MAX_QUIET_COUNT 8 typedef struct tagSQuietControl { - BOOL bEnable; + bool bEnable; DWORD dwStartTime; BYTE byPeriod; WORD wDuration; @@ -342,7 +342,7 @@ typedef struct tagSDeFragControlBlock struct sk_buff* skb; PBYTE pbyRxBuffer; unsigned int cbFrameLength; - BOOL bInUse; + bool bInUse; } SDeFragControlBlock, *PSDeFragControlBlock; /* flags for options */ diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index 208be2c..8349911 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -430,7 +430,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if (IS_FC_WEP(pbyFrame)) { - BOOL bRxDecryOK = FALSE; + bool bRxDecryOK = FALSE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n"); bIsWEP = TRUE; diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c index 93d7301..c07cca7 100644 --- a/drivers/staging/vt6656/firmware.c +++ b/drivers/staging/vt6656/firmware.c @@ -62,7 +62,7 @@ int FIRMWAREbDownload(struct vnt_private *pDevice) const struct firmware *fw; int NdisStatus; void *pBuffer = NULL; - BOOL result = FALSE; + bool result = FALSE; u16 wLength; int ii, rc; diff --git a/drivers/staging/vt6656/iocmd.h b/drivers/staging/vt6656/iocmd.h index ae6e2d2..c354a77 100644 --- a/drivers/staging/vt6656/iocmd.h +++ b/drivers/staging/vt6656/iocmd.h @@ -122,8 +122,8 @@ typedef struct tagSCmdBSSJoin { u16 wBBPType; u8 ssid[SSID_MAXLEN + 2]; u32 uChannel; - BOOL bPSEnable; - BOOL bShareKeyAuth; + bool bPSEnable; + bool bShareKeyAuth; } __packed SCmdBSSJoin, *PSCmdBSSJoin; @@ -133,7 +133,7 @@ typedef struct tagSCmdBSSJoin { typedef struct tagSCmdZoneTypeSet { - BOOL bWrite; + bool bWrite; WZONETYPE ZoneType; } __packed SCmdZoneTypeSet, *PSCmdZoneTypeSet; @@ -143,7 +143,7 @@ typedef struct tagSWPAResult { u8 proto; u8 key_mgmt; u8 eap_type; - BOOL authenticated; + bool authenticated; } __packed SWPAResult, *PSWPAResult; typedef struct tagSCmdStartAP { @@ -153,17 +153,17 @@ typedef struct tagSCmdStartAP { u8 ssid[SSID_MAXLEN + 2]; u32 uChannel; u32 uBeaconInt; - BOOL bShareKeyAuth; + bool bShareKeyAuth; u8 byBasicRate; } __packed SCmdStartAP, *PSCmdStartAP; typedef struct tagSCmdSetWEP { - BOOL bEnableWep; + bool bEnableWep; u8 byKeyIndex; u8 abyWepKey[WEP_NKEYS][WEP_KEYMAXLEN]; - BOOL bWepKeyAvailable[WEP_NKEYS]; + bool bWepKeyAvailable[WEP_NKEYS]; u32 auWepKeyLength[WEP_NKEYS]; } __packed SCmdSetWEP, *PSCmdSetWEP; @@ -176,7 +176,7 @@ typedef struct tagSBSSIDItem { u16 wBeaconInterval; u16 wCapInfo; u8 byNetType; - BOOL bWEPOn; + bool bWEPOn; u32 uRSSI; } __packed SBSSIDItem; @@ -197,12 +197,12 @@ typedef struct tagSNodeItem { u16 wInActiveCount; u16 wEnQueueCnt; u16 wFlags; - BOOL bPWBitOn; + bool bPWBitOn; u8 byKeyIndex; u16 wWepKeyLength; u8 abyWepKey[WEP_KEYMAXLEN]; // Auto rate fallback vars - BOOL bIsInFallback; + bool bIsInFallback; u32 uTxFailures; u32 uTxAttempts; u16 wFailureRatio; @@ -220,7 +220,7 @@ typedef struct tagSNodeList { typedef struct tagSCmdLinkStatus { - BOOL bLink; + bool bLink; u16 wBSSType; u8 byState; u8 abyBSSID[BSSID_LEN]; diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h index 8889423..7ecddcd 100644 --- a/drivers/staging/vt6656/key.h +++ b/drivers/staging/vt6656/key.h @@ -57,7 +57,7 @@ typedef struct tagSKeyItem { - BOOL bKeyValid; + bool bKeyValid; u32 uKeyLength; BYTE abyKey[MAX_KEY_LEN]; u64 KeyRSC; @@ -76,9 +76,9 @@ typedef struct tagSKeyTable SKeyItem PairwiseKey; SKeyItem GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328 DWORD dwGTKeyIndex; // GroupTransmitKey Index - BOOL bInUse; + bool bInUse; WORD wKeyCtl; - BOOL bSoftWEP; + bool bSoftWEP; BYTE byReserved1[6]; } SKeyTable, *PSKeyTable; //352 diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index d258cb2..9a5573a 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -228,7 +228,7 @@ static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); static int device_init_registers(struct vnt_private *pDevice, DEVICE_INIT_TYPE InitType); -static BOOL device_init_defrag_cb(struct vnt_private *pDevice); +static bool device_init_defrag_cb(struct vnt_private *pDevice); static void device_init_diversity_timer(struct vnt_private *pDevice); static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev); @@ -237,7 +237,7 @@ static void device_free_tx_bufs(struct vnt_private *pDevice); static void device_free_rx_bufs(struct vnt_private *pDevice); static void device_free_int_bufs(struct vnt_private *pDevice); static void device_free_frag_bufs(struct vnt_private *pDevice); -static BOOL device_alloc_bufs(struct vnt_private *pDevice); +static bool device_alloc_bufs(struct vnt_private *pDevice); static int Read_config_file(struct vnt_private *pDevice); static unsigned char *Config_FileOperation(struct vnt_private *pDevice); @@ -814,7 +814,7 @@ static void device_free_int_bufs(struct vnt_private *pDevice) } -static BOOL device_alloc_bufs(struct vnt_private *pDevice) +static bool device_alloc_bufs(struct vnt_private *pDevice) { PUSB_SEND_CONTEXT pTxContext; @@ -914,7 +914,7 @@ free_tx: -static BOOL device_init_defrag_cb(struct vnt_private *pDevice) +static bool device_init_defrag_cb(struct vnt_private *pDevice) { int i; PSDeFragControlBlock pDeF; diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index 92343f2..c52f7a9 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -2482,7 +2482,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, u8 *pbyBSSID; int bNodeExist = FALSE; PUSB_SEND_CONTEXT pContext; - BOOL fConvertedPacket; + bool fConvertedPacket; PTX_BUFFER pTX_Buffer; u32 status; u16 wKeepRate = pDevice->wCurrentRate; diff --git a/drivers/staging/vt6656/tether.c b/drivers/staging/vt6656/tether.c index 083b215..7c4a808 100644 --- a/drivers/staging/vt6656/tether.c +++ b/drivers/staging/vt6656/tether.c @@ -96,7 +96,7 @@ BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr) * Return Value: TRUE if ok; FALSE if error. * */ -BOOL ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) +bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) { DWORD dwCRC; diff --git a/drivers/staging/vt6656/tether.h b/drivers/staging/vt6656/tether.h index 8c1f5d2..2f8f485 100644 --- a/drivers/staging/vt6656/tether.h +++ b/drivers/staging/vt6656/tether.h @@ -161,6 +161,6 @@ S802_11Header, *PS802_11Header; BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr); //BYTE ETHbyGetHashIndexByCrc(PBYTE pbyMultiAddr); -BOOL ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength); +bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength); #endif /* __TETHER_H__ */ diff --git a/drivers/staging/vt6656/ttype.h b/drivers/staging/vt6656/ttype.h index 89ab494..436cd79 100644 --- a/drivers/staging/vt6656/ttype.h +++ b/drivers/staging/vt6656/ttype.h @@ -33,8 +33,6 @@ /******* Common definitions and typedefs ***********************************/ -typedef int BOOL; - #if !defined(TRUE) #define TRUE 1 #endif diff --git a/drivers/staging/vt6656/wcmd.h b/drivers/staging/vt6656/wcmd.h index a3d0323..c40e6ba 100644 --- a/drivers/staging/vt6656/wcmd.h +++ b/drivers/staging/vt6656/wcmd.h @@ -74,9 +74,9 @@ typedef enum tagCMD_STATUS { typedef struct tagCMD_ITEM { CMD_CODE eCmd; BYTE abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; - BOOL bNeedRadioOFF; - BOOL bRadioCmd; - BOOL bForceSCAN; + bool bNeedRadioOFF; + bool bRadioCmd; + bool bForceSCAN; WORD wDeAuthenReason; } CMD_ITEM, *PCMD_ITEM; diff --git a/drivers/staging/vt6656/wctl.c b/drivers/staging/vt6656/wctl.c index 18a09a3..269082b 100644 --- a/drivers/staging/vt6656/wctl.c +++ b/drivers/staging/vt6656/wctl.c @@ -67,7 +67,7 @@ * */ -BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader) +bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader) { unsigned int uIndex; unsigned int ii; @@ -182,8 +182,8 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE * */ -int WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, - unsigned int cbFrameLength, int bWEP, int bExtIV) +bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, + unsigned int cbFrameLength, bool bWEP, bool bExtIV) { unsigned int uHeaderSize; diff --git a/drivers/staging/vt6656/wctl.h b/drivers/staging/vt6656/wctl.h index a509f63..1b21e32e 100644 --- a/drivers/staging/vt6656/wctl.h +++ b/drivers/staging/vt6656/wctl.h @@ -96,9 +96,9 @@ /*--------------------- Export Functions --------------------------*/ -BOOL WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader); -int WCTLbHandleFragment(struct vnt_private *, PS802_11Header pMACHeader, - unsigned int cbFrameLength, BOOL bWEP, BOOL bExtIV); +bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader); +bool WCTLbHandleFragment(struct vnt_private *, PS802_11Header pMACHeader, + unsigned int cbFrameLength, bool bWEP, bool bExtIV); unsigned int WCTLuSearchDFCB(struct vnt_private *, PS802_11Header pMACHeader); unsigned int WCTLuInsertDFCB(struct vnt_private *, PS802_11Header pMACHeader); diff --git a/drivers/staging/vt6656/wmgr.c b/drivers/staging/vt6656/wmgr.c index 89491ae..4b310df 100644 --- a/drivers/staging/vt6656/wmgr.c +++ b/drivers/staging/vt6656/wmgr.c @@ -187,7 +187,7 @@ static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode, PKnownBSS pCurr, PCMD_STATUS pStatus); -static BOOL +static bool s_bCipherMatch ( PKnownBSS pBSSNode, NDIS_802_11_ENCRYPTION_STATUS EncStatus, @@ -1756,7 +1756,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) } // Sync Short Slot Time if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) { - BOOL bShortSlotTime; + bool bShortSlotTime; bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo); //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime)); @@ -2443,7 +2443,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) // Add current BSS to Candidate list // This should only work for WPA2 BSS, and WPA2 BSS check must be done before. if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) { - BOOL bResult = bAdd_PMKID_Candidate((void *) pDevice, + bool bResult = bAdd_PMKID_Candidate((void *) pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult); @@ -4364,7 +4364,7 @@ void vFlush_PMKID_Candidate(struct vnt_private *pDevice) return; } -static BOOL +static bool s_bCipherMatch ( PKnownBSS pBSSNode, NDIS_802_11_ENCRYPTION_STATUS EncStatus, diff --git a/drivers/staging/vt6656/wpa.c b/drivers/staging/vt6656/wpa.c index f6429a2..6336d88 100644 --- a/drivers/staging/vt6656/wpa.c +++ b/drivers/staging/vt6656/wpa.c @@ -239,7 +239,7 @@ WPA_ParseRSN( * Return Value: none. * -*/ -BOOL +bool WPA_SearchRSN( BYTE byCmd, BYTE byEncrypt, @@ -299,7 +299,7 @@ WPA_SearchRSN( * Return Value: none. * -*/ -BOOL +bool WPAb_Is_RSN( PWLAN_IE_RSN_EXT pRSN ) diff --git a/drivers/staging/vt6656/wpa.h b/drivers/staging/vt6656/wpa.h index 889489a..0369cbf 100644 --- a/drivers/staging/vt6656/wpa.h +++ b/drivers/staging/vt6656/wpa.h @@ -69,14 +69,14 @@ WPA_ParseRSN( PWLAN_IE_RSN_EXT pRSN ); -BOOL +bool WPA_SearchRSN( BYTE byCmd, BYTE byEncrypt, PKnownBSS pBSSList ); -BOOL +bool WPAb_Is_RSN( PWLAN_IE_RSN_EXT pRSN ); diff --git a/drivers/staging/vt6656/wpa2.c b/drivers/staging/vt6656/wpa2.c index 99b4589..97691a3 100644 --- a/drivers/staging/vt6656/wpa2.c +++ b/drivers/staging/vt6656/wpa2.c @@ -115,7 +115,7 @@ WPA2vParseRSN ( int i, j; WORD m = 0, n = 0; PBYTE pbyOUI; - BOOL bUseGK = FALSE; + bool bUseGK = FALSE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len); -- cgit v0.10.2 From e269fc2d129ade6543c22052755becf37e306e2a Mon Sep 17 00:00:00 2001 From: Andres More Date: Tue, 12 Feb 2013 20:36:29 -0500 Subject: staging: vt6656: replaced custom FALSE definition with false Checkpatch findings were not resolved, just direct replacement. sed -i 's/\bFALSE\b/false/g' drivers/staging/vt6656/*.[ch] Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/aes_ccmp.c b/drivers/staging/vt6656/aes_ccmp.c index 62fedc1..a6f79be 100644 --- a/drivers/staging/vt6656/aes_ccmp.c +++ b/drivers/staging/vt6656/aes_ccmp.c @@ -249,7 +249,7 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) WORD wHLen = 22; /* 8 is IV, 8 is MIC, 4 is CRC */ WORD wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN; - bool bA4 = FALSE; + bool bA4 = false; BYTE byTmp; WORD wCnt; int ii, jj, kk; @@ -382,5 +382,5 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) if (!memcmp(abyMIC, abyTmp, 8)) return TRUE; else - return FALSE; + return false; } diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c index cccd810..29817b8 100644 --- a/drivers/staging/vt6656/baseband.c +++ b/drivers/staging/vt6656/baseband.c @@ -768,7 +768,7 @@ void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength, int bCCK = pDevice->bCCK; cbBitCount = cbFrameLength * 8; - bExtBit = FALSE; + bExtBit = false; switch (wRate) { case RATE_1M : @@ -785,7 +785,7 @@ void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength, break; case RATE_5M : - if (bCCK == FALSE) + if (bCCK == false) cbBitCount ++; cbUsCount = (cbBitCount * 10) / 55; cbTmp = (cbUsCount * 55) / 10; @@ -799,7 +799,7 @@ void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength, case RATE_11M : - if (bCCK == FALSE) + if (bCCK == false) cbBitCount ++; cbUsCount = cbBitCount / 11; cbTmp = cbUsCount * 11; @@ -976,12 +976,12 @@ int BBbVT3184Init(struct vnt_private *pDevice) EEP_MAX_CONTEXT_SIZE, pDevice->abyEEPROM); if (ntStatus != STATUS_SUCCESS) { - return FALSE; + return false; } // if ((pDevice->abyEEPROM[EEP_OFS_RADIOCTL]&0x06)==0x04) -// return FALSE; +// return false; //zonetype initial pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE]; diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index edebc9a..bc10b0b 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -141,15 +141,15 @@ PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice, } } - if ((pbyBSSID != NULL)&&(pDevice->bRoaming == FALSE)) { + if ((pbyBSSID != NULL)&&(pDevice->bRoaming == false)) { // match BSSID first for (ii = 0; ii sBSSList[ii]); - pCurrBSS->bSelected = FALSE; + pCurrBSS->bSelected = false; if ((pCurrBSS->bActive) && - (pCurrBSS->bSelected == FALSE)) { + (pCurrBSS->bSelected == false)) { if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) { if (pSSID != NULL) { // compare ssid @@ -183,9 +183,9 @@ PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice, //2007-0721-01by MikeLiu // if ((pCurrBSS->bActive) && - // (pCurrBSS->bSelected == FALSE)) { + // (pCurrBSS->bSelected == false)) { - pCurrBSS->bSelected = FALSE; + pCurrBSS->bSelected = false; if (pCurrBSS->bActive) { if (pSSID != NULL) { @@ -237,7 +237,7 @@ pDevice->bSameBSSMaxNum = jj; if (pSelect != NULL) { pSelect->bSelected = TRUE; - if (pDevice->bRoaming == FALSE) { + if (pDevice->bRoaming == false) { // Einsn Add @20070907 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ; } @@ -274,12 +274,12 @@ void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID) //mike mark: there are two BSSID's in list. If that AP is in hidden ssid mode, one SSID is null, // but other's might not be obvious, so if it associate's with your STA, // you must keep the two of them!! - // bKeepCurrBSSID = FALSE; + // bKeepCurrBSSID = false; continue; } } - pMgmt->sBSSList[ii].bActive = FALSE; + pMgmt->sBSSList[ii].bActive = false; memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS)); } BSSvClearAnyBSSJoinRecord(pDevice); @@ -355,7 +355,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, (struct vnt_rx_mgmt *)pRxPacketContext; PKnownBSS pBSSList = NULL; unsigned int ii; - bool bParsingQuiet = FALSE; + bool bParsingQuiet = false; pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]); @@ -368,7 +368,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, if (ii == MAX_BSS_NUM){ DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n"); - return FALSE; + return false; } // save the BSS info pBSSList->bActive = TRUE; @@ -453,7 +453,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) { PSKeyItem pTransmitKey = NULL; - bool bIs802_1x = FALSE; + bool bIs802_1x = false; for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) { if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) { @@ -534,10 +534,10 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice, (struct vnt_rx_mgmt *)pRxPacketContext; int ii, jj; signed long ldBm, ldBmSum; - bool bParsingQuiet = FALSE; + bool bParsingQuiet = false; if (pBSSList == NULL) - return FALSE; + return false; pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp); @@ -669,7 +669,7 @@ int BSSbIsSTAInNodeDB(struct vnt_private *pDevice, } } - return FALSE; + return false; }; @@ -826,7 +826,7 @@ void BSSvAddMulticastNode(struct vnt_private *pDevice) memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN); pMgmt->sNodeDBTable[0].bActive = TRUE; - pMgmt->sNodeDBTable[0].bPSEnable = FALSE; + pMgmt->sNodeDBTable[0].bPSEnable = false; skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue); RATEvParseMaxRate((void *) pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, @@ -874,7 +874,7 @@ void BSSvSecondCallBack(struct vnt_private *pDevice) pDevice->ulPSModeWaitTx++; if ( pDevice->ulPSModeWaitTx >= 2 ) { pDevice->ulPSModeWaitTx = 0; - pDevice->bPSModeTxBurst = FALSE; + pDevice->bPSModeTxBurst = false; } } @@ -994,14 +994,14 @@ if(pDevice->byReAssocCount > 0) { else { if (pDevice->bProtectMode) { MACvDisableProtectMD(pDevice); - pDevice->bProtectMode = FALSE; + pDevice->bProtectMode = false; } } // on/off short slot time if (uNonShortSlotSTACnt > 0) { if (pDevice->bShortSlotTime) { - pDevice->bShortSlotTime = FALSE; + pDevice->bShortSlotTime = false; BBvSetShortSlotTime(pDevice); vUpdateIFS((void *)pDevice); } @@ -1025,7 +1025,7 @@ if(pDevice->byReAssocCount > 0) { else { if (pDevice->bBarkerPreambleMd) { MACvDisableBarkerPreambleMd(pDevice); - pDevice->bBarkerPreambleMd = FALSE; + pDevice->bBarkerPreambleMd = false; } } @@ -1037,7 +1037,7 @@ if(pDevice->byReAssocCount > 0) { if (uSleepySTACnt > 0) pMgmt->sNodeDBTable[0].bPSEnable = TRUE; else - pMgmt->sNodeDBTable[0].bPSEnable = FALSE; + pMgmt->sNodeDBTable[0].bPSEnable = false; } pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID; @@ -1062,14 +1062,14 @@ if(pDevice->byReAssocCount > 0) { } if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) { - pMgmt->sNodeDBTable[0].bActive = FALSE; + pMgmt->sNodeDBTable[0].bActive = false; pMgmt->eCurrMode = WMAC_MODE_STANDBY; pMgmt->eCurrState = WMAC_STATE_IDLE; netif_stop_queue(pDevice->dev); - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); pDevice->bRoaming = TRUE; - pDevice->bIsRoaming = FALSE; + pDevice->bIsRoaming = false; DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount); /* let wpa supplicant know AP may disconnect */ @@ -1098,12 +1098,12 @@ DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming ); pMgmt->abyDesireSSID); pDevice->uAutoReConnectTime = 0; pDevice->uIsroamingTime = 0; - pDevice->bRoaming = FALSE; + pDevice->bRoaming = false; } - else if ((pDevice->bRoaming == FALSE)&&(pDevice->bIsRoaming == TRUE)) { + else if ((pDevice->bRoaming == false)&&(pDevice->bIsRoaming == TRUE)) { pDevice->uIsroamingTime++; if (pDevice->uIsroamingTime >= 20) - pDevice->bIsRoaming = FALSE; + pDevice->bIsRoaming = false; } } @@ -1159,7 +1159,7 @@ else { pMgmt->sNodeDBTable[0].uInActiveCount = 0; pMgmt->eCurrState = WMAC_STATE_STARTED; netif_stop_queue(pDevice->dev); - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); } } @@ -1459,7 +1459,7 @@ void BSSvClearAnyBSSJoinRecord(struct vnt_private *pDevice) int ii; for (ii = 0; ii < MAX_BSS_NUM; ii++) - pMgmt->sBSSList[ii].bSelected = FALSE; + pMgmt->sBSSList[ii].bSelected = false; return; } @@ -1474,7 +1474,7 @@ static void s_vCheckPreEDThreshold(struct vnt_private *pDevice) pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID); if (pBSSList != NULL) { pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1); - BBvUpdatePreEDThreshold(pDevice, FALSE); + BBvUpdatePreEDThreshold(pDevice, false); } } } diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 9b8daed..21c24f7 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -501,7 +501,7 @@ void vUpdateIFS(struct vnt_private *pDevice) } else {// PK_TYPE_11GA & PK_TYPE_11GB BYTE byRate = 0; - bool bOFDMRate = FALSE; + bool bOFDMRate = false; unsigned int ii = 0; PWLAN_IE_SUPP_RATES pItemRates = NULL; @@ -521,7 +521,7 @@ void vUpdateIFS(struct vnt_private *pDevice) break; } } - if (bOFDMRate == FALSE) { + if (bOFDMRate == false) { pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt .abyCurrExtSuppRates; for (ii = 0; ii < pItemRates->len; ii++) { @@ -599,7 +599,7 @@ void CARDvUpdateBasicTopRate(struct vnt_private *pDevice) * Out: * none * - * Return Value: TRUE if succeeded; FALSE if failed. + * Return Value: TRUE if succeeded; false if failed. * */ void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx) @@ -620,7 +620,7 @@ int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice) if ((pDevice->wBasicRate) & ((WORD)(1<bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { - return FALSE; + return false; } - //if (pDevice->bRadioOff == FALSE) + //if (pDevice->bRadioOff == false) // return TRUE; - pDevice->bRadioOff = FALSE; + pDevice->bRadioOff = false; BBvExitDeepSleep(pDevice); diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c index b969ade..d58ca0a 100644 --- a/drivers/staging/vt6656/channel.c +++ b/drivers/staging/vt6656/channel.c @@ -50,7 +50,7 @@ static int msglevel = MSG_LEVEL_INFO; static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] = { - {0, 0, FALSE}, + {0, 0, false}, {1, 2412, TRUE}, {2, 2417, TRUE}, {3, 2422, TRUE}, @@ -392,14 +392,14 @@ ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex) { bool bValid; - bValid = FALSE; + bValid = false; /* * If Channel Index is invalid, return invalid */ if ((ChannelIndex > CB_MAX_CHANNEL) || (ChannelIndex == 0)) { - bValid = FALSE; + bValid = false; goto exit; } @@ -429,7 +429,7 @@ CHvChannelGetList ( ) { if (uCountryCodeIdx >= CCODE_MAX) { - return (FALSE); + return (false); } memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL); return (TRUE); @@ -438,18 +438,18 @@ CHvChannelGetList ( void CHvInitChannelTable(struct vnt_private *pDevice) { - int bMultiBand = FALSE; + int bMultiBand = false; int ii; for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) - sChannelTbl[ii].bValid = FALSE; + sChannelTbl[ii].bValid = false; switch (pDevice->byRFType) { case RF_AL2230: case RF_AL2230S: case RF_VT3226: case RF_VT3226D0: - bMultiBand = FALSE; + bMultiBand = false; break; case RF_AIROHA7230: case RF_VT3342A0: diff --git a/drivers/staging/vt6656/datarate.c b/drivers/staging/vt6656/datarate.c index 4a234e5..774a256 100644 --- a/drivers/staging/vt6656/datarate.c +++ b/drivers/staging/vt6656/datarate.c @@ -307,7 +307,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice, struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; u16 wIdxDownRate = 0; int ii; - int bAutoRate[MAX_RATE] = {TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, + int bAutoRate[MAX_RATE] = {TRUE, TRUE, TRUE, TRUE, false, false, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE}; u32 dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540}; @@ -339,7 +339,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice, wIdxUpRate = (WORD) ii; } } else { - bAutoRate[ii] = FALSE; + bAutoRate[ii] = false; } } diff --git a/drivers/staging/vt6656/device_cfg.h b/drivers/staging/vt6656/device_cfg.h index 98600d6..8608f76 100644 --- a/drivers/staging/vt6656/device_cfg.h +++ b/drivers/staging/vt6656/device_cfg.h @@ -38,12 +38,12 @@ struct _version { unsigned char build; } version_t, *pversion_t; -#ifndef FALSE -#define FALSE (0) +#ifndef false +#define false (0) #endif #ifndef TRUE -#define TRUE (!(FALSE)) +#define TRUE (!(false)) #endif #define VID_TABLE_SIZE 64 diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index 8349911..c68b81a 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -276,7 +276,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, PS802_11Header p802_11Header; u8 *pbyRsr, *pbyNewRsr, *pbyRSSI, *pbyFrame; u64 *pqwTSFTime; - u32 bDeFragRx = FALSE; + u32 bDeFragRx = false; u32 cbHeaderOffset, cbIVOffset; u32 FrameSize; u16 wEtherType = 0; @@ -289,7 +289,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, u32 dwRxTSC47_16 = 0; SKeyItem STempKey; /* signed long ldBm = 0; */ - int bIsWEP = FALSE; int bExtIV = FALSE; + int bIsWEP = false; int bExtIV = false; u32 dwWbkStatus; PRCB pRCBIndicate = pRCB; u8 *pbyDAddress; @@ -298,7 +298,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108}; u16 wPLCPwithPadding; PS802_11Header pMACHeader; - int bRxeapol_key = FALSE; + int bRxeapol_key = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n"); @@ -312,13 +312,13 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if (BytesToIndicate != FrameSize) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"------- WRONG Length 1\n"); - return FALSE; + return false; } if ((BytesToIndicate > 2372) || (BytesToIndicate <= 40)) { // Frame Size error drop this packet. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n"); - return FALSE; + return false; } pbyDAddress = (PBYTE)(skb->data); @@ -336,7 +336,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong PLCP Length %x\n", (int) *pwPLCP_Length); ASSERT(0); - return FALSE; + return false; } for ( ii=RATE_1M;iiabyAddr1)) { if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) { pDevice->s802_11Counter.FrameDuplicateCount++; - return FALSE; + return false; } if (compare_ether_addr(pDevice->abyCurrentNetAddr, pMACHeader->abyAddr1)) { - return FALSE; + return false; } } @@ -409,7 +409,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]), pDevice->abyCurrentNetAddr)) - return FALSE; + return false; if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) { if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) { @@ -424,13 +424,13 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) { - return FALSE; + return false; } } if (IS_FC_WEP(pbyFrame)) { - bool bRxDecryOK = FALSE; + bool bRxDecryOK = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n"); bIsWEP = TRUE; @@ -485,11 +485,11 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, // pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++; } } - return FALSE; + return false; } } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n"); - return FALSE; + return false; } if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) FrameSize -= 8; // Message Integrity Code @@ -518,14 +518,14 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, pbyFrame = skb->data + 8; } else { - return FALSE; + return false; } } // // Management & Control frame Handle // - if ((IS_TYPE_DATA((pbyFrame))) == FALSE) { + if ((IS_TYPE_DATA((pbyFrame))) == false) { // Handle Control & Manage Frame if (IS_TYPE_MGMT((pbyFrame))) { @@ -555,7 +555,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, //Discard beacon packet which channel is 0 if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) || (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) { - return FALSE; + return false; } } pRxPacket->byRxChannel = (*pbyRxSts) >> 2; @@ -581,10 +581,10 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, // EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate); pDevice->NumRecvMngList++; - if ( bDeFragRx == FALSE) { + if ( bDeFragRx == false) { pRCB->Ref++; } - if (pDevice->bIsRxMngWorkItemQueued == FALSE) { + if (pDevice->bIsRxMngWorkItemQueued == false) { pDevice->bIsRxMngWorkItemQueued = TRUE; tasklet_schedule(&pDevice->RxMngWorkItem); } @@ -593,7 +593,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, else { // Control Frame }; - return FALSE; + return false; } else { if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { @@ -605,12 +605,12 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, pDevice->dev->name); } } - return FALSE; + return false; } } else { // discard DATA packet while not associate || BSSID error - if ((pDevice->bLinkPass == FALSE) || + if ((pDevice->bLinkPass == false) || !(*pbyRsr & RSR_BSSIDOK)) { if (bDeFragRx) { if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) { @@ -618,7 +618,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, pDevice->dev->name); } } - return FALSE; + return false; } //mike add:station mode check eapol-key challenge---> { @@ -665,7 +665,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, } else { if (pMgmt->bInTIMWake == TRUE) { - pMgmt->bInTIMWake = FALSE; + pMgmt->bInTIMWake = false; } } } @@ -736,7 +736,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, } // check if 802.1x authorized if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED)) - return FALSE; + return false; } @@ -792,7 +792,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) || (pDevice->bRxMICFail == TRUE)) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n"); - pDevice->bRxMICFail = FALSE; + pDevice->bRxMICFail = false; //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++; pDevice->s802_11Counter.TKIPLocalMICFailures++; if (bDeFragRx) { @@ -826,7 +826,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, } - return FALSE; + return false; } } @@ -870,7 +870,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, pDevice->dev->name); } } - return FALSE; + return false; } } } @@ -883,7 +883,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, // Null data, framesize = 12 if (FrameSize < 12) - return FALSE; + return false; if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { if (s_bAPModeRxData(pDevice, @@ -892,7 +892,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, cbHeaderOffset, iSANodeIndex, iDANodeIndex - ) == FALSE) { + ) == false) { if (bDeFragRx) { if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) { @@ -900,7 +900,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, pDevice->dev->name); } } - return FALSE; + return false; } } @@ -918,7 +918,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n", pDevice->dev->name); } - return FALSE; + return false; } return TRUE; @@ -979,7 +979,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, // check Data PS state // if PW bit off, send out all PS bufferring packets. if (!IS_FC_POWERMGT(pbyFrame)) { - pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE; + pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false; pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; bScheduleCommand((void *) pDevice, WLAN_CMD_RX_PSPOLL, @@ -997,7 +997,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, else { // clear all pending PS frame. if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) { - pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE; + pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false; pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; bScheduleCommand((void *) pDevice, WLAN_CMD_RX_PSPOLL, @@ -1027,7 +1027,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, } } } - return FALSE; + return false; } @@ -1102,7 +1102,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, } else if (pDevice->bLinkPass == TRUE) { // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; } - return FALSE; + return false; } if (byDecMode != pKey->byCipherSuite) { if (byDecMode == KEY_CTL_WEP) { @@ -1111,7 +1111,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; } *pKeyOut = NULL; - return FALSE; + return false; } if (byDecMode == KEY_CTL_WEP) { // handle WEP @@ -1206,7 +1206,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, } else if (pDevice->bLinkPass == TRUE) { // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; } - return FALSE; + return false; } if (byDecMode == KEY_CTL_WEP) { @@ -1214,7 +1214,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n"); if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE) || - (bOnFly == FALSE)) { + (bOnFly == false)) { // Software WEP // 1. 3253A // 2. WEP 256 @@ -1247,7 +1247,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, if (byDecMode == KEY_CTL_TKIP) { - if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) { + if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == false)) { // Software TKIP // 1. 3253 A // 2. NotOnFly @@ -1267,7 +1267,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, } if (byDecMode == KEY_CTL_CCMP) { - if (bOnFly == FALSE) { + if (bOnFly == false) { // Software CCMP // NotOnFly DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n"); @@ -1292,14 +1292,14 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, { struct sk_buff *skbcpy; struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; - int bRelayAndForward = FALSE; - int bRelayOnly = FALSE; + int bRelayAndForward = false; + int bRelayOnly = false; u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; u16 wAID; if (FrameSize > CB_MAX_BUF_SIZE) - return FALSE; + return false; // check DA if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) { if (pMgmt->sNodeDBTable[0].bPSEnable) { @@ -1361,11 +1361,11 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, } if (bRelayOnly) - return FALSE; + return false; } // none associate, don't forward if (pDevice->uAssocCount == 0) - return FALSE; + return false; return TRUE; } @@ -1390,7 +1390,7 @@ void RXvWorkItem(struct vnt_private *pDevice) DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList); ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB); } - pDevice->bIsRxWorkItemQueued = FALSE; + pDevice->bIsRxWorkItemQueued = false; spin_unlock_irq(&pDevice->lock); } @@ -1406,7 +1406,7 @@ void RXvFreeRCB(PRCB pRCB, int bReAllocSkb) ASSERT(!pRCB->Ref); // should be 0 ASSERT(pRCB->pDevice); // shouldn't be NULL - if (bReAllocSkb == FALSE) { + if (bReAllocSkb == false) { kfree_skb(pRCB->skb); bReAllocSkb = TRUE; } @@ -1428,7 +1428,7 @@ void RXvFreeRCB(PRCB pRCB, int bReAllocSkb) if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) && - (pDevice->bIsRxWorkItemQueued == FALSE) ) { + (pDevice->bIsRxWorkItemQueued == false) ) { pDevice->bIsRxWorkItemQueued = TRUE; tasklet_schedule(&pDevice->ReadWorkItem); @@ -1441,7 +1441,7 @@ void RXvMngWorkItem(struct vnt_private *pDevice) { PRCB pRCB = NULL; struct vnt_rx_mgmt *pRxPacket; - int bReAllocSkb = FALSE; + int bReAllocSkb = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n"); @@ -1466,7 +1466,7 @@ void RXvMngWorkItem(struct vnt_private *pDevice) } } - pDevice->bIsRxMngWorkItemQueued = FALSE; + pDevice->bIsRxMngWorkItemQueued = false; spin_unlock_irq(&pDevice->lock); } diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c index c07cca7..d7f016d 100644 --- a/drivers/staging/vt6656/firmware.c +++ b/drivers/staging/vt6656/firmware.c @@ -62,7 +62,7 @@ int FIRMWAREbDownload(struct vnt_private *pDevice) const struct firmware *fw; int NdisStatus; void *pBuffer = NULL; - bool result = FALSE; + bool result = false; u16 wLength; int ii, rc; @@ -126,7 +126,7 @@ int FIRMWAREbBrach2Sram(struct vnt_private *pDevice) ); if (NdisStatus != STATUS_SUCCESS) { - return (FALSE); + return (false); } else { return (TRUE); } @@ -147,17 +147,17 @@ int FIRMWAREbCheckVersion(struct vnt_private *pDevice) DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion); if (ntStatus != STATUS_SUCCESS) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n"); - return FALSE; + return false; } if (pDevice->wFirmwareVersion == 0xFFFF) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n"); - return FALSE; + return false; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion); if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) { // branch to loader for download new firmware FIRMWAREbBrach2Sram(pDevice); - return FALSE; + return false; } return TRUE; } diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c index 432961c..cffe5cd 100644 --- a/drivers/staging/vt6656/hostap.c +++ b/drivers/staging/vt6656/hostap.c @@ -135,9 +135,9 @@ static int hostap_disable_hostapd(struct vnt_private *pDevice, int rtnl_locked) } kfree(pDevice->apdev); pDevice->apdev = NULL; - pDevice->bEnable8021x = FALSE; - pDevice->bEnableHostWEP = FALSE; - pDevice->bEncryptionEnable = FALSE; + pDevice->bEnable8021x = false; + pDevice->bEnableHostWEP = false; + pDevice->bEncryptionEnable = false; return 0; } @@ -230,7 +230,7 @@ static int hostap_add_sta(struct vnt_private *pDevice, pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability; // TODO listenInterval // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1; - pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE; + pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false; pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates; // set max tx rate @@ -422,7 +422,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, int ret = 0; s32 iNodeIndex = -1; int ii; - int bKeyTableFull = FALSE; + int bKeyTableFull = false; u16 wKeyCtl = 0; @@ -444,7 +444,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, iNodeIndex = 0; } else { - if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) { + if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) { param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); return -EINVAL; @@ -460,10 +460,10 @@ static int hostap_set_encryption(struct vnt_private *pDevice, &(pDevice->sKey), param->sta_addr, pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex - ) == FALSE) { + ) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n"); } - pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; + pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; } pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0; pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0; @@ -498,7 +498,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, if (param->u.crypt.alg == WPA_ALG_WEP) { - if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) { + if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) { KeybSetDefaultKey( pDevice, &(pDevice->sKey), dwKeyIndex & ~(BIT30 | USE_KEYRSC), @@ -524,7 +524,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, } else { // Key Table Full - pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; + pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; bKeyTableFull = TRUE; } } @@ -593,7 +593,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, } else { // Key Table Full - pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; + pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; bKeyTableFull = TRUE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n"); } @@ -661,7 +661,7 @@ static int hostap_get_encryption(struct vnt_private *pDevice, if (is_broadcast_ether_addr(param->sta_addr)) { iNodeIndex = 0; } else { - if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) { + if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) { param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); return -EINVAL; diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c index 97c6896..d309806 100644 --- a/drivers/staging/vt6656/int.c +++ b/drivers/staging/vt6656/int.c @@ -146,7 +146,7 @@ void INTnsProcessData(struct vnt_private *pDevice) if (pMgmt->byDTIMCount > 0) { pMgmt->byDTIMCount--; pMgmt->sNodeDBTable[0].bRxPSPoll = - FALSE; + false; } else if (pMgmt->byDTIMCount == 0) { /* check if multicast tx buffering */ pMgmt->byDTIMCount = @@ -163,7 +163,7 @@ void INTnsProcessData(struct vnt_private *pDevice) } /* if (pDevice->eOPMode == OP_MODE_AP) */ pDevice->bBeaconSent = TRUE; } else { - pDevice->bBeaconSent = FALSE; + pDevice->bBeaconSent = false; } if (pINTData->byISR0 & ISR_TBTT) { if (pDevice->bEnablePSMode) @@ -202,7 +202,7 @@ void INTnsProcessData(struct vnt_private *pDevice) WLAN_CMD_RADIO, NULL); pDevice->intBuf.uDataLen = 0; - pDevice->intBuf.bInUse = FALSE; + pDevice->intBuf.bInUse = false; pStats->tx_packets = pDevice->scStatistic.ullTsrOK; pStats->tx_bytes = pDevice->scStatistic.ullTxDirectedBytes + diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c index 880c025..e4a791f 100644 --- a/drivers/staging/vt6656/iwctl.c +++ b/drivers/staging/vt6656/iwctl.c @@ -455,7 +455,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL); } else { - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; pMgmt->eCurrState = WMAC_STATE_IDLE; memset(pMgmt->abyCurrBSSID, 0, 6); } @@ -479,7 +479,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, spin_unlock_irq(&pDevice->lock); } - pDevice->bCommit = FALSE; + pDevice->bCommit = false; } @@ -694,7 +694,7 @@ int iwctl_giwap(struct net_device *dev, struct iw_request_info *info, memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6); - if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)) + if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)) memset(wrq->sa_data, 0, 6); if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) @@ -784,7 +784,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n"); - pDevice->fWPA_Authened = FALSE; + pDevice->fWPA_Authened = false; // Check if we asked for `any' if (wrq->flags == 0) { // Just send an empty SSID list @@ -973,7 +973,7 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate); } } else { - pDevice->bFixRate = FALSE; + pDevice->bFixRate = false; pDevice->uConnectionRate = 13; } @@ -1244,8 +1244,8 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, // Read the flags if (wrq->flags & IW_ENCODE_DISABLED) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n"); - pMgmt->bShareKeyAlgorithm = FALSE; - pDevice->bEncryptionEnable = FALSE; + pMgmt->bShareKeyAlgorithm = false; + pDevice->bEncryptionEnable = false; pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; if (pDevice->flags & DEVICE_FLAGS_OPENED) { spin_lock_irq(&pDevice->lock); @@ -1260,7 +1260,7 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, } if (wrq->flags & IW_ENCODE_OPEN) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n"); - pMgmt->bShareKeyAlgorithm = FALSE; + pMgmt->bShareKeyAlgorithm = false; } memset(pMgmt->abyDesireBSSID, 0xFF, 6); @@ -1508,7 +1508,7 @@ int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info, case IW_AUTH_80211_AUTH_ALG: PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value); if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM) - pMgmt->bShareKeyAlgorithm = FALSE; + pMgmt->bShareKeyAlgorithm = false; else if (wrq->value == IW_AUTH_ALG_SHARED_KEY) pMgmt->bShareKeyAlgorithm = TRUE; break; @@ -1521,11 +1521,11 @@ int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info, break; case IW_AUTH_PRIVACY_INVOKED: pDevice->bEncryptionEnable = !!wrq->value; - if (pDevice->bEncryptionEnable == FALSE) { + if (pDevice->bEncryptionEnable == false) { wpa_version = 0; pairwise = 0; pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; - pMgmt->bShareKeyAlgorithm = FALSE; + pMgmt->bShareKeyAlgorithm = false; pMgmt->eAuthenMode = WMAC_AUTH_OPEN; PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n"); } @@ -1700,24 +1700,24 @@ int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info, pDevice->bwextstep0 = TRUE; } if ((pDevice->bwextstep0 == TRUE) && (param->u.wpa_key.key_index == 1)) { - pDevice->bwextstep0 = FALSE; + pDevice->bwextstep0 = false; pDevice->bwextstep1 = TRUE; } if ((pDevice->bwextstep1 == TRUE) && (param->u.wpa_key.key_index == 2)) { - pDevice->bwextstep1 = FALSE; + pDevice->bwextstep1 = false; pDevice->bwextstep2 = TRUE; } if ((pDevice->bwextstep2 == TRUE) && (param->u.wpa_key.key_index == 3)) { - pDevice->bwextstep2 = FALSE; + pDevice->bwextstep2 = false; pDevice->bwextstep3 = TRUE; } } if (pDevice->bwextstep3 == TRUE) { PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n"); - pDevice->bwextstep0 = FALSE; - pDevice->bwextstep1 = FALSE; - pDevice->bwextstep2 = FALSE; - pDevice->bwextstep3 = FALSE; + pDevice->bwextstep0 = false; + pDevice->bwextstep1 = false; + pDevice->bwextstep2 = false; + pDevice->bwextstep3 = false; pDevice->bWPASuppWextEnabled = TRUE; memset(pMgmt->abyDesireBSSID, 0xFF, 6); KeyvInitTable(pDevice, &pDevice->sKey); diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c index 87eab91..fa22dde 100644 --- a/drivers/staging/vt6656/key.c +++ b/drivers/staging/vt6656/key.c @@ -69,16 +69,16 @@ static void s_vCheckKeyTableValid(struct vnt_private *pDevice, for (i=0;iKeyTable[i].bInUse == TRUE) && - (pTable->KeyTable[i].PairwiseKey.bKeyValid == FALSE) && - (pTable->KeyTable[i].GroupKey[0].bKeyValid == FALSE) && - (pTable->KeyTable[i].GroupKey[1].bKeyValid == FALSE) && - (pTable->KeyTable[i].GroupKey[2].bKeyValid == FALSE) && - (pTable->KeyTable[i].GroupKey[3].bKeyValid == FALSE) + (pTable->KeyTable[i].PairwiseKey.bKeyValid == false) && + (pTable->KeyTable[i].GroupKey[0].bKeyValid == false) && + (pTable->KeyTable[i].GroupKey[1].bKeyValid == false) && + (pTable->KeyTable[i].GroupKey[2].bKeyValid == false) && + (pTable->KeyTable[i].GroupKey[3].bKeyValid == false) ) { - pTable->KeyTable[i].bInUse = FALSE; + pTable->KeyTable[i].bInUse = false; pTable->KeyTable[i].wKeyCtl = 0; - pTable->KeyTable[i].bSoftWEP = FALSE; + pTable->KeyTable[i].bSoftWEP = false; pbyData[wLength++] = (BYTE) i; //MACvDisableKeyEntry(pDevice, i); } @@ -118,18 +118,18 @@ void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable) spin_lock_irq(&pDevice->lock); for (i=0;iKeyTable[i].bInUse = FALSE; - pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; + pTable->KeyTable[i].bInUse = false; + pTable->KeyTable[i].PairwiseKey.bKeyValid = false; pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i]; for (jj=0; jj < MAX_GROUP_KEY; jj++) { - pTable->KeyTable[i].GroupKey[jj].bKeyValid = FALSE; + pTable->KeyTable[i].GroupKey[jj].bKeyValid = false; pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *) &(pTable->KeyTable[i]); } pTable->KeyTable[i].wKeyCtl = 0; pTable->KeyTable[i].dwGTKeyIndex = 0; - pTable->KeyTable[i].bSoftWEP = FALSE; + pTable->KeyTable[i].bSoftWEP = false; pbyData[i] = (BYTE) i; } pbyData[i] = (BYTE) i; @@ -158,7 +158,7 @@ void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable) * Out: * pKey - Key return * - * Return Value: TRUE if found otherwise FALSE + * Return Value: TRUE if found otherwise false * */ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, @@ -178,7 +178,7 @@ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, return (TRUE); } else { - return (FALSE); + return (false); } } else if (dwKeyIndex < MAX_GROUP_KEY) { if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) { @@ -186,15 +186,15 @@ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, return (TRUE); } else { - return (FALSE); + return (false); } } else { - return (FALSE); + return (false); } } } - return (FALSE); + return (false); } @@ -212,7 +212,7 @@ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, * Out: * none * - * Return Value: TRUE if success otherwise FALSE + * Return Value: TRUE if success otherwise false * */ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, @@ -228,7 +228,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, j = (MAX_KEY_TABLE-1); for (i=0;i<(MAX_KEY_TABLE-1);i++) { - if ((pTable->KeyTable[i].bInUse == FALSE) && + if ((pTable->KeyTable[i].bInUse == false) && (j == (MAX_KEY_TABLE-1))) { // found empty table j = i; @@ -245,7 +245,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, } else { // Group key if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) - return (FALSE); + return (false); pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); if ((dwKeyIndex & TRANSMIT_KEY) != 0) { // Group transmit key @@ -313,7 +313,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, } else { // Group key if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) - return (FALSE); + return (false); pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]); if ((dwKeyIndex & TRANSMIT_KEY) != 0) { // Group transmit key @@ -367,7 +367,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, return (TRUE); } - return (FALSE); + return (false); } @@ -382,7 +382,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise FALSE + * Return Value: TRUE if success otherwise false * */ @@ -390,19 +390,19 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex) { int i; - int bReturnValue = FALSE; + int bReturnValue = false; if (is_broadcast_ether_addr(pbyBSSID)) { // delete all keys if ((dwKeyIndex & PAIRWISE_KEY) != 0) { for (i=0;iKeyTable[i].PairwiseKey.bKeyValid = FALSE; + pTable->KeyTable[i].PairwiseKey.bKeyValid = false; } bReturnValue = TRUE; } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { for (i=0;iKeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; + pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) { // remove Group transmit key pTable->KeyTable[i].dwGTKeyIndex = 0; @@ -411,7 +411,7 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, bReturnValue = TRUE; } else { - bReturnValue = FALSE; + bReturnValue = false; } } else { @@ -420,12 +420,12 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { if ((dwKeyIndex & PAIRWISE_KEY) != 0) { - pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; + pTable->KeyTable[i].PairwiseKey.bKeyValid = false; bReturnValue = TRUE; break; } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { - pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; + pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) { // remove Group transmit key pTable->KeyTable[i].dwGTKeyIndex = 0; @@ -434,7 +434,7 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, break; } else { - bReturnValue = FALSE; + bReturnValue = false; break; } } //pTable->KeyTable[i].bInUse == TRUE @@ -459,7 +459,7 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise FALSE + * Return Value: TRUE if success otherwise false * */ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, @@ -470,16 +470,16 @@ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, for (i=0;iKeyTable[i].bInUse == TRUE) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { - pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; + pTable->KeyTable[i].PairwiseKey.bKeyValid = false; for (u = 0; u < MAX_GROUP_KEY; u++) - pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE; + pTable->KeyTable[i].GroupKey[u].bKeyValid = false; pTable->KeyTable[i].dwGTKeyIndex = 0; s_vCheckKeyTableValid(pDevice, pTable); return (TRUE); } } - return (FALSE); + return (false); } /* @@ -491,7 +491,7 @@ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise FALSE + * Return Value: TRUE if success otherwise false * */ void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable, @@ -501,7 +501,7 @@ void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable, if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) { if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) { - pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; + pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) { // remove Group transmit key pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0; @@ -531,7 +531,7 @@ void KeyvRemoveAllWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable) * Out: * pKey - Key return * - * Return Value: TRUE if found otherwise FALSE + * Return Value: TRUE if found otherwise false * */ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, @@ -561,14 +561,14 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, return (TRUE); } else { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n"); - return (FALSE); + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == false\n"); + return (false); } } // End of Type == PAIRWISE else { if (pTable->KeyTable[i].dwGTKeyIndex == 0) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n"); - return FALSE; + return false; } if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) { *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]); @@ -585,8 +585,8 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, return (TRUE); } else { - DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n"); - return (FALSE); + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == false\n"); + return (false); } } // End of Type = GROUP } // BSSID match @@ -596,7 +596,7 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii)); } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); - return (FALSE); + return (false); } @@ -609,7 +609,7 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, * Out: * none * - * Return Value: TRUE if found otherwise FALSE + * Return Value: TRUE if found otherwise false * */ int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) @@ -625,7 +625,7 @@ int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) return (TRUE); } } - return (FALSE); + return (false); } /* @@ -641,7 +641,7 @@ int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) * Out: * none * - * Return Value: TRUE if success otherwise FALSE + * Return Value: TRUE if success otherwise false * */ @@ -657,9 +657,9 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, (int) dwKeyIndex, (int) uKeyLength); if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key - return (FALSE); + return (false); } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { - return (FALSE); + return (false); } if (uKeyLength > MAX_KEY_LEN) @@ -691,7 +691,7 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE; } else { - if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE) + if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false) pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match } @@ -751,7 +751,7 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise FALSE + * Return Value: TRUE if success otherwise false * */ @@ -768,9 +768,9 @@ int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable, if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key - return (FALSE); + return (false); } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { - return (FALSE); + return (false); } for (i=0; i < MAX_KEY_TABLE-1; i++) { diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index 9a5573a..d2cc04f 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -288,9 +288,9 @@ device_set_options(struct vnt_private *pDevice) { pDevice->byAutoPwrTunning = 0; pDevice->wCTSDuration = 0; pDevice->byPreambleType = 0; - pDevice->bExistSWNetAddr = FALSE; + pDevice->bExistSWNetAddr = false; /* pDevice->bDiversityRegCtlON = TRUE; */ - pDevice->bDiversityRegCtlON = FALSE; + pDevice->bDiversityRegCtlON = false; } @@ -346,23 +346,23 @@ static int device_init_registers(struct vnt_private *pDevice, if ( !FIRMWAREbCheckVersion(pDevice) ) { if (FIRMWAREbDownload(pDevice) == TRUE) { - if (FIRMWAREbBrach2Sram(pDevice) == FALSE) { + if (FIRMWAREbBrach2Sram(pDevice) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n"); spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n"); spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } } if ( !BBbVT3184Init(pDevice) ) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n"); spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } } @@ -384,7 +384,7 @@ static int device_init_registers(struct vnt_private *pDevice, if ( ntStatus != STATUS_SUCCESS ) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n"); spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } if (InitType == DEVICE_INIT_COLD) { @@ -393,7 +393,7 @@ static int device_init_registers(struct vnt_private *pDevice, if (ntStatus != STATUS_SUCCESS) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n"); spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } /* local ID for AES functions */ @@ -406,17 +406,17 @@ static int device_init_registers(struct vnt_private *pDevice, if ( ntStatus != STATUS_SUCCESS ) { spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } /* do MACbSoftwareReset in MACvInitialize */ /* force CCK */ pDevice->bCCK = TRUE; - pDevice->bProtectMode = FALSE; + pDevice->bProtectMode = false; /* only used in 11g type, sync with ERP IE */ - pDevice->bNonERPPresent = FALSE; - pDevice->bBarkerPreambleMd = FALSE; + pDevice->bNonERPPresent = false; + pDevice->bBarkerPreambleMd = false; if ( pDevice->bFixRate ) { pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate; } else { @@ -472,7 +472,7 @@ static int device_init_registers(struct vnt_private *pDevice, if (byAntenna & EEP_ANTINV) pDevice->bTxRxAntInv = TRUE; else - pDevice->bTxRxAntInv = FALSE; + pDevice->bTxRxAntInv = false; byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); @@ -492,9 +492,9 @@ static int device_init_registers(struct vnt_private *pDevice, if (pDevice->bDiversityRegCtlON) pDevice->bDiversityEnable = TRUE; else - pDevice->bDiversityEnable = FALSE; + pDevice->bDiversityEnable = false; } else { - pDevice->bDiversityEnable = FALSE; + pDevice->bDiversityEnable = false; pDevice->byAntennaCount = 1; pDevice->dwTxAntennaSel = 0; pDevice->dwRxAntennaSel = 0; @@ -607,7 +607,7 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->bShortSlotTime = TRUE; } else { CARDbAddBasicRate(pDevice, RATE_1M); - pDevice->bShortSlotTime = FALSE; + pDevice->bShortSlotTime = false; } BBvSetShortSlotTime(pDevice); CARDvSetBSSMode(pDevice); @@ -619,7 +619,7 @@ static int device_init_registers(struct vnt_private *pDevice, } pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL]; - pDevice->bHWRadioOff = FALSE; + pDevice->bHWRadioOff = false; if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) { ntStatus = CONTROLnsRequestIn(pDevice, MESSAGE_TYPE_READ, @@ -630,14 +630,14 @@ static int device_init_registers(struct vnt_private *pDevice, if ( ntStatus != STATUS_SUCCESS ) { spin_unlock_irq(&pDevice->lock); - return FALSE; + return false; } if ( (byTmp & GPIO3_DATA) == 0 ) { pDevice->bHWRadioOff = TRUE; MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); } else { MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); - pDevice->bHWRadioOff = FALSE; + pDevice->bHWRadioOff = false; } } @@ -837,7 +837,7 @@ static bool device_alloc_bufs(struct vnt_private *pDevice) DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n"); goto free_tx; } - pTxContext->bBoolInUse = FALSE; + pTxContext->bBoolInUse = false; } /* allocate RCB mem */ @@ -872,7 +872,7 @@ static bool device_alloc_bufs(struct vnt_private *pDevice) goto free_rx_tx; } pRCB->skb->dev = pDevice->dev; - pRCB->bBoolInUse = FALSE; + pRCB->bBoolInUse = false; EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB); pDevice->NumRecvFreeList++; pRCB++; @@ -908,7 +908,7 @@ free_rx_tx: free_tx: device_free_tx_bufs(pDevice); - return FALSE; + return false; } @@ -934,7 +934,7 @@ static bool device_init_defrag_cb(struct vnt_private *pDevice) free_frag: device_free_frag_bufs(pDevice); - return FALSE; + return false; } @@ -961,7 +961,7 @@ int device_alloc_frag_buf(struct vnt_private *pDevice, pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); if (pDeF->skb == NULL) - return FALSE; + return false; ASSERT(pDeF->skb); pDeF->skb->dev = pDevice->dev; @@ -975,19 +975,19 @@ static int device_open(struct net_device *dev) { struct vnt_private *pDevice = netdev_priv(dev); - pDevice->fWPA_Authened = FALSE; + pDevice->fWPA_Authened = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n"); pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; - if (device_alloc_bufs(pDevice) == FALSE) { + if (device_alloc_bufs(pDevice) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n"); return -ENOMEM; } - if (device_init_defrag_cb(pDevice)== FALSE) { + if (device_init_defrag_cb(pDevice)== false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n"); goto free_rx_tx; } @@ -1001,7 +1001,7 @@ static int device_open(struct net_device *dev) /* read config file */ Read_config_file(pDevice); - if (device_init_registers(pDevice, DEVICE_INIT_COLD) == FALSE) { + if (device_init_registers(pDevice, DEVICE_INIT_COLD) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n"); goto free_all; } @@ -1013,11 +1013,11 @@ static int device_open(struct net_device *dev) memcpy(pDevice->vnt_mgmt.abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN); memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN); - pDevice->bStopTx0Pkt = FALSE; - pDevice->bStopDataPkt = FALSE; - pDevice->bRoaming = FALSE; - pDevice->bIsRoaming = FALSE; - pDevice->bEnableRoaming = FALSE; + pDevice->bStopTx0Pkt = false; + pDevice->bStopDataPkt = false; + pDevice->bRoaming = false; + pDevice->bIsRoaming = false; + pDevice->bEnableRoaming = false; if (pDevice->bDiversityRegCtlON) { device_init_diversity_timer(pDevice); } @@ -1031,15 +1031,15 @@ static int device_open(struct net_device *dev) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; pDevice->bIsRxWorkItemQueued = TRUE; - pDevice->fKillEventPollingThread = FALSE; - pDevice->bEventAvailable = FALSE; - - pDevice->bWPADEVUp = FALSE; - pDevice->bwextstep0 = FALSE; - pDevice->bwextstep1 = FALSE; - pDevice->bwextstep2 = FALSE; - pDevice->bwextstep3 = FALSE; - pDevice->bWPASuppWextEnabled = FALSE; + pDevice->fKillEventPollingThread = false; + pDevice->bEventAvailable = false; + + pDevice->bWPADEVUp = false; + pDevice->bwextstep0 = false; + pDevice->bwextstep1 = false; + pDevice->bwextstep2 = false; + pDevice->bwextstep3 = false; + pDevice->bWPASuppWextEnabled = false; pDevice->byReAssocCount = 0; RXvWorkItem(pDevice); @@ -1106,15 +1106,15 @@ static int device_close(struct net_device *dev) memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); - pMgmt->bShareKeyAlgorithm = FALSE; - pDevice->bEncryptionEnable = FALSE; + pMgmt->bShareKeyAlgorithm = false; + pDevice->bEncryptionEnable = false; pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; spin_lock_irq(&pDevice->lock); for (uu = 0; uu < MAX_KEY_TABLE; uu++) MACvDisableKeyEntry(pDevice,uu); spin_unlock_irq(&pDevice->lock); - if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) { + if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) { MACbShutdown(pDevice); } netif_stop_queue(pDevice->dev); @@ -1136,11 +1136,11 @@ static int device_close(struct net_device *dev) tasklet_kill(&pDevice->ReadWorkItem); tasklet_kill(&pDevice->EventWorkItem); - pDevice->bRoaming = FALSE; - pDevice->bIsRoaming = FALSE; - pDevice->bEnableRoaming = FALSE; - pDevice->bCmdRunning = FALSE; - pDevice->bLinkPass = FALSE; + pDevice->bRoaming = false; + pDevice->bIsRoaming = false; + pDevice->bEnableRoaming = false; + pDevice->bCmdRunning = false; + pDevice->bLinkPass = false; memset(pMgmt->abyCurrBSSID, 0, 6); pMgmt->eCurrState = WMAC_STATE_IDLE; @@ -1277,14 +1277,14 @@ static int Config_FileGetParameter(unsigned char *string, /* find target string start point */ start_p = kstrstr(source,buf1); if (start_p == NULL) - return FALSE; + return false; /* check if current config line is marked by "#" */ for (ii = 1; ; ii++) { if (memcmp(start_p - ii, "\n", 1) == 0) break; if (memcmp(start_p - ii, "#", 1) == 0) - return FALSE; + return false; } /* find target string end point */ @@ -1300,7 +1300,7 @@ static int Config_FileGetParameter(unsigned char *string, /* find value */ start_p = kstrstr(buf2,"="); if (start_p == NULL) - return FALSE; + return false; memset(buf1,0,100); strcpy(buf1,start_p+1); diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c index 43965bc..9f571507 100644 --- a/drivers/staging/vt6656/power.c +++ b/drivers/staging/vt6656/power.c @@ -146,12 +146,12 @@ void PSvDisablePowerSaving(struct vnt_private *pDevice) /* set always listen beacon */ MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); - pDevice->bEnablePSMode = FALSE; + pDevice->bEnablePSMode = false; if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) PSbSendNullPacket(pDevice); - pDevice->bPWBitOn = FALSE; + pDevice->bPWBitOn = false; } /* @@ -161,7 +161,7 @@ void PSvDisablePowerSaving(struct vnt_private *pDevice) * * Return Value: * TRUE, if power down success - * FALSE, if fail + * false, if fail */ int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, @@ -180,16 +180,16 @@ int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { /* check if in TIM wake period */ if (pMgmt->bInTIMWake) - return FALSE; + return false; } /* check scan state */ if (pDevice->bCmdRunning) - return FALSE; + return false; /* Tx Burst */ if (pDevice->bPSModeTxBurst) - return FALSE; + return false; /* Froce PSEN on */ MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); @@ -197,7 +197,7 @@ int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) { - return FALSE; + return false; } } @@ -265,12 +265,12 @@ int PSbSendNullPacket(struct vnt_private *pDevice) struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; u16 flags = 0; - if (pDevice->bLinkPass == FALSE) - return FALSE; + if (pDevice->bLinkPass == false) + return false; - if ((pDevice->bEnablePSMode == FALSE) && - (pDevice->fTxDataInSleep == FALSE)) { - return FALSE; + if ((pDevice->bEnablePSMode == false) && + (pDevice->fTxDataInSleep == false)) { + return false; } memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt) @@ -300,7 +300,7 @@ int PSbSendNullPacket(struct vnt_private *pDevice) /* log error if sending failed */ if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n"); - return FALSE; + return false; } return TRUE; } @@ -318,7 +318,7 @@ int PSbSendNullPacket(struct vnt_private *pDevice) int PSbIsNextTBTTWakeUp(struct vnt_private *pDevice) { struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; - int bWakeUp = FALSE; + int bWakeUp = false; if (pMgmt->wListenInterval >= 2) { if (pMgmt->wCountToWakeUp == 0) @@ -329,7 +329,7 @@ int PSbIsNextTBTTWakeUp(struct vnt_private *pDevice) if (pMgmt->wCountToWakeUp == 1) { /* Turn on wake up to listen next beacon */ MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); - pDevice->bPSRxBeacon = FALSE; + pDevice->bPSRxBeacon = false; bWakeUp = TRUE; } else if (!pDevice->bPSRxBeacon) { /* Listen until RxBeacon */ diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c index 5785eec..48c7c6d 100644 --- a/drivers/staging/vt6656/rf.c +++ b/drivers/staging/vt6656/rf.c @@ -719,7 +719,7 @@ const u8 RFaby11aChannelIndex[200] = { * Out: * none * - * Return Value: TRUE if succeeded; FALSE if failed. + * Return Value: TRUE if succeeded; false if failed. * */ int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData) @@ -749,7 +749,7 @@ int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData) * Out: * none * - * Return Value: TRUE if succeeded; FALSE if failed. + * Return Value: TRUE if succeeded; false if failed. * */ int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH) @@ -801,7 +801,7 @@ int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH) * Out: * none * - * Return Value: TRUE if succeeded; FALSE if failed. + * Return Value: TRUE if succeeded; false if failed. * */ @@ -818,7 +818,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) case RF_AL2230 : if (pDevice->byCurPwr >= AL2230_PWR_IDX_LEN) - return FALSE; + return false; bResult &= IFRFbWriteEmbedded(pDevice, dwAL2230PowerTable[pDevice->byCurPwr]); if (uRATE <= RATE_11M) bResult &= IFRFbWriteEmbedded(pDevice, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); @@ -828,7 +828,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) case RF_AL2230S : if (pDevice->byCurPwr >= AL2230_PWR_IDX_LEN) - return FALSE; + return false; bResult &= IFRFbWriteEmbedded(pDevice, dwAL2230PowerTable[pDevice->byCurPwr]); if (uRATE <= RATE_11M) { bResult &= IFRFbWriteEmbedded(pDevice, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); @@ -851,7 +851,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) bResult &= IFRFbWriteEmbedded(pDevice, 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW); } - if (pDevice->byCurPwr > AL7230_PWR_IDX_LEN) return FALSE; + if (pDevice->byCurPwr > AL7230_PWR_IDX_LEN) return false; // 0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value dwMax7230Pwr = 0x080C0B00 | ( (pDevice->byCurPwr) << 12 ) | @@ -867,7 +867,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) DWORD dwVT3226Pwr; if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN) - return FALSE; + return false; dwVT3226Pwr = ((0x3F-pDevice->byCurPwr) << 20 ) | ( 0x17 << 8 ) /* Reg7 */ | (BY_VT3226_REG_LEN << 3 ) | IFREGCTL_REGW; bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226Pwr); @@ -879,7 +879,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) DWORD dwVT3226Pwr; if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN) - return FALSE; + return false; if (uRATE <= RATE_11M) { @@ -924,7 +924,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) DWORD dwVT3342Pwr; if (pDevice->byCurPwr >= VT3342_PWR_IDX_LEN) - return FALSE; + return false; dwVT3342Pwr = ((0x3F-pDevice->byCurPwr) << 20 ) | ( 0x27 << 8 ) /* Reg7 */ | (BY_VT3342_REG_LEN << 3 ) | IFREGCTL_REGW; diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index c52f7a9..ebda989 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -169,7 +169,7 @@ static void *s_vGetFreeContext(struct vnt_private *pDevice) for (ii = 0; ii < pDevice->cbTD; ii++) { pContext = pDevice->apTD[ii]; - if (pContext->bBoolInUse == FALSE) { + if (pContext->bBoolInUse == false) { pContext->bBoolInUse = TRUE; pReturnContext = pContext; break; @@ -562,7 +562,7 @@ static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType, break; } - ASSERT(FALSE); + ASSERT(false); return 0; } @@ -1102,7 +1102,7 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice, { u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */ u16 wFifoCtl; - int bDisCRC = FALSE; + int bDisCRC = false; u8 byFBOption = AUTO_FB_NONE; //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n"); @@ -1227,7 +1227,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, u16 wTxBufSize; u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC; u32 *pdwMIC_L, *pdwMIC_R; - int bSoftWEP = FALSE; + int bSoftWEP = false; pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; @@ -1256,13 +1256,13 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8); if (pDevice->dwDiagRefCount != 0) { - bNeedACK = FALSE; + bNeedACK = false; pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); } else { //if (pDevice->dwDiagRefCount != 0) { if ((pDevice->eOPMode == OP_MODE_ADHOC) || (pDevice->eOPMode == OP_MODE_AP)) { if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) { - bNeedACK = FALSE; + bNeedACK = false; pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); } else { @@ -1342,7 +1342,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, cbICVlen = 8;//MIC cbMICHDR = sizeof(SMICHDRHead); } - if (bSoftWEP == FALSE) { + if (bSoftWEP == false) { //MAC Header should be padding 0 to DW alignment. uPadding = 4 - (cbMACHdLen%4); uPadding %= 4; @@ -1351,8 +1351,8 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen; - if ( (bNeedACK == FALSE) ||(cbFrameSize < pDevice->wRTSThreshold) ) { - bRTS = FALSE; + if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) { + bRTS = false; } else { bRTS = TRUE; pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY); @@ -1388,7 +1388,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB)); cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB); } - else if (bRTS == FALSE) { //RTS_needless + else if (bRTS == false) { //RTS_needless pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS)); pvRTS = NULL; @@ -1408,7 +1408,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab)); cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab); } - else if (bRTS == FALSE) { //RTS_needless, no MICHDR + else if (bRTS == false) { //RTS_needless, no MICHDR pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); pvRTS = NULL; @@ -1426,7 +1426,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB)); cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB); } - else if (bRTS == FALSE) { //RTS_needless + else if (bRTS == false) { //RTS_needless pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); pvRTS = NULL; @@ -1550,7 +1550,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, if (pDevice->bTxMICFail == TRUE) { *pdwMIC_L = 0; *pdwMIC_R = 0; - pDevice->bTxMICFail = FALSE; + pDevice->bTxMICFail = false; } //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen); @@ -1706,7 +1706,7 @@ static void s_vGenerateMACHeader(struct vnt_private *pDevice, * Out: * none * - * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise FALSE + * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false * -*/ @@ -1723,7 +1723,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, u8 byPktType, *pbyTxBufferAddr; void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR; u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize; - int bNeedACK, bIsPSPOLL = FALSE; + int bNeedACK, bIsPSPOLL = false; u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; u32 uPadding = 0; u16 wTxBufSize; @@ -1784,7 +1784,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) { - bNeedACK = FALSE; + bNeedACK = false; } else { bNeedACK = TRUE; @@ -1799,7 +1799,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, //pDevice->byPreambleType = PREAMBLE_LONG; // probe-response don't retry //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { - // bNeedACK = FALSE; + // bNeedACK = false; // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); //} } @@ -1819,7 +1819,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, // Notes: // Although spec says MMPDU can be fragmented; In most case, // no one will send a MMPDU under fragmentation. With RTS may occur. - pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP + pDevice->bAES = false; //Set FRAGCTL_WEPTYP if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { @@ -1914,7 +1914,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, (pDevice->bLinkPass == TRUE)) { pbyBSSID = pDevice->abyBSSID; // get pairwise key - if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) { + if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { // get group key if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); @@ -1927,13 +1927,13 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, } // get group key pbyBSSID = pDevice->abyBroadcastAddr; - if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) { + if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { pTransmitKey = NULL; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode); } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); } - } while(FALSE); + } while(false); //Fill TXKEY s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey, (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL); @@ -2029,7 +2029,7 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, ); //Get Duration and TimeStampOff pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A, - wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE)); + wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE)); pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]; cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab); } else { @@ -2042,7 +2042,7 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, ); //Get Duration and TimeStampOff pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B, - wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE)); + wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE)); pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]; cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab); } @@ -2082,7 +2082,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) u32 uDuration, cbReqCount; PS802_11Header pMACHeader; u32 cbHeaderSize, cbFrameBodySize; - int bNeedACK, bIsPSPOLL = FALSE; + int bNeedACK, bIsPSPOLL = false; PSTxBufHead pTxBufHead; u32 cbFrameSize; u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; @@ -2098,7 +2098,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) u32 wCurrentRate = RATE_1M; PUWLAN_80211HDR p80211Header; u32 uNodeIndex = 0; - int bNodeExist = FALSE; + int bNodeExist = false; SKeyItem STempKey; PSKeyItem pTransmitKey = NULL; u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr; @@ -2169,7 +2169,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) { - bNeedACK = FALSE; + bNeedACK = false; if (pDevice->bEnableHostWEP) { uNodeIndex = 0; bNodeExist = TRUE; @@ -2193,7 +2193,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) // probe-response don't retry //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { - // bNeedACK = FALSE; + // bNeedACK = false; // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); //} } @@ -2230,7 +2230,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) // Notes: // Although spec says MMPDU can be fragmented; In most case, // no one will send a MMPDU under fragmentation. With RTS may occur. - pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP + pDevice->bAES = false; //Set FRAGCTL_WEPTYP if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) { @@ -2383,7 +2383,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) if (pDevice->bTxMICFail == TRUE) { *pdwMIC_L = 0; *pdwMIC_R = 0; - pDevice->bTxMICFail = FALSE; + pDevice->bTxMICFail = false; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); @@ -2473,20 +2473,20 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; u16 wAID; u8 byPktType; - int bNeedEncryption = FALSE; + int bNeedEncryption = false; PSKeyItem pTransmitKey = NULL; SKeyItem STempKey; int ii; - int bTKIP_UseGTK = FALSE; - int bNeedDeAuth = FALSE; + int bTKIP_UseGTK = false; + int bNeedDeAuth = false; u8 *pbyBSSID; - int bNodeExist = FALSE; + int bNodeExist = false; PUSB_SEND_CONTEXT pContext; bool fConvertedPacket; PTX_BUFFER pTX_Buffer; u32 status; u16 wKeepRate = pDevice->wCurrentRate; - int bTxeapol_key = FALSE; + int bTxeapol_key = false; if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { @@ -2547,7 +2547,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, } } - if (bNodeExist == FALSE) { + if (bNodeExist == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n"); dev_kfree_skb_irq(skb); return 0; @@ -2610,7 +2610,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { pbyBSSID = pDevice->abyBSSID; // get pairwise key - if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) { + if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { // get group key if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) { bTKIP_UseGTK = TRUE; @@ -2635,7 +2635,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, } // get group key pbyBSSID = pDevice->abyBroadcastAddr; - if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) { + if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { pTransmitKey = NULL; if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); @@ -2646,7 +2646,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, bTKIP_UseGTK = TRUE; DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); } - } while(FALSE); + } while(false); } if (pDevice->bEnableHostWEP) { @@ -2753,7 +2753,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, if (bNeedEncryption == TRUE) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType)); if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) { - bNeedEncryption = FALSE; + bNeedEncryption = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType)); if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { if (pTransmitKey == NULL) { @@ -2784,7 +2784,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, if (pTransmitKey == NULL) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n"); - pContext->bBoolInUse = FALSE; + pContext->bBoolInUse = false; dev_kfree_skb_irq(skb); pStats->tx_dropped++; return STATUS_FAILURE; @@ -2800,8 +2800,8 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, &uHeaderLen, &BytesToWrite ); - if (fConvertedPacket == FALSE) { - pContext->bBoolInUse = FALSE; + if (fConvertedPacket == false) { + pContext->bBoolInUse = false; dev_kfree_skb_irq(skb); return STATUS_FAILURE; } @@ -2834,7 +2834,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, } if(status!=STATUS_PENDING) { - pContext->bBoolInUse = FALSE; + pContext->bBoolInUse = false; dev_kfree_skb_irq(skb); return STATUS_FAILURE; } @@ -2855,9 +2855,9 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, * pPacket - Pointer to rx packet * cbPacketSize - rx ethernet frame size * Out: - * TURE, FALSE + * TURE, false * - * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE + * Return Value: Return TRUE if packet is copy to dma1; otherwise false */ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, @@ -2866,7 +2866,7 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; u32 BytesToWrite = 0, uHeaderLen = 0; u8 byPktType = PK_TYPE_11B; - int bNeedEncryption = FALSE; + int bNeedEncryption = false; SKeyItem STempKey; PSKeyItem pTransmitKey = NULL; u8 *pbyBSSID; @@ -2882,7 +2882,7 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice); if (NULL == pContext) { - return FALSE; + return false; } memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN); @@ -2891,7 +2891,7 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, bNeedEncryption = TRUE; // get group key pbyBSSID = pDevice->abyBroadcastAddr; - if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) { + if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { pTransmitKey = NULL; DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode); } else { @@ -2915,8 +2915,8 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, } if ( bNeedEncryption && (pTransmitKey == NULL) ) { - pContext->bBoolInUse = FALSE; - return FALSE; + pContext->bBoolInUse = false; + return false; } byPktTyp = (BYTE)pDevice->byPacketType; @@ -2964,9 +2964,9 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, &uHeaderLen, &BytesToWrite ); - if (fConvertedPacket == FALSE) { - pContext->bBoolInUse = FALSE; - return FALSE; + if (fConvertedPacket == false) { + pContext->bBoolInUse = false; + return false; } pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]); diff --git a/drivers/staging/vt6656/tether.c b/drivers/staging/vt6656/tether.c index 7c4a808..c380733 100644 --- a/drivers/staging/vt6656/tether.c +++ b/drivers/staging/vt6656/tether.c @@ -93,7 +93,7 @@ BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr) * Out: * none * - * Return Value: TRUE if ok; FALSE if error. + * Return Value: TRUE if ok; false if error. * */ bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) @@ -102,7 +102,7 @@ bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4); if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) - return FALSE; + return false; return TRUE; } diff --git a/drivers/staging/vt6656/ttype.h b/drivers/staging/vt6656/ttype.h index 436cd79..5f7cb50 100644 --- a/drivers/staging/vt6656/ttype.h +++ b/drivers/staging/vt6656/ttype.h @@ -36,9 +36,6 @@ #if !defined(TRUE) #define TRUE 1 #endif -#if !defined(FALSE) -#define FALSE 0 -#endif /****** Simple typedefs ***************************************************/ diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c index 22a3dde..3550406 100644 --- a/drivers/staging/vt6656/usbpipe.c +++ b/drivers/staging/vt6656/usbpipe.c @@ -315,7 +315,7 @@ int PIPEnsInterruptRead(struct vnt_private *pDevice) return (STATUS_FAILURE); } pDevice->intBuf.bInUse = TRUE; -// pDevice->bEventAvailable = FALSE; +// pDevice->bEventAvailable = false; pDevice->ulIntInPosted++; // @@ -383,7 +383,7 @@ static void s_nsInterruptUsbIoCompleteRead(struct urb *urb) // otherwise interrupt data handler will free int buffer after it handle it. if (( ntStatus != STATUS_SUCCESS )) { pDevice->ulBulkInError++; - pDevice->intBuf.bInUse = FALSE; + pDevice->intBuf.bInUse = false; // if (ntStatus == USBD_STATUS_CRC) { // pDevice->ulIntInContCRCError++; @@ -505,8 +505,8 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) PRCB pRCB = (PRCB)urb->context; struct vnt_private *pDevice = pRCB->pDevice; unsigned long bytesRead; - int bIndicateReceive = FALSE; - int bReAllocSkb = FALSE; + int bIndicateReceive = false; + int bReAllocSkb = false; int status; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n"); @@ -578,7 +578,7 @@ int PIPEnsSendBulkOut(struct vnt_private *pDevice, PUSB_SEND_CONTEXT pContext) - pDevice->bPWBitOn = FALSE; + pDevice->bPWBitOn = false; /* if (pDevice->pPendingBulkOutContext != NULL) { @@ -610,13 +610,13 @@ int PIPEnsSendBulkOut(struct vnt_private *pDevice, PUSB_SEND_CONTEXT pContext) if (status != 0) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status); - pContext->bBoolInUse = FALSE; + pContext->bBoolInUse = false; return STATUS_FAILURE; } return STATUS_PENDING; } else { - pContext->bBoolInUse = FALSE; + pContext->bBoolInUse = false; return STATUS_RESOURCES; } } @@ -719,7 +719,7 @@ static void s_nsBulkOutIoCompleteWrite(struct urb *urb) if (netif_queue_stopped(pDevice->dev)) netif_wake_queue(pDevice->dev); } - pContext->bBoolInUse = FALSE; + pContext->bBoolInUse = false; return; } diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c index 51f48c1..b4d2989 100644 --- a/drivers/staging/vt6656/wcmd.c +++ b/drivers/staging/vt6656/wcmd.c @@ -114,7 +114,7 @@ static void vAdHocBeaconStop(struct vnt_private *pDevice) * or * (3.2) AdHoc channel is in A mode */ - bStop = FALSE; + bStop = false; if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState >= WMAC_STATE_STARTED)) { @@ -357,7 +357,7 @@ void vRunCommand(struct vnt_private *pDevice) if (pDevice->bUpdateBBVGA) { BBvSetShortSlotTime(pDevice); BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); - BBvUpdatePreEDThreshold(pDevice, FALSE); + BBvUpdatePreEDThreshold(pDevice, false); } // Set channel back vAdHocBeaconRestart(pDevice); @@ -369,7 +369,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->byRxMode |= RCR_BSSID; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel); - pDevice->bStopDataPkt = FALSE; + pDevice->bStopDataPkt = false; s_bCommandComplete(pDevice); spin_unlock_irq(&pDevice->lock); return; @@ -433,7 +433,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->eCommandState = WLAN_CMD_SCAN_END; } - if ((pMgmt->b11hEnable == FALSE) || + if ((pMgmt->b11hEnable == false) || (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) { s_vProbeChannel(pDevice); spin_unlock_irq(&pDevice->lock); @@ -460,7 +460,7 @@ void vRunCommand(struct vnt_private *pDevice) if (pDevice->bUpdateBBVGA) { BBvSetShortSlotTime(pDevice); BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); - BBvUpdatePreEDThreshold(pDevice, FALSE); + BBvUpdatePreEDThreshold(pDevice, false); } // Set channel back @@ -474,7 +474,7 @@ void vRunCommand(struct vnt_private *pDevice) } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel); pMgmt->eScanState = WMAC_NO_SCANNING; - pDevice->bStopDataPkt = FALSE; + pDevice->bStopDataPkt = false; /*send scan event to wpa_Supplicant*/ PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n"); @@ -493,12 +493,12 @@ void vRunCommand(struct vnt_private *pDevice) return; } else { - pDevice->bwextstep0 = FALSE; - pDevice->bwextstep1 = FALSE; - pDevice->bwextstep2 = FALSE; - pDevice->bwextstep3 = FALSE; - pDevice->bWPASuppWextEnabled = FALSE; - pDevice->fWPA_Authened = FALSE; + pDevice->bwextstep0 = false; + pDevice->bwextstep1 = false; + pDevice->bwextstep2 = false; + pDevice->bwextstep3 = false; + pDevice->bWPASuppWextEnabled = false; + pDevice->fWPA_Authened = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n"); // reason = 8 : disassoc because sta has left @@ -507,15 +507,15 @@ void vRunCommand(struct vnt_private *pDevice) pMgmt->abyCurrBSSID, (8), &Status); - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); // unlock command busy pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; pItemSSID->len = 0; memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN); pMgmt->eCurrState = WMAC_STATE_IDLE; - pMgmt->sNodeDBTable[0].bActive = FALSE; -// pDevice->bBeaconBufReady = FALSE; + pMgmt->sNodeDBTable[0].bActive = false; +// pDevice->bBeaconBufReady = false; } netif_stop_queue(pDevice->dev); if (pDevice->bNeedRadioOFF == TRUE) @@ -560,7 +560,7 @@ void vRunCommand(struct vnt_private *pDevice) } } netif_stop_queue(pDevice->dev); - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); } // set initial state @@ -706,14 +706,14 @@ void vRunCommand(struct vnt_private *pDevice) netif_wake_queue(pDevice->dev); } - if(pDevice->IsTxDataTrigger != FALSE) { //TxDataTimer is not triggered at the first time + if(pDevice->IsTxDataTrigger != false) { //TxDataTimer is not triggered at the first time // printk("Re-initial TxDataTimer****\n"); del_timer(&pDevice->sTimerTxData); init_timer(&pDevice->sTimerTxData); pDevice->sTimerTxData.data = (unsigned long) pDevice; pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData; pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback - pDevice->fTxDataInSleep = FALSE; + pDevice->fTxDataInSleep = false; pDevice->nTxDataTimeCout = 0; } else { @@ -745,7 +745,7 @@ void vRunCommand(struct vnt_private *pDevice) del_timer(&pMgmt->sTimerSecondCallback); pMgmt->eCurrState = WMAC_STATE_IDLE; pMgmt->eCurrMode = WMAC_MODE_STANDBY; - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); if (pDevice->bEnableHostWEP == TRUE) BSSvClearNodeDBTable(pDevice, 1); @@ -753,7 +753,7 @@ void vRunCommand(struct vnt_private *pDevice) BSSvClearNodeDBTable(pDevice, 0); pDevice->uAssocCount = 0; pMgmt->eCurrState = WMAC_STATE_IDLE; - pDevice->bFixRate = FALSE; + pDevice->bFixRate = false; vMgrCreateOwnIBSS((void *) pDevice, &Status); if (Status != CMD_STATUS_SUCCESS) { @@ -781,7 +781,7 @@ void vRunCommand(struct vnt_private *pDevice) while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) { if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) { pMgmt->abyPSTxMap[0] &= ~byMask[0]; - pDevice->bMoreData = FALSE; + pDevice->bMoreData = false; } else { pDevice->bMoreData = TRUE; @@ -806,7 +806,7 @@ void vRunCommand(struct vnt_private *pDevice) // clear tx map pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7]; - pDevice->bMoreData = FALSE; + pDevice->bMoreData = false; } else { pDevice->bMoreData = TRUE; @@ -828,7 +828,7 @@ void vRunCommand(struct vnt_private *pDevice) ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7]; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii); } - pMgmt->sNodeDBTable[ii].bRxPSPoll = FALSE; + pMgmt->sNodeDBTable[ii].bRxPSPoll = false; } } @@ -866,13 +866,13 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->cbFreeCmdQueue = CMD_Q_SIZE; pDevice->uCmdDequeueIdx = 0; pDevice->uCmdEnqueueIdx = 0; - //0415pDevice->bCmdRunning = FALSE; + //0415pDevice->bCmdRunning = false; pDevice->bCmdClear = TRUE; - pDevice->bStopTx0Pkt = FALSE; + pDevice->bStopTx0Pkt = false; pDevice->bStopDataPkt = TRUE; pDevice->byKeyIndex = 0; - pDevice->bTransmitKey = FALSE; + pDevice->bTransmitKey = false; spin_unlock_irq(&pDevice->lock); KeyvInitTable(pDevice,&pDevice->sKey); spin_lock_irq(&pDevice->lock); @@ -886,10 +886,10 @@ void vRunCommand(struct vnt_private *pDevice) pMgmt->abyCurrBSSID, (8), &Status); - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; // unlock command busy pMgmt->eCurrState = WMAC_STATE_IDLE; - pMgmt->sNodeDBTable[0].bActive = FALSE; + pMgmt->sNodeDBTable[0].bActive = false; // if(pDevice->bWPASuppWextEnabled == TRUE) { union iwreq_data wrqu; @@ -899,11 +899,11 @@ void vRunCommand(struct vnt_private *pDevice) wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL); } } - pDevice->bwextstep0 = FALSE; - pDevice->bwextstep1 = FALSE; - pDevice->bwextstep2 = FALSE; - pDevice->bwextstep3 = FALSE; - pDevice->bWPASuppWextEnabled = FALSE; + pDevice->bwextstep0 = false; + pDevice->bwextstep1 = false; + pDevice->bwextstep2 = false; + pDevice->bwextstep3 = false; + pDevice->bWPASuppWextEnabled = false; //clear current SSID pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; pItemSSID->len = 0; @@ -920,7 +920,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->bHWRadioOff = TRUE; } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n"); - pDevice->bHWRadioOff = FALSE; + pDevice->bHWRadioOff = false; CARDbRadioPowerOn(pDevice); MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON); @@ -937,7 +937,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->byBBVGACurrent = pDevice->byBBVGANew; BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent); - pDevice->bStopDataPkt = FALSE; + pDevice->bStopDataPkt = false; s_bCommandComplete(pDevice); break; @@ -999,9 +999,9 @@ void vRunCommand(struct vnt_private *pDevice) case WLAN_CMD_11H_CHSW_START: CARDbSetMediaChannel(pDevice, pDevice->byNewChannel); - pDevice->bChannelSwitch = FALSE; + pDevice->bChannelSwitch = false; pMgmt->uCurrChannel = pDevice->byNewChannel; - pDevice->bStopDataPkt = FALSE; + pDevice->bStopDataPkt = false; s_bCommandComplete(pDevice); break; @@ -1019,14 +1019,14 @@ static int s_bCommandComplete(struct vnt_private *pDevice) { struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PWLAN_IE_SSID pSSID; - int bRadioCmd = FALSE; + int bRadioCmd = false; int bForceSCAN = TRUE; pDevice->eCommandState = WLAN_CMD_IDLE; if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) { //Command Queue Empty - pDevice->bCmdRunning = FALSE; + pDevice->bCmdRunning = false; return TRUE; } else { @@ -1048,7 +1048,7 @@ static int s_bCommandComplete(struct vnt_private *pDevice) memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); } /* - if ((bForceSCAN == FALSE) && (pDevice->bLinkPass == TRUE)) { + if ((bForceSCAN == false) && (pDevice->bLinkPass == TRUE)) { if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) && ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) { pDevice->eCommandState = WLAN_CMD_IDLE; @@ -1124,7 +1124,7 @@ int bScheduleCommand(struct vnt_private *pDevice, { if (pDevice->cbFreeCmdQueue == 0) { - return (FALSE); + return (false); } pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand; pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE; @@ -1132,7 +1132,7 @@ int bScheduleCommand(struct vnt_private *pDevice, if (pbyItem0 != NULL) { switch (eCommand) { case WLAN_CMD_BSSID_SCAN: - pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = FALSE; + pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false; memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); break; @@ -1163,7 +1163,7 @@ int bScheduleCommand(struct vnt_private *pDevice, ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE); pDevice->cbFreeCmdQueue--; - if (pDevice->bCmdRunning == FALSE) { + if (pDevice->bCmdRunning == false) { s_bCommandComplete(pDevice); } else { @@ -1183,7 +1183,7 @@ int bScheduleCommand(struct vnt_private *pDevice, * Out: * none * - * Return Value: TRUE if success; otherwise FALSE + * Return Value: TRUE if success; otherwise false * */ static int s_bClearBSSID_SCAN(struct vnt_private *pDevice) @@ -1219,8 +1219,8 @@ void vResetCommandTimer(struct vnt_private *pDevice) pDevice->uCmdDequeueIdx = 0; pDevice->uCmdEnqueueIdx = 0; pDevice->eCommandState = WLAN_CMD_IDLE; - pDevice->bCmdRunning = FALSE; - pDevice->bCmdClear = FALSE; + pDevice->bCmdRunning = false; + pDevice->bCmdClear = false; } void BSSvSecondTxData(struct vnt_private *pDevice) @@ -1245,7 +1245,7 @@ void BSSvSecondTxData(struct vnt_private *pDevice) // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__); pDevice->fTxDataInSleep = TRUE; PSbSendNullPacket(pDevice); //send null packet - pDevice->fTxDataInSleep = FALSE; + pDevice->fTxDataInSleep = false; } spin_unlock_irq(&pDevice->lock); diff --git a/drivers/staging/vt6656/wctl.c b/drivers/staging/vt6656/wctl.c index 269082b..a4a7f43 100644 --- a/drivers/staging/vt6656/wctl.c +++ b/drivers/staging/vt6656/wctl.c @@ -54,7 +54,7 @@ /* * Description: * Scan Rx cache. Return TRUE if packet is duplicate, else - * inserts in receive cache and returns FALSE. + * inserts in receive cache and returns false. * * Parameters: * In: @@ -63,7 +63,7 @@ * Out: * none * - * Return Value: TRUE if packet duplicate; otherwise FALSE + * Return Value: TRUE if packet duplicate; otherwise false * */ @@ -95,7 +95,7 @@ bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader) memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN); pCacheEntry->wFrameCtl = pMACHeader->wFrameCtl; ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH); - return FALSE; + return false; } /* @@ -150,7 +150,7 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, if (pDevice->cbFreeDFCB == 0) return(pDevice->cbDFCB); for (ii = 0; ii < pDevice->cbDFCB; ii++) { - if (pDevice->sRxDFCB[ii].bInUse == FALSE) { + if (pDevice->sRxDFCB[ii].bInUse == false) { pDevice->cbFreeDFCB--; pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime; pDevice->sRxDFCB[ii].bInUse = TRUE; @@ -179,7 +179,7 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, * Out: * none * - * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE + * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise false * */ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, @@ -209,7 +209,7 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, else { pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader); if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) { - return(FALSE); + return(false); } } // reserve 8 byte to match MAC RX Buffer @@ -220,7 +220,7 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength; pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++; //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); - return(FALSE); + return(false); } else { pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader); @@ -238,21 +238,21 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, else { // seq error or frag # error flush DFCB pDevice->cbFreeDFCB++; - pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE; - return(FALSE); + pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; + return(false); } } else { - return(FALSE); + return(false); } if (IS_LAST_FRAGMENT_PKT(pMACHeader)) { //enq defragcontrolblock pDevice->cbFreeDFCB++; - pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE; + pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); return(TRUE); } - return(FALSE); + return(false); } } diff --git a/drivers/staging/vt6656/wmgr.c b/drivers/staging/vt6656/wmgr.c index 4b310df..0d63595 100644 --- a/drivers/staging/vt6656/wmgr.c +++ b/drivers/staging/vt6656/wmgr.c @@ -228,7 +228,7 @@ void vMgrObjectInit(struct vnt_private *pDevice) pMgmt->byCSSPK = KEY_CTL_NONE; pMgmt->byCSSGK = KEY_CTL_NONE; pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI; - BSSvClearBSSList((void *) pDevice, FALSE); + BSSvClearBSSList((void *) pDevice, false); init_timer(&pMgmt->sTimerSecondCallback); pMgmt->sTimerSecondCallback.data = (unsigned long)pDevice; @@ -244,16 +244,16 @@ void vMgrObjectInit(struct vnt_private *pDevice) pDevice->sTimerTxData.data = (unsigned long)pDevice; pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData; pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback - pDevice->fTxDataInSleep = FALSE; - pDevice->IsTxDataTrigger = FALSE; + pDevice->fTxDataInSleep = false; + pDevice->IsTxDataTrigger = false; pDevice->nTxDataTimeCout = 0; pDevice->cbFreeCmdQueue = CMD_Q_SIZE; pDevice->uCmdDequeueIdx = 0; pDevice->uCmdEnqueueIdx = 0; pDevice->eCommandState = WLAN_CMD_IDLE; - pDevice->bCmdRunning = FALSE; - pDevice->bCmdClear = FALSE; + pDevice->bCmdRunning = false; + pDevice->bCmdClear = false; return; } @@ -505,7 +505,7 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice, pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo); pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval); pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = - WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : FALSE; + WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : false; // Todo: check sta basic rate, if ap can't support, set status code if (pDevice->byBBType == BB_TYPE_11B) { uRateLen = WLAN_RATES_MAXLEN_11B; @@ -527,7 +527,7 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice, RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)abyCurrSuppRates, (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates, - FALSE, // do not change our basic rate + false, // do not change our basic rate &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), @@ -555,7 +555,7 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice, pDevice->bProtectMode = TRUE; pDevice->bNonERPPresent = TRUE; } - if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == FALSE) { + if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) { pDevice->bBarkerPreambleMd = TRUE; } @@ -651,7 +651,7 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice, pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo); pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval); pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = - WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : FALSE; + WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : false; // Todo: check sta basic rate, if ap can't support, set status code if (pDevice->byBBType == BB_TYPE_11B) { @@ -675,7 +675,7 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice, RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)abyCurrSuppRates, (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates, - FALSE, // do not change our basic rate + false, // do not change our basic rate &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), @@ -704,7 +704,7 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice, pDevice->bProtectMode = TRUE; pDevice->bNonERPPresent = TRUE; } - if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == FALSE) { + if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) { pDevice->bBarkerPreambleMd = TRUE; } @@ -872,11 +872,11 @@ static void s_vMgrRxAssocResponse(struct vnt_private *pDevice, } //need clear flags related to Networkmanager - pDevice->bwextstep0 = FALSE; - pDevice->bwextstep1 = FALSE; - pDevice->bwextstep2 = FALSE; - pDevice->bwextstep3 = FALSE; - pDevice->bWPASuppWextEnabled = FALSE; + pDevice->bwextstep0 = false; + pDevice->bwextstep1 = false; + pDevice->bwextstep2 = false; + pDevice->bwextstep3 = false; + pDevice->bWPASuppWextEnabled = false; if(pMgmt->eCurrState == WMAC_STATE_ASSOC) timer_expire(pDevice->sTimerCommand, 0); @@ -1399,13 +1399,13 @@ static void s_vMgrRxDisassociation(struct vnt_private *pDevice, vMgrDecodeDisassociation(&sFrame); DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason))); - pDevice->fWPA_Authened = FALSE; + pDevice->fWPA_Authened = false; //TODO: do something let upper layer know or //try to send associate packet again because of inactivity timeout if (pMgmt->eCurrState == WMAC_STATE_ASSOC) { - pDevice->bLinkPass = FALSE; - pMgmt->sNodeDBTable[0].bActive = FALSE; + pDevice->bLinkPass = false; + pMgmt->sNodeDBTable[0].bActive = false; pDevice->byReAssocCount = 0; pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state! pDevice->eCommandState = WLAN_ASSOCIATE_WAIT; @@ -1467,17 +1467,17 @@ static void s_vMgrRxDeauthentication(struct vnt_private *pDevice, sFrame.len = pRxPacket->cbMPDULen; sFrame.pBuf = (PBYTE)pRxPacket->p80211Header; vMgrDecodeDeauthen(&sFrame); - pDevice->fWPA_Authened = FALSE; + pDevice->fWPA_Authened = false; DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason)))); // TODO: update BSS list for specific BSSID if pre-authentication case if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID)) { if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) { - pMgmt->sNodeDBTable[0].bActive = FALSE; + pMgmt->sNodeDBTable[0].bActive = false; pMgmt->eCurrMode = WMAC_MODE_STANDBY; pMgmt->eCurrState = WMAC_STATE_IDLE; netif_stop_queue(pDevice->dev); - pDevice->bLinkPass = FALSE; + pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); } } @@ -1511,7 +1511,7 @@ static void s_vMgrRxDeauthentication(struct vnt_private *pDevice, -*/ static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel) { - int exceed = FALSE; + int exceed = false; switch(pDevice->byZoneType) { case 0x00: //USA:1~11 @@ -1548,13 +1548,13 @@ static void s_vMgrRxBeacon(struct vnt_private *pDevice, PKnownBSS pBSSList; WLAN_FR_BEACON sFrame; u64 qwTSFOffset; - int bIsBSSIDEqual = FALSE; - int bIsSSIDEqual = FALSE; - int bTSFLargeDiff = FALSE; - int bTSFOffsetPostive = FALSE; - int bUpdateTSF = FALSE; - int bIsAPBeacon = FALSE; - int bIsChannelEqual = FALSE; + int bIsBSSIDEqual = false; + int bIsSSIDEqual = false; + int bTSFLargeDiff = false; + int bTSFOffsetPostive = false; + int bUpdateTSF = false; + int bIsAPBeacon = false; + int bIsChannelEqual = false; u32 uLocateByteIndex; u8 byTIMBitOn = 0; u16 wAIDNumber = 0; @@ -1566,7 +1566,7 @@ static void s_vMgrRxBeacon(struct vnt_private *pDevice, u8 byCurrChannel = pRxPacket->byRxChannel; ERPObject sERP; u32 uRateLen = WLAN_RATES_MAXLEN; - int bChannelHit = FALSE; + int bChannelHit = false; u8 byOldPreambleType; @@ -1618,7 +1618,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) sERP.bERPExist = TRUE; } else { - sERP.bERPExist = FALSE; + sERP.bERPExist = false; sERP.byERP = 0; } @@ -1765,7 +1765,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) bShortSlotTime = TRUE; } else if (pDevice->byBBType == BB_TYPE_11B) { - bShortSlotTime = FALSE; + bShortSlotTime = false; } if (bShortSlotTime != pDevice->bShortSlotTime) { pDevice->bShortSlotTime = bShortSlotTime; @@ -1827,7 +1827,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) if (qwTimestamp >= qwLocalTSF) bTSFOffsetPostive = TRUE; else - bTSFOffsetPostive = FALSE; + bTSFOffsetPostive = false; if (bTSFOffsetPostive) { qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF)); @@ -1850,7 +1850,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) if ((pDevice->bEnablePSMode == TRUE) && (sFrame.pTIM)) { /* deal with DTIM, analysis TIM */ - pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? TRUE : FALSE ; + pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? TRUE : false ; pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount; pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod; wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15); @@ -1865,14 +1865,14 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250] if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) { byTIMBitOn = (0x01) << ((wAIDNumber) % 8); - pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? TRUE : FALSE; + pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? TRUE : false; } else { - pMgmt->bInTIM = FALSE; + pMgmt->bInTIM = false; }; } else { - pMgmt->bInTIM = FALSE; + pMgmt->bInTIM = false; }; if (pMgmt->bInTIM || @@ -1884,14 +1884,14 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) } else { - pMgmt->bInTIMWake = FALSE; + pMgmt->bInTIMWake = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n"); - if (pDevice->bPWBitOn == FALSE) { + if (pDevice->bPWBitOn == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n"); if (PSbSendNullPacket(pDevice)) pDevice->bPWBitOn = TRUE; } - if(PSbConsiderPowerDown(pDevice, FALSE, FALSE)) { + if(PSbConsiderPowerDown(pDevice, false, false)) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n"); } } @@ -2161,7 +2161,7 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus) if (pDevice->byBBType == BB_TYPE_11A) { pDevice->bShortSlotTime = TRUE; } else { - pDevice->bShortSlotTime = FALSE; + pDevice->bShortSlotTime = false; } BBvSetShortSlotTime(pDevice); // vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called @@ -2311,7 +2311,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) u16 wSuppRate; u8 byTopCCKBasicRate = RATE_1M; u8 byTopOFDMBasicRate = RATE_1M; - u8 bShortSlotTime = FALSE; + u8 bShortSlotTime = false; for (ii = 0; ii < MAX_BSS_NUM; ii++) { @@ -2349,14 +2349,14 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) { /* if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { - if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == FALSE) { + if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); // encryption mode error pMgmt->eCurrState = WMAC_STATE_IDLE; return; } } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { - if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == FALSE) { + if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); // encryption mode error pMgmt->eCurrState = WMAC_STATE_IDLE; @@ -2447,7 +2447,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult); - if (bResult == FALSE) { + if (bResult == false) { vFlush_PMKID_Candidate((void *) pDevice); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 4\n"); @@ -2500,7 +2500,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) bShortSlotTime = TRUE; } else if (pDevice->byBBType == BB_TYPE_11B) { - bShortSlotTime = FALSE; + bShortSlotTime = false; } else { bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo); @@ -2527,7 +2527,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { /* - if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == FALSE) { + if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) { // encryption mode error pMgmt->eCurrState = WMAC_STATE_IDLE; return; @@ -2535,7 +2535,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) */ } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { /* - if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == FALSE) { + if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) { // encryption mode error pMgmt->eCurrState = WMAC_STATE_IDLE; return; @@ -2641,7 +2641,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, if (s_bCipherMatch(pCurr, pDevice->eEncryptionStatus, &(pMgmt->byCSSPK), - &(pMgmt->byCSSGK)) == FALSE) { + &(pMgmt->byCSSGK)) == false) { DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n"); return; } @@ -2655,11 +2655,11 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, // Init the BSS informations pDevice->bCCK = TRUE; - pDevice->bProtectMode = FALSE; + pDevice->bProtectMode = false; MACvDisableProtectMD(pDevice); - pDevice->bBarkerPreambleMd = FALSE; + pDevice->bBarkerPreambleMd = false; MACvDisableBarkerPreambleMd(pDevice); - pDevice->bNonERPPresent = FALSE; + pDevice->bNonERPPresent = false; pDevice->byPreambleType = 0; pDevice->wBasicRate = 0; // Set Basic Rate @@ -2701,7 +2701,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) { pDevice->byBBType = BB_TYPE_11B; pMgmt->eCurrentPHYMode = PHY_TYPE_11B; - pDevice->bShortSlotTime = FALSE; + pDevice->bShortSlotTime = false; BBvSetShortSlotTime(pDevice); CARDvSetBSSMode(pDevice); } else { @@ -2717,7 +2717,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, CARDvSetBSSMode(pDevice); } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) { pDevice->byBBType = BB_TYPE_11B; - pDevice->bShortSlotTime = FALSE; + pDevice->bShortSlotTime = false; BBvSetShortSlotTime(pDevice); CARDvSetBSSMode(pDevice); } else { @@ -2823,8 +2823,8 @@ static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM) u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; u8 byMap; int ii, jj; - int bStartFound = FALSE; - int bMulticast = FALSE; + int bStartFound = false; + int bMulticast = false; u16 wStartIndex = 0; u16 wEndIndex = 0; @@ -3888,7 +3888,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) sERP.byERP = sFrame.pERP->byContext; sERP.bERPExist = TRUE; } else { - sERP.bERPExist = FALSE; + sERP.bERPExist = false; sERP.byERP = 0; } @@ -4037,7 +4037,7 @@ static void s_vMgrRxProbeRequest(struct vnt_private *pDevice, void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket) { - int bInScan = FALSE; + int bInScan = false; u32 uNodeIndex = 0; NODE_STATE eNodeState = 0; CMD_STATUS Status; @@ -4073,7 +4073,7 @@ void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, case WLAN_FSTYPE_ASSOCRESP: // Frame Clase = 2 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n"); - s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, FALSE); + s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n"); break; @@ -4175,7 +4175,7 @@ void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, * Prepare beacon to send * * Return Value: - * TRUE if success; FALSE if failed. + * TRUE if success; false if failed. * -*/ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, @@ -4183,7 +4183,7 @@ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, { struct vnt_tx_mgmt *pTxPacket; -// pDevice->bBeaconBufReady = FALSE; +// pDevice->bBeaconBufReady = false; if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){ pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1); } @@ -4206,7 +4206,7 @@ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->abyCurrBSSID[0] == 0)) - return FALSE; + return false; csBeacon_xmit(pDevice, pTxPacket); MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX); @@ -4303,10 +4303,10 @@ int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL)) - return FALSE; + return false; if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) - return FALSE; + return false; @@ -4377,7 +4377,7 @@ s_bCipherMatch ( int i; if (pBSSNode == NULL) - return FALSE; + return false; // check cap. of BSS if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) && @@ -4466,7 +4466,7 @@ s_bCipherMatch ( *pbyCCSPK = KEY_CTL_NONE; return TRUE; } else { - return FALSE; + return false; } } else if (EncStatus == Ndis802_11Encryption2Enabled) { @@ -4486,13 +4486,13 @@ s_bCipherMatch ( *pbyCCSPK = KEY_CTL_TKIP; return TRUE; } else { - return FALSE; + return false; } } else if (EncStatus == Ndis802_11Encryption3Enabled) { if ((byMulticastCipher == KEY_CTL_CCMP) && (byCipherMask == 0)) { // When CCMP is enable, "Use group cipher suite" shall not be a valid option. - return FALSE; + return false; } else if ((byMulticastCipher == KEY_CTL_WEP) && ((byCipherMask & 0x04) != 0)) { *pbyCCSGK = KEY_CTL_WEP; @@ -4509,7 +4509,7 @@ s_bCipherMatch ( *pbyCCSPK = KEY_CTL_CCMP; return TRUE; } else { - return FALSE; + return false; } } return TRUE; diff --git a/drivers/staging/vt6656/wpa.c b/drivers/staging/vt6656/wpa.c index 6336d88..568a6f4 100644 --- a/drivers/staging/vt6656/wpa.c +++ b/drivers/staging/vt6656/wpa.c @@ -83,9 +83,9 @@ WPA_ClearRSN( pBSSList->wAuthCount = 0; pBSSList->byDefaultK_as_PK = 0; pBSSList->byReplayIdx = 0; - pBSSList->sRSNCapObj.bRSNCapExist = FALSE; + pBSSList->sRSNCapObj.bRSNCapExist = false; pBSSList->sRSNCapObj.wRSNCap = 0; - pBSSList->bWPAValid = FALSE; + pBSSList->bWPAValid = false; } @@ -249,14 +249,14 @@ WPA_SearchRSN( int ii; BYTE byPKType = WPA_NONE; - if (pBSSList->bWPAValid == FALSE) - return FALSE; + if (pBSSList->bWPAValid == false) + return false; switch(byCmd) { case 0: if (byEncrypt != pBSSList->byGKType) - return FALSE; + return false; if (pBSSList->wPKCount > 0) { for (ii = 0; ii < pBSSList->wPKCount; ii ++) { @@ -270,7 +270,7 @@ WPA_SearchRSN( byPKType = WPA_WEP104; } if (byEncrypt != byPKType) - return FALSE; + return false; } return TRUE; // if (pBSSList->wAuthCount > 0) @@ -282,7 +282,7 @@ WPA_SearchRSN( default: break; } - return FALSE; + return false; } /*+ @@ -305,7 +305,7 @@ WPAb_Is_RSN( ) { if (pRSN == NULL) - return FALSE; + return false; if ((pRSN->len >= 6) && // oui1(4)+ver(2) (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) && @@ -313,6 +313,6 @@ WPAb_Is_RSN( return TRUE; } else - return FALSE; + return false; } diff --git a/drivers/staging/vt6656/wpa2.c b/drivers/staging/vt6656/wpa2.c index 97691a3..04d5cbb 100644 --- a/drivers/staging/vt6656/wpa2.c +++ b/drivers/staging/vt6656/wpa2.c @@ -78,7 +78,7 @@ WPA2_ClearRSN ( { int ii; - pBSSNode->bWPA2Valid = FALSE; + pBSSNode->bWPA2Valid = false; pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP; for (ii=0; ii < 4; ii ++) @@ -87,7 +87,7 @@ WPA2_ClearRSN ( for (ii=0; ii < 4; ii ++) pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X; pBSSNode->wAKMSSAuthCount = 1; - pBSSNode->sRSNCapObj.bRSNCapExist = FALSE; + pBSSNode->sRSNCapObj.bRSNCapExist = false; pBSSNode->sRSNCapObj.wRSNCap = 0; } @@ -115,7 +115,7 @@ WPA2vParseRSN ( int i, j; WORD m = 0, n = 0; PBYTE pbyOUI; - bool bUseGK = FALSE; + bool bUseGK = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len); diff --git a/drivers/staging/vt6656/wpactl.c b/drivers/staging/vt6656/wpactl.c index 569d1a7..de4a76a 100644 --- a/drivers/staging/vt6656/wpactl.c +++ b/drivers/staging/vt6656/wpactl.c @@ -87,9 +87,9 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) param->u.wpa_key.alg_name); if (param->u.wpa_key.alg_name == WPA_ALG_NONE) { pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; - pDevice->bEncryptionEnable = FALSE; + pDevice->bEncryptionEnable = false; pDevice->byKeyIndex = 0; - pDevice->bTransmitKey = FALSE; + pDevice->bTransmitKey = false; for (uu=0; uu Date: Tue, 12 Feb 2013 20:36:30 -0500 Subject: staging: vt6656: replaced custom TRUE definition with true Checkpatch findings were not resolved, just direct replacement. sed -i 's/\bTRUE\b/true/g' drivers/staging/vt6656/*.[ch] Signed-off-by: Andres More Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/vt6656/80211mgr.c b/drivers/staging/vt6656/80211mgr.c index 8221d65..534d490 100644 --- a/drivers/staging/vt6656/80211mgr.c +++ b/drivers/staging/vt6656/80211mgr.c @@ -180,7 +180,7 @@ vMgrDecodeBeacon( break; case WLAN_EID_RSN_WPA: if (pFrame->pRSNWPA == NULL) { - if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) + if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true) pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; } break; @@ -393,7 +393,7 @@ vMgrDecodeAssocRequest( break; case WLAN_EID_RSN_WPA: if (pFrame->pRSNWPA == NULL) { - if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) + if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true) pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; } break; @@ -563,7 +563,7 @@ vMgrDecodeReassocRequest( break; case WLAN_EID_RSN_WPA: if (pFrame->pRSNWPA == NULL) - if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) + if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true) pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; break; @@ -753,7 +753,7 @@ vMgrDecodeProbeResponse( break; case WLAN_EID_RSN_WPA: if (pFrame->pRSNWPA == NULL) { - if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) + if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true) pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; } break; diff --git a/drivers/staging/vt6656/aes_ccmp.c b/drivers/staging/vt6656/aes_ccmp.c index a6f79be..fb6124d 100644 --- a/drivers/staging/vt6656/aes_ccmp.c +++ b/drivers/staging/vt6656/aes_ccmp.c @@ -257,7 +257,7 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN; if (WLAN_GET_FC_TODS(*(PWORD) pbyFrame) && WLAN_GET_FC_FROMDS(*(PWORD) pbyFrame)) { - bA4 = TRUE; + bA4 = true; pbyIV += 6; /* 6 is 802.11 address4 */ wHLen += 6; wPayloadSize -= 6; @@ -380,7 +380,7 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) /* => above is the packet dec-MIC */ if (!memcmp(abyMIC, abyTmp, 8)) - return TRUE; + return true; else return false; } diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c index 29817b8..a9f525e 100644 --- a/drivers/staging/vt6656/baseband.c +++ b/drivers/staging/vt6656/baseband.c @@ -806,7 +806,7 @@ void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength, if (cbTmp != cbBitCount) { cbUsCount ++; if ((cbBitCount - cbTmp) <= 3) - bExtBit = TRUE; + bExtBit = true; } if (byPreambleType == 1) *pbyPhySgn = 0x0b; @@ -1097,7 +1097,7 @@ else { MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL2, SOFTPWRCTL_RFLEOPT); //}} } else { - return TRUE; + return true; } memcpy(abyArray, pbyAddr, wLength); @@ -1136,7 +1136,7 @@ else { ControlvWriteByte(pDevice,MESSAGE_REQUEST_BBREG,0x0D,0x01); RFbRFTableDownload(pDevice); - return TRUE;//ntStatus; + return true;//ntStatus; } diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c index bc10b0b..e214fcf 100644 --- a/drivers/staging/vt6656/bssdb.c +++ b/drivers/staging/vt6656/bssdb.c @@ -160,7 +160,7 @@ PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice, ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) || ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ) { - pCurrBSS->bSelected = TRUE; + pCurrBSS->bSelected = true; return(pCurrBSS); } } @@ -169,7 +169,7 @@ PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice, ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) || ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ) { - pCurrBSS->bSelected = TRUE; + pCurrBSS->bSelected = true; return(pCurrBSS); } } @@ -236,7 +236,7 @@ PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice, pDevice->bSameBSSMaxNum = jj; if (pSelect != NULL) { - pSelect->bSelected = TRUE; + pSelect->bSelected = true; if (pDevice->bRoaming == false) { // Einsn Add @20070907 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ; @@ -293,7 +293,7 @@ void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID) * search BSS list by BSSID & SSID if matched * * Return Value: - * TRUE if found. + * true if found. * -*/ PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *pDevice, @@ -328,7 +328,7 @@ PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *pDevice, * Insert a BSS set into known BSS list * * Return Value: - * TRUE if success. + * true if success. * -*/ @@ -371,7 +371,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, return false; } // save the BSS info - pBSSList->bActive = TRUE; + pBSSList->bActive = true; memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN); pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp); pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval); @@ -404,7 +404,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) { pBSSList->eNetworkTypeInUse = PHY_TYPE_11A; } else { - if (pBSSList->sERP.bERPExist == TRUE) { + if (pBSSList->sERP.bERPExist == true) { pBSSList->eNetworkTypeInUse = PHY_TYPE_11G; } else { pBSSList->eNetworkTypeInUse = PHY_TYPE_11B; @@ -420,7 +420,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { // assoc with BSS if (pBSSList == pMgmt->pCurrBSS) { - bParsingQuiet = TRUE; + bParsingQuiet = true; } } @@ -450,27 +450,27 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, } } - if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) { + if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) { PSKeyItem pTransmitKey = NULL; bool bIs802_1x = false; for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) { if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) { - bIs802_1x = TRUE; + bIs802_1x = true; break; } } - if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) && + if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) && ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) { bAdd_PMKID_Candidate((void *) pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj); - if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { - if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) || - (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) { + if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { + if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) || + (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) { pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList; pDevice->gsPMKIDCandidate.Version = 1; @@ -495,7 +495,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN; memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength); - return TRUE; + return true; } @@ -505,7 +505,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice, * Update BSS set in known BSS list * * Return Value: - * TRUE if success. + * true if success. * -*/ // TODO: input structure modify @@ -566,7 +566,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice, if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) { pBSSList->eNetworkTypeInUse = PHY_TYPE_11A; } else { - if (pBSSList->sERP.bERPExist == TRUE) { + if (pBSSList->sERP.bERPExist == true) { pBSSList->eNetworkTypeInUse = PHY_TYPE_11G; } else { pBSSList->eNetworkTypeInUse = PHY_TYPE_11B; @@ -583,7 +583,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice, (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { // assoc with BSS if (pBSSList == pMgmt->pCurrBSS) { - bParsingQuiet = TRUE; + bParsingQuiet = true; } } @@ -635,7 +635,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice, pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN; memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength); - return TRUE; + return true; } @@ -664,7 +664,7 @@ int BSSbIsSTAInNodeDB(struct vnt_private *pDevice, if (!compare_ether_addr(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) { *puNodeIndex = ii; - return TRUE; + return true; } } } @@ -722,7 +722,7 @@ void BSSvCreateOneNode(struct vnt_private *pDevice, u32 *puNodeIndex) } memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB)); - pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE; + pMgmt->sNodeDBTable[*puNodeIndex].bActive = true; pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND; // for AP mode PS queue skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue); @@ -777,7 +777,7 @@ void BSSvUpdateAPNode(struct vnt_private *pDevice, u16 *pwCapInfo, memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); - pMgmt->sNodeDBTable[0].bActive = TRUE; + pMgmt->sNodeDBTable[0].bActive = true; if (pDevice->byBBType == BB_TYPE_11B) { uRateLen = WLAN_RATES_MAXLEN_11B; } @@ -790,7 +790,7 @@ void BSSvUpdateAPNode(struct vnt_private *pDevice, u16 *pwCapInfo, RATEvParseMaxRate((void *) pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, - TRUE, + true, &(pMgmt->sNodeDBTable[0].wMaxBasicRate), &(pMgmt->sNodeDBTable[0].wMaxSuppRate), &(pMgmt->sNodeDBTable[0].wSuppRate), @@ -825,13 +825,13 @@ void BSSvAddMulticastNode(struct vnt_private *pDevice) if (!pDevice->bEnableHostWEP) memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN); - pMgmt->sNodeDBTable[0].bActive = TRUE; + pMgmt->sNodeDBTable[0].bActive = true; pMgmt->sNodeDBTable[0].bPSEnable = false; skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue); RATEvParseMaxRate((void *) pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, - TRUE, + true, &(pMgmt->sNodeDBTable[0].wMaxBasicRate), &(pMgmt->sNodeDBTable[0].wMaxSuppRate), &(pMgmt->sNodeDBTable[0].wSuppRate), @@ -870,7 +870,7 @@ void BSSvSecondCallBack(struct vnt_private *pDevice) pDevice->uAssocCount = 0; //Power Saving Mode Tx Burst - if ( pDevice->bEnablePSMode == TRUE ) { + if ( pDevice->bEnablePSMode == true ) { pDevice->ulPSModeWaitTx++; if ( pDevice->ulPSModeWaitTx >= 2 ) { pDevice->ulPSModeWaitTx = 0; @@ -891,10 +891,10 @@ void BSSvSecondCallBack(struct vnt_private *pDevice) if(pDevice->byReAssocCount > 0) { pDevice->byReAssocCount++; - if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) { //10 sec timeout + if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) { //10 sec timeout printk("Re-association timeout!!!\n"); pDevice->byReAssocCount = 0; - // if(pDevice->bWPASuppWextEnabled == TRUE) + // if(pDevice->bWPASuppWextEnabled == true) { union iwreq_data wrqu; memset(&wrqu, 0, sizeof (wrqu)); @@ -903,7 +903,7 @@ if(pDevice->byReAssocCount > 0) { wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL); } } - else if(pDevice->bLinkPass == TRUE) + else if(pDevice->bLinkPass == true) pDevice->byReAssocCount = 0; } @@ -988,7 +988,7 @@ if(pDevice->byReAssocCount > 0) { if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) { if (!pDevice->bProtectMode) { MACvEnableProtectMD(pDevice); - pDevice->bProtectMode = TRUE; + pDevice->bProtectMode = true; } } else { @@ -1008,7 +1008,7 @@ if(pDevice->byReAssocCount > 0) { } else { if (!pDevice->bShortSlotTime) { - pDevice->bShortSlotTime = TRUE; + pDevice->bShortSlotTime = true; BBvSetShortSlotTime(pDevice); vUpdateIFS((void *)pDevice); } @@ -1019,7 +1019,7 @@ if(pDevice->byReAssocCount > 0) { if (uLongPreambleSTACnt > 0) { if (!pDevice->bBarkerPreambleMd) { MACvEnableBarkerPreambleMd(pDevice); - pDevice->bBarkerPreambleMd = TRUE; + pDevice->bBarkerPreambleMd = true; } } else { @@ -1035,7 +1035,7 @@ if(pDevice->byReAssocCount > 0) { // Check if any STA in PS mode, enable DTIM multicast deliver if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { if (uSleepySTACnt > 0) - pMgmt->sNodeDBTable[0].bPSEnable = TRUE; + pMgmt->sNodeDBTable[0].bPSEnable = true; else pMgmt->sNodeDBTable[0].bPSEnable = false; } @@ -1068,7 +1068,7 @@ if(pDevice->byReAssocCount > 0) { netif_stop_queue(pDevice->dev); pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); - pDevice->bRoaming = TRUE; + pDevice->bRoaming = true; pDevice->bIsRoaming = false; DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount); @@ -1084,10 +1084,10 @@ if(pDevice->byReAssocCount > 0) { } else if (pItemSSID->len != 0) { //Davidwang - if ((pDevice->bEnableRoaming == TRUE)&&(!(pMgmt->Cisco_cckm))) { + if ((pDevice->bEnableRoaming == true)&&(!(pMgmt->Cisco_cckm))) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming ); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming ); - if ((pDevice->bRoaming == TRUE)&&(pDevice->bIsRoaming == TRUE)){ + if ((pDevice->bRoaming == true)&&(pDevice->bIsRoaming == true)){ DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n"); BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass); bScheduleCommand((void *) pDevice, @@ -1100,7 +1100,7 @@ DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming ); pDevice->uIsroamingTime = 0; pDevice->bRoaming = false; } - else if ((pDevice->bRoaming == false)&&(pDevice->bIsRoaming == TRUE)) { + else if ((pDevice->bRoaming == false)&&(pDevice->bIsRoaming == true)) { pDevice->uIsroamingTime++; if (pDevice->uIsroamingTime >= 20) pDevice->bIsRoaming = false; @@ -1111,7 +1111,7 @@ else { if (pDevice->uAutoReConnectTime < 10) { pDevice->uAutoReConnectTime++; //network manager support need not do Roaming scan??? - if(pDevice->bWPASuppWextEnabled ==TRUE) + if(pDevice->bWPASuppWextEnabled ==true) pDevice->uAutoReConnectTime = 0; } else { @@ -1165,7 +1165,7 @@ else { } } - if (pDevice->bLinkPass == TRUE) { + if (pDevice->bLinkPass == true) { if (netif_queue_stopped(pDevice->dev)) netif_wake_queue(pDevice->dev); } @@ -1426,7 +1426,7 @@ RxCnt = pDevice->scStatistic.RxFcsErrCnt + TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt); RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt); //decide link quality -if(pDevice->bLinkPass !=TRUE) +if(pDevice->bLinkPass !=true) { pDevice->scStatistic.LinkQuality = 0; pDevice->scStatistic.SignalStren = 0; diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 21c24f7..22918a1 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -517,7 +517,7 @@ void vUpdateIFS(struct vnt_private *pDevice) for (ii = 0; ii < pItemRates->len; ii++) { byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); if (RATEwGetRateIdx(byRate) > RATE_11M) { - bOFDMRate = TRUE; + bOFDMRate = true; break; } } @@ -527,12 +527,12 @@ void vUpdateIFS(struct vnt_private *pDevice) for (ii = 0; ii < pItemRates->len; ii++) { byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); if (RATEwGetRateIdx(byRate) > RATE_11M) { - bOFDMRate = TRUE; + bOFDMRate = true; break; } } } - if (bOFDMRate == TRUE) { + if (bOFDMRate == true) { pDevice->uCwMin = C_CWMIN_A; byMaxMin = 4; } else { @@ -599,7 +599,7 @@ void CARDvUpdateBasicTopRate(struct vnt_private *pDevice) * Out: * none * - * Return Value: TRUE if succeeded; false if failed. + * Return Value: true if succeeded; false if failed. * */ void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx) @@ -618,7 +618,7 @@ int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice) for (ii = RATE_54M; ii >= RATE_6M; ii --) { if ((pDevice->wBasicRate) & ((WORD)(1<qwCurrTSF; - return TRUE; + return true; } @@ -743,7 +743,7 @@ bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF) * In: * pDevice - The adapter to be read * - * Return Value: TRUE if success; otherwise false + * Return Value: true if success; otherwise false * */ bool CARDbClearCurrentTSF(struct vnt_private *pDevice) @@ -753,7 +753,7 @@ bool CARDbClearCurrentTSF(struct vnt_private *pDevice) pDevice->qwCurrTSF = 0; - return TRUE; + return true; } /* @@ -899,17 +899,17 @@ void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF, * Out: * none * - * Return Value: TRUE if success; otherwise false + * Return Value: true if success; otherwise false * */ int CARDbRadioPowerOff(struct vnt_private *pDevice) { - int bResult = TRUE; + int bResult = true; - //if (pDevice->bRadioOff == TRUE) - // return TRUE; + //if (pDevice->bRadioOff == true) + // return true; - pDevice->bRadioOff = TRUE; + pDevice->bRadioOff = true; switch (pDevice->byRFType) { case RF_AL2230: @@ -939,19 +939,19 @@ int CARDbRadioPowerOff(struct vnt_private *pDevice) * Out: * none * - * Return Value: TRUE if success; otherwise false + * Return Value: true if success; otherwise false * */ int CARDbRadioPowerOn(struct vnt_private *pDevice) { - int bResult = TRUE; + int bResult = true; - if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { + if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) { return false; } //if (pDevice->bRadioOff == false) - // return TRUE; + // return true; pDevice->bRadioOff = false; @@ -1034,7 +1034,7 @@ void CARDvSetBSSMode(struct vnt_private *pDevice) int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode, u8 byNewChannel, u8 byCount) { - int bResult = TRUE; + int bResult = true; if (byCount == 0) { pDevice->vnt_mgmt.uCurrChannel = byNewChannel; @@ -1043,11 +1043,11 @@ int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode, } pDevice->byChannelSwitchCount = byCount; pDevice->byNewChannel = byNewChannel; - pDevice->bChannelSwitch = TRUE; + pDevice->bChannelSwitch = true; if (byMode == 1) { //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL); - pDevice->bStopDataPkt = TRUE; + pDevice->bStopDataPkt = true; } return bResult; } diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c index d58ca0a..4181e3e 100644 --- a/drivers/staging/vt6656/channel.c +++ b/drivers/staging/vt6656/channel.c @@ -51,62 +51,62 @@ static int msglevel = MSG_LEVEL_INFO; static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] = { {0, 0, false}, - {1, 2412, TRUE}, - {2, 2417, TRUE}, - {3, 2422, TRUE}, - {4, 2427, TRUE}, - {5, 2432, TRUE}, - {6, 2437, TRUE}, - {7, 2442, TRUE}, - {8, 2447, TRUE}, - {9, 2452, TRUE}, - {10, 2457, TRUE}, - {11, 2462, TRUE}, - {12, 2467, TRUE}, - {13, 2472, TRUE}, - {14, 2484, TRUE}, - {183, 4915, TRUE}, //15 - {184, 4920, TRUE}, //16 - {185, 4925, TRUE}, //17 - {187, 4935, TRUE}, //18 - {188, 4940, TRUE}, //19 - {189, 4945, TRUE}, //20 - {192, 4960, TRUE}, //21 - {196, 4980, TRUE}, //22 - {7, 5035, TRUE}, //23 - {8, 5040, TRUE}, //24 - {9, 5045, TRUE}, //25 - {11, 5055, TRUE}, //26 - {12, 5060, TRUE}, //27 - {16, 5080, TRUE}, //28 - {34, 5170, TRUE}, //29 - {36, 5180, TRUE}, //30 - {38, 5190, TRUE}, //31 - {40, 5200, TRUE}, //32 - {42, 5210, TRUE}, //33 - {44, 5220, TRUE}, //34 - {46, 5230, TRUE}, //35 - {48, 5240, TRUE}, //36 - {52, 5260, TRUE}, //37 - {56, 5280, TRUE}, //38 - {60, 5300, TRUE}, //39 - {64, 5320, TRUE}, //40 - {100, 5500, TRUE}, //41 - {104, 5520, TRUE}, //42 - {108, 5540, TRUE}, //43 - {112, 5560, TRUE}, //44 - {116, 5580, TRUE}, //45 - {120, 5600, TRUE}, //46 - {124, 5620, TRUE}, //47 - {128, 5640, TRUE}, //48 - {132, 5660, TRUE}, //49 - {136, 5680, TRUE}, //50 - {140, 5700, TRUE}, //51 - {149, 5745, TRUE}, //52 - {153, 5765, TRUE}, //53 - {157, 5785, TRUE}, //54 - {161, 5805, TRUE}, //55 - {165, 5825, TRUE} //56 + {1, 2412, true}, + {2, 2417, true}, + {3, 2422, true}, + {4, 2427, true}, + {5, 2432, true}, + {6, 2437, true}, + {7, 2442, true}, + {8, 2447, true}, + {9, 2452, true}, + {10, 2457, true}, + {11, 2462, true}, + {12, 2467, true}, + {13, 2472, true}, + {14, 2484, true}, + {183, 4915, true}, //15 + {184, 4920, true}, //16 + {185, 4925, true}, //17 + {187, 4935, true}, //18 + {188, 4940, true}, //19 + {189, 4945, true}, //20 + {192, 4960, true}, //21 + {196, 4980, true}, //22 + {7, 5035, true}, //23 + {8, 5040, true}, //24 + {9, 5045, true}, //25 + {11, 5055, true}, //26 + {12, 5060, true}, //27 + {16, 5080, true}, //28 + {34, 5170, true}, //29 + {36, 5180, true}, //30 + {38, 5190, true}, //31 + {40, 5200, true}, //32 + {42, 5210, true}, //33 + {44, 5220, true}, //34 + {46, 5230, true}, //35 + {48, 5240, true}, //36 + {52, 5260, true}, //37 + {56, 5280, true}, //38 + {60, 5300, true}, //39 + {64, 5320, true}, //40 + {100, 5500, true}, //41 + {104, 5520, true}, //42 + {108, 5540, true}, //43 + {112, 5560, true}, //44 + {116, 5580, true}, //45 + {120, 5600, true}, //46 + {124, 5620, true}, //47 + {128, 5640, true}, //48 + {132, 5660, true}, //49 + {136, 5680, true}, //50 + {140, 5700, true}, //51 + {149, 5745, true}, //52 + {153, 5765, true}, //53 + {157, 5785, true}, //54 + {161, 5805, true}, //55 + {165, 5825, true} //56 }; @@ -380,7 +380,7 @@ static struct * 15 = 4.9G channel 183 * 16 = 4.9G channel 184 * ..... - * Output: TRUE if the specified 5GHz band is allowed to be used. + * Output: true if the specified 5GHz band is allowed to be used. False otherwise. // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) @@ -432,7 +432,7 @@ CHvChannelGetList ( return (false); } memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL); - return (TRUE); + return (true); } @@ -454,15 +454,15 @@ void CHvInitChannelTable(struct vnt_private *pDevice) case RF_AIROHA7230: case RF_VT3342A0: default : - bMultiBand = TRUE; + bMultiBand = true; break; } if ((pDevice->dwDiagRefCount != 0) || - (pDevice->b11hEable == TRUE)) { - if (bMultiBand == TRUE) { + (pDevice->b11hEable == true)) { + if (bMultiBand == true) { for (ii = 0; ii < CB_MAX_CHANNEL; ii++) { - sChannelTbl[ii+1].bValid = TRUE; + sChannelTbl[ii+1].bValid = true; //pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1]; //pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1]; } @@ -472,16 +472,16 @@ void CHvInitChannelTable(struct vnt_private *pDevice) } } else { for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) { - sChannelTbl[ii+1].bValid = TRUE; + sChannelTbl[ii+1].bValid = true; //pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1]; //pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1]; } } } else if (pDevice->byZoneType <= CCODE_MAX) { - if (bMultiBand == TRUE) { + if (bMultiBand == true) { for (ii = 0; ii < CB_MAX_CHANNEL; ii++) { if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) { - sChannelTbl[ii+1].bValid = TRUE; + sChannelTbl[ii+1].bValid = true; //pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; //pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; } @@ -489,7 +489,7 @@ void CHvInitChannelTable(struct vnt_private *pDevice) } else { for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) { if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) { - sChannelTbl[ii+1].bValid = TRUE; + sChannelTbl[ii+1].bValid = true; //pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; //pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; } diff --git a/drivers/staging/vt6656/datarate.c b/drivers/staging/vt6656/datarate.c index 774a256..77464e8 100644 --- a/drivers/staging/vt6656/datarate.c +++ b/drivers/staging/vt6656/datarate.c @@ -218,7 +218,7 @@ void RATEvParseMaxRate(struct vnt_private *pDevice, for (ii = 0; ii < uRateLen; ii++) { byRate = (BYTE)(pItemRates->abyRates[ii]); if (WLAN_MGMT_IS_BASICRATE(byRate) && - (bUpdateBasicRate == TRUE)) { + (bUpdateBasicRate == true)) { /* * add to basic rate set, update pDevice->byTopCCKBasicRate and * pDevice->byTopOFDMBasicRate @@ -307,8 +307,8 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice, struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; u16 wIdxDownRate = 0; int ii; - int bAutoRate[MAX_RATE] = {TRUE, TRUE, TRUE, TRUE, false, false, TRUE, - TRUE, TRUE, TRUE, TRUE, TRUE}; + int bAutoRate[MAX_RATE] = {true, true, true, true, false, false, true, + true, true, true, true, true}; u32 dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540}; u32 dwThroughput = 0; @@ -335,7 +335,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice, for (ii = 0; ii < MAX_RATE; ii++) { if (psNodeDBTable->wSuppRate & (0x0001<wTxDataRate; ii > 0;) { ii--; if ( (dwThroughputTbl[ii] > dwThroughput) && - (bAutoRate[ii]==TRUE) ) { + (bAutoRate[ii]==true) ) { dwThroughput = dwThroughputTbl[ii]; wIdxDownRate = (WORD) ii; } diff --git a/drivers/staging/vt6656/device_cfg.h b/drivers/staging/vt6656/device_cfg.h index 8608f76..62290d0 100644 --- a/drivers/staging/vt6656/device_cfg.h +++ b/drivers/staging/vt6656/device_cfg.h @@ -42,8 +42,8 @@ struct _version { #define false (0) #endif -#ifndef TRUE -#define TRUE (!(false)) +#ifndef true +#define true (!(false)) #endif #define VID_TABLE_SIZE 64 diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c index c68b81a..e83f95e 100644 --- a/drivers/staging/vt6656/dpc.c +++ b/drivers/staging/vt6656/dpc.c @@ -423,7 +423,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, } if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { - if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) { + if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == true) { return false; } } @@ -433,7 +433,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, bool bRxDecryOK = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n"); - bIsWEP = TRUE; + bIsWEP = true; if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) { pKey = &STempKey; pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite; @@ -573,7 +573,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, skb->protocol = htons(ETH_P_802_2); memset(skb->cb, 0, sizeof(skb->cb)); netif_rx(skb); - return TRUE; + return true; } // @@ -585,7 +585,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, pRCB->Ref++; } if (pDevice->bIsRxMngWorkItemQueued == false) { - pDevice->bIsRxMngWorkItemQueued = TRUE; + pDevice->bIsRxMngWorkItemQueued = true; tasklet_schedule(&pDevice->RxMngWorkItem); } @@ -637,7 +637,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header if(((Protocol_Version==1) ||(Protocol_Version==2)) && (Packet_Type==3)) { //802.1x OR eapol-key challenge frame receive - bRxeapol_key = TRUE; + bRxeapol_key = true; Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2]; Key_info = (skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+1]<<8) |skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+2] ; if(Descriptor_type==2) { //RSN @@ -664,7 +664,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, } } else { - if (pMgmt->bInTIMWake == TRUE) { + if (pMgmt->bInTIMWake == true) { pMgmt->bInTIMWake = false; } } @@ -673,7 +673,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps if (pDevice->bDiversityEnable && (FrameSize>50) && (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) && - (pDevice->bLinkPass == TRUE)) { + (pDevice->bLinkPass == true)) { BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0); } @@ -702,7 +702,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, // ----------------------------------------------- - if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){ + if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == true)){ BYTE abyMacHdr[24]; // Only 802.1x packet incoming allowed @@ -717,7 +717,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if (wEtherType == ETH_P_PAE) { skb->dev = pDevice->apdev; - if (bIsWEP == TRUE) { + if (bIsWEP == true) { // strip IV header(8) memcpy(&abyMacHdr[0], (skb->data + 8), 24); memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24); @@ -731,7 +731,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, skb->protocol = htons(ETH_P_802_2); memset(skb->cb, 0, sizeof(skb->cb)); netif_rx(skb); - return TRUE; + return true; } // check if 802.1x authorized @@ -790,7 +790,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) || - (pDevice->bRxMICFail == TRUE)) { + (pDevice->bRxMICFail == true)) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n"); pDevice->bRxMICFail = false; //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++; @@ -802,7 +802,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, } } //send event to wpa_supplicant - //if(pDevice->bWPASuppWextEnabled == TRUE) + //if(pDevice->bWPASuppWextEnabled == true) { union iwreq_data wrqu; struct iw_michaelmicfailure ev; @@ -921,7 +921,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB, return false; } - return TRUE; + return true; } static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, @@ -951,7 +951,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, &Status ); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n"); - return TRUE; + return true; } if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) { // send deassoc notification @@ -963,13 +963,13 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, &Status ); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n"); - return TRUE; + return true; } if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) { // delcare received ps-poll event if (IS_CTL_PSPOLL(pbyFrame)) { - pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; + pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true; bScheduleCommand((void *) pDevice, WLAN_CMD_RX_PSPOLL, NULL); @@ -980,7 +980,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, // if PW bit off, send out all PS bufferring packets. if (!IS_FC_POWERMGT(pbyFrame)) { pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false; - pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; + pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true; bScheduleCommand((void *) pDevice, WLAN_CMD_RX_PSPOLL, NULL); @@ -990,15 +990,15 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, } else { if (IS_FC_POWERMGT(pbyFrame)) { - pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE; + pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = true; // Once if STA in PS state, enable multicast bufferring - pMgmt->sNodeDBTable[0].bPSEnable = TRUE; + pMgmt->sNodeDBTable[0].bPSEnable = true; } else { // clear all pending PS frame. if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) { pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false; - pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; + pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true; bScheduleCommand((void *) pDevice, WLAN_CMD_RX_PSPOLL, NULL); @@ -1023,7 +1023,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n", p802_11Header->abyAddr1); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl ); - return TRUE; + return true; } } } @@ -1065,7 +1065,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, (pMgmt->byCSSPK != KEY_CTL_NONE)) { // unicast pkt use pairwise key DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n"); - if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) { + if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == true) { if (pMgmt->byCSSPK == KEY_CTL_TKIP) byDecMode = KEY_CTL_TKIP; else if (pMgmt->byCSSPK == KEY_CTL_CCMP) @@ -1099,7 +1099,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n"); if (byDecMode == KEY_CTL_WEP) { // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++; - } else if (pDevice->bLinkPass == TRUE) { + } else if (pDevice->bLinkPass == true) { // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; } return false; @@ -1107,7 +1107,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, if (byDecMode != pKey->byCipherSuite) { if (byDecMode == KEY_CTL_WEP) { // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++; - } else if (pDevice->bLinkPass == TRUE) { + } else if (pDevice->bLinkPass == true) { // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; } *pKeyOut = NULL; @@ -1116,7 +1116,7 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, if (byDecMode == KEY_CTL_WEP) { // handle WEP if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || - (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE)) { + (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true)) { // Software WEP // 1. 3253A // 2. WEP 256 @@ -1164,8 +1164,8 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, }// end of TKIP/AES if ((*(pbyIV+3) & 0x20) != 0) - *pbExtIV = TRUE; - return TRUE; + *pbExtIV = true; + return true; } static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, @@ -1203,7 +1203,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, if (byDecMode != pKey->byCipherSuite) { if (byDecMode == KEY_CTL_WEP) { // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++; - } else if (pDevice->bLinkPass == TRUE) { + } else if (pDevice->bLinkPass == true) { // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; } return false; @@ -1213,7 +1213,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, // handle WEP DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n"); if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || - (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE) || + (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true) || (bOnFly == false)) { // Software WEP // 1. 3253A @@ -1283,8 +1283,8 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame, }// end of TKIP/AES if ((*(pbyIV+3) & 0x20) != 0) - *pbExtIV = TRUE; - return TRUE; + *pbExtIV = true; + return true; } static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, @@ -1321,7 +1321,7 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, } } else { - bRelayAndForward = TRUE; + bRelayAndForward = true; } } else { @@ -1341,10 +1341,10 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n", iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]); - return TRUE; + return true; } else { - bRelayOnly = TRUE; + bRelayOnly = true; } } } @@ -1367,7 +1367,7 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb, if (pDevice->uAssocCount == 0) return false; - return TRUE; + return true; } @@ -1408,10 +1408,10 @@ void RXvFreeRCB(PRCB pRCB, int bReAllocSkb) if (bReAllocSkb == false) { kfree_skb(pRCB->skb); - bReAllocSkb = TRUE; + bReAllocSkb = true; } - if (bReAllocSkb == TRUE) { + if (bReAllocSkb == true) { pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); // todo error handling if (pRCB->skb == NULL) { @@ -1430,7 +1430,7 @@ void RXvFreeRCB(PRCB pRCB, int bReAllocSkb) if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) && (pDevice->bIsRxWorkItemQueued == false) ) { - pDevice->bIsRxWorkItemQueued = TRUE; + pDevice->bIsRxWorkItemQueued = true; tasklet_schedule(&pDevice->ReadWorkItem); } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList); diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c index d7f016d..4371a77 100644 --- a/drivers/staging/vt6656/firmware.c +++ b/drivers/staging/vt6656/firmware.c @@ -99,7 +99,7 @@ int FIRMWAREbDownload(struct vnt_private *pDevice) goto free_fw; } - result = TRUE; + result = true; free_fw: release_firmware(fw); @@ -128,7 +128,7 @@ int FIRMWAREbBrach2Sram(struct vnt_private *pDevice) if (NdisStatus != STATUS_SUCCESS) { return (false); } else { - return (TRUE); + return (true); } } @@ -159,5 +159,5 @@ int FIRMWAREbCheckVersion(struct vnt_private *pDevice) FIRMWAREbBrach2Sram(pDevice); return false; } - return TRUE; + return true; } diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c index cffe5cd..bc5e9da 100644 --- a/drivers/staging/vt6656/hostap.c +++ b/drivers/staging/vt6656/hostap.c @@ -455,7 +455,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, if (param->u.crypt.alg == WPA_ALG_NONE) { - if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) { + if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) { if (KeybRemoveKey( pDevice, &(pDevice->sKey), param->sta_addr, @@ -492,7 +492,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, dwKeyIndex = (DWORD)(param->u.crypt.idx); if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) { pDevice->byKeyIndex = (BYTE)dwKeyIndex; - pDevice->bTransmitKey = TRUE; + pDevice->bTransmitKey = true; dwKeyIndex |= (1 << 31); } @@ -517,19 +517,19 @@ static int hostap_set_encryption(struct vnt_private *pDevice, param->u.crypt.key_len, &KeyRSC, (PBYTE)abyKey, KEY_CTL_WEP - ) == TRUE) { + ) == true) { - pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; + pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true; } else { // Key Table Full pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; - bKeyTableFull = TRUE; + bKeyTableFull = true; } } pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; - pDevice->bEncryptionEnable = TRUE; + pDevice->bEncryptionEnable = true; pMgmt->byCSSPK = KEY_CTL_WEP; pMgmt->byCSSGK = KEY_CTL_WEP; pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP; @@ -575,7 +575,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, abyKey, byKeyDecMode ); - pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; + pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true; } else { dwKeyIndex |= (1 << 30); // set pairwise key @@ -587,20 +587,20 @@ static int hostap_set_encryption(struct vnt_private *pDevice, &KeyRSC, (PBYTE)abyKey, byKeyDecMode - ) == TRUE) { + ) == true) { - pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; + pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true; } else { // Key Table Full pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; - bKeyTableFull = TRUE; + bKeyTableFull = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n"); } } - if (bKeyTableFull == TRUE) { + if (bKeyTableFull == true) { wKeyCtl &= 0x7F00; // clear all key control filed wKeyCtl |= (byKeyDecMode << 4); wKeyCtl |= (byKeyDecMode); @@ -622,7 +622,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice, ); // set wep key - pDevice->bEncryptionEnable = TRUE; + pDevice->bEncryptionEnable = true; pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode; pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex; pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0; diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c index d309806..51990bd 100644 --- a/drivers/staging/vt6656/int.c +++ b/drivers/staging/vt6656/int.c @@ -82,7 +82,7 @@ void INTvWorkItem(struct vnt_private *pDevice) DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Interrupt Polling Thread\n"); spin_lock_irq(&pDevice->lock); - if (pDevice->fKillEventPollingThread != TRUE) + if (pDevice->fKillEventPollingThread != true) ntStatus = PIPEnsInterruptRead(pDevice); spin_unlock_irq(&pDevice->lock); } @@ -151,7 +151,7 @@ void INTnsProcessData(struct vnt_private *pDevice) /* check if multicast tx buffering */ pMgmt->byDTIMCount = pMgmt->byDTIMPeriod-1; - pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE; + pMgmt->sNodeDBTable[0].bRxPSPoll = true; if (pMgmt->sNodeDBTable[0].bPSEnable) bScheduleCommand((void *) pDevice, WLAN_CMD_RX_PSPOLL, @@ -161,7 +161,7 @@ void INTnsProcessData(struct vnt_private *pDevice) WLAN_CMD_BECON_SEND, NULL); } /* if (pDevice->eOPMode == OP_MODE_AP) */ - pDevice->bBeaconSent = TRUE; + pDevice->bBeaconSent = true; } else { pDevice->bBeaconSent = false; } diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c index e4a791f..69971f3 100644 --- a/drivers/staging/vt6656/iwctl.c +++ b/drivers/staging/vt6656/iwctl.c @@ -400,7 +400,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) { pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA; if (pDevice->flags & DEVICE_FLAGS_OPENED) - pDevice->bCommit = TRUE; + pDevice->bCommit = true; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n"); break; @@ -409,7 +409,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) { pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; if (pDevice->flags & DEVICE_FLAGS_OPENED) - pDevice->bCommit = TRUE; + pDevice->bCommit = true; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n"); break; @@ -422,7 +422,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, if (pMgmt->eConfigMode != WMAC_CONFIG_AP) { pMgmt->eConfigMode = WMAC_CONFIG_AP; if (pDevice->flags & DEVICE_FLAGS_OPENED) - pDevice->bCommit = TRUE; + pDevice->bCommit = true; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n"); break; @@ -672,7 +672,7 @@ int iwctl_siwap(struct net_device *dev, struct iw_request_info *info, } if (pDevice->flags & DEVICE_FLAGS_OPENED) - pDevice->bCommit = TRUE; + pDevice->bCommit = true; } return rc; } @@ -816,7 +816,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info, // Wext wil order another command of siwap to link // with desired AP, so here need not associate?? - if (pDevice->bWPASuppWextEnabled == TRUE) { + if (pDevice->bWPASuppWextEnabled == true) { /*******search if in hidden ssid mode ****/ PKnownBSS pCurr = NULL; BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; @@ -867,7 +867,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info, } if (pDevice->flags & DEVICE_FLAGS_OPENED) - pDevice->bCommit = TRUE; + pDevice->bCommit = true; return 0; } @@ -965,7 +965,7 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info, if (wrq->fixed != 0) { // Fixed mode // One rate, fixed - pDevice->bFixRate = TRUE; + pDevice->bFixRate = true; if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) { pDevice->uConnectionRate = 3; } else { @@ -1024,8 +1024,8 @@ int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info, brate = abySupportedRates[pDevice->wCurrentRate]; wrq->value = brate * 500000; // If more than one rate, set auto - if (pDevice->bFixRate == TRUE) - wrq->fixed = TRUE; + if (pDevice->bFixRate == true) + wrq->fixed = true; } return 0; @@ -1229,8 +1229,8 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, } pDevice->byKeyIndex = (BYTE)dwKeyIndex; pDevice->uKeyLength = wrq->length; - pDevice->bTransmitKey = TRUE; - pDevice->bEncryptionEnable = TRUE; + pDevice->bTransmitKey = true; + pDevice->bEncryptionEnable = true; pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; // Do we want to just set the transmit key index? @@ -1256,7 +1256,7 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, } if (wrq->flags & IW_ENCODE_RESTRICTED) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n"); - pMgmt->bShareKeyAlgorithm = TRUE; + pMgmt->bShareKeyAlgorithm = true; } if (wrq->flags & IW_ENCODE_OPEN) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n"); @@ -1423,7 +1423,7 @@ int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info, long ldBm; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS\n"); - if (pDevice->bLinkPass == TRUE) { + if (pDevice->bLinkPass == true) { RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm); wrq->value = ldBm; } else { @@ -1510,7 +1510,7 @@ int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info, if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM) pMgmt->bShareKeyAlgorithm = false; else if (wrq->value == IW_AUTH_ALG_SHARED_KEY) - pMgmt->bShareKeyAlgorithm = TRUE; + pMgmt->bShareKeyAlgorithm = true; break; case IW_AUTH_WPA_ENABLED: break; @@ -1697,28 +1697,28 @@ int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info, /****this method is so foolish,but there is no other way??? */ if (param->u.wpa_key.alg_name == WPA_ALG_NONE) { if (param->u.wpa_key.key_index ==0) { - pDevice->bwextstep0 = TRUE; + pDevice->bwextstep0 = true; } - if ((pDevice->bwextstep0 == TRUE) && (param->u.wpa_key.key_index == 1)) { + if ((pDevice->bwextstep0 == true) && (param->u.wpa_key.key_index == 1)) { pDevice->bwextstep0 = false; - pDevice->bwextstep1 = TRUE; + pDevice->bwextstep1 = true; } - if ((pDevice->bwextstep1 == TRUE) && (param->u.wpa_key.key_index == 2)) { + if ((pDevice->bwextstep1 == true) && (param->u.wpa_key.key_index == 2)) { pDevice->bwextstep1 = false; - pDevice->bwextstep2 = TRUE; + pDevice->bwextstep2 = true; } - if ((pDevice->bwextstep2 == TRUE) && (param->u.wpa_key.key_index == 3)) { + if ((pDevice->bwextstep2 == true) && (param->u.wpa_key.key_index == 3)) { pDevice->bwextstep2 = false; - pDevice->bwextstep3 = TRUE; + pDevice->bwextstep3 = true; } } - if (pDevice->bwextstep3 == TRUE) { + if (pDevice->bwextstep3 == true) { PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n"); pDevice->bwextstep0 = false; pDevice->bwextstep1 = false; pDevice->bwextstep2 = false; pDevice->bwextstep3 = false; - pDevice->bWPASuppWextEnabled = TRUE; + pDevice->bWPASuppWextEnabled = true; memset(pMgmt->abyDesireBSSID, 0xFF, 6); KeyvInitTable(pDevice, &pDevice->sKey); } @@ -1758,7 +1758,7 @@ int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info, switch (mlme->cmd){ case IW_MLME_DEAUTH: case IW_MLME_DISASSOC: - if (pDevice->bLinkPass == TRUE) { + if (pDevice->bLinkPass == true) { PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n"); bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL); diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c index fa22dde..416175e 100644 --- a/drivers/staging/vt6656/key.c +++ b/drivers/staging/vt6656/key.c @@ -68,7 +68,7 @@ static void s_vCheckKeyTableValid(struct vnt_private *pDevice, u8 pbyData[MAX_KEY_TABLE]; for (i=0;iKeyTable[i].bInUse == TRUE) && + if ((pTable->KeyTable[i].bInUse == true) && (pTable->KeyTable[i].PairwiseKey.bKeyValid == false) && (pTable->KeyTable[i].GroupKey[0].bKeyValid == false) && (pTable->KeyTable[i].GroupKey[1].bKeyValid == false) && @@ -158,7 +158,7 @@ void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable) * Out: * pKey - Key return * - * Return Value: TRUE if found otherwise false + * Return Value: true if found otherwise false * */ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, @@ -170,20 +170,20 @@ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, *pKey = NULL; for (i=0;iKeyTable[i].bInUse == TRUE) && + if ((pTable->KeyTable[i].bInUse == true) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { if (dwKeyIndex == 0xFFFFFFFF) { - if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) { + if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) { *pKey = &(pTable->KeyTable[i].PairwiseKey); - return (TRUE); + return (true); } else { return (false); } } else if (dwKeyIndex < MAX_GROUP_KEY) { - if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) { + if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) { *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]); - return (TRUE); + return (true); } else { return (false); @@ -212,7 +212,7 @@ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex, * Out: * none * - * Return Value: TRUE if success otherwise false + * Return Value: true if success otherwise false * */ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, @@ -233,7 +233,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, // found empty table j = i; } - if ((pTable->KeyTable[i].bInUse == TRUE) && + if ((pTable->KeyTable[i].bInUse == true) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { // found table already exist if ((dwKeyIndex & PAIRWISE_KEY) != 0) { @@ -261,7 +261,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, } pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly - pKey->bKeyValid = TRUE; + pKey->bKeyValid = true; pKey->uKeyLength = uKeyLength; pKey->dwKeyIndex = dwKeyIndex; pKey->byCipherSuite = byKeyDecMode; @@ -298,12 +298,12 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ", pKey->dwKeyIndex); - return (TRUE); + return (true); } } if (j < (MAX_KEY_TABLE-1)) { memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN); - pTable->KeyTable[j].bInUse = TRUE; + pTable->KeyTable[j].bInUse = true; if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key pKey = &(pTable->KeyTable[j].PairwiseKey); @@ -329,7 +329,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, } pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly - pKey->bKeyValid = TRUE; + pKey->bKeyValid = true; pKey->uKeyLength = uKeyLength; pKey->dwKeyIndex = dwKeyIndex; pKey->byCipherSuite = byKeyDecMode; @@ -365,7 +365,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ", pKey->dwKeyIndex); - return (TRUE); + return (true); } return (false); } @@ -382,7 +382,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise false + * Return Value: true if success otherwise false * */ @@ -398,7 +398,7 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, for (i=0;iKeyTable[i].PairwiseKey.bKeyValid = false; } - bReturnValue = TRUE; + bReturnValue = true; } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { for (i=0;iKeyTable[i].dwGTKeyIndex = 0; } } - bReturnValue = TRUE; + bReturnValue = true; } else { bReturnValue = false; @@ -416,12 +416,12 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, } else { for (i=0;iKeyTable[i].bInUse == TRUE) && + if ( (pTable->KeyTable[i].bInUse == true) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { if ((dwKeyIndex & PAIRWISE_KEY) != 0) { pTable->KeyTable[i].PairwiseKey.bKeyValid = false; - bReturnValue = TRUE; + bReturnValue = true; break; } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { @@ -430,16 +430,16 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, // remove Group transmit key pTable->KeyTable[i].dwGTKeyIndex = 0; } - bReturnValue = TRUE; + bReturnValue = true; break; } else { bReturnValue = false; break; } - } //pTable->KeyTable[i].bInUse == TRUE + } //pTable->KeyTable[i].bInUse == true } //for - bReturnValue = TRUE; + bReturnValue = true; } s_vCheckKeyTableValid(pDevice,pTable); @@ -459,7 +459,7 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise false + * Return Value: true if success otherwise false * */ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, @@ -468,7 +468,7 @@ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, int i, u; for (i=0;iKeyTable[i].bInUse == TRUE) && + if ((pTable->KeyTable[i].bInUse == true) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { pTable->KeyTable[i].PairwiseKey.bKeyValid = false; for (u = 0; u < MAX_GROUP_KEY; u++) @@ -476,7 +476,7 @@ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, pTable->KeyTable[i].dwGTKeyIndex = 0; s_vCheckKeyTableValid(pDevice, pTable); - return (TRUE); + return (true); } } return (false); @@ -491,7 +491,7 @@ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise false + * Return Value: true if success otherwise false * */ void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable, @@ -499,7 +499,7 @@ void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable, { if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { - if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) { + if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) { if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) { pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) { @@ -531,7 +531,7 @@ void KeyvRemoveAllWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable) * Out: * pKey - Key return * - * Return Value: TRUE if found otherwise false + * Return Value: true if found otherwise false * */ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, @@ -542,12 +542,12 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, *pKey = NULL; for (i = 0; i < MAX_KEY_TABLE; i++) { - if ((pTable->KeyTable[i].bInUse == TRUE) && + if ((pTable->KeyTable[i].bInUse == true) && !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { if (dwKeyType == PAIRWISE_KEY) { - if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) { + if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) { *pKey = &(pTable->KeyTable[i].PairwiseKey); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:"); @@ -558,7 +558,7 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); - return (TRUE); + return (true); } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == false\n"); @@ -570,7 +570,7 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n"); return false; } - if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) { + if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) { *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:"); @@ -582,7 +582,7 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %X\n", pTable->KeyTable[i].dwGTKeyIndex); - return (TRUE); + return (true); } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == false\n"); @@ -609,7 +609,7 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType, * Out: * none * - * Return Value: TRUE if found otherwise false + * Return Value: true if found otherwise false * */ int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) @@ -619,10 +619,10 @@ int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) *pKey = NULL; for (i=0;iKeyTable[i].bInUse == TRUE) && - (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) { + if ((pTable->KeyTable[i].bInUse == true) && + (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) { *pKey = &(pTable->KeyTable[i].PairwiseKey); - return (TRUE); + return (true); } } return (false); @@ -641,7 +641,7 @@ int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) * Out: * none * - * Return Value: TRUE if success otherwise false + * Return Value: true if success otherwise false * */ @@ -665,7 +665,7 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, if (uKeyLength > MAX_KEY_LEN) return false; - pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE; + pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true; for (ii = 0; ii < ETH_ALEN; ii++) pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF; @@ -689,13 +689,13 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, if ((uKeyLength == WLAN_WEP232_KEYLEN) && (byKeyDecMode == KEY_CTL_WEP)) { pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match - pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE; + pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true; } else { if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false) pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match } - pKey->bKeyValid = TRUE; + pKey->bKeyValid = true; pKey->uKeyLength = uKeyLength; pKey->dwKeyIndex = dwKeyIndex; pKey->byCipherSuite = byKeyDecMode; @@ -734,7 +734,7 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n", pKey->dwKeyIndex); - return (TRUE); + return (true); } @@ -751,7 +751,7 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable, * Out: * none * - * Return Value: TRUE if success otherwise false + * Return Value: true if success otherwise false * */ @@ -774,7 +774,7 @@ int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable, } for (i=0; i < MAX_KEY_TABLE-1; i++) { - if (pTable->KeyTable[i].bInUse == TRUE) { + if (pTable->KeyTable[i].bInUse == true) { // found table already exist // Group key pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); @@ -793,7 +793,7 @@ int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable, pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly - pKey->bKeyValid = TRUE; + pKey->bKeyValid = true; pKey->uKeyLength = uKeyLength; pKey->dwKeyIndex = dwKeyIndex; pKey->byCipherSuite = byKeyDecMode; @@ -828,7 +828,7 @@ int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable, //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0)); //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex)); - } // (pTable->KeyTable[i].bInUse == TRUE) + } // (pTable->KeyTable[i].bInUse == true) } - return (TRUE); + return (true); } diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index d2cc04f..d5f53e1 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -279,17 +279,17 @@ device_set_options(struct vnt_private *pDevice) { pDevice->b11hEnable = X80211h_MODE_DEF; pDevice->eOPMode = OP_MODE_DEF; pDevice->uConnectionRate = DATA_RATE_DEF; - if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE; + if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true; pDevice->byBBType = BBP_TYPE_DEF; pDevice->byPacketType = pDevice->byBBType; pDevice->byAutoFBCtrl = AUTO_FB_0; - pDevice->bUpdateBBVGA = TRUE; + pDevice->bUpdateBBVGA = true; pDevice->byFOETuning = 0; pDevice->byAutoPwrTunning = 0; pDevice->wCTSDuration = 0; pDevice->byPreambleType = 0; pDevice->bExistSWNetAddr = false; - /* pDevice->bDiversityRegCtlON = TRUE; */ + /* pDevice->bDiversityRegCtlON = true; */ pDevice->bDiversityRegCtlON = false; } @@ -345,7 +345,7 @@ static int device_init_registers(struct vnt_private *pDevice, ETH_ALEN); if ( !FIRMWAREbCheckVersion(pDevice) ) { - if (FIRMWAREbDownload(pDevice) == TRUE) { + if (FIRMWAREbDownload(pDevice) == true) { if (FIRMWAREbBrach2Sram(pDevice) == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n"); spin_unlock_irq(&pDevice->lock); @@ -412,7 +412,7 @@ static int device_init_registers(struct vnt_private *pDevice, /* do MACbSoftwareReset in MACvInitialize */ /* force CCK */ - pDevice->bCCK = TRUE; + pDevice->bCCK = true; pDevice->bProtectMode = false; /* only used in 11g type, sync with ERP IE */ pDevice->bNonERPPresent = false; @@ -470,7 +470,7 @@ static int device_init_registers(struct vnt_private *pDevice, byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA]; if (byAntenna & EEP_ANTINV) - pDevice->bTxRxAntInv = TRUE; + pDevice->bTxRxAntInv = true; else pDevice->bTxRxAntInv = false; @@ -484,13 +484,13 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->byTxAntennaMode = ANT_B; pDevice->dwTxAntennaSel = 1; pDevice->dwRxAntennaSel = 1; - if (pDevice->bTxRxAntInv == TRUE) + if (pDevice->bTxRxAntInv == true) pDevice->byRxAntennaMode = ANT_A; else pDevice->byRxAntennaMode = ANT_B; if (pDevice->bDiversityRegCtlON) - pDevice->bDiversityEnable = TRUE; + pDevice->bDiversityEnable = true; else pDevice->bDiversityEnable = false; } else { @@ -500,13 +500,13 @@ static int device_init_registers(struct vnt_private *pDevice, pDevice->dwRxAntennaSel = 0; if (byAntenna & EEP_ANTENNA_AUX) { pDevice->byTxAntennaMode = ANT_A; - if (pDevice->bTxRxAntInv == TRUE) + if (pDevice->bTxRxAntInv == true) pDevice->byRxAntennaMode = ANT_B; else pDevice->byRxAntennaMode = ANT_A; } else { pDevice->byTxAntennaMode = ANT_B; - if (pDevice->bTxRxAntInv == TRUE) + if (pDevice->bTxRxAntInv == true) pDevice->byRxAntennaMode = ANT_A; else pDevice->byRxAntennaMode = ANT_B; @@ -604,7 +604,7 @@ static int device_init_registers(struct vnt_private *pDevice, */ if (pDevice->byBBType == BB_TYPE_11A) { CARDbAddBasicRate(pDevice, RATE_6M); - pDevice->bShortSlotTime = TRUE; + pDevice->bShortSlotTime = true; } else { CARDbAddBasicRate(pDevice, RATE_1M); pDevice->bShortSlotTime = false; @@ -633,7 +633,7 @@ static int device_init_registers(struct vnt_private *pDevice, return false; } if ( (byTmp & GPIO3_DATA) == 0 ) { - pDevice->bHWRadioOff = TRUE; + pDevice->bHWRadioOff = true; MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); } else { MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); @@ -646,7 +646,7 @@ static int device_init_registers(struct vnt_private *pDevice, ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01); - if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { + if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) { CARDbRadioPowerOff(pDevice); } else { CARDbRadioPowerOn(pDevice); @@ -654,7 +654,7 @@ static int device_init_registers(struct vnt_private *pDevice, spin_unlock_irq(&pDevice->lock); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n"); - return TRUE; + return true; } #ifdef CONFIG_PM /* Minimal support for suspend and resume */ @@ -900,7 +900,7 @@ static bool device_alloc_bufs(struct vnt_private *pDevice) goto free_rx_tx; } - return TRUE; + return true; free_rx_tx: device_free_rx_bufs(pDevice); @@ -930,7 +930,7 @@ static bool device_init_defrag_cb(struct vnt_private *pDevice) } pDevice->cbDFCB = CB_MAX_RX_FRAG; pDevice->cbFreeDFCB = pDevice->cbDFCB; - return TRUE; + return true; free_frag: device_free_frag_bufs(pDevice); @@ -965,7 +965,7 @@ int device_alloc_frag_buf(struct vnt_private *pDevice, ASSERT(pDeF->skb); pDeF->skb->dev = pDevice->dev; - return TRUE; + return true; } @@ -1030,7 +1030,7 @@ static int device_open(struct net_device *dev) pDevice->int_interval = 100; /* max 100 microframes */ pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; - pDevice->bIsRxWorkItemQueued = TRUE; + pDevice->bIsRxWorkItemQueued = true; pDevice->fKillEventPollingThread = false; pDevice->bEventAvailable = false; @@ -1046,7 +1046,7 @@ static int device_open(struct net_device *dev) INTvWorkItem(pDevice); /* if WEP key already set by iwconfig but device not yet open */ - if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) { + if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) { spin_lock_irq(&pDevice->lock); KeybSetDefaultKey( pDevice, &(pDevice->sKey), @@ -1121,7 +1121,7 @@ static int device_close(struct net_device *dev) MP_SET_FLAG(pDevice, fMP_DISCONNECTED); MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES); MP_CLEAR_FLAG(pDevice, fMP_POST_READS); - pDevice->fKillEventPollingThread = TRUE; + pDevice->fKillEventPollingThread = true; del_timer(&pDevice->sTimerCommand); del_timer(&pMgmt->sTimerSecondCallback); @@ -1314,7 +1314,7 @@ static int Config_FileGetParameter(unsigned char *string, } memcpy(dest,tmp_p,strlen(tmp_p)); - return TRUE; + return true; } /* if read fails, return NULL, or return data pointer */ @@ -1390,7 +1390,7 @@ static int Read_config_file(struct vnt_private *pDevice) /* get zonetype */ { memset(tmpbuffer,0,sizeof(tmpbuffer)); - if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==TRUE) { + if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) { if(memcmp(tmpbuffer,"USA",3)==0) { pDevice->config_file.ZoneType=ZoneType_USA; } @@ -1409,12 +1409,12 @@ static int Read_config_file(struct vnt_private *pDevice) /* get other parameter */ { memset(tmpbuffer,0,sizeof(tmpbuffer)); - if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==TRUE) { + if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) { pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10); } memset(tmpbuffer,0,sizeof(tmpbuffer)); - if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==TRUE) { + if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) { pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10); } } diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c index 9f571507..527c259f 100644 --- a/drivers/staging/vt6656/power.c +++ b/drivers/staging/vt6656/power.c @@ -114,13 +114,13 @@ void PSvEnablePowerSaving(struct vnt_private *pDevice, u16 wListenInterval) pMgmt->wCountToWakeUp = 0; } - pDevice->bEnablePSMode = TRUE; + pDevice->bEnablePSMode = true; /* We don't send null pkt in ad hoc mode since beacon will handle this. */ if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) PSbSendNullPacket(pDevice); - pDevice->bPWBitOn = TRUE; + pDevice->bPWBitOn = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable...\n"); } @@ -160,7 +160,7 @@ void PSvDisablePowerSaving(struct vnt_private *pDevice) * Consider to power down when no more packets to tx or rx. * * Return Value: - * TRUE, if power down success + * true, if power down success * false, if fail */ @@ -175,7 +175,7 @@ int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, MAC_REG_PSCTL, &byData); if ((byData & PSCTL_PS) != 0) - return TRUE; + return true; if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { /* check if in TIM wake period */ @@ -201,12 +201,12 @@ int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA, } } - pDevice->bPSRxBeacon = TRUE; + pDevice->bPSRxBeacon = true; /* no Tx, no Rx isr, now go to Doze */ MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); - return TRUE; + return true; } /* @@ -302,7 +302,7 @@ int PSbSendNullPacket(struct vnt_private *pDevice) DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n"); return false; } - return TRUE; + return true; } /* @@ -330,7 +330,7 @@ int PSbIsNextTBTTWakeUp(struct vnt_private *pDevice) /* Turn on wake up to listen next beacon */ MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); pDevice->bPSRxBeacon = false; - bWakeUp = TRUE; + bWakeUp = true; } else if (!pDevice->bPSRxBeacon) { /* Listen until RxBeacon */ MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c index 48c7c6d..a415705 100644 --- a/drivers/staging/vt6656/rf.c +++ b/drivers/staging/vt6656/rf.c @@ -719,7 +719,7 @@ const u8 RFaby11aChannelIndex[200] = { * Out: * none * - * Return Value: TRUE if succeeded; false if failed. + * Return Value: true if succeeded; false if failed. * */ int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData) @@ -735,7 +735,7 @@ int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData) MESSAGE_TYPE_WRITE_IFRF, 0, 0, 4, pbyData); - return TRUE; + return true; } @@ -749,16 +749,16 @@ int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData) * Out: * none * - * Return Value: TRUE if succeeded; false if failed. + * Return Value: true if succeeded; false if failed. * */ int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH) { - int bResult = TRUE; + int bResult = true; u8 byPwr = pDevice->byCCKPwr; if (pDevice->dwDiagRefCount) - return TRUE; + return true; if (uCH == 0) return -EINVAL; @@ -801,16 +801,16 @@ int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH) * Out: * none * - * Return Value: TRUE if succeeded; false if failed. + * Return Value: true if succeeded; false if failed. * */ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE) { - int bResult = TRUE; + int bResult = true; if (pDevice->byCurPwr == byPwr) - return TRUE; + return true; pDevice->byCurPwr = byPwr; @@ -1125,7 +1125,7 @@ void RFbRFTableDownload(struct vnt_private *pDevice) int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *pDevice, u8 byChannel, int b11bMode) { - int bResult = TRUE; + int bResult = true; if (b11bMode) bResult &= IFRFbWriteEmbedded(pDevice, diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index ebda989..b939dcf 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -170,7 +170,7 @@ static void *s_vGetFreeContext(struct vnt_private *pDevice) for (ii = 0; ii < pDevice->cbTD; ii++) { pContext = pDevice->apTD[ii]; if (pContext->bBoolInUse == false) { - pContext->bBoolInUse = TRUE; + pContext->bBoolInUse = true; pReturnContext = pContext; break; } @@ -1111,7 +1111,7 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice, wFifoCtl = pFifoHead->wFIFOCtl; if (wFifoCtl & FIFOCTL_CRCDIS) { - bDisCRC = TRUE; + bDisCRC = true; } if (wFifoCtl & FIFOCTL_AUTO_FB_0) { @@ -1232,8 +1232,8 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; if (bNeedEncryption && pTransmitKey->pvKeyTable) { - if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == TRUE) - bSoftWEP = TRUE; /* WEP 256 */ + if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true) + bSoftWEP = true; /* WEP 256 */ } pTxBufHead = (PTX_BUFFER) usbPacketBuf; @@ -1266,13 +1266,13 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); } else { - bNeedACK = TRUE; + bNeedACK = true; pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; } } else { // MSDUs in Infra mode always need ACK - bNeedACK = TRUE; + bNeedACK = true; pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; } } //if (pDevice->dwDiagRefCount != 0) { @@ -1296,7 +1296,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10); //Set FIFOCTL_GrpAckPolicy - if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000 + if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; } @@ -1311,7 +1311,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, } } - if (bSoftWEP != TRUE) { + if (bSoftWEP != true) { if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; @@ -1354,7 +1354,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) { bRTS = false; } else { - bRTS = TRUE; + bRTS = true; pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY); } @@ -1362,7 +1362,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, wTxBufSize = sizeof(STxBufHead); if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet if (byFBOption == AUTO_FB_NONE) { - if (bRTS == TRUE) {//RTS_need + if (bRTS == true) {//RTS_need pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS)); pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR); @@ -1380,7 +1380,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, } } else { // Auto Fall Back - if (bRTS == TRUE) {//RTS_need + if (bRTS == true) {//RTS_need pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS)); pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR); @@ -1400,7 +1400,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, } else {//802.11a/b packet if (byFBOption == AUTO_FB_NONE) { - if (bRTS == TRUE) {//RTS_need + if (bRTS == true) {//RTS_need pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR); @@ -1418,7 +1418,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, } } else { // Auto Fall Back - if (bRTS == TRUE) {//RTS_need + if (bRTS == true) {//RTS_need pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR); @@ -1462,7 +1462,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption, byFragType, uDMAIdx, 0); - if (bNeedEncryption == TRUE) { + if (bNeedEncryption == true) { //Fill TXKEY s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey, pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR); @@ -1507,7 +1507,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, ASSERT(uLength == cbNdisBodySize); - if ((bNeedEncryption == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { + if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { /////////////////////////////////////////////////////////////////// @@ -1547,7 +1547,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, MIC_vGetMIC(pdwMIC_L, pdwMIC_R); MIC_vUnInit(); - if (pDevice->bTxMICFail == TRUE) { + if (pDevice->bTxMICFail == true) { *pdwMIC_L = 0; *pdwMIC_R = 0; pDevice->bTxMICFail = false; @@ -1558,17 +1558,17 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, } - if (bSoftWEP == TRUE) { + if (bSoftWEP == true) { s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen)); - } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == TRUE)) || - ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == TRUE)) || - ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == TRUE)) ) { + } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) || + ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) || + ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) { cbFrameSize -= cbICVlen; } - if (pDevice->bSoftwareGenCrcErr == TRUE) { + if (pDevice->bSoftwareGenCrcErr == true) { unsigned int cbLen; PDWORD pdwCRC; @@ -1593,7 +1593,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, pTxBufHead->wFragCtl |= (WORD)byFragType; - return TRUE; + return true; } @@ -1787,7 +1787,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, bNeedACK = false; } else { - bNeedACK = TRUE; + bNeedACK = true; pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; }; @@ -1807,7 +1807,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { - bIsPSPOLL = TRUE; + bIsPSPOLL = true; cbMacHdLen = WLAN_HDR_ADDR2_LEN; } else { cbMacHdLen = WLAN_HDR_ADDR3_LEN; @@ -1840,7 +1840,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, cbIVlen = 8;//RSN Header cbICVlen = 8;//MIC pTxBufHead->wFragCtl |= FRAGCTL_AES; - pDevice->bAES = TRUE; + pDevice->bAES = true; } //MAC Header should be padding 0 to DW alignment. uPadding = 4 - (cbMacHdLen%4); @@ -1850,7 +1850,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen; //Set FIFOCTL_GrpAckPolicy - if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000 + if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; } //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() @@ -1911,12 +1911,12 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); do { if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) && - (pDevice->bLinkPass == TRUE)) { + (pDevice->bLinkPass == true)) { pbyBSSID = pDevice->abyBSSID; // get pairwise key if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { // get group key - if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) { + if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); break; } @@ -2172,15 +2172,15 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) bNeedACK = false; if (pDevice->bEnableHostWEP) { uNodeIndex = 0; - bNodeExist = TRUE; + bNodeExist = true; } } else { if (pDevice->bEnableHostWEP) { if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex)) - bNodeExist = TRUE; + bNodeExist = true; } - bNeedACK = TRUE; + bNeedACK = true; pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; }; @@ -2201,7 +2201,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { - bIsPSPOLL = TRUE; + bIsPSPOLL = true; cbMacHdLen = WLAN_HDR_ADDR2_LEN; } else { cbMacHdLen = WLAN_HDR_ADDR3_LEN; @@ -2253,7 +2253,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) cbICVlen = 8;//MIC cbMICHDR = sizeof(SMICHDRHead); pTxBufHead->wFragCtl |= FRAGCTL_AES; - pDevice->bAES = TRUE; + pDevice->bAES = true; } //MAC Header should be padding 0 to DW alignment. uPadding = 4 - (cbMacHdLen%4); @@ -2263,7 +2263,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate; //Set FIFOCTL_GrpAckPolicy - if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000 + if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; } //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() @@ -2380,7 +2380,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) MIC_vGetMIC(pdwMIC_L, pdwMIC_R); MIC_vUnInit(); - if (pDevice->bTxMICFail == TRUE) { + if (pDevice->bTxMICFail == true) { *pdwMIC_L = 0; *pdwMIC_R = 0; pDevice->bTxMICFail = false; @@ -2498,7 +2498,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, if (is_multicast_ether_addr((PBYTE)(skb->data))) { uNodeIndex = 0; - bNodeExist = TRUE; + bNodeExist = true; if (pMgmt->sNodeDBTable[0].bPSEnable) { skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb); @@ -2543,7 +2543,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, }else { pDevice->byPreambleType = PREAMBLE_LONG; } - bNodeExist = TRUE; + bNodeExist = true; } } @@ -2579,22 +2579,22 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, /* 802.1x OR eapol-key challenge frame transfer */ if (((Protocol_Version == 1) || (Protocol_Version == 2)) && (Packet_Type == 3)) { - bTxeapol_key = TRUE; + bTxeapol_key = true; if(!(Key_info & BIT3) && //WPA or RSN group-key challenge (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key if(Descriptor_type==254) { - pDevice->fWPA_Authened = TRUE; + pDevice->fWPA_Authened = true; PRINT_K("WPA "); } else { - pDevice->fWPA_Authened = TRUE; + pDevice->fWPA_Authened = true; PRINT_K("WPA2(re-keying) "); } PRINT_K("Authentication completed!!\n"); } else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge (Key_info & BIT8) && (Key_info & BIT9)) { - pDevice->fWPA_Authened = TRUE; + pDevice->fWPA_Authened = true; PRINT_K("WPA2 Authentication completed!!\n"); } } @@ -2602,8 +2602,8 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, } //mike add:station mode check eapol-key challenge<--- - if (pDevice->bEncryptionEnable == TRUE) { - bNeedEncryption = TRUE; + if (pDevice->bEncryptionEnable == true) { + bNeedEncryption = true; // get Transmit key do { if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && @@ -2612,8 +2612,8 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, // get pairwise key if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { // get group key - if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) { - bTKIP_UseGTK = TRUE; + if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { + bTKIP_UseGTK = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); break; } @@ -2630,7 +2630,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n"); // get pairwise key - if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) + if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) break; } // get group key @@ -2643,7 +2643,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, else DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); } else { - bTKIP_UseGTK = TRUE; + bTKIP_UseGTK = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); } } while(false); @@ -2651,7 +2651,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, if (pDevice->bEnableHostWEP) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex); - if (pDevice->bEncryptionEnable == TRUE) { + if (pDevice->bEncryptionEnable == true) { pTransmitKey = &STempKey; pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; @@ -2750,7 +2750,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, byPktType = PK_TYPE_11B; } - if (bNeedEncryption == TRUE) { + if (bNeedEncryption == true) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType)); if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) { bNeedEncryption = false; @@ -2760,13 +2760,13 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n"); } else { - if (bTKIP_UseGTK == TRUE) { + if (bTKIP_UseGTK == true) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n"); } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", pTransmitKey->dwKeyIndex); - bNeedEncryption = TRUE; + bNeedEncryption = true; } } } @@ -2776,7 +2776,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", pTransmitKey->dwKeyIndex); - bNeedEncryption = TRUE; + bNeedEncryption = true; } } } @@ -2806,12 +2806,12 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, return STATUS_FAILURE; } - if ( pDevice->bEnablePSMode == TRUE ) { + if ( pDevice->bEnablePSMode == true ) { if ( !pDevice->bPSModeTxBurst ) { bScheduleCommand((void *) pDevice, WLAN_CMD_MAC_DISPOWERSAVING, NULL); - pDevice->bPSModeTxBurst = TRUE; + pDevice->bPSModeTxBurst = true; } } @@ -2827,7 +2827,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, status = PIPEnsSendBulkOut(pDevice,pContext); - if (bNeedDeAuth == TRUE) { + if (bNeedDeAuth == true) { WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE; bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason); @@ -2857,7 +2857,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice, * Out: * TURE, false * - * Return Value: Return TRUE if packet is copy to dma1; otherwise false + * Return Value: Return true if packet is copy to dma1; otherwise false */ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, @@ -2887,8 +2887,8 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN); - if (pDevice->bEncryptionEnable == TRUE) { - bNeedEncryption = TRUE; + if (pDevice->bEncryptionEnable == true) { + bNeedEncryption = true; // get group key pbyBSSID = pDevice->abyBroadcastAddr; if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { @@ -2981,6 +2981,6 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, status = PIPEnsSendBulkOut(pDevice,pContext); - return TRUE; + return true; } diff --git a/drivers/staging/vt6656/tether.c b/drivers/staging/vt6656/tether.c index c380733..95286c4 100644 --- a/drivers/staging/vt6656/tether.c +++ b/drivers/staging/vt6656/tether.c @@ -93,7 +93,7 @@ BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr) * Out: * none * - * Return Value: TRUE if ok; false if error. + * Return Value: true if ok; false if error. * */ bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) @@ -103,6 +103,6 @@ bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4); if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) return false; - return TRUE; + return true; } diff --git a/drivers/staging/vt6656/ttype.h b/drivers/staging/vt6656/ttype.h index 5f7cb50..d7b6489 100644 --- a/drivers/staging/vt6656/ttype.h +++ b/drivers/staging/vt6656/ttype.h @@ -33,10 +33,6 @@ /******* Common definitions and typedefs ***********************************/ -#if !defined(TRUE) -#define TRUE 1 -#endif - /****** Simple typedefs ***************************************************/ typedef u8 BYTE; diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c index 3550406..00fd0f8 100644 --- a/drivers/staging/vt6656/usbpipe.c +++ b/drivers/staging/vt6656/usbpipe.c @@ -311,10 +311,10 @@ int PIPEnsInterruptRead(struct vnt_private *pDevice) DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n"); - if(pDevice->intBuf.bInUse == TRUE){ + if(pDevice->intBuf.bInUse == true){ return (STATUS_FAILURE); } - pDevice->intBuf.bInUse = TRUE; + pDevice->intBuf.bInUse = true; // pDevice->bEventAvailable = false; pDevice->ulIntInPosted++; @@ -391,20 +391,20 @@ static void s_nsInterruptUsbIoCompleteRead(struct urb *urb) // if (ntStatus == STATUS_NOT_CONNECTED ) // { - pDevice->fKillEventPollingThread = TRUE; + pDevice->fKillEventPollingThread = true; // } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus ); } else { pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length; pDevice->ulIntInContCRCError = 0; - pDevice->bEventAvailable = TRUE; + pDevice->bEventAvailable = true; INTnsProcessData(pDevice); } STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus); - if (pDevice->fKillEventPollingThread != TRUE) { + if (pDevice->fKillEventPollingThread != true) { usb_fill_bulk_urb(pDevice->pInterruptURB, pDevice->usb, usb_rcvbulkpipe(pDevice->usb, 1), @@ -477,7 +477,7 @@ int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, PRCB pRCB) return STATUS_FAILURE ; } pRCB->Ref = 1; - pRCB->bBoolInUse= TRUE; + pRCB->bBoolInUse= true; return ntStatus; } @@ -528,7 +528,7 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) // } } else { if (bytesRead) - bIndicateReceive = TRUE; + bIndicateReceive = true; pDevice->ulBulkInContCRCError = 0; pDevice->ulBulkInBytesRead += bytesRead; @@ -540,8 +540,8 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb) if (bIndicateReceive) { spin_lock(&pDevice->lock); - if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == TRUE) - bReAllocSkb = TRUE; + if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == true) + bReAllocSkb = true; spin_unlock(&pDevice->lock); } pRCB->Ref--; @@ -715,7 +715,7 @@ static void s_nsBulkOutIoCompleteWrite(struct urb *urb) } } - if (pDevice->bLinkPass == TRUE) { + if (pDevice->bLinkPass == true) { if (netif_queue_stopped(pDevice->dev)) netif_wake_queue(pDevice->dev); } diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c index b4d2989..4bb652b 100644 --- a/drivers/staging/vt6656/wcmd.c +++ b/drivers/staging/vt6656/wcmd.c @@ -121,11 +121,11 @@ static void vAdHocBeaconStop(struct vnt_private *pDevice) if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) { - bStop = TRUE; + bStop = true; } if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G) { - bStop = TRUE; + bStop = true; } } @@ -319,7 +319,7 @@ void vRunCommand(struct vnt_private *pDevice) if (pDevice->dwDiagRefCount != 0) return; - if (pDevice->bCmdRunning != TRUE) + if (pDevice->bCmdRunning != true) return; spin_lock_irq(&pDevice->lock); @@ -329,7 +329,7 @@ void vRunCommand(struct vnt_private *pDevice) case WLAN_CMD_SCAN_START: pDevice->byReAssocCount = 0; - if (pDevice->bRadioOff == TRUE) { + if (pDevice->bRadioOff == true) { s_bCommandComplete(pDevice); spin_unlock_irq(&pDevice->lock); return; @@ -395,7 +395,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->bLinkPass); */ pMgmt->eScanState = WMAC_IS_SCANNING; pDevice->byScanBBType = pDevice->byBBType; //lucas - pDevice->bStopDataPkt = TRUE; + pDevice->bStopDataPkt = true; // Turn off RCR_BSSID filter every time MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID); pDevice->byRxMode &= ~RCR_BSSID; @@ -419,7 +419,7 @@ void vRunCommand(struct vnt_private *pDevice) if (pDevice->bUpdateBBVGA) { BBvSetShortSlotTime(pDevice); BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]); - BBvUpdatePreEDThreshold(pDevice, TRUE); + BBvUpdatePreEDThreshold(pDevice, true); } pMgmt->uScanChannel++; @@ -518,7 +518,7 @@ void vRunCommand(struct vnt_private *pDevice) // pDevice->bBeaconBufReady = false; } netif_stop_queue(pDevice->dev); - if (pDevice->bNeedRadioOFF == TRUE) + if (pDevice->bNeedRadioOFF == true) CARDbRadioPowerOff(pDevice); s_bCommandComplete(pDevice); break; @@ -527,7 +527,7 @@ void vRunCommand(struct vnt_private *pDevice) case WLAN_CMD_SSID_START: pDevice->byReAssocCount = 0; - if (pDevice->bRadioOff == TRUE) { + if (pDevice->bRadioOff == true) { s_bCommandComplete(pDevice); spin_unlock_irq(&pDevice->lock); return; @@ -597,9 +597,9 @@ void vRunCommand(struct vnt_private *pDevice) if (netif_queue_stopped(pDevice->dev)){ netif_wake_queue(pDevice->dev); } - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); - pMgmt->sNodeDBTable[0].bActive = TRUE; + pMgmt->sNodeDBTable[0].bActive = true; pMgmt->sNodeDBTable[0].uInActiveCount = 0; } else { @@ -630,7 +630,7 @@ void vRunCommand(struct vnt_private *pDevice) BSSvAddMulticastNode(pDevice); s_bClearBSSID_SCAN(pDevice); /* - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); if (netif_queue_stopped(pDevice->dev)){ netif_wake_queue(pDevice->dev); @@ -640,7 +640,7 @@ void vRunCommand(struct vnt_private *pDevice) } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n"); - // if(pDevice->bWPASuppWextEnabled == TRUE) + // if(pDevice->bWPASuppWextEnabled == true) { union iwreq_data wrqu; memset(&wrqu, 0, sizeof (wrqu)); @@ -698,7 +698,7 @@ void vRunCommand(struct vnt_private *pDevice) */ pDevice->byLinkWaitCount = 0; pDevice->byReAssocCount = 0; - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); s_bClearBSSID_SCAN(pDevice); @@ -719,7 +719,7 @@ void vRunCommand(struct vnt_private *pDevice) else { // printk("mike:-->First time trigger TimerTxData InSleep\n"); } - pDevice->IsTxDataTrigger = TRUE; + pDevice->IsTxDataTrigger = true; add_timer(&pDevice->sTimerTxData); } @@ -747,7 +747,7 @@ void vRunCommand(struct vnt_private *pDevice) pMgmt->eCurrMode = WMAC_MODE_STANDBY; pDevice->bLinkPass = false; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); - if (pDevice->bEnableHostWEP == TRUE) + if (pDevice->bEnableHostWEP == true) BSSvClearNodeDBTable(pDevice, 1); else BSSvClearNodeDBTable(pDevice, 0); @@ -768,7 +768,7 @@ void vRunCommand(struct vnt_private *pDevice) if (netif_queue_stopped(pDevice->dev)){ netif_wake_queue(pDevice->dev); } - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); add_timer(&pMgmt->sTimerSecondCallback); } @@ -784,7 +784,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->bMoreData = false; } else { - pDevice->bMoreData = TRUE; + pDevice->bMoreData = true; } if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) { @@ -809,7 +809,7 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->bMoreData = false; } else { - pDevice->bMoreData = TRUE; + pDevice->bMoreData = true; } if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) { @@ -838,7 +838,7 @@ void vRunCommand(struct vnt_private *pDevice) case WLAN_CMD_RADIO_START: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n"); - // if (pDevice->bRadioCmd == TRUE) + // if (pDevice->bRadioCmd == true) // CARDbRadioPowerOn(pDevice); // else // CARDbRadioPowerOff(pDevice); @@ -867,9 +867,9 @@ void vRunCommand(struct vnt_private *pDevice) pDevice->uCmdDequeueIdx = 0; pDevice->uCmdEnqueueIdx = 0; //0415pDevice->bCmdRunning = false; - pDevice->bCmdClear = TRUE; + pDevice->bCmdClear = true; pDevice->bStopTx0Pkt = false; - pDevice->bStopDataPkt = TRUE; + pDevice->bStopDataPkt = true; pDevice->byKeyIndex = 0; pDevice->bTransmitKey = false; @@ -879,7 +879,7 @@ void vRunCommand(struct vnt_private *pDevice) pMgmt->byCSSPK = KEY_CTL_NONE; pMgmt->byCSSGK = KEY_CTL_NONE; - if (pDevice->bLinkPass == TRUE) { + if (pDevice->bLinkPass == true) { // reason = 8 : disassoc because sta has left vMgrDisassocBeginSta((void *) pDevice, pMgmt, @@ -890,7 +890,7 @@ void vRunCommand(struct vnt_private *pDevice) // unlock command busy pMgmt->eCurrState = WMAC_STATE_IDLE; pMgmt->sNodeDBTable[0].bActive = false; - // if(pDevice->bWPASuppWextEnabled == TRUE) + // if(pDevice->bWPASuppWextEnabled == true) { union iwreq_data wrqu; memset(&wrqu, 0, sizeof (wrqu)); @@ -917,7 +917,7 @@ void vRunCommand(struct vnt_private *pDevice) CARDbRadioPowerOff(pDevice); MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF); - pDevice->bHWRadioOff = TRUE; + pDevice->bHWRadioOff = true; } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n"); pDevice->bHWRadioOff = false; @@ -933,7 +933,7 @@ void vRunCommand(struct vnt_private *pDevice) case WLAN_CMD_CHANGE_BBSENSITIVITY_START: - pDevice->bStopDataPkt = TRUE; + pDevice->bStopDataPkt = true; pDevice->byBBVGACurrent = pDevice->byBBVGANew; BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent); @@ -962,13 +962,13 @@ void vRunCommand(struct vnt_private *pDevice) DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel); if ( pDevice->dwRxAntennaSel == 0) { pDevice->dwRxAntennaSel=1; - if (pDevice->bTxRxAntInv == TRUE) + if (pDevice->bTxRxAntInv == true) BBvSetAntennaMode(pDevice, ANT_RXA); else BBvSetAntennaMode(pDevice, ANT_RXB); } else { pDevice->dwRxAntennaSel=0; - if (pDevice->bTxRxAntInv == TRUE) + if (pDevice->bTxRxAntInv == true) BBvSetAntennaMode(pDevice, ANT_RXB); else BBvSetAntennaMode(pDevice, ANT_RXA); @@ -1020,14 +1020,14 @@ static int s_bCommandComplete(struct vnt_private *pDevice) struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; PWLAN_IE_SSID pSSID; int bRadioCmd = false; - int bForceSCAN = TRUE; + int bForceSCAN = true; pDevice->eCommandState = WLAN_CMD_IDLE; if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) { //Command Queue Empty pDevice->bCmdRunning = false; - return TRUE; + return true; } else { pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd; @@ -1036,7 +1036,7 @@ static int s_bCommandComplete(struct vnt_private *pDevice) bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN; ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE); pDevice->cbFreeCmdQueue++; - pDevice->bCmdRunning = TRUE; + pDevice->bCmdRunning = true; switch ( pDevice->eCommand ) { case WLAN_CMD_BSSID_SCAN: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n"); @@ -1048,7 +1048,7 @@ static int s_bCommandComplete(struct vnt_private *pDevice) memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); } /* - if ((bForceSCAN == false) && (pDevice->bLinkPass == TRUE)) { + if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) { if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) && ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) { pDevice->eCommandState = WLAN_CMD_IDLE; @@ -1116,7 +1116,7 @@ static int s_bCommandComplete(struct vnt_private *pDevice) vCommandTimerWait(pDevice, 0); } - return TRUE; + return true; } int bScheduleCommand(struct vnt_private *pDevice, @@ -1127,7 +1127,7 @@ int bScheduleCommand(struct vnt_private *pDevice, return (false); } pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand; - pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE; + pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true; memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); if (pbyItem0 != NULL) { switch (eCommand) { @@ -1168,7 +1168,7 @@ int bScheduleCommand(struct vnt_private *pDevice, } else { } - return (TRUE); + return (true); } @@ -1183,7 +1183,7 @@ int bScheduleCommand(struct vnt_private *pDevice, * Out: * none * - * Return Value: TRUE if success; otherwise false + * Return Value: true if success; otherwise false * */ static int s_bClearBSSID_SCAN(struct vnt_private *pDevice) @@ -1200,7 +1200,7 @@ static int s_bClearBSSID_SCAN(struct vnt_private *pDevice) break; } } - return TRUE; + return true; } @@ -1239,11 +1239,11 @@ void BSSvSecondTxData(struct vnt_private *pDevice) spin_lock_irq(&pDevice->lock); //is wap_supplicant running successful OR only open && sharekey mode! - if (((pDevice->bLinkPass == TRUE) && + if (((pDevice->bLinkPass == true) && (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking - (pDevice->fWPA_Authened == TRUE)) { //wpa linking + (pDevice->fWPA_Authened == true)) { //wpa linking // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__); - pDevice->fTxDataInSleep = TRUE; + pDevice->fTxDataInSleep = true; PSbSendNullPacket(pDevice); //send null packet pDevice->fTxDataInSleep = false; } diff --git a/drivers/staging/vt6656/wctl.c b/drivers/staging/vt6656/wctl.c index a4a7f43..baa48a1 100644 --- a/drivers/staging/vt6656/wctl.c +++ b/drivers/staging/vt6656/wctl.c @@ -53,7 +53,7 @@ /* * Description: - * Scan Rx cache. Return TRUE if packet is duplicate, else + * Scan Rx cache. Return true if packet is duplicate, else * inserts in receive cache and returns false. * * Parameters: @@ -63,7 +63,7 @@ * Out: * none * - * Return Value: TRUE if packet duplicate; otherwise false + * Return Value: true if packet duplicate; otherwise false * */ @@ -84,7 +84,7 @@ bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader) (LOBYTE(pCacheEntry->wFrameCtl) == LOBYTE(pMACHeader->wFrameCtl)) ) { /* Duplicate match */ - return TRUE; + return true; } ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH); } @@ -119,7 +119,7 @@ unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice, unsigned int ii; for (ii = 0; ii < pDevice->cbDFCB; ii++) { - if ((pDevice->sRxDFCB[ii].bInUse == TRUE) && + if ((pDevice->sRxDFCB[ii].bInUse == true) && (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0])))) { return ii; @@ -153,7 +153,7 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, if (pDevice->sRxDFCB[ii].bInUse == false) { pDevice->cbFreeDFCB--; pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime; - pDevice->sRxDFCB[ii].bInUse = TRUE; + pDevice->sRxDFCB[ii].bInUse = true; pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4); pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F); memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), @@ -179,7 +179,7 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, * Out: * none * - * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise false + * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false * */ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, @@ -188,7 +188,7 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, unsigned int uHeaderSize; - if (bWEP == TRUE) { + if (bWEP == true) { uHeaderSize = 28; if (bExtIV) // ExtIV @@ -250,7 +250,7 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader, pDevice->cbFreeDFCB++; pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); - return(TRUE); + return(true); } return(false); } diff --git a/drivers/staging/vt6656/wmgr.c b/drivers/staging/vt6656/wmgr.c index 0d63595..5dced0a 100644 --- a/drivers/staging/vt6656/wmgr.c +++ b/drivers/staging/vt6656/wmgr.c @@ -291,7 +291,7 @@ void vMgrAssocBeginSta(struct vnt_private *pDevice, // ERP Phy (802.11g) should support short preamble. if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) { pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); - if (pDevice->bShortSlotTime == TRUE) + if (pDevice->bShortSlotTime == true) pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1); } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) { @@ -299,7 +299,7 @@ void vMgrAssocBeginSta(struct vnt_private *pDevice, pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); } } - if (pMgmt->b11hEnable == TRUE) + if (pMgmt->b11hEnable == true) pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1); // build an assocreq frame and send it @@ -363,7 +363,7 @@ void vMgrReAssocBeginSta(struct vnt_private *pDevice, // ERP Phy (802.11g) should support short preamble. if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) { pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); - if (pDevice->bShortSlotTime == TRUE) + if (pDevice->bShortSlotTime == true) pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1); } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) { @@ -371,7 +371,7 @@ void vMgrReAssocBeginSta(struct vnt_private *pDevice, pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); } } - if (pMgmt->b11hEnable == TRUE) + if (pMgmt->b11hEnable == true) pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1); @@ -505,7 +505,7 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice, pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo); pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval); pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = - WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : false; + WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false; // Todo: check sta basic rate, if ap can't support, set status code if (pDevice->byBBType == BB_TYPE_11B) { uRateLen = WLAN_RATES_MAXLEN_11B; @@ -548,15 +548,15 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice, wAssocAID = (WORD)uNodeIndex; // check if ERP support if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M) - pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE; + pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true; if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) { // B only STA join - pDevice->bProtectMode = TRUE; - pDevice->bNonERPPresent = TRUE; + pDevice->bProtectMode = true; + pDevice->bNonERPPresent = true; } if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) { - pDevice->bBarkerPreambleMd = TRUE; + pDevice->bBarkerPreambleMd = true; } DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID); @@ -651,7 +651,7 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice, pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo); pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval); pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = - WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : false; + WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false; // Todo: check sta basic rate, if ap can't support, set status code if (pDevice->byBBType == BB_TYPE_11B) { @@ -697,15 +697,15 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice, // if suppurt ERP if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M) - pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE; + pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true; if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) { // B only STA join - pDevice->bProtectMode = TRUE; - pDevice->bNonERPPresent = TRUE; + pDevice->bProtectMode = true; + pDevice->bNonERPPresent = true; } if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) { - pDevice->bBarkerPreambleMd = TRUE; + pDevice->bBarkerPreambleMd = true; } DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID); @@ -815,10 +815,10 @@ static void s_vMgrRxAssocResponse(struct vnt_private *pDevice, sFrame.pExtSuppRates); pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID); - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); - //if(pDevice->bWPASuppWextEnabled == TRUE) + //if(pDevice->bWPASuppWextEnabled == true) { BYTE buf[512]; size_t len; @@ -1121,7 +1121,7 @@ static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice, sFrame.pChallenge->len = WLAN_CHALLENGE_LEN; memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN); // get group key - if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == TRUE) { + if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) { rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3); rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN); } @@ -1416,7 +1416,7 @@ static void s_vMgrRxDisassociation(struct vnt_private *pDevice, } } - // if(pDevice->bWPASuppWextEnabled == TRUE) + // if(pDevice->bWPASuppWextEnabled == true) { union iwreq_data wrqu; memset(&wrqu, 0, sizeof (wrqu)); @@ -1482,7 +1482,7 @@ static void s_vMgrRxDeauthentication(struct vnt_private *pDevice, } } - // if(pDevice->bWPASuppWextEnabled == TRUE) + // if(pDevice->bWPASuppWextEnabled == true) { union iwreq_data wrqu; memset(&wrqu, 0, sizeof (wrqu)); @@ -1516,12 +1516,12 @@ static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel) switch(pDevice->byZoneType) { case 0x00: //USA:1~11 if((byCurrChannel<1) ||(byCurrChannel>11)) - exceed = TRUE; + exceed = true; break; case 0x01: //Japan:1~13 case 0x02: //Europe:1~13 if((byCurrChannel<1) ||(byCurrChannel>13)) - exceed = TRUE; + exceed = true; break; default: //reserve for other zonetype break; @@ -1594,28 +1594,28 @@ static void s_vMgrRxBeacon(struct vnt_private *pDevice, { if (sFrame.pDSParms != NULL) { if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]) - bChannelHit = TRUE; + bChannelHit = true; byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]; } else { - bChannelHit = TRUE; + bChannelHit = true; } } else { if (sFrame.pDSParms != NULL) { if (byCurrChannel == sFrame.pDSParms->byCurrChannel) - bChannelHit = TRUE; + bChannelHit = true; byCurrChannel = sFrame.pDSParms->byCurrChannel; } else { - bChannelHit = TRUE; + bChannelHit = true; } } -if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) +if(ChannelExceedZoneType(pDevice,byCurrChannel)==true) return; if (sFrame.pERP != NULL) { sERP.byERP = sFrame.pERP->byContext; - sERP.bERPExist = TRUE; + sERP.bERPExist = true; } else { sERP.bERPExist = false; @@ -1673,7 +1673,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) } if(byCurrChannel == (BYTE)pMgmt->uCurrChannel) - bIsChannelEqual = TRUE; + bIsChannelEqual = true; if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) { @@ -1702,7 +1702,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) pMgmt->abyCurrBSSID, WLAN_BSSID_LEN) == 0) { - bIsBSSIDEqual = TRUE; + bIsBSSIDEqual = true; pDevice->uCurrRSSI = pRxPacket->uRSSI; pDevice->byCurrSQ = pRxPacket->bySQ; if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) { @@ -1716,22 +1716,22 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, sFrame.pSSID->len ) == 0) { - bIsSSIDEqual = TRUE; + bIsSSIDEqual = true; } } - if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== TRUE) && - (bIsBSSIDEqual == TRUE) && - (bIsSSIDEqual == TRUE) && + if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) && + (bIsBSSIDEqual == true) && + (bIsSSIDEqual == true) && (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { // add state check to prevent reconnect fail since we'll receive Beacon - bIsAPBeacon = TRUE; + bIsAPBeacon = true; if (pBSSList != NULL) { // Sync ERP field - if ((pBSSList->sERP.bERPExist == TRUE) && (pDevice->byBBType == BB_TYPE_11G)) { + if ((pBSSList->sERP.bERPExist == true) && (pDevice->byBBType == BB_TYPE_11G)) { if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010 pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION); if (pDevice->bProtectMode) { @@ -1762,7 +1762,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime)); //Kyle check if it is OK to set G. if (pDevice->byBBType == BB_TYPE_11A) { - bShortSlotTime = TRUE; + bShortSlotTime = true; } else if (pDevice->byBBType == BB_TYPE_11B) { bShortSlotTime = false; @@ -1801,7 +1801,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, - TRUE, + true, &(pMgmt->sNodeDBTable[0].wMaxBasicRate), &(pMgmt->sNodeDBTable[0].wMaxSuppRate), &(pMgmt->sNodeDBTable[0].wSuppRate), @@ -1825,7 +1825,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) // check if beacon TSF larger or small than our local TSF if (qwTimestamp >= qwLocalTSF) - bTSFOffsetPostive = TRUE; + bTSFOffsetPostive = true; else bTSFOffsetPostive = false; @@ -1837,20 +1837,20 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) } if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE) - bTSFLargeDiff = TRUE; + bTSFLargeDiff = true; // if infra mode - if (bIsAPBeacon == TRUE) { + if (bIsAPBeacon == true) { // Infra mode: Local TSF always follow AP's TSF if Difference huge. if (bTSFLargeDiff) - bUpdateTSF = TRUE; + bUpdateTSF = true; - if ((pDevice->bEnablePSMode == TRUE) && (sFrame.pTIM)) { + if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM)) { /* deal with DTIM, analysis TIM */ - pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? TRUE : false ; + pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ; pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount; pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod; wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15); @@ -1865,7 +1865,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250] if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) { byTIMBitOn = (0x01) << ((wAIDNumber) % 8); - pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? TRUE : false; + pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false; } else { pMgmt->bInTIM = false; @@ -1877,7 +1877,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) if (pMgmt->bInTIM || (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) { - pMgmt->bInTIMWake = TRUE; + pMgmt->bInTIMWake = true; /* send out ps-poll packet */ if (pMgmt->bInTIM) PSvSendPSPOLL(pDevice); @@ -1889,7 +1889,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) if (pDevice->bPWBitOn == false) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n"); if (PSbSendNullPacket(pDevice)) - pDevice->bPWBitOn = TRUE; + pDevice->bPWBitOn = true; } if(PSbConsiderPowerDown(pDevice, false, false)) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n"); @@ -1909,7 +1909,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) // adhoc mode:TSF updated only when beacon larger then local TSF if (bTSFLargeDiff && bTSFOffsetPostive && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) - bUpdateTSF = TRUE; + bUpdateTSF = true; // During dpc, already in spinlocked. if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) { @@ -1922,7 +1922,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, NULL, - TRUE, + true, &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), @@ -1943,7 +1943,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, NULL, - TRUE, + true, &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), @@ -1957,7 +1957,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) /* pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo); if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M) - pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE; + pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true; */ } @@ -1965,12 +1965,12 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) if (pMgmt->eCurrState == WMAC_STATE_STARTED) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n"); pMgmt->eCurrState = WMAC_STATE_JOINTED; - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); if (netif_queue_stopped(pDevice->dev)){ netif_wake_queue(pDevice->dev); } - pMgmt->sNodeDBTable[0].bActive = TRUE; + pMgmt->sNodeDBTable[0].bActive = true; pMgmt->sNodeDBTable[0].uInActiveCount = 0; } @@ -2152,14 +2152,14 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus) RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, - (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, TRUE, + (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, &byTopCCKBasicRate, &byTopOFDMBasicRate); if (pDevice->byBBType == BB_TYPE_11A) { - pDevice->bShortSlotTime = TRUE; + pDevice->bShortSlotTime = true; } else { pDevice->bShortSlotTime = false; } @@ -2232,7 +2232,7 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus) MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID); pDevice->byRxMode |= RCR_BSSID; - pMgmt->bCurrBSSIDFilterOn = TRUE; + pMgmt->bCurrBSSIDFilterOn = true; // Set Capability Info pMgmt->wCurrCapInfo = 0; @@ -2315,7 +2315,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) for (ii = 0; ii < MAX_BSS_NUM; ii++) { - if (pMgmt->sBSSList[ii].bActive == TRUE) + if (pMgmt->sBSSList[ii].bActive == true) break; } @@ -2366,7 +2366,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) */ } - //if(pDevice->bWPASuppWextEnabled == TRUE) + //if(pDevice->bWPASuppWextEnabled == true) Encyption_Rebuild(pDevice, pCurr); // Infrastructure BSS @@ -2422,7 +2422,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) } } - RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, TRUE, + RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, &byTopCCKBasicRate, &byTopOFDMBasicRate); vUpdateIFS(pDevice); @@ -2497,7 +2497,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) //DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo)); if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) { if (pDevice->byBBType == BB_TYPE_11A) { - bShortSlotTime = TRUE; + bShortSlotTime = true; } else if (pDevice->byBBType == BB_TYPE_11B) { bShortSlotTime = false; @@ -2568,7 +2568,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) // set basic rate RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, - NULL, TRUE, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, + NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, &byTopCCKBasicRate, &byTopOFDMBasicRate); vUpdateIFS(pDevice); pMgmt->wCurrCapInfo = pCurr->wCapInfo; @@ -2581,7 +2581,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus) pMgmt->eCurrState = WMAC_STATE_STARTED; // Adopt BSS state in Adapter Device Object pDevice->eOPMode = OP_MODE_ADHOC; - pDevice->bLinkPass = TRUE; + pDevice->bLinkPass = true; ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN); @@ -2654,7 +2654,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, } // Init the BSS informations - pDevice->bCCK = TRUE; + pDevice->bCCK = true; pDevice->bProtectMode = false; MACvDisableProtectMD(pDevice); pDevice->bBarkerPreambleMd = false; @@ -2689,7 +2689,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) { pDevice->byBBType = BB_TYPE_11A; pMgmt->eCurrentPHYMode = PHY_TYPE_11A; - pDevice->bShortSlotTime = TRUE; + pDevice->bShortSlotTime = true; BBvSetShortSlotTime(pDevice); CARDvSetBSSMode(pDevice); } else { @@ -2712,7 +2712,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) { pDevice->byBBType = BB_TYPE_11G; pMgmt->eCurrentPHYMode = PHY_TYPE_11G; - pDevice->bShortSlotTime = TRUE; + pDevice->bShortSlotTime = true; BBvSetShortSlotTime(pDevice); CARDvSetBSSMode(pDevice); } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) { @@ -2729,7 +2729,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC); MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID); pDevice->byRxMode |= RCR_BSSID; - pMgmt->bCurrBSSIDFilterOn = TRUE; + pMgmt->bCurrBSSIDFilterOn = true; } // set channel and clear NAV @@ -2753,7 +2753,7 @@ static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode, MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC); MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID); pDevice->byRxMode |= RCR_BSSID; - pMgmt->bCurrBSSIDFilterOn = TRUE; + pMgmt->bCurrBSSIDFilterOn = true; } if (pDevice->byBBType == BB_TYPE_11A) { @@ -2779,7 +2779,7 @@ static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr) if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { - if (pCurr->bWPAValid == TRUE) { /*WPA-PSK */ + if (pCurr->bWPAValid == true) { /*WPA-PSK */ pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK; if(pCurr->abyPKType[0] == WPA_TKIP) { pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP @@ -2790,7 +2790,7 @@ static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr) PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n"); } } - else if(pCurr->bWPA2Valid == TRUE) { //WPA2-PSK + else if(pCurr->bWPA2Valid == true) { //WPA2-PSK pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK; if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) { pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP @@ -2836,13 +2836,13 @@ static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM) // Mask out the broadcast bit which is indicated separately. bMulticast = (byMap & byMask[0]) != 0; if(bMulticast) { - pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE; + pMgmt->sNodeDBTable[0].bRxPSPoll = true; } byMap = 0; } if (byMap) { if (!bStartFound) { - bStartFound = TRUE; + bStartFound = true; wStartIndex = (WORD)ii; } wEndIndex = (WORD)ii; @@ -3005,11 +3005,11 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice, sFrame.pERP->byElementID = WLAN_EID_ERP; sFrame.pERP->len = 1; sFrame.pERP->byContext = 0; - if (pDevice->bProtectMode == TRUE) + if (pDevice->bProtectMode == true) sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION; - if (pDevice->bNonERPPresent == TRUE) + if (pDevice->bNonERPPresent == true) sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT; - if (pDevice->bBarkerPreambleMd == TRUE) + if (pDevice->bBarkerPreambleMd == true) sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE; } if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) { @@ -3021,7 +3021,7 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice, ); } // hostapd wpa/wpa2 IE - if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == TRUE)) { + if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) { if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) { if (pMgmt->wWPAIELen != 0) { sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len); @@ -3131,11 +3131,11 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice, sFrame.pERP->byElementID = WLAN_EID_ERP; sFrame.pERP->len = 1; sFrame.pERP->byContext = 0; - if (pDevice->bProtectMode == TRUE) + if (pDevice->bProtectMode == true) sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION; - if (pDevice->bNonERPPresent == TRUE) + if (pDevice->bNonERPPresent == true) sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT; - if (pDevice->bBarkerPreambleMd == TRUE) + if (pDevice->bBarkerPreambleMd == true) sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE; } @@ -3149,7 +3149,7 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice, } // hostapd wpa/wpa2 IE - if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == TRUE)) { + if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) { if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) { if (pMgmt->wWPAIELen != 0) { sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len); @@ -3376,7 +3376,7 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice, sFrame.pRSN->len +=6; // RSN Capabilites - if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) { + if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) { memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2); } else { sFrame.pRSN->abyRSN[16] = 0; @@ -3384,7 +3384,7 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice, } sFrame.pRSN->len +=2; - if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == TRUE) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { + if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { // RSN PMKID pbyRSN = &sFrame.pRSN->abyRSN[18]; pwPMKID = (PWORD)pbyRSN; // Point to PMKID count @@ -3632,7 +3632,7 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice, sFrame.pRSN->len +=6; // RSN Capabilites - if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) { + if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) { memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2); } else { sFrame.pRSN->abyRSN[16] = 0; @@ -3640,7 +3640,7 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice, } sFrame.pRSN->len +=2; - if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == TRUE) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { + if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { // RSN PMKID pbyRSN = &sFrame.pRSN->abyRSN[18]; pwPMKID = (PWORD)pbyRSN; // Point to PMKID count @@ -3833,7 +3833,7 @@ static void s_vMgrRxProbeResponse(struct vnt_private *pDevice, WLAN_FR_PROBERESP sFrame; u8 byCurrChannel = pRxPacket->byRxChannel; ERPObject sERP; - int bChannelHit = TRUE; + int bChannelHit = true; memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP)); @@ -3864,29 +3864,29 @@ static void s_vMgrRxProbeResponse(struct vnt_private *pDevice, if (sFrame.pDSParms) { if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]) - bChannelHit = TRUE; + bChannelHit = true; byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]; } else { - bChannelHit = TRUE; + bChannelHit = true; } } else { if (sFrame.pDSParms) { if (byCurrChannel == sFrame.pDSParms->byCurrChannel) - bChannelHit = TRUE; + bChannelHit = true; byCurrChannel = sFrame.pDSParms->byCurrChannel; } else { - bChannelHit = TRUE; + bChannelHit = true; } } //RobertYu:20050201 -if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) +if(ChannelExceedZoneType(pDevice,byCurrChannel)==true) return; if (sFrame.pERP) { sERP.byERP = sFrame.pERP->byContext; - sERP.bERPExist = TRUE; + sERP.bERPExist = true; } else { sERP.bERPExist = false; sERP.byERP = 0; @@ -4100,7 +4100,7 @@ void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, case WLAN_FSTYPE_REASSOCRESP: // Frame Clase = 2 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n"); - s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, TRUE); + s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true); break; case WLAN_FSTYPE_PROBEREQ: @@ -4120,7 +4120,7 @@ void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, // Frame Clase = 0 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n"); if (pMgmt->eScanState != WMAC_NO_SCANNING) { - bInScan = TRUE; + bInScan = true; } s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan); break; @@ -4175,7 +4175,7 @@ void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt, * Prepare beacon to send * * Return Value: - * TRUE if success; false if failed. + * true if success; false if failed. * -*/ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, @@ -4211,7 +4211,7 @@ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice, csBeacon_xmit(pDevice, pTxPacket); MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX); - return TRUE; + return true; } @@ -4314,7 +4314,7 @@ int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID, for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) { pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii]; if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) { - if ((psRSNCapObj->bRSNCapExist == TRUE) + if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) { pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED; @@ -4322,13 +4322,13 @@ int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID, pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED); } - return TRUE; + return true; } } // New Candidate pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates]; - if ((psRSNCapObj->bRSNCapExist == TRUE) && (psRSNCapObj->wRSNCap & BIT0)) { + if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) { pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED; } else { pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED); @@ -4336,7 +4336,7 @@ int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID, memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN); pDevice->gsPMKIDCandidate.NumCandidates++; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); - return TRUE; + return true; } /* @@ -4387,7 +4387,7 @@ s_bCipherMatch ( } if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) && - (pBSSNode->bWPA2Valid == TRUE) && + (pBSSNode->bWPA2Valid == true) && ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) { @@ -4422,7 +4422,7 @@ s_bCipherMatch ( } } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) && - (pBSSNode->bWPAValid == TRUE) && + (pBSSNode->bWPAValid == true) && ((EncStatus == Ndis802_11Encryption2Enabled) || (EncStatus == Ndis802_11Encryption3Enabled))) { //WPA // check Group Key Cipher @@ -4464,7 +4464,7 @@ s_bCipherMatch ( (byCipherMask == 0)) { *pbyCCSGK = KEY_CTL_WEP; *pbyCCSPK = KEY_CTL_NONE; - return TRUE; + return true; } else { return false; } @@ -4474,17 +4474,17 @@ s_bCipherMatch ( (byCipherMask == 0)) { *pbyCCSGK = KEY_CTL_TKIP; *pbyCCSPK = KEY_CTL_NONE; - return TRUE; + return true; } else if ((byMulticastCipher == KEY_CTL_WEP) && ((byCipherMask & 0x02) != 0)) { *pbyCCSGK = KEY_CTL_WEP; *pbyCCSPK = KEY_CTL_TKIP; - return TRUE; + return true; } else if ((byMulticastCipher == KEY_CTL_TKIP) && ((byCipherMask & 0x02) != 0)) { *pbyCCSGK = KEY_CTL_TKIP; *pbyCCSPK = KEY_CTL_TKIP; - return TRUE; + return true; } else { return false; } @@ -4497,22 +4497,22 @@ s_bCipherMatch ( ((byCipherMask & 0x04) != 0)) { *pbyCCSGK = KEY_CTL_WEP; *pbyCCSPK = KEY_CTL_CCMP; - return TRUE; + return true; } else if ((byMulticastCipher == KEY_CTL_TKIP) && ((byCipherMask & 0x04) != 0)) { *pbyCCSGK = KEY_CTL_TKIP; *pbyCCSPK = KEY_CTL_CCMP; - return TRUE; + return true; } else if ((byMulticastCipher == KEY_CTL_CCMP) && ((byCipherMask & 0x04) != 0)) { *pbyCCSGK = KEY_CTL_CCMP; *pbyCCSPK = KEY_CTL_CCMP; - return TRUE; + return true; } else { return false; } } - return TRUE; + return true; } diff --git a/drivers/staging/vt6656/wpa.c b/drivers/staging/vt6656/wpa.c index 568a6f4..f037be3 100644 --- a/drivers/staging/vt6656/wpa.c +++ b/drivers/staging/vt6656/wpa.c @@ -212,14 +212,14 @@ WPA_ParseRSN( pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI; pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG; pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS); - pBSSList->sRSNCapObj.bRSNCapExist = TRUE; + pBSSList->sRSNCapObj.bRSNCapExist = true; pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps; //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps)); //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK)); //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx)); } } - pBSSList->bWPAValid = TRUE; + pBSSList->bWPAValid = true; } } @@ -272,7 +272,7 @@ WPA_SearchRSN( if (byEncrypt != byPKType) return false; } - return TRUE; + return true; // if (pBSSList->wAuthCount > 0) // for (ii=0; ii < pBSSList->wAuthCount; ii ++) // if (byAuth == pBSSList->abyAuthType[ii]) @@ -310,7 +310,7 @@ WPAb_Is_RSN( if ((pRSN->len >= 6) && // oui1(4)+ver(2) (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) && (pRSN->wVersion == 1)) { - return TRUE; + return true; } else return false; diff --git a/drivers/staging/vt6656/wpa2.c b/drivers/staging/vt6656/wpa2.c index 04d5cbb..a89456a 100644 --- a/drivers/staging/vt6656/wpa2.c +++ b/drivers/staging/vt6656/wpa2.c @@ -123,7 +123,7 @@ WPA2vParseRSN ( if (pRSN->len == 2) { // ver(2) if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) { - pBSSNode->bWPA2Valid = TRUE; + pBSSNode->bWPA2Valid = true; } return; } @@ -158,7 +158,7 @@ WPA2vParseRSN ( DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK); if (pRSN->len == 6) { - pBSSNode->bWPA2Valid = TRUE; + pBSSNode->bWPA2Valid = true; return; } @@ -172,7 +172,7 @@ WPA2vParseRSN ( if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i) if ( !memcmp(pbyOUI, abyOUIGK, 4)) { pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP; - bUseGK = TRUE; + bUseGK = true; } else if ( !memcmp(pbyOUI, abyOUIWEP40, 4)) { // Invalid CSS, continue parsing } else if ( !memcmp(pbyOUI, abyOUITKIP, 4)) { @@ -194,7 +194,7 @@ WPA2vParseRSN ( break; } //for - if (bUseGK == TRUE) { + if (bUseGK == true) { if (j != 1) { // invalid CSS, This should be only PK CSS. return; @@ -236,12 +236,12 @@ WPA2vParseRSN ( n = *((PWORD) &(pRSN->abyRSN[6+4*m])); if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2) - pBSSNode->sRSNCapObj.bRSNCapExist = TRUE; + pBSSNode->sRSNCapObj.bRSNCapExist = true; pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n])); } } //ignore PMKID lists bcs only (Re)Assocrequest has this field - pBSSNode->bWPA2Valid = TRUE; + pBSSNode->bWPA2Valid = true; } } @@ -325,7 +325,7 @@ unsigned int WPA2uSetIEs(void *pMgmtHandle, PWLAN_IE_RSN pRSNIEs) pRSNIEs->len +=6; // RSN Capabilites - if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) { + if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) { memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2); } else { pRSNIEs->abyRSN[16] = 0; @@ -334,7 +334,7 @@ unsigned int WPA2uSetIEs(void *pMgmtHandle, PWLAN_IE_RSN pRSNIEs) pRSNIEs->len +=2; if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) && - (pMgmt->bRoaming == TRUE) && + (pMgmt->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { /* RSN PMKID, pointer to PMKID count */ pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]); diff --git a/drivers/staging/vt6656/wpactl.c b/drivers/staging/vt6656/wpactl.c index de4a76a..53629b2 100644 --- a/drivers/staging/vt6656/wpactl.c +++ b/drivers/staging/vt6656/wpactl.c @@ -109,7 +109,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) } else { if (param->u.wpa_key.set_tx) { pDevice->byKeyIndex = (BYTE)dwKeyIndex; - pDevice->bTransmitKey = TRUE; + pDevice->bTransmitKey = true; dwKeyIndex |= (1 << 31); } KeybSetDefaultKey( pDevice, @@ -123,7 +123,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) } pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; - pDevice->bEncryptionEnable = TRUE; + pDevice->bEncryptionEnable = true; return ret; } @@ -206,7 +206,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) &KeyRSC, (PBYTE)abyKey, byKeyDecMode - ) == TRUE) && + ) == true) && (KeybSetDefaultKey(pDevice, &(pDevice->sKey), dwKeyIndex, @@ -214,7 +214,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) &KeyRSC, (PBYTE)abyKey, byKeyDecMode - ) == TRUE) ) { + ) == true) ) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n"); } else { return -EINVAL; @@ -235,7 +235,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) if (KeybSetKey(pDevice, &(pDevice->sKey), ¶m->addr[0], dwKeyIndex, param->u.wpa_key.key_len, &KeyRSC, (PBYTE)abyKey, byKeyDecMode - ) == TRUE) { + ) == true) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n"); } else { // Key Table Full @@ -251,9 +251,9 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx) } // BSSID not 0xffffffffffff if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) { pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index; - pDevice->bTransmitKey = TRUE; + pDevice->bTransmitKey = true; } - pDevice->bEncryptionEnable = TRUE; + pDevice->bEncryptionEnable = true; return ret; } -- cgit v0.10.2 From 66b43eb25759b5bf76465c97107dc45b73eeb0e3 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 20:37:09 +0100 Subject: staging/xgifb: Consolidate if/else if with identical code branches Both branches of this if statement execute the same code. Thus we can || them together and remove code duplication Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 3d5c424..0b134af 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -5572,13 +5572,10 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info, if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) { if (!(pVBInfo->SetFlag & DisableChA)) { - if (pVBInfo->SetFlag & EnableChA) { + if ((pVBInfo->SetFlag & EnableChA) || + (pVBInfo->VBInfo & SetCRT2ToDualEdge)) { /* Power on */ xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20); - } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) { - /* Power on */ - xgifb_reg_set(pVBInfo->Part1Port, - 0x1E, 0x20); } } -- cgit v0.10.2 From 9388ad9c6a3188015b407cacabd68004f93f2165 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 20:37:10 +0100 Subject: staging/xgifb: Remove unnecessary casts Both functions xgifb_reg_get and inb return an u8 value, so we don't need to cast their return value to unsigned char. -> remove the cast Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c index 82170d4..df127e4 100644 --- a/drivers/staging/xgifb/vb_init.c +++ b/drivers/staging/xgifb/vb_init.c @@ -1341,7 +1341,7 @@ unsigned char XGIInitNew(struct pci_dev *pdev) xgifb_reg_and_or(pVBInfo->Part0Port, 0x3F, 0xEF, 0x00); xgifb_reg_set(pVBInfo->Part1Port, 0x00, 0x00); /* chk if BCLK>=100MHz */ - temp1 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x7B); + temp1 = xgifb_reg_get(pVBInfo->P3d4, 0x7B); temp = (unsigned char) ((temp1 >> 4) & 0x0F); xgifb_reg_set(pVBInfo->Part1Port, diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index 0b134af..f5a9bb2 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -82,7 +82,7 @@ static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension, unsigned char CRTCdata; unsigned short i; - CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); + CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11); CRTCdata &= 0x7f; xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */ @@ -139,7 +139,7 @@ static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo) } if (pVBInfo->ModeType > ModeVGA) { - GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05); + GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05); GRdata &= 0xBF; /* 256 color disable */ xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata); } @@ -287,7 +287,7 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo, unsigned short i, j; /* unlock cr0-7 */ - data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); + data = xgifb_reg_get(pVBInfo->P3d4, 0x11); data &= 0x7F; xgifb_reg_set(pVBInfo->P3d4, 0x11, data); @@ -304,7 +304,7 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo, xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data); } - j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e); + j = xgifb_reg_get(pVBInfo->P3c4, 0x0e); j &= 0x1F; data = pVBInfo->TimingH.data[7]; data &= 0xE0; @@ -312,17 +312,16 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo, xgifb_reg_set(pVBInfo->P3c4, 0x0e, data); if (HwDeviceExtension->jChipType >= XG20) { - data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04); + data = xgifb_reg_get(pVBInfo->P3d4, 0x04); data = data - 1; xgifb_reg_set(pVBInfo->P3d4, 0x04, data); - data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05); + data = xgifb_reg_get(pVBInfo->P3d4, 0x05); data1 = data; data1 &= 0xE0; data &= 0x1F; if (data == 0) { pushax = data; - data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, - 0x0c); + data = xgifb_reg_get(pVBInfo->P3c4, 0x0c); data &= 0xFB; xgifb_reg_set(pVBInfo->P3c4, 0x0c, data); data = pushax; @@ -330,7 +329,7 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo, data = data - 1; data |= data1; xgifb_reg_set(pVBInfo->P3d4, 0x05, data); - data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e); + data = xgifb_reg_get(pVBInfo->P3c4, 0x0e); data = data >> 5; data = data + 3; if (data > 7) @@ -362,7 +361,7 @@ static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex, xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data); } - j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a); + j = xgifb_reg_get(pVBInfo->P3c4, 0x0a); j &= 0xC0; data = pVBInfo->TimingV.data[6]; data &= 0x3F; @@ -378,7 +377,7 @@ static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex, if (i) data |= 0x80; - j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09); + j = xgifb_reg_get(pVBInfo->P3d4, 0x09); j &= 0x5F; data |= j; xgifb_reg_set(pVBInfo->P3d4, 0x09, data); @@ -396,7 +395,7 @@ static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex, index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; index = index & IndexMask; - data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); + data = xgifb_reg_get(pVBInfo->P3d4, 0x11); data &= 0x7F; xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */ @@ -741,8 +740,8 @@ static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension, tempax -= 1; tempbx -= 1; tempcx = tempax; - temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); - data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); + temp = xgifb_reg_get(pVBInfo->P3d4, 0x11); + data = xgifb_reg_get(pVBInfo->P3d4, 0x11); data &= 0x7F; xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */ xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff)); @@ -759,7 +758,7 @@ static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension, tempax |= 0x40; xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax); - data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07); + data = xgifb_reg_get(pVBInfo->P3d4, 0x07); data &= 0xFF; tempax = 0; @@ -1779,7 +1778,7 @@ static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex, } } /* {End of VB} */ - tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02)); + tempal = inb((pVBInfo->P3ca + 0x02)); tempal = tempal >> 2; tempal &= 0x03; @@ -3796,8 +3795,7 @@ static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex, } if (pVBInfo->TVInfo & TVSetPALM) { - tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port, - 0x01); + tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01); tempax--; xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax); @@ -4405,7 +4403,7 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info, temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability & (LCDPolarity << 8)) >> 8); temp &= LCDPolarity; - Miscdata = (unsigned char) inb(pVBInfo->P3cc); + Miscdata = inb(pVBInfo->P3cc); outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2); @@ -4465,7 +4463,7 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info, LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE; - temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); + temp = xgifb_reg_get(pVBInfo->P3d4, 0x11); xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */ if (!(modeflag & Charx8Dot)) @@ -5482,25 +5480,25 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo) /* to fix XG42 single LCD sense to CRT+LCD */ xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A); - xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get( + xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get( pVBInfo->P3d4, 0x53) | 0x02)); - SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31); - CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63); - SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01); + SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31); + CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63); + SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01); xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF)); xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF)); - CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17); + CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17); xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80)); - SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F); + SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F); xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04)); - SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07); + SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07); xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB)); - SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06); + SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06); xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3)); xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00); @@ -5558,7 +5556,7 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo) xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63); xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31); - xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get( + xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get( pVBInfo->P3d4, 0x53) & 0xFD)); xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F); } @@ -5583,8 +5581,7 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info, if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV | SetCRT2ToRAMDAC))) { - tempah = (unsigned char) xgifb_reg_get( - pVBInfo->P3c4, 0x32); + tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32); tempah &= 0xDF; if (pVBInfo->VBInfo & SetInSlaveMode) { if (!(pVBInfo->VBInfo & @@ -5594,8 +5591,8 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info, xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah); xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20); - tempah = (unsigned char) xgifb_reg_get( - pVBInfo->Part1Port, 0x2E); + tempah = xgifb_reg_get(pVBInfo->Part1Port, + 0x2E); if (!(tempah & 0x80)) xgifb_reg_or(pVBInfo->Part1Port, @@ -5668,8 +5665,7 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info, /* enable CRT2 */ xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20); - tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port, - 0x2E); + tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E); if (!(tempah & 0x80)) xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80); -- cgit v0.10.2 From 516354e0b458c3c16555364e105bdee5cd1cf5f1 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 20:37:11 +0100 Subject: staging/xgifb: Remove code without effect The tempal variable is assigned and then immediately overwritten. -> remove everything without effect. The inb is kept for possible side effects. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index f5a9bb2..a602d43 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -1778,14 +1778,7 @@ static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex, } } /* {End of VB} */ - tempal = inb((pVBInfo->P3ca + 0x02)); - tempal = tempal >> 2; - tempal &= 0x03; - - /* for Dot8 Scaling LCD */ - if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot)) - tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */ - + inb((pVBInfo->P3ca + 0x02)); tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; return tempal; } -- cgit v0.10.2 From 053004b375ca8f684f778d354eeeaf4e8b17c1f0 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 20:37:12 +0100 Subject: staging/xgifb: Consolidate return paths Both branches of this if statement end in the same return statement. -> move the return to the bottom and get rid of the else statement. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index a602d43..edbe70b 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -2860,10 +2860,8 @@ static unsigned short XGI_GetOffset(unsigned short ModeNo, temp = 0x6B; if (infoflag & InterlaceMode) temp = temp << 1; - return temp * colordepth; - } else { - return temp * colordepth; } + return temp * colordepth; } static void XGI_SetCRT2Offset(unsigned short ModeNo, -- cgit v0.10.2 From 771f3eed631be02b08544fc46cdfd2558599cf5d Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 20:37:13 +0100 Subject: staging/xgifb: Remove duplicated code in loops. Instead of calling the same function three times in a loop, multiply the loop counter by three. And since the value in DAC_TEST_PARMS is always the same we can use the value directly. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c index edbe70b..dfa5303 100644 --- a/drivers/staging/xgifb/vb_setmode.c +++ b/drivers/staging/xgifb/vb_setmode.c @@ -5464,7 +5464,6 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo) unsigned char CR17, CR63, SR31; unsigned short temp; - unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F }; int i; xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86); @@ -5518,10 +5517,8 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo) outb(0x00, pVBInfo->P3c8); - for (i = 0; i < 256; i++) { - outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1)); - outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1)); - outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1)); + for (i = 0; i < 256 * 3; i++) { + outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */ } mdelay(1); @@ -5537,9 +5534,7 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo) /* avoid display something, set BLACK DAC if not restore DAC */ outb(0x00, pVBInfo->P3c8); - for (i = 0; i < 256; i++) { - outb(0, (pVBInfo->P3c8 + 1)); - outb(0, (pVBInfo->P3c8 + 1)); + for (i = 0; i < 256 * 3; i++) { outb(0, (pVBInfo->P3c8 + 1)); } -- cgit v0.10.2 From ff6944304eda0cfae6aad088d4a7c100b0215b92 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 20:39:57 +0100 Subject: staging/usbip: Mark local functions as static (fix sparse warnings) sparse complains about these functions: usbip/stub_dev.c:529:5: warning: symbol 'stub_pre_reset' was not declared. Should it be static? usbip/stub_dev.c:535:5: warning: symbol 'stub_post_reset' was not declared. Should it be static? -> add static keyword to silence the warning and make sparse happy. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c index ca5de9d..67556ac 100644 --- a/drivers/staging/usbip/stub_dev.c +++ b/drivers/staging/usbip/stub_dev.c @@ -526,13 +526,13 @@ static void stub_disconnect(struct usb_interface *interface) * when the device is being reset */ -int stub_pre_reset(struct usb_interface *interface) +static int stub_pre_reset(struct usb_interface *interface) { dev_dbg(&interface->dev, "pre_reset\n"); return 0; } -int stub_post_reset(struct usb_interface *interface) +static int stub_post_reset(struct usb_interface *interface) { dev_dbg(&interface->dev, "post_reset\n"); return 0; -- cgit v0.10.2 From 4f9d5b2f9a9f193e422d9b8e05537cde748eca65 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 21:17:21 +0100 Subject: staging/ozwpan: Add missing header includes ozcdev.c and ozhcd.c should include their own header file, so sparse knows which functions are declared and which not. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c index a38716f..25f677ad 100644 --- a/drivers/staging/ozwpan/ozcdev.c +++ b/drivers/staging/ozwpan/ozcdev.c @@ -19,6 +19,7 @@ #include "ozpd.h" #include "ozproto.h" #include "ozevent.h" +#include "ozcdev.h" /*------------------------------------------------------------------------------ */ #define OZ_RD_BUF_SZ 256 diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index b48663e..417a52d 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -36,6 +36,7 @@ #include "oztrace.h" #include "ozurbparanoia.h" #include "ozevent.h" +#include "ozhcd.h" /*------------------------------------------------------------------------------ * Number of units of buffering to capture for an isochronous IN endpoint before * allowing data to be indicated up. -- cgit v0.10.2 From a7f74c3005cf6830a20d71c4e1d8d6d77443e5cb Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 21:17:22 +0100 Subject: staging/ozwpan: Mark local functions as static (fix sparse warnings) sparse complains about the following functions ozhcd.c:330:20: warning: symbol 'oz_uncancel_urb' was not declared. Should it be static? ozhcd.c:420:6: warning: symbol 'oz_complete_buffered_urb' was not declared. Should it be static? ozmain.c:25:6: warning: symbol 'g_net_dev' was not declared. Should it be static? ozevent.c:95:5: warning: symbol 'oz_events_open' was not declared. Should it be static? ozevent.c:110:5: warning: symbol 'oz_events_release' was not declared. Should it be static? ozevent.c:121:9: warning: symbol 'oz_events_read' was not declared. Should it be static? ozevent.c:160:30: warning: symbol 'oz_events_fops' was not declared. Should it be static? ozcdev.c:47:14: warning: symbol 'g_oz_class' was not declared. Should it be static? ozcdev.c:74:5: warning: symbol 'oz_cdev_open' was not declared. Should it be static? ozcdev.c:86:5: warning: symbol 'oz_cdev_release' was not declared. Should it be static? ozcdev.c:94:9: warning: symbol 'oz_cdev_read' was not declared. Should it be static? ozcdev.c:146:9: warning: symbol 'oz_cdev_write' was not declared. Should it be static? ozcdev.c:236:6: warning: symbol 'oz_cdev_ioctl' was not declared. Should it be static? ozcdev.c:300:14: warning: symbol 'oz_cdev_poll' was not declared. Should it be static? ozcdev.c:321:30: warning: symbol 'oz_fops' was not declared. Should it be static? ozproto.c:958:6: warning: context imbalance in 'oz_polling_lock_bh' - wrong count at exit ozproto.c:964:6: warning: context imbalance in 'oz_polling_unlock_bh' - unexpected unlock ozusbsvc1.c:308:6: warning: symbol 'oz_usb_handle_ep_data' was not declared. Should it be static? ozpd.c:410:6: warning: symbol 'oz_set_more_bit' was not declared. Should it be static? ozpd.c:418:6: warning: symbol 'oz_set_last_pkt_nb' was not declared. Should it be static? -> add static keyword to silence the warning and make sparse happy. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c index 25f677ad..04e0054 100644 --- a/drivers/staging/ozwpan/ozcdev.c +++ b/drivers/staging/ozwpan/ozcdev.c @@ -44,7 +44,7 @@ struct oz_serial_ctx { /*------------------------------------------------------------------------------ */ static struct oz_cdev g_cdev; -struct class *g_oz_class; +static struct class *g_oz_class; /*------------------------------------------------------------------------------ * Context: process and softirq */ @@ -71,7 +71,7 @@ static void oz_cdev_release_ctx(struct oz_serial_ctx *ctx) /*------------------------------------------------------------------------------ * Context: process */ -int oz_cdev_open(struct inode *inode, struct file *filp) +static int oz_cdev_open(struct inode *inode, struct file *filp) { struct oz_cdev *dev; oz_trace("oz_cdev_open()\n"); @@ -83,7 +83,7 @@ int oz_cdev_open(struct inode *inode, struct file *filp) /*------------------------------------------------------------------------------ * Context: process */ -int oz_cdev_release(struct inode *inode, struct file *filp) +static int oz_cdev_release(struct inode *inode, struct file *filp) { oz_trace("oz_cdev_release()\n"); return 0; @@ -91,7 +91,7 @@ int oz_cdev_release(struct inode *inode, struct file *filp) /*------------------------------------------------------------------------------ * Context: process */ -ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count, +static ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count, loff_t *fpos) { int n; @@ -143,8 +143,8 @@ out2: /*------------------------------------------------------------------------------ * Context: process */ -ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count, - loff_t *fpos) +static ssize_t oz_cdev_write(struct file *filp, const char __user *buf, + size_t count, loff_t *fpos) { struct oz_pd *pd; struct oz_elt_buf *eb; @@ -233,7 +233,8 @@ static int oz_set_active_pd(u8 *addr) /*------------------------------------------------------------------------------ * Context: process */ -long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +static long oz_cdev_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) { int rc = 0; if (_IOC_TYPE(cmd) != OZ_IOCTL_MAGIC) @@ -297,7 +298,7 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) /*------------------------------------------------------------------------------ * Context: process */ -unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) +static unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) { unsigned int ret = 0; struct oz_cdev *dev = filp->private_data; @@ -318,7 +319,7 @@ unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) } /*------------------------------------------------------------------------------ */ -const struct file_operations oz_fops = { +static const struct file_operations oz_fops = { .owner = THIS_MODULE, .open = oz_cdev_open, .release = oz_cdev_release, diff --git a/drivers/staging/ozwpan/ozevent.c b/drivers/staging/ozwpan/ozevent.c index 50578ba..77e8675 100644 --- a/drivers/staging/ozwpan/ozevent.c +++ b/drivers/staging/ozwpan/ozevent.c @@ -92,7 +92,7 @@ static void oz_events_clear(struct oz_evtdev *dev) /*------------------------------------------------------------------------------ * Context: process */ -int oz_events_open(struct inode *inode, struct file *filp) +static int oz_events_open(struct inode *inode, struct file *filp) { oz_trace("oz_evt_open()\n"); oz_trace("Open flags: 0x%x\n", filp->f_flags); @@ -107,7 +107,7 @@ int oz_events_open(struct inode *inode, struct file *filp) /*------------------------------------------------------------------------------ * Context: process */ -int oz_events_release(struct inode *inode, struct file *filp) +static int oz_events_release(struct inode *inode, struct file *filp) { oz_events_clear(&g_evtdev); atomic_dec(&g_evtdev.users); @@ -118,7 +118,7 @@ int oz_events_release(struct inode *inode, struct file *filp) /*------------------------------------------------------------------------------ * Context: process */ -ssize_t oz_events_read(struct file *filp, char __user *buf, size_t count, +static ssize_t oz_events_read(struct file *filp, char __user *buf, size_t count, loff_t *fpos) { struct oz_evtdev *dev = &g_evtdev; @@ -157,7 +157,7 @@ out: } /*------------------------------------------------------------------------------ */ -const struct file_operations oz_events_fops = { +static const struct file_operations oz_events_fops = { .owner = THIS_MODULE, .open = oz_events_open, .release = oz_events_release, diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index 417a52d..ed2addb 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -327,7 +327,7 @@ static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size) * disabled. * Context: softirq or process */ -struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb) +static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb) { struct oz_urb_link *urbl; struct list_head *e; @@ -417,7 +417,8 @@ static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep) /*------------------------------------------------------------------------------ * Context: softirq */ -void oz_complete_buffered_urb(struct oz_port *port, struct oz_endpoint *ep, +static void oz_complete_buffered_urb(struct oz_port *port, + struct oz_endpoint *ep, struct urb *urb) { u8 data_len, available_space, copy_len; diff --git a/drivers/staging/ozwpan/ozmain.c b/drivers/staging/ozwpan/ozmain.c index ef6c5ab..57a0cbd 100644 --- a/drivers/staging/ozwpan/ozmain.c +++ b/drivers/staging/ozwpan/ozmain.c @@ -22,7 +22,7 @@ * bind to nothing. '*' means bind to all netcards - this includes non-802.11 * netcards. Bindings can be added later using an IOCTL. */ -char *g_net_dev = ""; +static char *g_net_dev = ""; /*------------------------------------------------------------------------------ * Context: process */ diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c index d969ed7..a54f89c 100644 --- a/drivers/staging/ozwpan/ozpd.c +++ b/drivers/staging/ozwpan/ozpd.c @@ -407,7 +407,7 @@ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f) /*------------------------------------------------------------------------------ * Context: softirq-serialized */ -void oz_set_more_bit(struct sk_buff *skb) +static void oz_set_more_bit(struct sk_buff *skb) { struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); oz_hdr->control |= OZ_F_MORE_DATA; @@ -415,7 +415,7 @@ void oz_set_more_bit(struct sk_buff *skb) /*------------------------------------------------------------------------------ * Context: softirq-serialized */ -void oz_set_last_pkt_nb(struct oz_pd *pd, struct sk_buff *skb) +static void oz_set_last_pkt_nb(struct oz_pd *pd, struct sk_buff *skb) { struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); oz_hdr->last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK; diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c index ea4a238b..c54614d 100644 --- a/drivers/staging/ozwpan/ozusbsvc1.c +++ b/drivers/staging/ozwpan/ozusbsvc1.c @@ -305,7 +305,7 @@ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb) /*------------------------------------------------------------------------------ * Context: softirq-serialized */ -void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx, +static void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx, struct oz_usb_hdr *usb_hdr, int len) { struct oz_data *data_hdr = (struct oz_data *)usb_hdr; -- cgit v0.10.2 From 89fe22b6acd394c2c4bcdcbc779ddf0e4730fbc9 Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 21:17:23 +0100 Subject: staging/ozwpan: Remove empty and unused function oz_cdev_heartbeat oz_cdev_heartbeat is empty and unused -> safe to remove. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c index 04e0054..89d454e 100644 --- a/drivers/staging/ozwpan/ozcdev.c +++ b/drivers/staging/ozwpan/ozcdev.c @@ -525,9 +525,3 @@ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt) out: oz_cdev_release_ctx(ctx); } -/*------------------------------------------------------------------------------ - * Context: softirq - */ -void oz_cdev_heartbeat(struct oz_pd *pd) -{ -} diff --git a/drivers/staging/ozwpan/ozcdev.h b/drivers/staging/ozwpan/ozcdev.h index 698014b..dd11935 100644 --- a/drivers/staging/ozwpan/ozcdev.h +++ b/drivers/staging/ozwpan/ozcdev.h @@ -13,6 +13,5 @@ void oz_cdev_term(void); int oz_cdev_start(struct oz_pd *pd, int resume); void oz_cdev_stop(struct oz_pd *pd, int pause); void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt); -void oz_cdev_heartbeat(struct oz_pd *pd); #endif /* _OZCDEV_H */ -- cgit v0.10.2 From dc7f5b3594fdb846890192fd75793a791d7ba83b Mon Sep 17 00:00:00 2001 From: Peter Huewe Date: Fri, 15 Feb 2013 21:17:24 +0100 Subject: staging/ozwpan: Mark read only parameters and structs as const This patch marks function parameters that are used read only as well as readonly structs (and corresponding pointers) as const. Signed-off-by: Peter Huewe Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c index 89d454e..ba15aeb 100644 --- a/drivers/staging/ozwpan/ozcdev.c +++ b/drivers/staging/ozwpan/ozcdev.c @@ -200,7 +200,7 @@ out: /*------------------------------------------------------------------------------ * Context: process */ -static int oz_set_active_pd(u8 *addr) +static int oz_set_active_pd(const u8 *addr) { int rc = 0; struct oz_pd *pd; diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index ed2addb..8ac26f5 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -759,7 +759,7 @@ void oz_hcd_pd_reset(void *hpd, void *hport) /*------------------------------------------------------------------------------ * Context: softirq */ -void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, u8 *desc, +void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc, int length, int offset, int total_size) { struct oz_port *port = (struct oz_port *)hport; @@ -895,7 +895,7 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, /*------------------------------------------------------------------------------ * Context: softirq */ -void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, +void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, int data_len) { struct oz_port *port = (struct oz_port *)hport; @@ -948,7 +948,8 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, /*------------------------------------------------------------------------------ * Context: softirq-serialized */ -static int oz_hcd_buffer_data(struct oz_endpoint *ep, u8 *data, int data_len) +static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data, + int data_len) { int space; int copy_len; @@ -983,7 +984,7 @@ static int oz_hcd_buffer_data(struct oz_endpoint *ep, u8 *data, int data_len) /*------------------------------------------------------------------------------ * Context: softirq-serialized */ -void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) +void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) { struct oz_port *port = (struct oz_port *)hport; struct oz_endpoint *ep; diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c index a54f89c..f8b9da0 100644 --- a/drivers/staging/ozwpan/ozpd.c +++ b/drivers/staging/ozwpan/ozpd.c @@ -46,7 +46,7 @@ static void oz_def_app_rx(struct oz_pd *pd, struct oz_elt *elt); static atomic_t g_submitted_isoc = ATOMIC_INIT(0); /* Application handler functions. */ -static struct oz_app_if g_app_if[OZ_APPID_MAX] = { +static const struct oz_app_if g_app_if[OZ_APPID_MAX] = { {oz_usb_init, oz_usb_term, oz_usb_start, @@ -157,7 +157,7 @@ void oz_pd_put(struct oz_pd *pd) /*------------------------------------------------------------------------------ * Context: softirq-serialized */ -struct oz_pd *oz_pd_alloc(u8 *mac_addr) +struct oz_pd *oz_pd_alloc(const u8 *mac_addr) { struct oz_pd *pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC); if (pd) { @@ -235,7 +235,7 @@ void oz_pd_destroy(struct oz_pd *pd) */ int oz_services_start(struct oz_pd *pd, u16 apps, int resume) { - struct oz_app_if *ai; + const struct oz_app_if *ai; int rc = 0; oz_trace("oz_services_start(0x%x) resume(%d)\n", apps, resume); for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { @@ -260,7 +260,7 @@ int oz_services_start(struct oz_pd *pd, u16 apps, int resume) */ void oz_services_stop(struct oz_pd *pd, u16 apps, int pause) { - struct oz_app_if *ai; + const struct oz_app_if *ai; oz_trace("oz_stop_services(0x%x) pause(%d)\n", apps, pause); for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { if (apps & (1<app_id)) { @@ -281,7 +281,7 @@ void oz_services_stop(struct oz_pd *pd, u16 apps, int pause) */ void oz_pd_heartbeat(struct oz_pd *pd, u16 apps) { - struct oz_app_if *ai; + const struct oz_app_if *ai; int more = 0; for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { if (ai->heartbeat && (apps & (1<app_id))) { @@ -774,7 +774,7 @@ static void oz_isoc_destructor(struct sk_buff *skb) /*------------------------------------------------------------------------------ * Context: softirq */ -int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) +int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len) { struct net_device *dev = pd->net_dev; struct oz_isoc_stream *st; @@ -913,7 +913,7 @@ void oz_apps_term(void) */ void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt) { - struct oz_app_if *ai; + const struct oz_app_if *ai; if (app_id == 0 || app_id > OZ_APPID_MAX) return; ai = &g_app_if[app_id-1]; @@ -925,7 +925,7 @@ void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt) void oz_pd_indicate_farewells(struct oz_pd *pd) { struct oz_farewell *f; - struct oz_app_if *ai = &g_app_if[OZ_APPID_USB-1]; + const struct oz_app_if *ai = &g_app_if[OZ_APPID_USB-1]; while (1) { oz_polling_lock_bh(); if (list_empty(&pd->farewell_list)) { diff --git a/drivers/staging/ozwpan/ozpd.h b/drivers/staging/ozwpan/ozpd.h index d35b0ea..fbf47cb 100644 --- a/drivers/staging/ozwpan/ozpd.h +++ b/drivers/staging/ozwpan/ozpd.h @@ -99,7 +99,7 @@ struct oz_pd { #define OZ_MAX_QUEUED_FRAMES 4 -struct oz_pd *oz_pd_alloc(u8 *mac_addr); +struct oz_pd *oz_pd_alloc(const u8 *mac_addr); void oz_pd_destroy(struct oz_pd *pd); void oz_pd_get(struct oz_pd *pd); void oz_pd_put(struct oz_pd *pd); @@ -115,7 +115,7 @@ void oz_send_queued_frames(struct oz_pd *pd, int backlog); void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn); int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num); int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num); -int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len); +int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len); void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt); void oz_apps_init(void); void oz_apps_term(void); diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c index 40c283c..3badf15 100644 --- a/drivers/staging/ozwpan/ozproto.c +++ b/drivers/staging/ozwpan/ozproto.c @@ -171,7 +171,7 @@ static void pd_set_presleep(struct oz_pd *pd, u8 presleep) * Context: softirq-serialized */ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, - u8 *pd_addr, struct net_device *net_dev) + const u8 *pd_addr, struct net_device *net_dev) { struct oz_pd *pd; struct oz_elt_connect_req *body = @@ -306,7 +306,7 @@ done: * Context: softirq-serialized */ static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index, - u8 *report, u8 len) + const u8 *report, u8 len) { struct oz_farewell *f; struct oz_farewell *f2; @@ -734,7 +734,7 @@ void oz_pd_request_heartbeat(struct oz_pd *pd) /*------------------------------------------------------------------------------ * Context: softirq or process */ -struct oz_pd *oz_pd_find(u8 *mac_addr) +struct oz_pd *oz_pd_find(const u8 *mac_addr) { struct oz_pd *pd; struct list_head *e; diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h index 755a08d..93bb4c0 100644 --- a/drivers/staging/ozwpan/ozproto.h +++ b/drivers/staging/ozwpan/ozproto.h @@ -62,7 +62,7 @@ int oz_protocol_init(char *devs); void oz_protocol_term(void); int oz_get_pd_list(struct oz_mac_addr *addr, int max_count); void oz_app_enable(int app_id, int enable); -struct oz_pd *oz_pd_find(u8 *mac_addr); +struct oz_pd *oz_pd_find(const u8 *mac_addr); void oz_binding_add(char *net_dev); void oz_binding_remove(char *net_dev); void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, diff --git a/drivers/staging/ozwpan/ozusbif.h b/drivers/staging/ozwpan/ozusbif.h index 3acf598..8531438 100644 --- a/drivers/staging/ozwpan/ozusbif.h +++ b/drivers/staging/ozwpan/ozusbif.h @@ -21,7 +21,7 @@ int oz_usb_stream_delete(void *hpd, u8 ep_num); /* Request functions. */ int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, - u8 *data, int data_len); + const u8 *data, int data_len); int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, u8 index, u16 windex, int offset, int len); int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb); @@ -30,13 +30,13 @@ void oz_usb_request_heartbeat(void *hpd); /* Confirmation functions. */ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, - u8 *desc, int length, int offset, int total_size); + const u8 *desc, int length, int offset, int total_size); void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, - u8 *data, int data_len); + const u8 *data, int data_len); /* Indication functions. */ -void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len); +void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len); int oz_hcd_heartbeat(void *hport); diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c index c54614d..4e4b650 100644 --- a/drivers/staging/ozwpan/ozusbsvc1.c +++ b/drivers/staging/ozwpan/ozusbsvc1.c @@ -157,7 +157,7 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type, * Context: tasklet */ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, - u8 request, __le16 value, __le16 index, u8 *data, int data_len) + u8 request, __le16 value, __le16 index, const u8 *data, int data_len) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; @@ -184,7 +184,7 @@ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, * Context: tasklet */ int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, - u8 *data, int data_len) + const u8 *data, int data_len) { unsigned wvalue = le16_to_cpu(setup->wValue); unsigned windex = le16_to_cpu(setup->wIndex); -- cgit v0.10.2 From bdafb167d30da85ccd563a12197e0370d0667923 Mon Sep 17 00:00:00 2001 From: Robert Berger Date: Sat, 16 Feb 2013 10:35:51 +0200 Subject: staging/zache checkpatch ERROR: spaces prohibited around that zbud.c:106: ERROR: spaces prohibited around that ':' (ctx:VxW) zbud.c:107: ERROR: spaces prohibited around that ':' (ctx:VxW) Signed-off-by: Robert Berger Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/zcache/zbud.c b/drivers/staging/zcache/zbud.c index ee927e8..328c397 100644 --- a/drivers/staging/zcache/zbud.c +++ b/drivers/staging/zcache/zbud.c @@ -103,8 +103,8 @@ struct zbudpage { struct { unsigned long space_for_flags; struct { - unsigned zbud0_size: PAGE_SHIFT; - unsigned zbud1_size: PAGE_SHIFT; + unsigned zbud0_size:PAGE_SHIFT; + unsigned zbud1_size:PAGE_SHIFT; unsigned unevictable:2; }; struct list_head budlist; -- cgit v0.10.2 From 2e38027588479421d244266f6edc0b4945546271 Mon Sep 17 00:00:00 2001 From: Kumar Amit Mehta Date: Sat, 16 Feb 2013 05:01:22 -0800 Subject: staging: wlan-ng: hfa384x.h: fix for error reported by smatch Add the missing header include for 'struct urb' datatypes to avoid potential build issues. Found using smatch. Signed-off-by: Kumar Amit Mehta Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h index 04c0433..3dfa85c 100644 --- a/drivers/staging/wlan-ng/hfa384x.h +++ b/drivers/staging/wlan-ng/hfa384x.h @@ -59,6 +59,7 @@ #define HFA384x_FIRMWARE_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) #include +#include /*--- Mins & Maxs -----------------------------------*/ #define HFA384x_PORTID_MAX ((u16)7) -- cgit v0.10.2 From bf7edd87f1c9618ac0bae712aa7a8047058a2731 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Sat, 16 Feb 2013 19:12:00 +0000 Subject: staging: et131x: Remove assignment of skb->dev The call eth_type_trans() sets skb->dev to netdev, so there's no needto set it before the call. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c index ebf5e49..3a733f7 100644 --- a/drivers/staging/et131x/et131x.c +++ b/drivers/staging/et131x/et131x.c @@ -2730,7 +2730,6 @@ static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter) rx_local->fbr[ring_index]->virt[buff_index], rfd->len); - skb->dev = adapter->netdev; skb->protocol = eth_type_trans(skb, adapter->netdev); skb->ip_summed = CHECKSUM_NONE; netif_rx_ni(skb); -- cgit v0.10.2 From deb95fac28b6678f014c95909fc1bee21c1bace5 Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Sat, 16 Feb 2013 19:12:01 +0000 Subject: staging: et131x: Update TODO list David Miller had provided some review comments for this driver. Update the TODO list with some action points from his review. Signed-off-by: Mark Einon Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/et131x/README b/drivers/staging/et131x/README index 38537d4..05ad085 100644 --- a/drivers/staging/et131x/README +++ b/drivers/staging/et131x/README @@ -9,6 +9,10 @@ driver as they did not build properly at the time. TODO: - some rx packets have CRC/code/frame errors + - Look at reducing the number of spinlocks + - Simplify code in nic_rx_pkts(), when determining multicast_pkts_rcvd + - Implement NAPI support + - in et131x_tx(), don't return NETDEV_TX_BUSY, just drop the packet with kfree_skb(). Please send patches to: Greg Kroah-Hartman -- cgit v0.10.2 From 6b07b30892ad972286871787079ed68d07779ba4 Mon Sep 17 00:00:00 2001 From: Kumar Amit Mehta Date: Sat, 16 Feb 2013 22:54:58 -0800 Subject: staging: comedi: drivers: addi-data: hwdrv_apci3200.c: Add a missing semicolon fix for missing end-of-statement by adding a semicolon Signed-off-by: Kumar Amit Mehta Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c index 829af18..c790873 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c @@ -633,7 +633,7 @@ static int apci3200_do_insn_bits(struct comedi_device *dev, s->state = inl(devpriv->i_IobaseAddon) & 0xf; if (mask) { s->state &= ~mask; - s->state |= (bits & mask) + s->state |= (bits & mask); outl(s->state, devpriv->i_IobaseAddon); } -- cgit v0.10.2 From 951348b377385475aa256c27e1c9e2564c9ec160 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 18 Feb 2013 11:15:55 +0000 Subject: staging: comedi: vmk80xx: wait for URBs to complete For Velleman K8055 (aka VM110), `vmk80xx_read_packet()` and `vmk8055_write_packet()` send an URB asynchronously and do not wait for it complete. However, callers of `vmk80xx_read_packet()` are assuming the contents of the data buffer `devpriv->usb_rx_buf` are valid immediately after that function returns. For Velleman K8061 (aka VM140), `vmk80xx_read_packet()` and `vmk80xx_write_packet()` punt the requests to `vmk80xx_do_bulk_msg()` which *does* wait for the URBs to complete (albeit with no error checking!). Change `vmk80xx_read_packet()` and `vmk80xx_write_packet()` to use `usb_interrupt_msg()` for the K8055, so the callers of `vmk80xx_read_packet()` can assume the data buffer contents are valid (if no error occurred). Remove all the code for checking for transfers in progress and busy waiting, as it's no longer needed. Pretty much all the callers of `vmk80xx_read_packet()` and `vmk80xx_write_packet()` hold the same semaphore anyway, and the only caller that doesn't (`vmk80xx_reset_device()` called during initialization of the device) doesn't really matter. Signed-off-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 7984e03..2be5087 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -100,16 +100,9 @@ enum { #define VMK8061_CMD_RD_AO 0x0f #define VMK8061_CMD_RD_PWM 0x10 -#define TRANS_OUT_BUSY 1 -#define TRANS_IN_BUSY 2 -#define TRANS_IN_RUNNING 3 - #define IC3_VERSION (1 << 0) #define IC6_VERSION (1 << 1) -#define URB_RCV_FLAG (1 << 0) -#define URB_SND_FLAG (1 << 1) - enum vmk80xx_model { VMK8055_MODEL, VMK8061_MODEL @@ -170,60 +163,13 @@ struct vmk80xx_private { struct usb_interface *intf; struct usb_endpoint_descriptor *ep_rx; struct usb_endpoint_descriptor *ep_tx; - struct usb_anchor rx_anchor; - struct usb_anchor tx_anchor; struct firmware_version fw; struct semaphore limit_sem; - wait_queue_head_t read_wait; - wait_queue_head_t write_wait; unsigned char *usb_rx_buf; unsigned char *usb_tx_buf; - unsigned long flags; enum vmk80xx_model model; }; -static void vmk80xx_tx_callback(struct urb *urb) -{ - struct vmk80xx_private *devpriv = urb->context; - unsigned long *flags = &devpriv->flags; - - if (!test_bit(TRANS_OUT_BUSY, flags)) - return; - - clear_bit(TRANS_OUT_BUSY, flags); - - wake_up_interruptible(&devpriv->write_wait); -} - -static void vmk80xx_rx_callback(struct urb *urb) -{ - struct vmk80xx_private *devpriv = urb->context; - unsigned long *flags = &devpriv->flags; - int stat = urb->status; - - switch (stat) { - case 0: - break; - case -ENOENT: - case -ECONNRESET: - case -ESHUTDOWN: - break; - default: - /* Try to resubmit the urb */ - if (test_bit(TRANS_IN_RUNNING, flags) && devpriv->intf) { - usb_anchor_urb(urb, &devpriv->rx_anchor); - - if (usb_submit_urb(urb, GFP_KERNEL)) - usb_unanchor_urb(urb); - } - break; - } - - clear_bit(TRANS_IN_BUSY, flags); - - wake_up_interruptible(&devpriv->read_wait); -} - static int vmk80xx_check_data_link(struct vmk80xx_private *devpriv) { struct usb_device *usb = devpriv->usb; @@ -277,50 +223,15 @@ static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag) strncpy(devpriv->fw.ic6_vers, rx + 25, 24); } -static void vmk80xx_build_int_urb(struct urb *urb, int flag) -{ - struct vmk80xx_private *devpriv = urb->context; - struct usb_device *usb = devpriv->usb; - __u8 rx_addr; - __u8 tx_addr; - unsigned int pipe; - unsigned char *buf; - size_t size; - void (*callback) (struct urb *); - int ival; - - if (flag & URB_RCV_FLAG) { - rx_addr = devpriv->ep_rx->bEndpointAddress; - pipe = usb_rcvintpipe(usb, rx_addr); - buf = devpriv->usb_rx_buf; - size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); - callback = vmk80xx_rx_callback; - ival = devpriv->ep_rx->bInterval; - } else { /* URB_SND_FLAG */ - tx_addr = devpriv->ep_tx->bEndpointAddress; - pipe = usb_sndintpipe(usb, tx_addr); - buf = devpriv->usb_tx_buf; - size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); - callback = vmk80xx_tx_callback; - ival = devpriv->ep_tx->bInterval; - } - - usb_fill_int_urb(urb, usb, pipe, buf, size, callback, devpriv, ival); -} - static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv) { struct usb_device *usb = devpriv->usb; - unsigned long *flags = &devpriv->flags; __u8 tx_addr; __u8 rx_addr; unsigned int tx_pipe; unsigned int rx_pipe; size_t size; - set_bit(TRANS_IN_BUSY, flags); - set_bit(TRANS_OUT_BUSY, flags); - tx_addr = devpriv->ep_tx->bEndpointAddress; rx_addr = devpriv->ep_rx->bEndpointAddress; tx_pipe = usb_sndbulkpipe(usb, tx_addr); @@ -335,102 +246,52 @@ static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv) usb_bulk_msg(usb, tx_pipe, devpriv->usb_tx_buf, size, NULL, devpriv->ep_tx->bInterval); usb_bulk_msg(usb, rx_pipe, devpriv->usb_rx_buf, size, NULL, HZ * 10); - - clear_bit(TRANS_OUT_BUSY, flags); - clear_bit(TRANS_IN_BUSY, flags); } static int vmk80xx_read_packet(struct vmk80xx_private *devpriv) { - unsigned long *flags = &devpriv->flags; - struct urb *urb; - int retval; + struct usb_device *usb; + struct usb_endpoint_descriptor *ep; + unsigned int pipe; if (!devpriv->intf) return -ENODEV; - /* Only useful for interrupt transfers */ - if (test_bit(TRANS_IN_BUSY, flags)) - if (wait_event_interruptible(devpriv->read_wait, - !test_bit(TRANS_IN_BUSY, flags))) - return -ERESTART; - if (devpriv->model == VMK8061_MODEL) { vmk80xx_do_bulk_msg(devpriv); - return 0; } - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) - return -ENOMEM; - - urb->context = devpriv; - vmk80xx_build_int_urb(urb, URB_RCV_FLAG); - - set_bit(TRANS_IN_RUNNING, flags); - set_bit(TRANS_IN_BUSY, flags); - - usb_anchor_urb(urb, &devpriv->rx_anchor); - - retval = usb_submit_urb(urb, GFP_KERNEL); - if (!retval) - goto exit; - - clear_bit(TRANS_IN_RUNNING, flags); - usb_unanchor_urb(urb); - -exit: - usb_free_urb(urb); - - return retval; + usb = devpriv->usb; + ep = devpriv->ep_rx; + pipe = usb_rcvintpipe(usb, ep->bEndpointAddress); + return usb_interrupt_msg(usb, pipe, devpriv->usb_rx_buf, + le16_to_cpu(ep->wMaxPacketSize), NULL, + HZ * 10); } static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd) { - unsigned long *flags = &devpriv->flags; - struct urb *urb; - int retval; + struct usb_device *usb; + struct usb_endpoint_descriptor *ep; + unsigned int pipe; if (!devpriv->intf) return -ENODEV; - if (test_bit(TRANS_OUT_BUSY, flags)) - if (wait_event_interruptible(devpriv->write_wait, - !test_bit(TRANS_OUT_BUSY, flags))) - return -ERESTART; + devpriv->usb_tx_buf[0] = cmd; if (devpriv->model == VMK8061_MODEL) { - devpriv->usb_tx_buf[0] = cmd; vmk80xx_do_bulk_msg(devpriv); - return 0; } - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) - return -ENOMEM; - - urb->context = devpriv; - vmk80xx_build_int_urb(urb, URB_SND_FLAG); - - set_bit(TRANS_OUT_BUSY, flags); - - usb_anchor_urb(urb, &devpriv->tx_anchor); - - devpriv->usb_tx_buf[0] = cmd; - - retval = usb_submit_urb(urb, GFP_KERNEL); - if (!retval) - goto exit; - - clear_bit(TRANS_OUT_BUSY, flags); - usb_unanchor_urb(urb); - -exit: - usb_free_urb(urb); - - return retval; + usb = devpriv->usb; + ep = devpriv->ep_tx; + pipe = usb_sndintpipe(usb, ep->bEndpointAddress); + return usb_interrupt_msg(usb, pipe, devpriv->usb_tx_buf, + le16_to_cpu(ep->wMaxPacketSize), NULL, + HZ * 10); } static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) @@ -447,25 +308,6 @@ static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) return vmk80xx_write_packet(devpriv, VMK8055_CMD_WRT_AD); } -#define DIR_IN 1 -#define DIR_OUT 2 - -static int rudimentary_check(struct vmk80xx_private *devpriv, int dir) -{ - if (!devpriv) - return -EFAULT; - if (dir & DIR_IN) { - if (test_bit(TRANS_IN_BUSY, &devpriv->flags)) - return -EBUSY; - } - if (dir & DIR_OUT) { - if (test_bit(TRANS_OUT_BUSY, &devpriv->flags)) - return -EBUSY; - } - - return 0; -} - static int vmk80xx_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -476,10 +318,6 @@ static int vmk80xx_ai_insn_read(struct comedi_device *dev, int reg[2]; int n; - n = rudimentary_check(devpriv, DIR_IN); - if (n) - return n; - down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); @@ -529,10 +367,6 @@ static int vmk80xx_ao_insn_write(struct comedi_device *dev, int reg; int n; - n = rudimentary_check(devpriv, DIR_OUT); - if (n) - return n; - down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); @@ -573,10 +407,6 @@ static int vmk80xx_ao_insn_read(struct comedi_device *dev, int reg; int n; - n = rudimentary_check(devpriv, DIR_IN); - if (n) - return n; - down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); @@ -606,10 +436,6 @@ static int vmk80xx_di_insn_bits(struct comedi_device *dev, int reg; int retval; - retval = rudimentary_check(devpriv, DIR_IN); - if (retval) - return retval; - down(&devpriv->limit_sem); rx_buf = devpriv->usb_rx_buf; @@ -646,16 +472,10 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, { struct vmk80xx_private *devpriv = dev->private; unsigned char *rx_buf, *tx_buf; - int dir, reg, cmd; + int reg, cmd; int retval; - dir = 0; - - if (data[0]) - dir |= DIR_OUT; - if (devpriv->model == VMK8061_MODEL) { - dir |= DIR_IN; reg = VMK8061_DO_REG; cmd = VMK8061_CMD_DO; } else { /* VMK8055_MODEL */ @@ -663,10 +483,6 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, cmd = VMK8055_CMD_WRT_AD; } - retval = rudimentary_check(devpriv, dir); - if (retval) - return retval; - down(&devpriv->limit_sem); rx_buf = devpriv->usb_rx_buf; @@ -712,10 +528,6 @@ static int vmk80xx_cnt_insn_read(struct comedi_device *dev, int reg[2]; int n; - n = rudimentary_check(devpriv, DIR_IN); - if (n) - return n; - down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); @@ -762,10 +574,6 @@ static int vmk80xx_cnt_insn_config(struct comedi_device *dev, int reg; int n; - n = rudimentary_check(devpriv, DIR_OUT); - if (n) - return n; - insn_cmd = data[0]; if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET) return -EINVAL; @@ -809,10 +617,6 @@ static int vmk80xx_cnt_insn_write(struct comedi_device *dev, int cmd; int n; - n = rudimentary_check(devpriv, DIR_OUT); - if (n) - return n; - down(&devpriv->limit_sem); chan = CR_CHAN(insn->chanspec); @@ -856,10 +660,6 @@ static int vmk80xx_pwm_insn_read(struct comedi_device *dev, int reg[2]; int n; - n = rudimentary_check(devpriv, DIR_IN); - if (n) - return n; - down(&devpriv->limit_sem); tx_buf = devpriv->usb_tx_buf; @@ -893,10 +693,6 @@ static int vmk80xx_pwm_insn_write(struct comedi_device *dev, int cmd; int n; - n = rudimentary_check(devpriv, DIR_OUT); - if (n) - return n; - down(&devpriv->limit_sem); tx_buf = devpriv->usb_tx_buf; @@ -1106,11 +902,6 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, return ret; sema_init(&devpriv->limit_sem, 8); - init_waitqueue_head(&devpriv->read_wait); - init_waitqueue_head(&devpriv->write_wait); - - init_usb_anchor(&devpriv->rx_anchor); - init_usb_anchor(&devpriv->tx_anchor); usb_set_intfdata(intf, devpriv); @@ -1141,9 +932,6 @@ static void vmk80xx_detach(struct comedi_device *dev) usb_set_intfdata(devpriv->intf, NULL); - usb_kill_anchored_urbs(&devpriv->rx_anchor); - usb_kill_anchored_urbs(&devpriv->tx_anchor); - kfree(devpriv->usb_rx_buf); kfree(devpriv->usb_tx_buf); -- cgit v0.10.2